/*---------------------------------------------------------------------------*\ ========= | \\ / 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 . \*---------------------------------------------------------------------------*/ #ifndef GeometricFieldReuseFunctions_H #define GeometricFieldReuseFunctions_H // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam { // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template < class Type, template class PatchField, class GeoMesh > bool reusable(const tmp>& tgf) { if (tgf.isTmp()) { if (GeometricField::debug) { const GeometricField& gf = tgf(); const typename GeometricField:: GeometricBoundaryField& gbf = gf.boundaryField(); forAll(gbf, patchi) { if ( !polyPatch::constraintType(gbf[patchi].patch().type()) && !isA::Calculated>(gbf[patchi]) ) { WarningInFunction << "Attempt to reuse temporary with non-reusable BC " << gbf[patchi].type() << endl; return false; } } } return true; } else { return false; } } template class PatchField, class GeoMesh> tmp> New ( const tmp>& tgf1, const word& name, const dimensionSet& dimensions, const bool initRet = false ) { GeometricField& gf1 = const_cast& >(tgf1()); if (reusable(tgf1)) { gf1.rename(name); gf1.dimensions().reset(dimensions); return tgf1; } else { tmp> rtgf ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); if (initRet) { rtgf.ref() == tgf1(); } return rtgf; } } template < class TypeR, class Type1, template class PatchField, class GeoMesh > class reuseTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const word& name, const dimensionSet& dimensions ) { const GeometricField& gf1 = tgf1(); return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } }; template class PatchField, class GeoMesh> class reuseTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const word& name, const dimensionSet& dimensions ) { GeometricField& gf1 = const_cast& >(tgf1()); if (reusable(tgf1)) { gf1.rename(name); gf1.dimensions().reset(dimensions); return tgf1; } else { return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } } }; template < class TypeR, class Type1, class Type12, class Type2, template class PatchField, class GeoMesh > class reuseTmpTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const tmp>& tgf2, const word& name, const dimensionSet& dimensions ) { const GeometricField& gf1 = tgf1(); return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } }; template < class TypeR, class Type1, class Type12, template class PatchField, class GeoMesh > class reuseTmpTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const tmp>& tgf2, const word& name, const dimensionSet& dimensions ) { const GeometricField& gf1 = tgf1(); GeometricField& gf2 = const_cast& >(tgf2()); if (reusable(tgf2)) { gf2.rename(name); gf2.dimensions().reset(dimensions); return tgf2; } else { return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } } }; template < class TypeR, class Type2, template class PatchField, class GeoMesh > class reuseTmpTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const tmp>& tgf2, const word& name, const dimensionSet& dimensions ) { GeometricField& gf1 = const_cast& >(tgf1()); if (reusable(tgf1)) { gf1.rename(name); gf1.dimensions().reset(dimensions); return tgf1; } else { return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } } }; template class PatchField, class GeoMesh> class reuseTmpTmpGeometricField { public: static tmp> New ( const tmp>& tgf1, const tmp>& tgf2, const word& name, const dimensionSet& dimensions ) { GeometricField& gf1 = const_cast& >(tgf1()); GeometricField& gf2 = const_cast& >(tgf2()); if (reusable(tgf1)) { gf1.rename(name); gf1.dimensions().reset(dimensions); return tgf1; } else if (reusable(tgf2)) { gf2.rename(name); gf2.dimensions().reset(dimensions); return tgf2; } else { return tmp> ( new GeometricField ( IOobject ( name, gf1.instance(), gf1.db() ), gf1.mesh(), dimensions ) ); } } }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #endif // ************************************************************************* //