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-------------------------------------------------------------------------------
11License
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
37namespace Foam
38{
41}
42
43
44// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
45
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
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());
111
112 Foam::zip(result, re, im);
113
114 return result;
115}
116
117
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
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
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
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
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
184
185// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
186
187namespace Foam
188{
189
190template<>
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
204BINARY_TYPE_OPERATOR(complex, complex, complex, +, add)
205BINARY_TYPE_OPERATOR(complex, complex, complex, -, subtract)
206
207BINARY_OPERATOR(complex, complex, complex, *, multiply)
208BINARY_OPERATOR(complex, complex, complex, /, divide)
209
210
211// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212
213UNARY_FUNCTION(complex, complex, pow3)
214UNARY_FUNCTION(complex, complex, pow4)
215UNARY_FUNCTION(complex, complex, pow5)
216UNARY_FUNCTION(complex, complex, pow6)
217UNARY_FUNCTION(complex, complex, pow025)
218UNARY_FUNCTION(complex, complex, sqrt)
219UNARY_FUNCTION(complex, complex, exp)
220UNARY_FUNCTION(complex, complex, log)
221UNARY_FUNCTION(complex, complex, log10)
222UNARY_FUNCTION(complex, complex, sin)
223UNARY_FUNCTION(complex, complex, cos)
224UNARY_FUNCTION(complex, complex, tan)
225UNARY_FUNCTION(complex, complex, asin)
226UNARY_FUNCTION(complex, complex, acos)
227UNARY_FUNCTION(complex, complex, atan)
228UNARY_FUNCTION(complex, complex, sinh)
229UNARY_FUNCTION(complex, complex, cosh)
230UNARY_FUNCTION(complex, complex, tanh)
231UNARY_FUNCTION(complex, complex, asinh)
232UNARY_FUNCTION(complex, complex, acosh)
233UNARY_FUNCTION(complex, complex, atanh)
234
235
236// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237
238} // End namespace Foam
239
240// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241
242#include "undefFieldFunctionsM.H"
243
244// ************************************************************************* //
#define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc)
#define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc)
#define TFOR_ALL_S_OP_F_OP_F(typeS, s, OP1, typeF1, f1, OP2, typeF2, f2)
Definition: FieldM.H:389
Macros for easy insertion into run-time selection tables.
Generic templated field type.
Definition: Field.H:82
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A complex number, similar to the C++ complex type.
Definition: complex.H:83
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Namespace for OpenFOAM.
dimensionedScalar pow6(const dimensionedScalar &ds)
dimensionedScalar pow5(const dimensionedScalar &ds)
dimensionedScalar asin(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
scalarField Re(const UList< complex > &cf)
Extract real component.
Definition: complexField.C:159
dimensionedScalar tan(const dimensionedScalar &ds)
dimensionedScalar pow3(const dimensionedScalar &ds)
dimensionedScalar cosh(const dimensionedScalar &ds)
void subtract(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar tanh(const dimensionedScalar &ds)
dimensionedScalar sinh(const dimensionedScalar &ds)
complexField ImComplexField(const UList< scalar > &im)
Create complex field from a list of imag (using real == 0)
Definition: complexField.C:132
dimensionedScalar log10(const dimensionedScalar &ds)
dimensionedScalar log(const dimensionedScalar &ds)
dimensionedScalar acosh(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
complex sumProd(const UList< complex > &f1, const UList< complex > &f2)
Sum product.
Definition: complexField.C:191
complexField ReComplexField(const UList< scalar > &re)
Create complex field from a list of real (using imag == 0)
Definition: complexField.C:118
dimensionedScalar pow4(const dimensionedScalar &ds)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
void multiply(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar atanh(const dimensionedScalar &ds)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
complexField ComplexField(const UList< scalar > &re, const UList< scalar > &im)
Zip up two lists of values into a list of complex.
Definition: complexField.C:105
void unzip(const FieldField< Field, SphericalTensor< Cmpt > > &input, FieldField< Field, Cmpt > &ii)
Unzip sphericalTensor field field into components.
error FatalError
dimensionedScalar atan(const dimensionedScalar &ds)
void divide(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, scalar > &f2)
dimensionedScalar cos(const dimensionedScalar &ds)
dimensionedScalar acos(const dimensionedScalar &ds)
void zip(FieldField< Field, SphericalTensor< Cmpt > > &result, const FieldField< Field, Cmpt > &ii)
Zip together sphericalTensor field field from components.
scalarField Im(const UList< complex > &cf)
Extract imag component.
Definition: complexField.C:172
dimensionedScalar pow025(const dimensionedScalar &ds)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
scalarField ReImSum(const UList< complex > &cf)
Sum real and imag components.
Definition: complexField.C:146
dimensionedScalar asinh(const dimensionedScalar &ds)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
#define addCompoundToRunTimeSelectionTable(Type, Tag)
Add compound to selection table, lookup using typeName.
Definition: token.H:720
#define defineCompoundTypeName(Type, UnusedTag)
Define compound using Type for its name.
Definition: token.H:712