FreeFOAM The Cross-Platform CFD Toolkit
complexFields.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Specialisation of Field<T> for complex and complexVector.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "complexFields.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 defineCompoundTypeName(List<complex>, complexList);
40 addCompoundToRunTimeSelectionTable(List<complex>, complexList);
41 
43 {
44  complexField cf(re.size());
45 
46  forAll(cf, i)
47  {
48  cf[i].Re() = re[i];
49  cf[i].Im() = im[i];
50  }
51 
52  return cf;
53 }
54 
55 
57 {
58  complexField cf(sf.size());
59 
60  forAll(cf, i)
61  {
62  cf[i].Re() = sf[i];
63  cf[i].Im() = 0.0;
64  }
65 
66  return cf;
67 }
68 
69 
71 {
72  complexField cf(sf.size());
73 
74  forAll(cf, i)
75  {
76  cf[i].Re() = 0.0;
77  cf[i].Im() = sf[i];
78  }
79 
80  return cf;
81 }
82 
83 
85 {
86  scalarField sf(cf.size());
87 
88  forAll(sf, i)
89  {
90  sf[i] = cf[i].Re() + cf[i].Im();
91  }
92 
93  return sf;
94 }
95 
96 
98 {
99  scalarField sf(cf.size());
100 
101  forAll(sf, i)
102  {
103  sf[i] = cf[i].Re();
104  }
105 
106  return sf;
107 }
108 
109 
111 {
112  scalarField sf(cf.size());
113 
114  forAll(sf, i)
115  {
116  sf[i] = cf[i].Im();
117  }
118 
119  return sf;
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 defineCompoundTypeName(List<complexVector>, complexVectorList);
126 addCompoundToRunTimeSelectionTable(List<complexVector>, complexVectorList);
127 
129 {
130  complexVectorField cvf(re.size());
131 
132  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
133  {
134  forAll(cvf, i)
135  {
136  cvf[i].component(cmpt).Re() = re[i].component(cmpt);
137  cvf[i].component(cmpt).Im() = im[i].component(cmpt);
138  }
139  }
140 
141  return cvf;
142 }
143 
144 
146 {
147  complexVectorField cvf(vf.size());
148 
149  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
150  {
151  forAll(cvf, i)
152  {
153  cvf[i].component(cmpt).Re() = vf[i].component(cmpt);
154  cvf[i].component(cmpt).Im() = 0.0;
155  }
156  }
157 
158  return cvf;
159 }
160 
161 
163 {
164  complexVectorField cvf(vf.size());
165 
166  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
167  {
168  forAll(cvf, i)
169  {
170  cvf[i].component(cmpt).Re() = 0.0;
171  cvf[i].component(cmpt).Im() = vf[i].component(cmpt);
172  }
173  }
174 
175  return cvf;
176 }
177 
178 
180 {
181  vectorField vf(cvf.size());
182 
183  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
184  {
185  forAll(cvf, i)
186  {
187  vf[i].component(cmpt) =
188  cvf[i].component(cmpt).Re() + cvf[i].component(cmpt).Im();
189  }
190  }
191 
192  return vf;
193 }
194 
195 
197 {
198  vectorField vf(cvf.size());
199 
200  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
201  {
202  forAll(cvf, i)
203  {
204  vf[i].component(cmpt) = cvf[i].component(cmpt).Re();
205  }
206  }
207 
208  return vf;
209 }
210 
211 
213 {
214  vectorField vf(cvf.size());
215 
216  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
217  {
218  forAll(cvf, i)
219  {
220  vf[i].component(cmpt) = cvf[i].component(cmpt).Im();
221  }
222  }
223 
224  return vf;
225 }
226 
227 
228 complexVectorField operator^
229 (
230  const UList<vector>& vf,
231  const UList<complexVector>& cvf
232 )
233 {
234  return ComplexField(vf^Re(cvf), vf^Im(cvf));
235 }
236 
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 } // End namespace Foam
241 
242 // ************************ vim: set sw=4 sts=4 et: ************************ //