/*---------------------------------------------------------------------------*\ ========= | \\ / 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 "mappedValueFvPatchField.H" #include "mappedPolyPatch.H" #include "volFields.H" // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // template const Foam::mappedPatchBase& Foam::mappedValueFvPatchField::mapper() const { return mapperPtr_.valid() ? mapperPtr_() : mappedPatchBase::getMap(patch().poly()); } template const Foam::fvPatchField& Foam::mappedValueFvPatchField::nbrPatchField() const { const fvMesh& nbrMesh = refCast(this->mapper().nbrMesh()); const VolField& nbrField = this->mapper().sameRegion() && this->fieldName_ == internalField().name() ? refCast>(internalField()) : nbrMesh.template lookupObject>(this->fieldName_); const label nbrPatchi = this->mapper().nbrPolyPatch().index(); return nbrField.boundaryField()[nbrPatchi]; } template Foam::tmp> Foam::mappedValueFvPatchField::mappedValues ( const Field& nbrPatchField ) const { // Since we're inside initEvaluate/evaluate there might be processor // comms underway. Change the tag we use. int oldTag = UPstream::msgType(); UPstream::msgType() = oldTag + 1; // Map values tmp> tResult = this->mapper().fromNeighbour(nbrPatchField); // Set the average, if necessary if (setAverage_) { const Type nbrAverageValue = gSum(patch().magSf()*tResult()) /gSum(patch().magSf()); if (mag(nbrAverageValue)/mag(average_) > 0.5) { tResult.ref() *= mag(average_)/mag(nbrAverageValue); } else { tResult.ref() += average_ - nbrAverageValue; } } // Restore tag UPstream::msgType() = oldTag; return tResult; } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::mappedValueFvPatchField::mappedValueFvPatchField ( const fvPatch& p, const DimensionedField& iF ) : fixedValueFvPatchField(p, iF), fieldName_(iF.name()), setAverage_(false), average_(Zero), mapperPtr_(nullptr) {} template Foam::mappedValueFvPatchField::mappedValueFvPatchField ( const fvPatch& p, const DimensionedField& iF, const dictionary& dict ) : fixedValueFvPatchField(p, iF, dict), fieldName_(dict.lookupOrDefault("field", iF.name())), setAverage_ ( dict.lookupOrDefault("setAverage", dict.found("average")) ), average_ ( setAverage_ ? dict.lookup("average", iF.dimensions()) : Zero ), mapperPtr_ ( mappedPatchBase::specified(dict) ? new mappedPatchBase ( p.poly(), dict, mappedPatchBase::transformType::specified ) : nullptr ) { if (!mapperPtr_.valid() && !isA(p.poly())) { OStringStream str; str << "Field " << internalField().name() << " of type " << type() << " on patch " << patch().name() << " of type " << p.poly().type() << " does not " << "have mapping specified (i.e., neighbourPatch, and/or " << "neighbourRegion entries) nor is the patch of " << mappedPolyPatch::typeName << " type"; FatalIOErrorInFunction(dict) << stringOps::breakIntoIndentedLines(str.str()).c_str() << exit(FatalIOError); } this->mapper().validateForField ( *this, iF, dict, this->mapper().sameUntransformedPatch() && this->fieldName_ == internalField().name() ? mappedPatchBase::from::differentPatch : mappedPatchBase::from::any ); } template Foam::mappedValueFvPatchField::mappedValueFvPatchField ( const mappedValueFvPatchField& ptf, const fvPatch& p, const DimensionedField& iF, const fieldMapper& mapper ) : fixedValueFvPatchField(ptf, p, iF, mapper), fieldName_(ptf.fieldName_), setAverage_(ptf.setAverage_), average_(ptf.average_), mapperPtr_ ( ptf.mapperPtr_.valid() ? new mappedPatchBase(p.poly(), ptf.mapperPtr_()) : nullptr ) {} template Foam::mappedValueFvPatchField::mappedValueFvPatchField ( const mappedValueFvPatchField& ptf, const DimensionedField& iF ) : fixedValueFvPatchField(ptf, iF), fieldName_(ptf.fieldName_), setAverage_(ptf.setAverage_), average_(ptf.average_), mapperPtr_ ( ptf.mapperPtr_.valid() ? new mappedPatchBase(ptf.patch().poly(), ptf.mapperPtr_()) : nullptr ) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::mappedValueFvPatchField::map ( const fvPatchField& ptf, const fieldMapper& mapper ) { fixedValueFvPatchField::map(ptf, mapper); if (mapperPtr_.valid()) { mapperPtr_->clearOut(false); } } template void Foam::mappedValueFvPatchField::reset ( const fvPatchField& ptf ) { fixedValueFvPatchField::reset(ptf); if (mapperPtr_.valid()) { mapperPtr_->clearOut(false); } } template void Foam::mappedValueFvPatchField::updateCoeffs() { if (this->updated()) { return; } this->operator==(mappedValues(nbrPatchField())); fixedValueFvPatchField::updateCoeffs(); } template void Foam::mappedValueFvPatchField::write(Ostream& os) const { fvPatchField::write(os); writeEntryIfDifferent ( os, "field", internalField().name(), fieldName_ ); if (setAverage_) { writeEntry(os, "average", average_); } if (mapperPtr_.valid()) { mapperPtr_->write(os); } writeEntry(os, "value", *this); } // ************************************************************************* //