Skip to content
Snippets Groups Projects
Commit 37819905 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

ENH: add some function support for complexField (#1247)

- operators are still incomplete, as are dimensioned fields,
  field-fields etc.

- split complexFields into separate complexField, complexVectorField files
parent fcba6491
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -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
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "complexField.H"
#include "addToRunTimeSelectionTable.H"
#define TEMPLATE
#include "FieldFunctionsM.C"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineCompoundTypeName(List<complex>, complexList);
addCompoundToRunTimeSelectionTable(List<complex>, complexList);
}
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
Foam::complexField Foam::ComplexField
(
const UList<scalar>& re,
const UList<scalar>& 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<scalar>& 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<scalar>& 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<complex>& cf)
{
scalarField sf(cf.size());
forAll(sf, i)
{
sf[i] = cf[i].Re() + cf[i].Im();
}
return sf;
}
Foam::scalarField Foam::Re(const UList<complex>& cf)
{
scalarField sf(cf.size());
forAll(sf, i)
{
sf[i] = cf[i].Re();
}
return sf;
}
Foam::scalarField Foam::Im(const UList<complex>& 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"
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::complexField
Description
Specialisation of Field\<T\> 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<complex> complexField;
//- Zip up two lists of values into a list of complex
complexField ComplexField
(
const UList<scalar>& re,
const UList<scalar>& im
);
//- Create complex field from a list of real (using imag == 0)
complexField ReComplexField(const UList<scalar>& re);
//- Create complex field from a list of imag (using real == 0)
complexField ImComplexField(const UList<scalar>& im);
//- Extract real component
scalarField Re(const UList<complex>& cf);
//- Extract imag component
scalarField Im(const UList<complex>& cf);
//- Sum real and imag components
scalarField ReImSum(const UList<complex>& 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
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
InClass
Foam::complexFields
Description
Specialisations of Field\<T\> for complex and complexVector
\*---------------------------------------------------------------------------*/
#ifndef complexFields_H
#define complexFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "complexField.H"
#include "complexVectorField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation
......@@ -23,111 +23,23 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
Specialisation of Field\<T\> for complex and complexVector.
\*---------------------------------------------------------------------------*/
#include "complexFields.H"
#include "complexVectorField.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
defineCompoundTypeName(List<complex>, complexList);
addCompoundToRunTimeSelectionTable(List<complex>, complexList);
complexField ComplexField(const UList<scalar>& re, const UList<scalar>& im)
{
complexField cf(re.size());
forAll(cf, i)
{
cf[i].Re() = re[i];
cf[i].Im() = im[i];
}
return cf;
}
complexField ReComplexField(const UList<scalar>& sf)
{
complexField cf(sf.size());
forAll(cf, i)
{
cf[i].Re() = sf[i];
cf[i].Im() = 0.0;
}
return cf;
}
complexField ImComplexField(const UList<scalar>& sf)
{
complexField cf(sf.size());
forAll(cf, i)
{
cf[i].Re() = 0.0;
cf[i].Im() = sf[i];
}
return cf;
defineCompoundTypeName(List<complexVector>, complexVectorList);
addCompoundToRunTimeSelectionTable(List<complexVector>, complexVectorList);
}
scalarField ReImSum(const UList<complex>& cf)
{
scalarField sf(cf.size());
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
forAll(sf, i)
{
sf[i] = cf[i].Re() + cf[i].Im();
}
return sf;
}
scalarField Re(const UList<complex>& cf)
{
scalarField sf(cf.size());
forAll(sf, i)
{
sf[i] = cf[i].Re();
}
return sf;
}
scalarField Im(const UList<complex>& cf)
{
scalarField sf(cf.size());
forAll(sf, i)
{
sf[i] = cf[i].Im();
}
return sf;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
defineCompoundTypeName(List<complexVector>, complexVectorList);
addCompoundToRunTimeSelectionTable(List<complexVector>, complexVectorList);
complexVectorField ComplexField
Foam::complexVectorField Foam::ComplexField
(
const UList<vector>& re,
const UList<vector>& im
......@@ -135,7 +47,7 @@ complexVectorField ComplexField
{
complexVectorField cvf(re.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
......@@ -148,15 +60,15 @@ complexVectorField ComplexField
}
complexVectorField ReComplexField(const UList<vector>& vf)
Foam::complexVectorField Foam::ReComplexField(const UList<vector>& re)
{
complexVectorField cvf(vf.size());
complexVectorField cvf(re.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
cvf[i].component(cmpt).Re() = vf[i].component(cmpt);
cvf[i].component(cmpt).Re() = re[i].component(cmpt);
cvf[i].component(cmpt).Im() = 0.0;
}
}
......@@ -165,16 +77,16 @@ complexVectorField ReComplexField(const UList<vector>& vf)
}
complexVectorField ImComplexField(const UList<vector>& vf)
Foam::complexVectorField Foam::ImComplexField(const UList<vector>& im)
{
complexVectorField cvf(vf.size());
complexVectorField cvf(im.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
cvf[i].component(cmpt).Re() = 0.0;
cvf[i].component(cmpt).Im() = vf[i].component(cmpt);
cvf[i].component(cmpt).Im() = im[i].component(cmpt);
}
}
......@@ -182,11 +94,11 @@ complexVectorField ImComplexField(const UList<vector>& vf)
}
vectorField ReImSum(const UList<complexVector>& cvf)
Foam::vectorField Foam::ReImSum(const UList<complexVector>& cvf)
{
vectorField vf(cvf.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
......@@ -199,11 +111,11 @@ vectorField ReImSum(const UList<complexVector>& cvf)
}
vectorField Re(const UList<complexVector>& cvf)
Foam::vectorField Foam::Re(const UList<complexVector>& cvf)
{
vectorField vf(cvf.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
......@@ -215,11 +127,11 @@ vectorField Re(const UList<complexVector>& cvf)
}
vectorField Im(const UList<complexVector>& cvf)
Foam::vectorField Foam::Im(const UList<complexVector>& cvf)
{
vectorField vf(cvf.size());
for (direction cmpt=0; cmpt<vector::nComponents; cmpt++)
for (direction cmpt=0; cmpt<vector::nComponents; ++cmpt)
{
forAll(cvf, i)
{
......@@ -231,7 +143,7 @@ vectorField Im(const UList<complexVector>& cvf)
}
complexVectorField operator^
Foam::complexVectorField Foam::operator^
(
const UList<vector>& vf,
const UList<complexVector>& cvf
......@@ -241,8 +153,4 @@ complexVectorField operator^
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 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 <http://www.gnu.org/licenses/>.
Typedef
Foam::complexField
Description
Specialisation of Field\<T\> for complex.
Typedef
Foam::complexVectorField
......@@ -36,16 +30,16 @@ Description
Specialisation of Field\<T\> 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"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -54,31 +48,35 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
typedef Field<complex> complexField;
typedef Field<complexVector> complexVectorField;
complexField ComplexField(const UList<scalar>&, const UList<scalar>&);
complexField ReComplexField(const UList<scalar>&);
complexField ImComplexField(const UList<scalar>&);
scalarField Re(const UList<complex>&);
scalarField Im(const UList<complex>&);
scalarField ReImSum(const UList<complex>&);
//- Zip up two lists of values into a list of complex
complexVectorField ComplexField
(
const UList<vector>& re,
const UList<vector>& im
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Create complex field from a list of real (using imag == 0)
complexVectorField ReComplexField(const UList<vector>& re);
typedef Field<complexVector> complexVectorField;
//- Create complex field from a list of imag (using real == 0)
complexVectorField ImComplexField(const UList<vector>& im);
//- Extract real component
vectorField Re(const UList<complexVector>& cvf);
//- Extract imag component
vectorField Im(const UList<complexVector>& cvf);
complexVectorField ComplexField(const UList<vector>&, const UList<vector>&);
complexVectorField ReComplexField(const UList<vector>&);
complexVectorField ImComplexField(const UList<vector>&);
vectorField Re(const UList<complexVector>&);
vectorField Im(const UList<complexVector>&);
vectorField ReImSum(const UList<complexVector>&);
//- Sum real and imag components
vectorField ReImSum(const UList<complexVector>& cvf);
complexVectorField operator^
(
const UList<vector>&,
const UList<complexVector>&
const UList<vector>& vf,
const UList<complexVector>& cvf
);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment