complexField.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "complexField.H"
31 
32 #define TEMPLATE
33 #include "FieldFunctionsM.C"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineCompoundTypeName(List<complex>, complexList);
41 }
42 
43 
44 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
45 
46 void Foam::zip
47 (
48  complexField& result,
49  const UList<scalar>& re,
50  const UList<scalar>& im
51 )
52 {
53  const label len = result.size();
54 
55  #ifdef FULLDEBUG
56  if (len != re.size() || len != im.size())
57  {
59  << "Components sizes do not match: " << len << " ("
60  << re.size() << ' ' << im.size() << ')'
61  << nl
62  << abort(FatalError);
63  }
64  #endif
65 
66  for (label i=0; i < len; ++i)
67  {
68  result[i].Re() = re[i];
69  result[i].Im() = im[i];
70  }
71 }
72 
73 
74 void Foam::unzip
75 (
76  const UList<complex>& input,
77  scalarField& re,
78  scalarField& im
79 )
80 {
81  const label len = input.size();
82 
83  #ifdef FULLDEBUG
84  if (len != re.size() || len != im.size())
85  {
87  << "Components sizes do not match: " << len << " ("
88  << re.size() << ' ' << im.size() << ')'
89  << nl
90  << abort(FatalError);
91  }
92  #endif
93 
94  for (label i=0; i < len; ++i)
95  {
96  re[i] = input[i].Re();
97  im[i] = input[i].Im();
98  }
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103 
105 (
106  const UList<scalar>& re,
107  const UList<scalar>& im
108 )
109 {
110  complexField result(re.size());
112  Foam::zip(result, re, im);
113 
114  return result;
115 }
116 
117 
118 Foam::complexField Foam::ReComplexField(const UList<scalar>& re)
119 {
120  complexField cf(re.size());
121 
122  forAll(cf, i)
123  {
124  cf[i].Re() = re[i];
125  cf[i].Im() = Zero;
126  }
127 
128  return cf;
129 }
130 
131 
132 Foam::complexField Foam::ImComplexField(const UList<scalar>& im)
133 {
134  complexField cf(im.size());
135 
136  forAll(cf, i)
137  {
138  cf[i].Re() = Zero;
139  cf[i].Im() = im[i];
140  }
141 
142  return cf;
143 }
144 
145 
146 Foam::scalarField Foam::ReImSum(const UList<complex>& cf)
147 {
148  scalarField sf(cf.size());
149 
150  forAll(sf, i)
151  {
152  sf[i] = cf[i].Re() + cf[i].Im();
153  }
154 
155  return sf;
156 }
157 
158 
159 Foam::scalarField Foam::Re(const UList<complex>& cf)
160 {
161  scalarField sf(cf.size());
162 
163  forAll(sf, i)
164  {
165  sf[i] = cf[i].Re();
166  }
167 
168  return sf;
169 }
170 
171 
172 Foam::scalarField Foam::Im(const UList<complex>& cf)
173 {
174  scalarField sf(cf.size());
175 
176  forAll(sf, i)
177  {
178  sf[i] = cf[i].Im();
179  }
180 
181  return sf;
182 }
183 
185 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186 
187 namespace Foam
188 {
189 
190 template<>
191 complex sumProd(const UList<complex>& f1, const UList<complex>& f2)
192 {
193  complex result = Zero;
194  if (f1.size() && (f1.size() == f2.size()))
195  {
196  TFOR_ALL_S_OP_F_OP_F(complex, result, +=, complex, f1, *, complex, f2)
197  }
198  return result;
199 }
200 
201 
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 
206 
209 
210 
211 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #include "undefFieldFunctionsM.H"
243 
244 // ************************************************************************* //
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar tanh(const dimensionedScalar &ds)
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:118
dimensionedScalar acos(const dimensionedScalar &ds)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar log(const dimensionedScalar &ds)
addCompoundToRunTimeSelectionTable(List< complex >, complexList)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:578
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
defineCompoundTypeName(List< complex >, complexList)
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
Field< complex > complexField
Specialisation of Field<T> for complex.
Definition: complexField.H:50
const dimensionedScalar re
Classical electron radius: default SI units: [m].
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
void zip(FieldField< Field, SphericalTensor< Cmpt >> &result, const FieldField< Field, Cmpt > &ii)
Zip together sphericalTensor field field from components.
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensionedScalar pow025(const dimensionedScalar &ds)
complexField ImComplexField(const UList< scalar > &im)
Create complex field from a list of imag (using real == 0)
Definition: complexField.C:125
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar asin(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
complexField ComplexField(const UList< scalar > &re, const UList< scalar > &im)
Zip up two lists of values into a list of complex.
Definition: complexField.C:98
Macros for easy insertion into run-time selection tables.
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
Definition: complexField.C:184
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
void unzip(const FieldField< Field, SphericalTensor< Cmpt >> &input, FieldField< Field, Cmpt > &ii)
Unzip sphericalTensor field field into components.
dimensionedScalar acosh(const dimensionedScalar &ds)
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
scalarField Im(const UList< complex > &cf)
Extract imag component.
Definition: complexField.C:165
Generic templated field type.
Definition: Field.H:61
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
dimensionedScalar asinh(const dimensionedScalar &ds)
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:48
scalarField Re(const UList< complex > &cf)
Extract real component.
Definition: complexField.C:152
dimensionedScalar atanh(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Definition: errorManip.H:139
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:99
dimensionedScalar sin(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:435
scalarField ReImSum(const UList< complex > &cf)
Sum real and imag components.
Definition: complexField.C:139
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensionedScalar sinh(const dimensionedScalar &ds)
dimensionedScalar atan(const dimensionedScalar &ds)
dimensionedScalar pow4(const dimensionedScalar &ds)
dimensionedScalar pow6(const dimensionedScalar &ds)
A complex number, similar to the C++ complex type.
Definition: complex.H:78
complexField ReComplexField(const UList< scalar > &re)
Create complex field from a list of real (using imag == 0)
Definition: complexField.C:111
dimensionedScalar cosh(const dimensionedScalar &ds)
dimensionedScalar tan(const dimensionedScalar &ds)
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
dimensionedScalar log10(const dimensionedScalar &ds)
Namespace for OpenFOAM.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:157