/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "FunctionalGeometricField.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
void Foam::FunctionalGeometricField::setPatchFields()
{
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFieldPtrs_.set
(
patchi,
new SlicedDimensionedField
(
IOobject
(
this->name(),
this->mesh().time().name(),
this->mesh().db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
this->mesh().boundary()[patchi],
this->dimensions(),
this->boundaryFieldRef()[patchi]
)
);
}
}
}
template
bool Foam::FunctionalGeometricField::readFuncs
(
const dictionary& dict
)
{
if (!dict.isDict(funcName_)) return false;
internalFuncPtr_.set
(
DimensionedFieldFunction>::New
(
dict.subDict(funcName_),
this->internalFieldRef()
).ptr()
);
setPatchFields();
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFuncPtrs_.set
(
patchi,
DimensionedFieldFunction>::New
(
dict.subDict(funcName_),
patchFieldPtrs_[patchi]
).ptr()
);
}
}
return true;
}
template
void Foam::FunctionalGeometricField::cloneFuncs
(
const FunctionalGeometricField& udff
)
{
if (!udff.internalFuncPtr_.valid()) return;
internalFuncPtr_.set
(
udff.internalFuncPtr_.clone
(
this->internalFieldRef()
).ptr()
);
setPatchFields();
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFuncPtrs_.set
(
patchi,
udff.boundaryFuncPtrs_[patchi].clone
(
patchFieldPtrs_[patchi]
).ptr()
);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::FunctionalGeometricField::FunctionalGeometricField
(
const word& name,
const word& funcName,
const GeoMesh& mesh,
const dimensionSet& dimensions,
const dictionary& dict
)
:
GeometricField
(
IOobject
(
name,
mesh.time().name(),
mesh.db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
dimensions,
GeometricField::PatchField::calculatedType()
),
funcName_(funcName),
internalFuncPtr_(),
patchFieldPtrs_(mesh.boundary().size()),
patchFuncPtrs_(mesh.boundary().size()),
defaultValue_
(
readFuncs(dict)
? pTraits::nan
: dimensioned(funcName, dimensions, dict).value()
)
{
if (internalFuncPtr_.valid())
{
if (mesh.time().completeCase())
{
internalFuncPtr_->evaluate();
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFuncPtrs_[patchi].evaluate();
}
}
this->correctBoundaryConditions();
}
}
else
{
*this == dimensioned(dimensions, defaultValue_);
}
}
template
Foam::FunctionalGeometricField::FunctionalGeometricField
(
const word& name,
const word& funcName,
const GeoMesh& mesh,
const dimensionSet& dimensions,
const dictionary& dict,
const Type& defaultValue
)
:
GeometricField
(
IOobject
(
name,
mesh.time().name(),
mesh.db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh,
dimensions,
defaultValue
),
funcName_(funcName),
internalFuncPtr_(),
patchFieldPtrs_(mesh.boundary().size()),
patchFuncPtrs_(mesh.boundary().size()),
defaultValue_
(
readFuncs(dict)
? pTraits::nan
: dict.found(funcName)
? dimensioned(funcName, dimensions, dict).value()
: defaultValue_
)
{
if (internalFuncPtr_.valid())
{
if (mesh.time().completeCase())
{
internalFuncPtr_->evaluate();
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFuncPtrs_[patchi].evaluate();
}
}
this->correctBoundaryConditions();
}
}
else
{
*this == dimensioned(dimensions, defaultValue_);
}
}
template
Foam::FunctionalGeometricField::FunctionalGeometricField
(
const FunctionalGeometricField& udff,
const GeoMesh& mesh
)
:
GeometricField(udff, mesh, udff.dimensions()),
funcName_(udff.funcName_),
internalFuncPtr_(),
patchFieldPtrs_(mesh.boundary().size()),
patchFuncPtrs_(mesh.boundary().size()),
defaultValue_(udff.defaultValue_)
{
cloneFuncs(udff);
}
template
Foam::FunctionalGeometricField::FunctionalGeometricField
(
const FunctionalGeometricField& udff
)
:
GeometricField(udff),
funcName_(udff.funcName_),
internalFuncPtr_(),
patchFieldPtrs_(this->mesh().boundary().size()),
patchFuncPtrs_(this->mesh().boundary().size()),
defaultValue_(udff.defaultValue_)
{
cloneFuncs(udff);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
void Foam::FunctionalGeometricField::reset()
{
GeometricField::reset
(
GeometricField
(
static_cast(*this),
this->mesh(),
dimensioned("NaN", this->dimensions(), pTraits::nan)
)
);
setPatchFields();
if (internalFuncPtr_.valid())
{
internalFuncPtr_->reset();
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
patchFuncPtrs_[patchi].reset();
}
}
this->correctBoundaryConditions();
}
else
{
*this == dimensioned(this->dimensions(), defaultValue_);
}
}
template
bool Foam::FunctionalGeometricField::update()
{
if (internalFuncPtr_.valid())
{
bool result = false;
result = internalFuncPtr_->update() || result;
forAll(this->mesh().boundary(), patchi)
{
if (!this->mesh().boundary()[patchi].constraint())
{
result = patchFuncPtrs_[patchi].update() || result;
}
}
if (result) this->correctBoundaryConditions();
return result;
}
else
{
return false;
}
}
template
void Foam::FunctionalGeometricField::write(Ostream& os) const
{
if (internalFuncPtr_.valid())
{
internalFuncPtr_->write(os);
}
}
template
void Foam::writeEntry
(
Ostream& os,
const FunctionalGeometricField& udff
)
{
if (udff.internalFuncPtr_.valid())
{
writeEntry(os, udff.funcName_, udff.internalFuncPtr_());
}
else
{
writeEntry(os, udff.funcName_, udff.defaultValue_);
}
}
// ************************************************************************* //