/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2023 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fixedGradientFaPatchField.H"
#include "dictionary.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template
bool Foam::fixedGradientFaPatchField::readGradientEntry
(
const dictionary& dict,
IOobjectOption::readOption readOpt
)
{
if (!IOobjectOption::isAnyRead(readOpt)) return false;
const auto& p = faPatchFieldBase::patch();
const auto* eptr = dict.findEntry("gradient", keyType::LITERAL);
if (eptr)
{
gradient_.assign(*eptr, p.size());
return true;
}
if (IOobjectOption::isReadRequired(readOpt))
{
FatalIOErrorInFunction(dict)
<< "Required entry 'gradient' : missing for patch " << p.name()
<< " in dictionary " << dict.relativeName() << nl
<< exit(FatalIOError);
}
return false;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
Foam::fixedGradientFaPatchField::fixedGradientFaPatchField
(
const faPatch& p,
const DimensionedField& iF
)
:
faPatchField(p, iF),
gradient_(p.size(), Zero)
{}
template
Foam::fixedGradientFaPatchField::fixedGradientFaPatchField
(
const faPatch& p,
const DimensionedField& iF,
const dictionary& dict,
IOobjectOption::readOption requireGrad
)
:
faPatchField(p, iF, dict, IOobjectOption::NO_READ),
gradient_(p.size())
{
if (readGradientEntry(dict, requireGrad))
{
evaluate();
}
else
{
// Not read (eg, optional and missing):
// - treat as zero-gradient, do not evaluate
faPatchField::extrapolateInternal();
gradient_ = Zero;
}
}
template
Foam::fixedGradientFaPatchField::fixedGradientFaPatchField
(
const fixedGradientFaPatchField& ptf,
const faPatch& p,
const DimensionedField& iF,
const faPatchFieldMapper& mapper
)
:
faPatchField(ptf, p, iF, mapper),
gradient_(ptf.gradient_, mapper)
{}
template
Foam::fixedGradientFaPatchField::fixedGradientFaPatchField
(
const fixedGradientFaPatchField& ptf
)
:
faPatchField(ptf),
gradient_(ptf.gradient_)
{}
template
Foam::fixedGradientFaPatchField::fixedGradientFaPatchField
(
const fixedGradientFaPatchField& ptf,
const DimensionedField& iF
)
:
faPatchField(ptf, iF),
gradient_(ptf.gradient_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template
void Foam::fixedGradientFaPatchField::autoMap
(
const faPatchFieldMapper& m
)
{
Field::autoMap(m);
gradient_.autoMap(m);
}
template
void Foam::fixedGradientFaPatchField::rmap
(
const faPatchField& ptf,
const labelList& addr
)
{
faPatchField::rmap(ptf, addr);
const fixedGradientFaPatchField& fgptf =
refCast>(ptf);
gradient_.rmap(fgptf.gradient_, addr);
}
template
void Foam::fixedGradientFaPatchField::evaluate(const Pstream::commsTypes)
{
if (!this->updated())
{
this->updateCoeffs();
}
Field::operator=
(
this->patchInternalField() + gradient_/this->patch().deltaCoeffs()
);
faPatchField::evaluate();
}
template
Foam::tmp>
Foam::fixedGradientFaPatchField::valueInternalCoeffs
(
const tmp&
) const
{
return tmp>::New(this->size(), pTraits::one);
}
template
Foam::tmp>
Foam::fixedGradientFaPatchField::valueBoundaryCoeffs
(
const tmp&
) const
{
return gradient()/this->patch().deltaCoeffs();
}
template
Foam::tmp>
Foam::fixedGradientFaPatchField::gradientInternalCoeffs() const
{
return tmp>::New(this->size(), Zero);
}
template
Foam::tmp>
Foam::fixedGradientFaPatchField::gradientBoundaryCoeffs() const
{
return gradient();
}
template
void Foam::fixedGradientFaPatchField::write(Ostream& os) const
{
faPatchField::write(os);
gradient_.writeEntry("gradient", os);
}
// ************************************************************************* //