/*---------------------------------------------------------------------------* \ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\/ 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 . \*---------------------------------------------------------------------------*/ #include "GeometricFieldReuseFunctions.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define UNARY_FUNCTION(ReturnType, Type1, Func, Dfunc) \ \ TEMPLATE \ void Func \ ( \ GeometricField& res, \ const GeometricField& gf1 \ ) \ { \ Foam::Func(res.internalField(), gf1.internalField()); \ Foam::Func(res.boundaryField(), gf1.boundaryField()); \ } \ \ TEMPLATE \ tmp> Func \ ( \ const GeometricField& gf1 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ #Func "(" + gf1.name() + ')', \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ Dfunc(gf1.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const tmp>& tgf1 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ #Func "(" + gf1.name() + ')', \ Dfunc(gf1.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1); \ \ tgf1.clear(); \ \ return tRes; \ } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define UNARY_OPERATOR(ReturnType, Type1, Op, OpFunc, Dfunc) \ \ TEMPLATE \ void OpFunc \ ( \ GeometricField& res, \ const GeometricField& gf1 \ ) \ { \ Foam::OpFunc(res.internalField(), gf1.internalField()); \ Foam::OpFunc(res.boundaryField(), gf1.boundaryField()); \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const GeometricField& gf1 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ #Op + gf1.name(), \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ Dfunc(gf1.dimensions()) \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tgf1 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ #Op + gf1.name(), \ Dfunc(gf1.dimensions()) \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1); \ \ tgf1.clear(); \ \ return tRes; \ } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define BINARY_FUNCTION(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ GeometricField& res, \ const GeometricField& gf1, \ const GeometricField& gf2 \ ) \ { \ Foam::Func(res.internalField(), gf1.internalField(), gf2.internalField());\ Foam::Func(res.boundaryField(), gf1.boundaryField(), gf2.boundaryField());\ } \ \ TEMPLATE \ tmp> Func \ ( \ const GeometricField& gf1, \ const GeometricField& gf2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ Func(gf1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const GeometricField& gf1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf2, \ #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ Func(gf1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ tgf2.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const tmp>& tgf1, \ const GeometricField& gf2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ Func(gf1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ tgf1.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const tmp>& tgf1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpTmpGeometricField \ \ ::New \ ( \ tgf1, \ tgf2, \ #Func "(" + gf1.name() + ',' + gf2.name() + ')', \ Func(gf1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, gf2); \ \ tgf1.clear(); \ tgf2.clear(); \ \ return tRes; \ } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ GeometricField& res, \ const dimensioned& dt1, \ const GeometricField& gf2 \ ) \ { \ Foam::Func(res.internalField(), dt1.value(), gf2.internalField()); \ Foam::Func(res.boundaryField(), dt1.value(), gf2.boundaryField()); \ } \ \ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ const GeometricField& gf2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ #Func "(" + dt1.name() + ',' + gf2.name() + ')', \ gf2.instance(), \ gf2.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf2.mesh(), \ Func(dt1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), dt1, gf2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const Type1& t1, \ const GeometricField& gf2 \ ) \ { \ return Func(dimensioned(t1), gf2); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ const dimensioned& dt1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf2, \ #Func "(" + dt1.name() + gf2.name() + ',' + ')', \ Func(dt1.dimensions(), gf2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), dt1, gf2); \ \ tgf2.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const Type1& t1, \ const tmp>& tgf2 \ ) \ { \ return Func(dimensioned(t1), tgf2); \ } #define BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) \ \ TEMPLATE \ void Func \ ( \ GeometricField& res, \ const GeometricField& gf1, \ const dimensioned& dt2 \ ) \ { \ Foam::Func(res.internalField(), gf1.internalField(), dt2.value()); \ Foam::Func(res.boundaryField(), gf1.boundaryField(), dt2.value()); \ } \ \ TEMPLATE \ tmp> Func \ ( \ const GeometricField& gf1, \ const dimensioned& dt2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ #Func "(" + gf1.name() + ',' + dt2.name() + ')', \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ Func(gf1.dimensions(), dt2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, dt2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const GeometricField& gf1, \ const Type2& t2 \ ) \ { \ return Func(gf1, dimensioned(t2)); \ } \ \ \ TEMPLATE \ tmp> Func \ ( \ const tmp>& tgf1, \ const dimensioned& dt2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ #Func "(" + gf1.name() + ',' + dt2.name() + ')', \ Func(gf1.dimensions(), dt2.dimensions()) \ ) \ ); \ \ Foam::Func(tRes.ref(), gf1, dt2); \ \ tgf1.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> Func \ ( \ const tmp>& tgf1, \ const Type2& t2 \ ) \ { \ return Func(tgf1, dimensioned(t2)); \ } #define BINARY_TYPE_FUNCTION(ReturnType, Type1, Type2, Func) \ BINARY_TYPE_FUNCTION_SF(ReturnType, Type1, Type2, Func) \ BINARY_TYPE_FUNCTION_FS(ReturnType, Type1, Type2, Func) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define BINARY_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ void OpFunc \ ( \ GeometricField& res, \ const GeometricField& gf1, \ const GeometricField& gf2 \ ) \ { \ Foam::OpFunc \ (res.internalField(), gf1.internalField(), gf2.internalField()); \ Foam::OpFunc \ (res.boundaryField(), gf1.boundaryField(), gf2.boundaryField()); \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const GeometricField& gf1, \ const GeometricField& gf2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ '(' + gf1.name() + OpName + gf2.name() + ')', \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ gf1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const GeometricField& gf1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf2, \ '(' + gf1.name() + OpName + gf2.name() + ')', \ gf1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ tgf2.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tgf1, \ const GeometricField& gf2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ '(' + gf1.name() + OpName + gf2.name() + ')', \ gf1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ tgf1.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tgf1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpTmpGeometricField \ ::New \ ( \ tgf1, \ tgf2, \ '(' + gf1.name() + OpName + gf2.name() + ')', \ gf1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, gf2); \ \ tgf1.clear(); \ tgf2.clear(); \ \ return tRes; \ } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ void OpFunc \ ( \ GeometricField& res, \ const dimensioned& dt1, \ const GeometricField& gf2 \ ) \ { \ Foam::OpFunc(res.internalField(), dt1.value(), gf2.internalField()); \ Foam::OpFunc(res.boundaryField(), dt1.value(), gf2.boundaryField()); \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ const GeometricField& gf2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ '(' + dt1.name() + OpName + gf2.name() + ')', \ gf2.instance(), \ gf2.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf2.mesh(), \ dt1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), dt1, gf2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const Type1& t1, \ const GeometricField& gf2 \ ) \ { \ return dimensioned(t1) Op gf2; \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ const dimensioned& dt1, \ const tmp>& tgf2 \ ) \ { \ const GeometricField& gf2 = tgf2(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf2, \ '(' + dt1.name() + OpName + gf2.name() + ')', \ dt1.dimensions() Op gf2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), dt1, gf2); \ \ tgf2.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const Type1& t1, \ const tmp>& tgf2 \ ) \ { \ return dimensioned(t1) Op tgf2; \ } #define BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ \ TEMPLATE \ void OpFunc \ ( \ GeometricField& res, \ const GeometricField& gf1, \ const dimensioned& dt2 \ ) \ { \ Foam::OpFunc(res.internalField(), gf1.internalField(), dt2.value()); \ Foam::OpFunc(res.boundaryField(), gf1.boundaryField(), dt2.value()); \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const GeometricField& gf1, \ const dimensioned& dt2 \ ) \ { \ tmp> tRes \ ( \ new GeometricField \ ( \ IOobject \ ( \ '(' + gf1.name() + OpName + dt2.name() + ')', \ gf1.instance(), \ gf1.db(), \ IOobject::NO_READ, \ IOobject::NO_WRITE \ ), \ gf1.mesh(), \ gf1.dimensions() Op dt2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, dt2); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const GeometricField& gf1, \ const Type2& t2 \ ) \ { \ return gf1 Op dimensioned(t2); \ } \ \ \ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tgf1, \ const dimensioned& dt2 \ ) \ { \ const GeometricField& gf1 = tgf1(); \ \ tmp> tRes \ ( \ reuseTmpGeometricField::New \ ( \ tgf1, \ '(' + gf1.name() + OpName + dt2.name() + ')', \ gf1.dimensions() Op dt2.dimensions() \ ) \ ); \ \ Foam::OpFunc(tRes.ref(), gf1, dt2); \ \ tgf1.clear(); \ \ return tRes; \ } \ \ TEMPLATE \ tmp> operator Op \ ( \ const tmp>& tgf1, \ const Type2& t2 \ ) \ { \ return tgf1 Op dimensioned(t2); \ } #define BINARY_TYPE_OPERATOR(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ BINARY_TYPE_OPERATOR_SF(ReturnType, Type1, Type2, Op, OpName, OpFunc) \ BINARY_TYPE_OPERATOR_FS(ReturnType, Type1, Type2, Op, OpName, OpFunc) // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //