diff --git a/applications/test/complex/Test-complex.C b/applications/test/complex/Test-complex.C index 3c9ef77384..bc4d3d05dc 100644 --- a/applications/test/complex/Test-complex.C +++ b/applications/test/complex/Test-complex.C @@ -29,8 +29,6 @@ Description \*---------------------------------------------------------------------------*/ #include "argList.H" -#include "complex.H" -#include "complexVector.H" #include "complexFields.H" using namespace Foam; @@ -82,27 +80,45 @@ int main(int argc, char *argv[]) } complexField fld1(3, complex(2.0, 1.0)); + complexField fld2(fld1); + + for (complex& c : fld2) + { + c = ~c; + } Info<< "Field " << flatOutput(fld1) << nl; + Info<< "Conjugate: " << flatOutput(fld2) << nl; + + // Some arbitrary change + for (complex& c : fld2) + { + c.Im() *= 5; + } + Info<< "sum = " << sum(fld1) << nl; // Not yet Info<< "min = " << min(fld1) << nl; fld1 *= 10; - Info<< "Multiply: " << flatOutput(fld1) << nl; + Info<< "scalar multiply: " << flatOutput(fld1) << nl; - // Not yet: - // #ifdef TEST_FOAM_OVERLOAD - // Info<< "sin: " << sin(fld1) << nl; - // #endif + fld1 /= 10; + Info<< "scalar divide: " << flatOutput(fld1) << nl; + Info<< "sin: " << sin(fld1) << nl; - for (complex& c : fld1) - { - c = ~c; - } + Info<< "operator + : " << (fld1 + fld2) << nl; + + // Some operators are still incomplete + + // Info<< "operator * : " << (fld1 * fld2) << nl; + // Info<< "operator / : " << (fld1 / fld2) << nl; + Info<< "operator / : " << (fld1 / 2) << nl; + // Info<< "operator / : " << (fld1 / fld2) << nl; + Info<< "sqrt : " << sqrt(fld1) << nl; + // Info<< "pow(2) : " << pow(fld1, 2) << nl; - Info<< "Conjugate: " << flatOutput(fld1) << nl; Info<< "\nEnd\n" << endl; return 0; diff --git a/src/OpenFOAM/Make/files b/src/OpenFOAM/Make/files index 54c3b2a19a..b3c9ecfdcc 100644 --- a/src/OpenFOAM/Make/files +++ b/src/OpenFOAM/Make/files @@ -672,7 +672,8 @@ $(Fields)/quaternionField/quaternionField.C $(Fields)/quaternionField/quaternionIOField.C $(Fields)/triadField/triadField.C $(Fields)/triadField/triadIOField.C -$(Fields)/complexFields/complexFields.C +$(Fields)/complex/complexField.C +$(Fields)/complex/complexVectorField.C $(Fields)/transformField/transformField.C $(Fields)/fieldTypes.C diff --git a/src/OpenFOAM/fields/Fields/complex/complexField.C b/src/OpenFOAM/fields/Fields/complex/complexField.C new file mode 100644 index 0000000000..5662ab4076 --- /dev/null +++ b/src/OpenFOAM/fields/Fields/complex/complexField.C @@ -0,0 +1,168 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- + | Copyright (C) 2011 OpenFOAM Foundation +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "complexField.H" +#include "addToRunTimeSelectionTable.H" + +#define TEMPLATE +#include "FieldFunctionsM.C" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineCompoundTypeName(List, complexList); + addCompoundToRunTimeSelectionTable(List, complexList); +} + + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +Foam::complexField Foam::ComplexField +( + const UList& re, + const UList& im +) +{ + complexField cf(re.size()); + + forAll(cf, i) + { + cf[i].Re() = re[i]; + cf[i].Im() = im[i]; + } + + return cf; +} + + +Foam::complexField Foam::ReComplexField(const UList& re) +{ + complexField cf(re.size()); + + forAll(cf, i) + { + cf[i].Re() = re[i]; + cf[i].Im() = 0.0; + } + + return cf; +} + + +Foam::complexField Foam::ImComplexField(const UList& im) +{ + complexField cf(im.size()); + + forAll(cf, i) + { + cf[i].Re() = 0.0; + cf[i].Im() = im[i]; + } + + return cf; +} + + +Foam::scalarField Foam::ReImSum(const UList& cf) +{ + scalarField sf(cf.size()); + + forAll(sf, i) + { + sf[i] = cf[i].Re() + cf[i].Im(); + } + + return sf; +} + + +Foam::scalarField Foam::Re(const UList& cf) +{ + scalarField sf(cf.size()); + + forAll(sf, i) + { + sf[i] = cf[i].Re(); + } + + return sf; +} + + +Foam::scalarField Foam::Im(const UList& cf) +{ + scalarField sf(cf.size()); + + forAll(sf, i) + { + sf[i] = cf[i].Im(); + } + + return sf; +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +UNARY_FUNCTION(complex, complex, pow3) +UNARY_FUNCTION(complex, complex, pow4) +UNARY_FUNCTION(complex, complex, pow5) +UNARY_FUNCTION(complex, complex, pow6) +UNARY_FUNCTION(complex, complex, pow025) +UNARY_FUNCTION(complex, complex, sqrt) +UNARY_FUNCTION(complex, complex, exp) +UNARY_FUNCTION(complex, complex, log) +UNARY_FUNCTION(complex, complex, log10) +UNARY_FUNCTION(complex, complex, sin) +UNARY_FUNCTION(complex, complex, cos) +UNARY_FUNCTION(complex, complex, tan) +UNARY_FUNCTION(complex, complex, asin) +UNARY_FUNCTION(complex, complex, acos) +UNARY_FUNCTION(complex, complex, atan) +UNARY_FUNCTION(complex, complex, sinh) +UNARY_FUNCTION(complex, complex, cosh) +UNARY_FUNCTION(complex, complex, tanh) +UNARY_FUNCTION(complex, complex, asinh) +UNARY_FUNCTION(complex, complex, acosh) +UNARY_FUNCTION(complex, complex, atanh) + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "undefFieldFunctionsM.H" + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/complex/complexField.H b/src/OpenFOAM/fields/Fields/complex/complexField.H new file mode 100644 index 0000000000..c9b9351364 --- /dev/null +++ b/src/OpenFOAM/fields/Fields/complex/complexField.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- + | Copyright (C) 2011 OpenFOAM Foundation +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +Typedef + Foam::complexField + +Description + Specialisation of Field\ for complex. + +SourceFiles + complexField.C + +\*---------------------------------------------------------------------------*/ + +#ifndef complexField_H +#define complexField_H + +#include "complex.H" +#include "scalarField.H" + +#define TEMPLATE +#include "FieldFunctionsM.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +typedef Field complexField; + +//- Zip up two lists of values into a list of complex +complexField ComplexField +( + const UList& re, + const UList& im +); + +//- Create complex field from a list of real (using imag == 0) +complexField ReComplexField(const UList& re); + +//- Create complex field from a list of imag (using real == 0) +complexField ImComplexField(const UList& im); + +//- Extract real component +scalarField Re(const UList& cf); + +//- Extract imag component +scalarField Im(const UList& cf); + +//- Sum real and imag components +scalarField ReImSum(const UList& cf); + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +UNARY_FUNCTION(complex, complex, pow3) +UNARY_FUNCTION(complex, complex, pow4) +UNARY_FUNCTION(complex, complex, pow5) +UNARY_FUNCTION(complex, complex, pow6) +UNARY_FUNCTION(complex, complex, pow025) +UNARY_FUNCTION(complex, complex, sqrt) +UNARY_FUNCTION(complex, complex, exp) +UNARY_FUNCTION(complex, complex, log) +UNARY_FUNCTION(complex, complex, log10) +UNARY_FUNCTION(complex, complex, sin) +UNARY_FUNCTION(complex, complex, cos) +UNARY_FUNCTION(complex, complex, tan) +UNARY_FUNCTION(complex, complex, asin) +UNARY_FUNCTION(complex, complex, acos) +UNARY_FUNCTION(complex, complex, atan) +UNARY_FUNCTION(complex, complex, sinh) +UNARY_FUNCTION(complex, complex, cosh) +UNARY_FUNCTION(complex, complex, tanh) +UNARY_FUNCTION(complex, complex, asinh) +UNARY_FUNCTION(complex, complex, acosh) +UNARY_FUNCTION(complex, complex, atanh) + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "undefFieldFunctionsM.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/complex/complexFields.H b/src/OpenFOAM/fields/Fields/complex/complexFields.H new file mode 100644 index 0000000000..ef031db0e4 --- /dev/null +++ b/src/OpenFOAM/fields/Fields/complex/complexFields.H @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +InClass + Foam::complexFields + +Description + Specialisations of Field\ for complex and complexVector + +\*---------------------------------------------------------------------------*/ + +#ifndef complexFields_H +#define complexFields_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "complexField.H" +#include "complexVectorField.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/complex/complexVectorField.C b/src/OpenFOAM/fields/Fields/complex/complexVectorField.C new file mode 100644 index 0000000000..3ac98022f5 --- /dev/null +++ b/src/OpenFOAM/fields/Fields/complex/complexVectorField.C @@ -0,0 +1,156 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. + \\/ M anipulation | +------------------------------------------------------------------------------- + | Copyright (C) 2011 OpenFOAM Foundation +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "complexVectorField.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineCompoundTypeName(List, complexVectorList); + addCompoundToRunTimeSelectionTable(List, complexVectorList); +} + + +// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * // + +Foam::complexVectorField Foam::ComplexField +( + const UList& re, + const UList& im +) +{ + complexVectorField cvf(re.size()); + + for (direction cmpt=0; cmpt& re) +{ + complexVectorField cvf(re.size()); + + for (direction cmpt=0; cmpt& im) +{ + complexVectorField cvf(im.size()); + + for (direction cmpt=0; cmpt& cvf) +{ + vectorField vf(cvf.size()); + + for (direction cmpt=0; cmpt& cvf) +{ + vectorField vf(cvf.size()); + + for (direction cmpt=0; cmpt& cvf) +{ + vectorField vf(cvf.size()); + + for (direction cmpt=0; cmpt& vf, + const UList& cvf +) +{ + return ComplexField(vf^Re(cvf), vf^Im(cvf)); +} + + +// ************************************************************************* // diff --git a/src/OpenFOAM/fields/Fields/complexFields/complexFields.H b/src/OpenFOAM/fields/Fields/complex/complexVectorField.H similarity index 64% rename from src/OpenFOAM/fields/Fields/complexFields/complexFields.H rename to src/OpenFOAM/fields/Fields/complex/complexVectorField.H index 13e02472c9..507a6dc51d 100644 --- a/src/OpenFOAM/fields/Fields/complexFields/complexFields.H +++ b/src/OpenFOAM/fields/Fields/complex/complexVectorField.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011 OpenFOAM Foundation @@ -23,12 +23,6 @@ License You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . -Typedef - Foam::complexField - -Description - Specialisation of Field\ for complex. - Typedef Foam::complexVectorField @@ -36,49 +30,53 @@ Description Specialisation of Field\ for complexVector. SourceFiles - complexFields.C + complexVectorField.C \*---------------------------------------------------------------------------*/ -#ifndef complexFields_H -#define complexFields_H +#ifndef complexVectorField_H +#define complexVectorField_H #include "complex.H" #include "complexVector.H" -#include "primitiveFields.H" +#include "vectorField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -typedef Field complexField; - -complexField ComplexField(const UList&, const UList&); -complexField ReComplexField(const UList&); -complexField ImComplexField(const UList&); -scalarField Re(const UList&); -scalarField Im(const UList&); -scalarField ReImSum(const UList&); - - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // typedef Field complexVectorField; -complexVectorField ComplexField(const UList&, const UList&); -complexVectorField ReComplexField(const UList&); -complexVectorField ImComplexField(const UList&); -vectorField Re(const UList&); -vectorField Im(const UList&); -vectorField ReImSum(const UList&); +//- Zip up two lists of values into a list of complex +complexVectorField ComplexField +( + const UList& re, + const UList& im +); + + +//- Create complex field from a list of real (using imag == 0) +complexVectorField ReComplexField(const UList& re); + +//- Create complex field from a list of imag (using real == 0) +complexVectorField ImComplexField(const UList& im); + +//- Extract real component +vectorField Re(const UList& cvf); + +//- Extract imag component +vectorField Im(const UList& cvf); + +//- Sum real and imag components +vectorField ReImSum(const UList& cvf); complexVectorField operator^ ( - const UList&, - const UList& + const UList& vf, + const UList& cvf ); diff --git a/src/OpenFOAM/fields/Fields/complexFields/complexFields.C b/src/OpenFOAM/fields/Fields/complexFields/complexFields.C deleted file mode 100644 index df9203067c..0000000000 --- a/src/OpenFOAM/fields/Fields/complexFields/complexFields.C +++ /dev/null @@ -1,248 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd. - \\/ M anipulation | -------------------------------------------------------------------------------- - | Copyright (C) 2011 OpenFOAM Foundation -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Description - Specialisation of Field\ for complex and complexVector. - -\*---------------------------------------------------------------------------*/ - -#include "complexFields.H" -#include "addToRunTimeSelectionTable.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -defineCompoundTypeName(List, complexList); -addCompoundToRunTimeSelectionTable(List, complexList); - -complexField ComplexField(const UList& re, const UList& im) -{ - complexField cf(re.size()); - - forAll(cf, i) - { - cf[i].Re() = re[i]; - cf[i].Im() = im[i]; - } - - return cf; -} - - -complexField ReComplexField(const UList& sf) -{ - complexField cf(sf.size()); - - forAll(cf, i) - { - cf[i].Re() = sf[i]; - cf[i].Im() = 0.0; - } - - return cf; -} - - -complexField ImComplexField(const UList& sf) -{ - complexField cf(sf.size()); - - forAll(cf, i) - { - cf[i].Re() = 0.0; - cf[i].Im() = sf[i]; - } - - return cf; -} - - -scalarField ReImSum(const UList& cf) -{ - scalarField sf(cf.size()); - - forAll(sf, i) - { - sf[i] = cf[i].Re() + cf[i].Im(); - } - - return sf; -} - - -scalarField Re(const UList& cf) -{ - scalarField sf(cf.size()); - - forAll(sf, i) - { - sf[i] = cf[i].Re(); - } - - return sf; -} - - -scalarField Im(const UList& cf) -{ - scalarField sf(cf.size()); - - forAll(sf, i) - { - sf[i] = cf[i].Im(); - } - - return sf; -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -defineCompoundTypeName(List, complexVectorList); -addCompoundToRunTimeSelectionTable(List, complexVectorList); - -complexVectorField ComplexField -( - const UList& re, - const UList& im -) -{ - complexVectorField cvf(re.size()); - - for (direction cmpt=0; cmpt& vf) -{ - complexVectorField cvf(vf.size()); - - for (direction cmpt=0; cmpt& vf) -{ - complexVectorField cvf(vf.size()); - - for (direction cmpt=0; cmpt& cvf) -{ - vectorField vf(cvf.size()); - - for (direction cmpt=0; cmpt& cvf) -{ - vectorField vf(cvf.size()); - - for (direction cmpt=0; cmpt& cvf) -{ - vectorField vf(cvf.size()); - - for (direction cmpt=0; cmpt& vf, - const UList& cvf -) -{ - return ComplexField(vf^Re(cvf), vf^Im(cvf)); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// ************************************************************************* //