/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-2026 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 "GeometricField.H" #include "Time.H" #include "demandDrivenData.H" #include "dictionary.H" #include "localIOdictionary.H" #include "solutionControl.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #define checkFieldAssignment(gf1, gf2) \ \ if \ ( \ static_cast(&gf1) \ == static_cast(&gf2) \ ) \ { \ FatalErrorInFunction \ << "attempted assignment to self for field " \ << (gf1).name() << abort(FatalError); \ } #define checkFieldOperation(gf1, gf2, op) \ \ if ((gf1).mesh() != (gf2).mesh()) \ { \ FatalErrorInFunction \ << "different mesh for fields " \ << (gf1).name() << " and " << (gf2).name() \ << " during operation " << op \ << abort(FatalError); \ } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // template class PrimitiveField> void Foam::GeometricField::readFields ( const dictionary& dict ) { printDictionary print(dict); Internal::readField(dict, "internalField"); boundaryField_.readField(*this, dict.subDict("boundaryField")); // Don't use subOrEmptyDict here, or line numbers will be lost from any IO // error messages. Use an actual sub-dict reference here if possible. if (dict.found("sources")) { sources_.readField(*this, dict.subDict("sources")); } else { sources_.readField(*this, dictionary("sources", dict)); } if (dict.found("referenceLevel")) { Type fieldAverage(pTraits(dict.lookup("referenceLevel"))); Field::operator+=(fieldAverage); forAll(boundaryField_, patchi) { boundaryField_[patchi] == boundaryField_[patchi] + fieldAverage; } } } template class PrimitiveField> void Foam::GeometricField::readFields() { const localIOdictionary dict ( IOobject ( this->name(), this->instance(), this->local(), this->db(), IOobject::MUST_READ, IOobject::NO_WRITE, false ), typeName ); this->close(); readFields(dict); } template class PrimitiveField> bool Foam::GeometricField::readIfPresent() { if ( this->readOpt() == IOobject::MUST_READ || this->readOpt() == IOobject::MUST_READ_IF_MODIFIED || (this->readOpt() == IOobject::READ_IF_PRESENT && this->headerOk()) ) { readFields(); // Check compatibility between field and mesh if (this->size() != this->mesh().size()) { FatalIOErrorInFunction(this->readStream(typeName)) << " number of field elements = " << this->size() << " number of mesh elements = " << this->mesh().size() << exit(FatalIOError); } readOldTimeIfPresent(); return true; } return false; } // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * // template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensionSet& ds, const word& patchFieldType ) : Internal(io, mesh, ds, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldType), sources_() { if (debug) { InfoInFunction << "Constructing field" << endl << this->info() << endl; } readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensionSet& ds, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, mesh, ds, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field" << endl << this->info() << endl; } readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensioned& dt, const word& patchFieldType ) : Internal(io, mesh, dt, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldType), sources_() { if (debug) { InfoInFunction << "Constructing field" << endl << this->info() << endl; } boundaryField_ == dt.value(); readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensioned& dt, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, mesh, dt, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, patchFieldTypes, actualPatchTypes), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field" << endl << this->info() << endl; } boundaryField_ == dt.value(); readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const Internal& diField, const PtrField& ptfl, const HashPtrTable& stft ) : Internal(io, diField, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, ptfl), sources_(*this, stft) { if (debug) { InfoInFunction << "Constructing field from components" << endl << this->info() << endl; } readIfPresent(); } template class PrimitiveField> template Foam::GeometricField::GeometricField ( const IOobject& io, const InternalExpression& ie, const BoundaryExpression& be, const HashPtrTable& stft ) : Internal(io, ie, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), internalField(), be), sources_(*this, stft) { if (debug) { InfoInFunction << "Constructing field from component expressions" << endl << this->info() << endl; } readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensionSet& ds, const PrimitiveField& iField, const PtrField& ptfl, const HashPtrTable& stft ) : Internal(io, mesh, ds, iField), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), *this, ptfl), sources_(*this, stft) { if (debug) { InfoInFunction << "Constructing field from components" << endl << this->info() << endl; } } template class PrimitiveField> template Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensionSet& ds, const InternalExpression& ie, const BoundaryExpression& be, const HashPtrTable& stft ) : Internal(io, mesh, ds, ie), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary(), internalField(), be), sources_(*this, stft) { if (debug) { InfoInFunction << "Constructing field from components" << endl << this->info() << endl; } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dimensionSet& dims ) : Internal(io, mesh, dims, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary()), sources_() { readFields(); // Check compatibility between field and mesh if (this->size() != this->mesh().size()) { FatalIOErrorInFunction(this->readStream(typeName)) << " number of field elements = " << this->size() << " number of mesh elements = " << this->mesh().size() << exit(FatalIOError); } readOldTimeIfPresent(); if (debug) { InfoInFunction << "Finishing read-construction of" << endl << this->info() << endl; } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const GeoMesh& mesh, const dictionary& dict, const dimensionSet& dims ) : Internal(io, mesh, dims, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(mesh.boundary()), sources_() { readFields(dict); // Check compatibility between field and mesh if (this->size() != this->mesh().size()) { FatalErrorInFunction << " number of field elements = " << this->size() << " number of mesh elements = " << this->mesh().size() << exit(FatalIOError); } if (debug) { InfoInFunction << "Finishing dictionary-construct of " << endl << this->info() << endl; } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const GeometricField& gf ) : Internal(gf.internalField()), OldTimeField(gf), fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field as copy" << endl << this->info() << endl; } this->writeOpt() = IOobject::NO_WRITE; } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const GeometricField& gf ) : Internal(gf.internalField()), OldTimeField(gf), fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field as copy" << endl << this->info() << endl; } this->writeOpt() = IOobject::NO_WRITE; } template class PrimitiveField> Foam::GeometricField::GeometricField ( GeometricField&& gf ) : Internal(move(gf.internalFieldRef())), OldTimeField(move(gf)), fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field by moving" << endl << this->info() << endl; } this->writeOpt() = IOobject::NO_WRITE; } template class PrimitiveField> Foam::GeometricField::GeometricField ( const tmp>& tgf ) : Internal ( const_cast&>(tgf()), tgf.isTmp() ), OldTimeField(tgf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_), sources_(*this, tgf().sources_) { if (debug) { InfoInFunction << "Constructing field from tmp" << endl << this->info() << endl; } this->writeOpt() = IOobject::NO_WRITE; tgf.clear(); } template class PrimitiveField> template Foam::GeometricField::GeometricField ( const Expression& e ) : Internal(expression::access(e, GeometricField_InternalField())), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( internalField().mesh().boundary(), internalField(), expression::access ( e, expression::Value(), GeometricField_BoundaryField() ) ) { if (debug) { InfoInFunction << "Constructing field from expression" << nl << this->info() << endl; } this->writeOpt() = IOobject::NO_WRITE; } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const IOobject& io, const GeometricField& gf ) : Internal(io, gf.internalField(), false), OldTimeField(gf.timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field as copy resetting IO params" << endl << this->info() << endl; } if (!readIfPresent()) { copyOldTimes(io, gf); } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const tmp>& tgf ) : Internal ( io, const_cast&>(tgf()), tgf.isTmp(), false ), OldTimeField(tgf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_), sources_(*this, tgf().sources_) { if (debug) { InfoInFunction << "Constructing field from tmp resetting IO params" << endl << this->info() << endl; } tgf.clear(); readIfPresent(); } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const word& newName, const GeometricField& gf ) : Internal(newName, gf.internalField()), OldTimeField(gf.timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(*this, gf.boundaryField_), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field as copy resetting name" << endl << this->info() << endl; } copyOldTimes(newName, gf); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const word& newName, const tmp>& tgf ) : Internal ( newName, const_cast&>(tgf()), tgf.isTmp() ), OldTimeField(tgf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(*this, tgf().boundaryField_), sources_(*this, tgf().sources_) { if (debug) { InfoInFunction << "Constructing field from tmp resetting name" << endl << this->info() << endl; } tgf.clear(); } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const IOobject& io, const GeometricField& gf, const word& patchFieldType ) : Internal(io, gf.internalField(), false), OldTimeField(gf.timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, patchFieldType), sources_(*this, gf.sources_) { if (debug) { InfoInFunction << "Constructing field as copy resetting IO params" << endl << this->info() << endl; } boundaryField_ == gf.boundaryField_; if (!readIfPresent()) { copyOldTimes(io, gf); } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const tmp>& tgf, const word& patchFieldType ) : Internal ( io, const_cast&>(tgf()), tgf.isTmp(), false ), OldTimeField(tgf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, patchFieldType), sources_(*this, tgf().sources_) { if (debug) { InfoInFunction << "Constructing field as copy resetting IO params" << endl << this->info() << endl; } boundaryField_ == tgf().boundaryField_; tgf.clear(); readIfPresent(); } template class PrimitiveField> template Foam::GeometricField::GeometricField ( const IOobject& io, const Expression& e, const word& patchFieldType ) : Internal(io, expression::access(e, GeometricField_InternalField()), false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldType ), sources_() { if (debug) { InfoInFunction << "Constructing field as copy resetting IO params" << endl << this->info() << endl; } boundaryField_ == expression::access ( e, expression::Value(), GeometricField_BoundaryField() ); readIfPresent(); } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const IOobject& io, const DimensionedField& df, const word& patchFieldType ) : Internal(io, df, false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, patchFieldType), sources_() { if (debug) { InfoInFunction << "Constructing field from components" << endl << this->info() << endl; } if (!readIfPresent()) { boundaryField_.evaluate(); } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const tmp& tdf, const word& patchFieldType ) : Internal(io, const_cast(tdf()), tdf.isTmp(), false), OldTimeField(tdf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_(this->mesh().boundary(), *this, patchFieldType), sources_() { if (debug) { InfoInFunction << "Constructing field from components" << endl << this->info() << endl; } if (!readIfPresent()) { boundaryField_.evaluate(); } } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const IOobject& io, const GeometricField& gf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, gf.internalField(), false), OldTimeField(gf.timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldTypes, actualPatchTypes ), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field as copy resetting IO params and patch types" << endl << this->info() << endl; } boundaryField_ == gf.boundaryField_; if (!readIfPresent()) { copyOldTimes(io, gf); } } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const tmp>& tgf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal ( io, const_cast&>(tgf()), tgf.isTmp(), false ), OldTimeField(tgf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldTypes, actualPatchTypes ), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field from tmp resetting IO params and patch types" << endl << this->info() << endl; } boundaryField_ == tgf().boundaryField_; tgf.clear(); readIfPresent(); } template class PrimitiveField> template Foam::GeometricField::GeometricField ( const IOobject& io, const Expression& e, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, expression::access(e, GeometricField_InternalField()), false), OldTimeField(this->time().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldTypes, actualPatchTypes ), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field from tmp resetting IO params and patch types" << endl << this->info() << endl; } boundaryField_ == expression::access ( e, expression::Value(), GeometricField_BoundaryField() ); readIfPresent(); } template class PrimitiveField> template class PrimitiveField2> Foam::GeometricField::GeometricField ( const IOobject& io, const DimensionedField& df, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, df, false), OldTimeField(df.timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldTypes, actualPatchTypes ), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field from internal field and patch types" << endl << this->info() << endl; } readIfPresent(); } template class PrimitiveField> Foam::GeometricField::GeometricField ( const IOobject& io, const tmp& tdf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) : Internal(io, const_cast(tdf()), tdf.isTmp(), false), OldTimeField(tdf().timeIndex()), fieldPrevIterPtr_(nullptr), boundaryField_ ( this->mesh().boundary(), *this, patchFieldTypes, actualPatchTypes ), sources_(*this, fieldSourceTypes, fieldSourceErrorLocation) { if (debug) { InfoInFunction << "Constructing field from tmp internal field and patch types" << endl << this->info() << endl; } tdf.clear(); readIfPresent(); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::clone() const { return tmp> ( new GeometricField(*this) ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::cloneUnSliced() const { return tmp> ( new GeometricField ( IOobject ( this->name(), this->mesh().db().time().name(), this->mesh().db(), IOobject::NO_READ, IOobject::NO_WRITE, false ), *this, PatchField::calculatedType() ) ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& name, const Internal& diField, const PtrField& ptfl, const HashPtrTable& stft ) { const bool cacheTmp = diField.mesh().db().temporaryObjectCached(name); return tmp> ( new GeometricField ( IOobject ( name, diField.mesh().db().time().name(), diField.mesh().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), diField, ptfl, stft ), cacheTmp ); } template class PrimitiveField> template Foam::tmp> Foam::GeometricField::New ( const word& name, const InternalExpression& ie, const BoundaryExpression& be, const HashPtrTable& stft ) { const GeoMesh& mesh = expression::getFirst>(ie); const bool cacheTmp = mesh.db().temporaryObjectCached(name); return tmp> ( new GeometricField ( IOobject ( name, mesh.db().time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), ie, be, stft ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& name, const GeoMesh& mesh, const dimensionSet& ds, const word& patchFieldType ) { const bool cacheTmp = mesh.db().temporaryObjectCached(name); return tmp> ( new GeometricField ( IOobject ( name, mesh.db().time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), mesh, ds, patchFieldType ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& name, const GeoMesh& mesh, const dimensioned& dt, const word& patchFieldType ) { const bool cacheTmp = mesh.db().temporaryObjectCached(name); return tmp> ( new GeometricField ( IOobject ( name, mesh.db().time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), mesh, dt, patchFieldType ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& name, const GeoMesh& mesh, const dimensioned& dt, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) { const bool cacheTmp = mesh.db().temporaryObjectCached(name); return tmp> ( new GeometricField ( IOobject ( name, mesh.db().time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), mesh, dt, patchFieldTypes, actualPatchTypes, fieldSourceTypes, fieldSourceErrorLocation ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& newName, const tmp>& tgf ) { const bool cacheTmp = tgf().db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, tgf().instance(), tgf().local(), tgf().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), tgf ), cacheTmp ); } template class PrimitiveField> template class PrimitiveField2> Foam::tmp> Foam::GeometricField::New ( const word& newName, const GeometricField& gf, const word& patchFieldType ) { const bool cacheTmp = gf.db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, gf.instance(), gf.local(), gf.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), gf, patchFieldType ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& newName, const tmp>& tgf, const word& patchFieldType ) { const bool cacheTmp = tgf().db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, tgf().instance(), tgf().local(), tgf().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), tgf, patchFieldType ), cacheTmp ); } template class PrimitiveField> template class PrimitiveField2> Foam::tmp> Foam::GeometricField::New ( const word& newName, const DimensionedField& df, const word& patchFieldType ) { const bool cacheTmp = df.db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, df.instance(), df.local(), df.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), df, patchFieldType ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& newName, const tmp& tdf, const word& patchFieldType ) { const bool cacheTmp = tdf().db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, tdf().instance(), tdf().local(), tdf().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), tdf, patchFieldType ), cacheTmp ); } template class PrimitiveField> template Foam::tmp> Foam::GeometricField::New ( const word& newName, const Expression& e, const word& patchFieldType ) { return New(newName, eval(e), patchFieldType); } template class PrimitiveField> template class PrimitiveField2> Foam::tmp> Foam::GeometricField::New ( const word& newName, const GeometricField& gf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) { const bool cacheTmp = gf.db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, gf.instance(), gf.local(), gf.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), gf, patchFieldTypes, actualPatchTypes, fieldSourceTypes, fieldSourceErrorLocation ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& newName, const tmp>& tgf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) { const bool cacheTmp = tgf().db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, tgf().instance(), tgf().local(), tgf().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), tgf, patchFieldTypes, actualPatchTypes, fieldSourceTypes, fieldSourceErrorLocation ), cacheTmp ); } template class PrimitiveField> template class PrimitiveField2> Foam::tmp> Foam::GeometricField::New ( const word& newName, const DimensionedField& df, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) { const bool cacheTmp = df.db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, df.instance(), df.local(), df.db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), df, patchFieldTypes, actualPatchTypes, fieldSourceTypes, fieldSourceErrorLocation ), cacheTmp ); } template class PrimitiveField> Foam::tmp> Foam::GeometricField::New ( const word& newName, const tmp& tdf, const wordList& patchFieldTypes, const wordList& actualPatchTypes, const HashTable& fieldSourceTypes, const IOerrorLocation& fieldSourceErrorLocation ) { const bool cacheTmp = tdf().db().temporaryObjectCached(newName); return tmp> ( new GeometricField ( IOobject ( newName, tdf().instance(), tdf().local(), tdf().db(), IOobject::NO_READ, IOobject::NO_WRITE, cacheTmp ), tdf, patchFieldTypes, actualPatchTypes, fieldSourceTypes, fieldSourceErrorLocation ), cacheTmp ); } // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * * // template class PrimitiveField> Foam::GeometricField::~GeometricField() { this->db().cacheTemporaryObject(*this); clearPrevIter(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template class PrimitiveField> typename Foam::GeometricField::Internal& Foam::GeometricField::internalFieldRef() { this->setUpToDate(); storeOldTimes(); return *this; } template class PrimitiveField> typename Foam::GeometricField::Internal::FieldType& Foam::GeometricField::primitiveFieldRef() { this->setUpToDate(); storeOldTimes(); return *this; } template class PrimitiveField> typename Foam::GeometricField::Boundary& Foam::GeometricField::boundaryRef() { this->setUpToDate(); storeOldTimes(); return boundaryField_; } template class PrimitiveField> typename Foam::GeometricField::Boundary& Foam::GeometricField:: boundaryRefNoStoreOldTimes() { this->setUpToDate(); return boundaryField_; } template class PrimitiveField> typename Foam::GeometricField::BoundaryField& Foam::GeometricField::boundaryFieldRef() { this->setUpToDate(); storeOldTimes(); return boundaryField_; } template class PrimitiveField> typename Foam::GeometricField::BoundaryField& Foam::GeometricField:: boundaryFieldRefNoStoreOldTimes() { this->setUpToDate(); return boundaryField_; } template class PrimitiveField> typename Foam::GeometricField::Sources& Foam::GeometricField::sourcesRef() { this->setUpToDate(); storeOldTimes(); return sources_; } template class PrimitiveField> void Foam::GeometricField::storePrevIter() const { if (!fieldPrevIterPtr_) { if (debug) { InfoInFunction << "Allocating previous iteration field" << endl << this->info() << endl; } fieldPrevIterPtr_ = new GeometricField ( this->name() + "PrevIter", *this ); } else { *fieldPrevIterPtr_ == *this; } } template class PrimitiveField> void Foam::GeometricField::clearPrevIter() { deleteDemandDrivenData(fieldPrevIterPtr_); } template class PrimitiveField> const Foam::GeometricField& Foam::GeometricField::prevIter() const { if (!fieldPrevIterPtr_) { FatalErrorInFunction << "previous iteration field" << endl << this->info() << endl << " not stored." << " Use field.storePrevIter() at start of iteration." << abort(FatalError); } return *fieldPrevIterPtr_; } template class PrimitiveField> void Foam::GeometricField:: correctBoundaryConditions() { this->setUpToDate(); storeOldTimes(); boundaryField_.evaluate(); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::reset ( const GeometricField& gf ) { Internal::reset(gf); boundaryField_.reset(gf.boundary()); sources_.reset(*this, gf.sources()); } template class PrimitiveField> void Foam::GeometricField::reset ( const tmp>& tgf ) { const GeometricField& gf = tgf(); checkFieldAssignment(*this, gf); this->dimensions() = gf.dimensions(); if (tgf.isTmp()) { PrimitiveField::transfer(tgf.ref()); } else { PrimitiveField::operator=(gf.primitiveField()); } boundaryField_.reset(gf.boundary()); sources_.reset(*this, gf.sources()); tgf.clear(); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::reset ( const tmp>& tgf ) { reset(tgf()); tgf.clear(); } template class PrimitiveField> bool Foam::GeometricField::needReference() const { // Search all boundary conditions, if any are // fixed-value or mixed (Robin) do not set reference level for solution. bool needRef = true; forAll(boundaryField_, patchi) { if (boundaryField_[patchi].fixesValue()) { needRef = false; break; } } reduce(needRef, andOp()); return needRef; } template class PrimitiveField> void Foam::GeometricField::relax ( const scalar alpha ) { if (alpha < 1) { if (debug) { InfoInFunction << "Relaxing" << endl << this->info() << " by " << alpha << endl; } operator==(prevIter() + alpha*(*this - prevIter())); } } template class PrimitiveField> Foam::scalar Foam::GeometricField::relaxationFactor() const { if ( solutionControl::finalIteration(this->mesh()) && this->mesh().solution().relaxField(this->name() + "Final") ) { return this->mesh().solution().fieldRelaxationFactor ( this->name() + "Final" ); } else if (this->mesh().solution().relaxField(this->name())) { return this->mesh().solution().fieldRelaxationFactor(this->name()); } else { return 1; } } template class PrimitiveField> void Foam::GeometricField::relax() { relax(relaxationFactor()); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::relax ( const tmp>& tgf, const scalar alpha ) { if (alpha < 1) { if (debug) { InfoInFunction << "Relaxing" << endl << this->info() << " by " << alpha << endl; } operator==(*this + alpha*(tgf - *this)); } else { operator==(tgf); } } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::relax ( const tmp>& tgf ) { relax(tgf, relaxationFactor()); } template class PrimitiveField> Foam::word Foam::GeometricField::select ( bool final ) const { if (final) { return this->name() + "Final"; } else { return this->name(); } } template class PrimitiveField> void Foam::GeometricField::writeMinMax ( Ostream& os ) const { os << "min/max(" << this->name() << ") = " << Foam::min(*this).value() << ", " << Foam::max(*this).value() << endl; } template class PrimitiveField> bool Foam::GeometricField::writeData ( Ostream& os ) const { os << *this; return os.good(); } // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::replace ( const direction d, const GeometricField < typename GeometricField::cmptType, GeoMesh, PrimitiveField2 >& gcf ) { internalFieldRef().replace(d, gcf.internalField()); boundaryFieldRef().replace(d, gcf.boundaryField()); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::replace ( const direction d, const tmp < GeometricField < typename GeometricField::cmptType, GeoMesh, PrimitiveField2 > >& gcf ) { replace(d, gcf()); gcf.clear(); } template class PrimitiveField> template void Foam::GeometricField::replace ( const direction d, const Expression& e ) { internalFieldRef().replace ( d, expression::access ( e, GeometricField_InternalField() ) ); boundaryFieldRef().replace ( d, expression::access ( e, expression::Value(), GeometricField_BoundaryField() ) ); } template class PrimitiveField> void Foam::GeometricField::replace ( const direction d, const dimensioned& ds ) { internalFieldRef().replace(d, ds); boundaryFieldRef().replace(d, ds.value()); } template class PrimitiveField> void Foam::GeometricField::boundLower ( const dimensioned& lower ) { internalFieldRef().boundLower(lower); boundaryFieldRef().boundLower(lower.value()); } template class PrimitiveField> void Foam::GeometricField::boundUpper ( const dimensioned& upper ) { internalFieldRef().boundUpper(upper); boundaryFieldRef().boundUpper(upper.value()); } template class PrimitiveField> void Foam::GeometricField::bound ( const dimensioned& lower, const dimensioned& upper ) { internalFieldRef().bound(lower, upper); boundaryFieldRef().bound(lower.value(), upper.value()); } template class PrimitiveField> void Foam::GeometricField::negate() { internalFieldRef().negate(); boundaryFieldRef().negate(); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template class PrimitiveField> void Foam::GeometricField::operator= ( const GeometricField& gf ) { checkFieldAssignment(*this, gf); checkFieldOperation(*this, gf, "="); internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); } template class PrimitiveField> void Foam::GeometricField::operator= ( GeometricField&& gf ) { checkFieldAssignment(*this, gf); checkFieldOperation(*this, gf, "="); internalFieldRef() = move(gf.internalField()); boundaryFieldRef() = move(gf.boundaryField()); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::operator= ( const GeometricField& gf ) { checkFieldOperation(*this, gf, "="); internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); } template class PrimitiveField> void Foam::GeometricField::operator= ( const tmp>& tgf ) { const GeometricField& gf = tgf(); checkFieldAssignment(*this, gf); checkFieldOperation(*this, gf, "="); this->dimensions() = gf.dimensions(); if (tgf.isTmp()) { primitiveFieldRef().transfer(tgf.ref()); } else { primitiveFieldRef() = gf.primitiveField(); } boundaryFieldRef() = gf.boundaryField(); tgf.clear(); } template class PrimitiveField> template void Foam::GeometricField::operator= ( const Expression& e ) { internalFieldRef() = expression::access ( e, GeometricField_InternalField() ); boundaryFieldRef() = expression::access ( e, expression::Value(), GeometricField_BoundaryField() ); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::operator= ( const tmp>& tgf ) { const GeometricField& gf = tgf(); checkFieldOperation(*this, gf, "="); internalFieldRef() = gf.internalField(); boundaryFieldRef() = gf.boundaryField(); tgf.clear(); } template class PrimitiveField> void Foam::GeometricField::operator= ( const dimensioned& dt ) { internalFieldRef() = dt; boundaryFieldRef() = dt.value(); } template class PrimitiveField> void Foam::GeometricField::operator= ( const zero& ) { internalFieldRef() = Zero; boundaryFieldRef() = Zero; } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::operator== ( const GeometricField& gf ) { checkFieldOperation(*this, gf, "=="); internalFieldRef() = gf.internalField(); boundaryRef() == gf.boundary(); } template class PrimitiveField> void Foam::GeometricField::operator== ( const tmp>& tgf ) { const GeometricField& gf = tgf(); checkFieldOperation(*this, gf, "=="); this->dimensions() = gf.dimensions(); if (tgf.isTmp()) { primitiveFieldRef().transfer(tgf.ref()); } else { primitiveFieldRef() = gf.primitiveField(); } boundaryRef() == gf.boundary(); tgf.clear(); } template class PrimitiveField> template class PrimitiveField2> void Foam::GeometricField::operator== ( const tmp>& tgf ) { const GeometricField& gf = tgf(); checkFieldOperation(*this, gf, "="); internalFieldRef() = gf.internalField(); boundaryRef() == gf.boundary(); tgf.clear(); } template class PrimitiveField> template void Foam::GeometricField::operator== ( const Expression& e ) { internalFieldRef() = expression::access ( e, GeometricField_InternalField() ); boundaryRef() == expression::access ( e, expression::Value(), GeometricField_BoundaryField() ); } template class PrimitiveField> void Foam::GeometricField::operator== ( const dimensioned& dt ) { internalFieldRef() = dt; boundaryRef() == dt.value(); } template class PrimitiveField> void Foam::GeometricField::operator== ( const zero& ) { internalFieldRef() = Zero; boundaryRef() == Zero; } #define COMPUTED_ASSIGNMENT(TYPE, op) \ \ template class PrimitiveField> \ template class PrimitiveField2> \ void Foam::GeometricField::operator op \ ( \ const GeometricField& gf \ ) \ { \ checkFieldOperation(*this, gf, #op); \ \ internalFieldRef() op gf.internalField(); \ boundaryFieldRef() op gf.boundary(); \ } \ \ template class PrimitiveField> \ template class PrimitiveField2> \ void Foam::GeometricField::operator op \ ( \ const tmp>& tgf \ ) \ { \ operator op(tgf()); \ tgf.clear(); \ } \ \ template class PrimitiveField> \ template \ void Foam::GeometricField::operator op \ ( \ const Expression& e \ ) \ { \ internalFieldRef() op expression::access \ ( \ e, \ GeometricField_InternalField() \ ); \ \ boundaryFieldRef() op expression::access \ ( \ e, \ expression::Value(), \ GeometricField_BoundaryField() \ ); \ } \ \ template class PrimitiveField> \ void Foam::GeometricField::operator op \ ( \ const dimensioned& dt \ ) \ { \ internalFieldRef() op dt; \ boundaryFieldRef() op dt.value(); \ } COMPUTED_ASSIGNMENT(Type, +=) COMPUTED_ASSIGNMENT(Type, -=) COMPUTED_ASSIGNMENT(scalar, *=) COMPUTED_ASSIGNMENT(scalar, /=) #undef COMPUTED_ASSIGNMENT // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // template class PrimitiveField> Foam::Ostream& Foam::operator<< ( Ostream& os, const GeometricField& gf ) { gf().writeData(os, "internalField"); os << nl; gf.boundary().writeEntry("boundaryField", os); if (!gf.sources().empty()) { os << nl; gf.sources().writeEntry("sources", os); } // Check state of IOstream os.check ( "Ostream& operator<<(Ostream&, " "const GeometricField&)" ); return (os); } // * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * * // template class PrimitiveField> bool Foam::reusable ( const tmp>& tgf ) { typedef GeometricField geoField; if (tgf.isTmp()) { if (geoField::debug) { const geoField& gf = tgf(); const typename geoField::BoundaryField& gbf = gf.boundaryField(); forAll(gbf, patchi) { if ( !gbf[patchi].patch().constraint() && !isA(gbf[patchi]) ) { WarningInFunction << "Attempt to reuse temporary with non-reusable BC " << gbf[patchi].type() << endl; return false; } } } return true; } else { return false; } } template Foam::tmp> Foam::New ( const tmp>& tgf1, const word& name, const dimensionSet& dimensions, const bool initRet ) { GeometricField& gf1 = const_cast&>(tgf1()); if (reusable(tgf1)) { gf1.rename(name); gf1.dimensions().reset(dimensions); return tgf1; } else { tmp> rtgf ( GeometricField::New ( name, gf1.mesh(), dimensions ) ); if (initRet) { rtgf.ref() == tgf1(); } return rtgf; } } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #undef checkFieldAssignment #undef checkFieldOperation // ************************************************************************* //