/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "Surfaces_DimensionedFieldFunction.H"
#include "searchableSurfacesInsideFraction.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template
void Foam::DimensionedFieldFunctions::Surfaces::
readSurfacesAndValues()
{
const objectRegistry& db = this->field_.mesh().db();
surfacesPtr_.set
(
new searchableSurfaceList
(
IOobject
(
searchableSurfaceList::typeName,
db.time().constant(),
searchableSurface::geometryDir(db.time()),
db,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
surfacesDict_,
false
)
);
values_.setSize(surfacesPtr_().size());
forAll(surfacesPtr_(), i)
{
values_.set
(
i,
new dimensioned
(
"value",
this->field_.dimensions(),
surfacesDict_.subDict(surfacesPtr_()[i].name())
)
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template
Foam::DimensionedFieldFunctions::Surfaces::Surfaces
(
const dictionary& dict,
DimensionedFieldType& field
)
:
DimensionedFieldFunction(dict, field),
defaultValue_("defaultValue", this->field_.dimensions(), dict),
surfacesDict_(dict.subDict("surfaces"))
{
readSurfacesAndValues();
}
template
Foam::DimensionedFieldFunctions::Surfaces::Surfaces
(
const Surfaces& dff,
DimensionedFieldType& field
)
:
DimensionedFieldFunction(dff, field),
defaultValue_(dff.defaultValue_),
surfacesDict_(dff.surfacesDict_)
{
readSurfacesAndValues();
}
template
Foam::autoPtr
<
Foam::DimensionedFieldFunction
> Foam::DimensionedFieldFunctions::Surfaces::clone
(
DimensionedFieldType& field
) const
{
return autoPtr>
(
new Surfaces(*this, field)
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
void Foam::DimensionedFieldFunctions::Surfaces::evaluate()
{
this->field_ = defaultValue_;
forAll(surfacesPtr_(), i)
{
this->field_ += eval
(
DimensionedField
<
scalar,
typename DimensionedFieldType::GeoMesh_
>::New
(
IOobject::groupName("alpha", surfacesPtr_()[i].name()),
this->field_.mesh(),
dimless,
searchableSurfaces::insideFraction
(
surfacesPtr_()[i],
this->field_.mesh().poly()
)
)
*(values_[i] - this->field_)
);
}
}
template
void Foam::DimensionedFieldFunctions::Surfaces::write
(
Ostream& os
) const
{
writeEntry(os, defaultValue_);
writeEntry(os, surfacesDict_.dictName(), surfacesDict_);
}
// ************************************************************************* //