/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 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 "FunctionalDimensionedField.H" // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // template Foam::FunctionalDimensionedField::FunctionalDimensionedField ( const word& name, const word& funcName, const GeoMesh& mesh, const dimensionSet& dimensions, const dictionary& dict ) : DimensionedField ( IOobject ( word(name, '_', funcName), mesh.time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, false ), mesh, dimensions, false ), funcName_(funcName), funcPtr_ ( dict.isDict(funcName) ? DimensionedFieldFunction>::New ( dict.subDict(funcName), *this ) : autoPtr>> ( nullptr ) ) { if (funcPtr_.valid()) { if (mesh.time().completeCase()) { funcPtr_->evaluate(); } } else { this->primitiveFieldRef() = Field(funcName_, dimensions, dict, mesh.size()); } } template Foam::FunctionalDimensionedField::FunctionalDimensionedField ( const word& name, const word& funcName, const GeoMesh& mesh, const dimensionSet& dimensions, const dictionary& dict, const Type& defaultValue ) : DimensionedField ( IOobject ( word(name, '_', funcName), mesh.time().name(), mesh.db(), IOobject::NO_READ, IOobject::NO_WRITE, false ), mesh, dimensions, defaultValue ), funcName_(funcName), funcPtr_ ( dict.isDict(funcName) ? DimensionedFieldFunction>::New ( dict.subDict(funcName), *this ) : autoPtr>> ( nullptr ) ) { if (funcPtr_.valid()) { if (mesh.time().completeCase()) { funcPtr_->evaluate(); } } else if (dict.found(funcName)) { this->primitiveFieldRef() = Field(funcName_, dimensions, dict, mesh.size()); } else { this->primitiveFieldRef() = Field(mesh.size(), defaultValue); } } template Foam::FunctionalDimensionedField::FunctionalDimensionedField ( const FunctionalDimensionedField& udff, const GeoMesh& mesh ) : DimensionedField ( udff, mesh, udff.dimensions(), false ), funcName_(udff.funcName_), funcPtr_ ( udff.funcPtr_.valid() ? udff.funcPtr_->clone(*this) : autoPtr>> ( nullptr ) ) {} template Foam::FunctionalDimensionedField::FunctionalDimensionedField ( const FunctionalDimensionedField& udff, const GeoMesh& mesh, const fieldMapper& mapper ) : DimensionedField ( udff, mesh, udff.dimensions(), false ), funcName_(udff.funcName_), funcPtr_ ( udff.funcPtr_.valid() ? udff.funcPtr_->clone(*this) : autoPtr>> ( nullptr ) ) { if (!funcPtr_.valid()) { mapper(*this, udff); } } template Foam::FunctionalDimensionedField::FunctionalDimensionedField ( const FunctionalDimensionedField& udff ) : DimensionedField(udff), funcName_(udff.funcName_), funcPtr_ ( udff.funcPtr_.valid() ? udff.funcPtr_->clone(*this) : autoPtr>> ( nullptr ) ) {} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template void Foam::FunctionalDimensionedField::map ( const DimensionedField& df, const fieldMapper& mapper ) { if (!mapper.direct() && funcPtr_.valid()) { this->setSize(this->mesh().size()); funcPtr_->reset(); } else { mapper(*this, df); } } template void Foam::FunctionalDimensionedField::reset() { this->setSize(this->mesh().size()); if (funcPtr_.valid()) { funcPtr_->reset(); } } template bool Foam::FunctionalDimensionedField::update() { if (funcPtr_.valid()) { return funcPtr_->update(); } else { return false; } } template void Foam::FunctionalDimensionedField::write(Ostream& os) const { if (funcPtr_.valid()) { funcPtr_->write(os); } } template void Foam::writeEntry ( Ostream& os, const FunctionalDimensionedField& udff ) { if (udff.funcPtr_.valid()) { writeEntry(os, udff.funcName_, *udff.funcPtr_); } else { writeEntry(os, udff.funcName_, udff.primitiveField()); } } // ************************************************************************* //