Files
openfoam/src/finiteVolume/fields/fvPatchFields/basic/basicSymmetry/basicSymmetryFvPatchField.C
Mark Olesen 25139e492e ENH: replace patchField specializations with if constexpr
- simplifies future code changes

STYLE: noexcept access for wedgePatch methods
2025-05-28 17:50:55 +02:00

151 lines
4.0 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2025 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "basicSymmetryFvPatchField.H"
#include "symmTransformField.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::basicSymmetryFvPatchField<Type>::basicSymmetryFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
transformFvPatchField<Type>(p, iF)
{}
template<class Type>
Foam::basicSymmetryFvPatchField<Type>::basicSymmetryFvPatchField
(
const basicSymmetryFvPatchField<Type>& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
transformFvPatchField<Type>(ptf, p, iF, mapper)
{}
template<class Type>
Foam::basicSymmetryFvPatchField<Type>::basicSymmetryFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
transformFvPatchField<Type>(p, iF, dict)
{
this->evaluate();
}
template<class Type>
Foam::basicSymmetryFvPatchField<Type>::basicSymmetryFvPatchField
(
const basicSymmetryFvPatchField<Type>& ptf,
const DimensionedField<Type, volMesh>& iF
)
:
transformFvPatchField<Type>(ptf, iF)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::basicSymmetryFvPatchField<Type>::snGrad() const
{
if constexpr (!is_rotational_vectorspace_v<Type>)
{
// Rotational-invariant type : treat like zero-gradient
return tmp<Field<Type>>::New(this->size(), Foam::zero{});
}
else
{
tmp<vectorField> nHat = this->patch().nf();
const auto& dc = this->patch().deltaCoeffs();
const Field<Type> pif(this->patchInternalField());
return
(
(0.5*dc)
* (transform(I - 2.0*sqr(nHat), pif) - pif)
);
}
}
template<class Type>
void Foam::basicSymmetryFvPatchField<Type>::evaluate(const Pstream::commsTypes)
{
if (!this->updated())
{
this->updateCoeffs();
}
if constexpr (!is_rotational_vectorspace_v<Type>)
{
// Rotational-invariant type : treat like zero-gradient
this->extrapolateInternal();
}
else
{
tmp<vectorField> nHat = this->patch().nf();
const Field<Type> pif(this->patchInternalField());
Field<Type>::operator=
(
0.5*(pif + transform(I - 2.0*sqr(nHat), pif))
);
}
transformFvPatchField<Type>::evaluate();
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::basicSymmetryFvPatchField<Type>::snGradTransformDiag() const
{
tmp<vectorField> diag(cmptMag(this->patch().nf()));
return transformFieldMask<Type>(pow<vector, pTraits<Type>::rank>(diag));
}
// ************************************************************************* //