/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2025-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 "CloudAverageField.H" #include "LagrangianFields.H" #include "LagrangianSubFields.H" #include "fvMesh.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template template void Foam::CloudAverageField::op ( MethodWeightSum mws, MethodNoWeightSum mnws, const LagrangianSubMesh& subMesh, const Args& ... args ) const { tcellWeightSum_.valid() ? ( notNull(weightPsiOrPsiState_) ? (psiAveragePtr_().*mws) ( subMesh.sub(weightPsiOrPsiState_), args ... ) // isNull(weightPsiOrPsiState_) : (psiAveragePtr_().*mws) ( toSubField(weightPsiOrPsiDerived_(subMesh)), args ... ) ) : ( notNull(weightState_) && notNull(weightPsiOrPsiState_) ? (psiAveragePtr_().*mnws) ( subMesh.sub(weightState_), subMesh.sub(weightPsiOrPsiState_), args ... ) : notNull(weightState_) && isNull(weightPsiOrPsiState_) ? (psiAveragePtr_().*mnws) ( subMesh.sub(weightState_), toSubField(weightPsiOrPsiDerived_(subMesh)), args ... ) : isNull(weightState_) && notNull(weightPsiOrPsiState_) ? (psiAveragePtr_().*mnws) ( toSubField(weightDerived_(subMesh)), subMesh.sub(weightPsiOrPsiState_), args ... ) // isNull(weightState_) && isNull(weightPsiOrPsiState_) : (psiAveragePtr_().*mnws) ( toSubField(weightDerived_(subMesh)), toSubField(weightPsiOrPsiDerived_(subMesh)), args ... ) ); } template Foam::tmp> Foam::CloudAverageField::interpolate ( const LagrangianModelRef&, const LagrangianSubMesh& subMesh ) const { const LagrangianMesh& mesh = subMesh.mesh(); if (psiAverageState_ == psiAverageState::removed) { FatalErrorInFunction << "Cannot interpolate an average that has removed elements" << exit(FatalError); } if (!psiAveragePtr_.valid()) { psiAveragePtr_ = tcellWeightSum_.valid() ? ( notNull(weightPsiOrPsiState_) ? LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), tcellWeightSum_(), weightPsiOrPsiState_(mesh) ) // isNull(weightPsiOrPsiState_) : LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), tcellWeightSum_(), weightPsiOrPsiDerived_(mesh)() ) ) : ( notNull(weightState_) && notNull(weightPsiOrPsiState_) ? LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), weightState_(mesh), weightPsiOrPsiState_(mesh) ) : notNull(weightState_) && isNull(weightPsiOrPsiState_) ? LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), weightState_(mesh), weightPsiOrPsiDerived_(mesh)() ) : isNull(weightState_) && notNull(weightPsiOrPsiState_) ? LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), weightDerived_(mesh)(), weightPsiOrPsiState_(mesh) ) // isNull(weightState_) && isNull(weightPsiOrPsiState_) : LagrangianAverage::New ( word(mesh.schemes().averaging(this->name_)), word("average(", this->name_, ')'), weightDerived_(mesh)(), weightPsiOrPsiDerived_(mesh)() ) ); // Pointers to average manipulation methods void (LagrangianAverage::*removeWeightSum) ( const LagrangianSubSubField& ) = &LagrangianAverage::remove; void (LagrangianAverage::*removeNoWeightSum) ( const LagrangianSubSubField&, const LagrangianSubSubField& ) = &LagrangianAverage::remove; void (LagrangianAverage::*addWeightSum) ( const LagrangianSubSubField&, const bool ) = &LagrangianAverage::add; void (LagrangianAverage::*addNoWeightSum) ( const LagrangianSubSubField&, const LagrangianSubSubField&, const bool ) = &LagrangianAverage::add; switch (psiAverageState_) { case psiAverageState::removed: op(removeWeightSum, removeNoWeightSum, subMesh); break; case psiAverageState::complete: break; case psiAverageState::cached: op(removeWeightSum, removeNoWeightSum, subMesh); op(addWeightSum, addNoWeightSum, subMesh, true); break; } } return psiAveragePtr_->interpolate(subMesh); } // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::CloudAverageField::CloudAverageField ( const word& name, const DimensionedField& cellWeightSum, const CloudDerivedField& weightPsi ) : CloudDerivedField(name, *this, &CloudAverageField::interpolate), tcellWeightSum_(cellWeightSum), weightState_(NullObjectRef>()), weightDerived_(NullObjectRef>()), weightPsiOrPsiState_(NullObjectRef>()), weightPsiOrPsiDerived_(weightPsi), psiAveragePtr_(nullptr), psiAverageState_(psiAverageState::complete) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::CloudAverageField::remove(const LagrangianSubMesh& subMesh) { psiAverageState_ = psiAverageState::removed; if (!psiAveragePtr_.valid()) return; CloudDerivedField::clear(false); // Pointers to average manipulation methods void (LagrangianAverage::*removeWeightSum) ( const LagrangianSubSubField& ) = &LagrangianAverage::remove; void (LagrangianAverage::*removeNoWeightSum) ( const LagrangianSubSubField&, const LagrangianSubSubField& ) = &LagrangianAverage::remove; op(removeWeightSum, removeNoWeightSum, subMesh); } template void Foam::CloudAverageField::add ( const LagrangianSubMesh& subMesh, const bool cache ) { psiAverageState_ = cache ? psiAverageState::cached : psiAverageState::complete; if (!psiAveragePtr_.valid()) return; CloudDerivedField::clear(false); // Pointers to average manipulation methods void (LagrangianAverage::*addWeightSum) ( const LagrangianSubSubField&, const bool ) = &LagrangianAverage::add; void (LagrangianAverage::*addNoWeightSum) ( const LagrangianSubSubField&, const LagrangianSubSubField&, const bool ) = &LagrangianAverage::add; op(addWeightSum, addNoWeightSum, subMesh, cache); } template void Foam::CloudAverageField::correct ( const LagrangianSubMesh& subMesh, const bool cache ) { psiAverageState_ = cache ? psiAverageState::cached : psiAverageState::complete; if (!psiAveragePtr_.valid()) return; CloudDerivedField::clear(!cache); // Pointers to average manipulation methods void (LagrangianAverage::*correctWeightSum) ( const LagrangianSubSubField&, const bool ) = &LagrangianAverage::correct; void (LagrangianAverage::*correctNoWeightSum) ( const LagrangianSubSubField&, const LagrangianSubSubField&, const bool ) = &LagrangianAverage::correct; op(correctWeightSum, correctNoWeightSum, subMesh, cache); } template void Foam::CloudAverageField::reset() { CloudDerivedField::clear(true); psiAveragePtr_.clear(); psiAverageState_ = psiAverageState::complete; } // ************************************************************************* //