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) 2011 OpenFOAM Foundation
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);
127 
129 (
130  const UList<vector>& re,
131  const UList<vector>& im
132 )
133 {
134  complexVectorField cvf(re.size());
135 
136  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
137  {
138  forAll(cvf, i)
139  {
140  cvf[i].component(cmpt).Re() = re[i].component(cmpt);
141  cvf[i].component(cmpt).Im() = im[i].component(cmpt);
142  }
143  }
144 
145  return cvf;
146 }
147 
148 
150 {
151  complexVectorField cvf(vf.size());
152 
153  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
154  {
155  forAll(cvf, i)
156  {
157  cvf[i].component(cmpt).Re() = vf[i].component(cmpt);
158  cvf[i].component(cmpt).Im() = 0.0;
159  }
160  }
161 
162  return cvf;
163 }
164 
165 
167 {
168  complexVectorField cvf(vf.size());
169 
170  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
171  {
172  forAll(cvf, i)
173  {
174  cvf[i].component(cmpt).Re() = 0.0;
175  cvf[i].component(cmpt).Im() = vf[i].component(cmpt);
176  }
177  }
178 
179  return cvf;
180 }
181 
182 
184 {
185  vectorField vf(cvf.size());
186 
187  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
188  {
189  forAll(cvf, i)
190  {
191  vf[i].component(cmpt) =
192  cvf[i].component(cmpt).Re() + cvf[i].component(cmpt).Im();
193  }
194  }
195 
196  return vf;
197 }
198 
199 
201 {
202  vectorField vf(cvf.size());
203 
204  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
205  {
206  forAll(cvf, i)
207  {
208  vf[i].component(cmpt) = cvf[i].component(cmpt).Re();
209  }
210  }
211 
212  return vf;
213 }
214 
215 
217 {
218  vectorField vf(cvf.size());
219 
220  for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
221  {
222  forAll(cvf, i)
223  {
224  vf[i].component(cmpt) = cvf[i].component(cmpt).Im();
225  }
226  }
227 
228  return vf;
229 }
230 
231 
232 complexVectorField operator^
233 (
234  const UList<vector>& vf,
235  const UList<complexVector>& cvf
236 )
237 {
238  return ComplexField(vf^Re(cvf), vf^Im(cvf));
239 }
240 
241 
242 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
243 
244 } // End namespace Foam
245 
246 // ************************************************************************* //
unsigned char direction
Definition: direction.H:43
scalarField Im(const UList< complex > &cf)
complexField ImComplexField(const UList< scalar > &sf)
Definition: complexFields.C:70
volScalarField sf(fieldObject, mesh)
complexField ReComplexField(const UList< scalar > &sf)
Definition: complexFields.C:56
Namespace for OpenFOAM.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Number of components in this vector space.
Definition: VectorSpace.H:88
scalarField ReImSum(const UList< complex > &cf)
Definition: complexFields.C:84
complexField ComplexField(const UList< scalar > &re, const UList< scalar > &im)
Definition: complexFields.C:42
#define forAll(list, i)
Definition: UList.H:421
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
Macros for easy insertion into run-time selection tables.
Pre-declare SubField and related Field type.
Definition: Field.H:57
defineCompoundTypeName(List< complex >, complexList)
addCompoundToRunTimeSelectionTable(List< complex >, complexList)
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
const dimensionedScalar re
Classical electron radius: default SI units: [m].
scalarField Re(const UList< complex > &cf)
Definition: complexFields.C:97