/*---------------------------------------------------------------------------*\ ========= | \\ / 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 "CloudStateFieldRef.H" #include "toSubField.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::CloudStateFieldRef::CloudStateFieldRef ( LagrangianDynamicField& ref ) : ref_(ref), psiAllPtr_(ref_.mesh().subAll().sub(ref_).ptr()) {} // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // template const Foam::word& Foam::CloudStateFieldRef::name() const { return ref_.name(); } template const Foam::LagrangianMesh& Foam::CloudStateFieldRef::mesh() const { return ref_.mesh(); } template const Foam::dimensionSet& Foam::CloudStateFieldRef::dimensions() const { return ref_.dimensions(); } template const Foam::LagrangianSubSubField& Foam::CloudStateFieldRef::ref ( const LagrangianSubMesh& subMesh ) const { // Error if this is the all-mesh if (&subMesh == &subMesh.mesh().subAll()) { FatalErrorInFunction << "Non-constant access is not provided to the all-mesh sub-field" << exit(FatalError); } // Evaluate and store if it doesn't already exist for the sub-mesh if (!psiSubSubPtr_.valid() || psiSubSubMeshIndex_ != subMesh.index()) { psiSubSubPtr_.reset(subMesh.sub(ref_).ptr()); psiSubSubMeshIndex_ = subMesh.index(); } return psiSubSubPtr_(); } template Foam::LagrangianSubSubField& Foam::CloudStateFieldRef::ref ( const LagrangianSubMesh& subMesh ) { // Evaluate and store if it doesn't already exist for the sub-mesh static_cast&>(*this).ref(subMesh); return psiSubSubPtr_(); } // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template Foam::CloudStateFieldRef::operator const Foam::LagrangianDynamicField&() const { return ref_; } template Foam::CloudStateFieldRef::operator LagrangianDynamicField&() { return ref_; } template const Foam::LagrangianDynamicField& Foam::CloudStateFieldRef::operator()(const LagrangianMesh&) const { return ref_; } template const Foam::LagrangianSubSubField& Foam::CloudStateFieldRef::operator() ( const LagrangianSubMesh& subMesh ) const { // Update and return the all-mesh field if (&subMesh == &subMesh.mesh().subAll()) { psiAllPtr_->UList::shallowCopy(ref_); return psiAllPtr_(); } // Evaluate and store if it doesn't already exist for the sub-mesh if (!psiSubSubPtr_.valid() || psiSubSubMeshIndex_ != subMesh.index()) { psiSubSubPtr_.reset(subMesh.sub(ref_).ptr()); psiSubSubMeshIndex_ = subMesh.index(); } return psiSubSubPtr_(); } template Foam::tmp> Foam::CloudStateFieldRef::operator() ( const LagrangianModelRef& model, const LagrangianSubMesh& subMesh ) const { if (model.isSource()) { return toSubField ( ref_.sources()[model.source().name()].value ( model.source(), subMesh // !!! <-- Replace with model.S() ) ); } if (model.isInjection()) { return toSubField ( ref_.sources()[model.injection().name()].value ( model.injection(), subMesh ) ); } return tmp>(operator()(subMesh)); } // ************************************************************************* //