ENH: gradSchemes: new gradient scheme iterativeGaussGrad
A second-order gradient scheme using face-interpolation, Gauss' theorem and iterative skew correction. Minimal example by using system/fvSchemes: gradSchemes { grad(<term>) iterativeGauss <interpolation scheme> <number of iters>; }
This commit is contained in:
parent
563456087c
commit
adf6869bba
@ -433,6 +433,7 @@ $(divSchemes)/gaussDivScheme/gaussDivSchemes.C
|
||||
gradSchemes = finiteVolume/gradSchemes
|
||||
$(gradSchemes)/gradScheme/gradSchemes.C
|
||||
$(gradSchemes)/gaussGrad/gaussGrads.C
|
||||
$(gradSchemes)/iterativeGaussGrad/iterativeGaussGrads.C
|
||||
|
||||
$(gradSchemes)/leastSquaresGrad/leastSquaresVectors.C
|
||||
$(gradSchemes)/leastSquaresGrad/leastSquaresGrads.C
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 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 "iterativeGaussGrad.H"
|
||||
#include "skewCorrectionVectors.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
Foam::tmp
|
||||
<
|
||||
Foam::GeometricField
|
||||
<
|
||||
typename Foam::outerProduct<Foam::vector, Type>::type,
|
||||
Foam::fvPatchField,
|
||||
Foam::volMesh
|
||||
>
|
||||
>
|
||||
Foam::fv::iterativeGaussGrad<Type>::calcGrad
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& vsf,
|
||||
const word& name
|
||||
) const
|
||||
{
|
||||
typedef typename outerProduct<vector, Type>::type GradType;
|
||||
typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
|
||||
typedef GeometricField<GradType, fvsPatchField, surfaceMesh>
|
||||
GradSurfFieldType;
|
||||
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfFieldType;
|
||||
|
||||
tmp<SurfFieldType> tssf = linearInterpolate(vsf);
|
||||
const SurfFieldType& ssf = tssf.cref();
|
||||
|
||||
tmp<GradFieldType> tgGrad = fv::gaussGrad<Type>::gradf(ssf, name);
|
||||
GradFieldType& gGrad = tgGrad.ref();
|
||||
|
||||
const skewCorrectionVectors& skv = skewCorrectionVectors::New(vsf.mesh());
|
||||
|
||||
for (label i = 0; i < nIter_; ++i)
|
||||
{
|
||||
tmp<GradSurfFieldType> tsgGrad = linearInterpolate(gGrad);
|
||||
|
||||
tmp<SurfFieldType> tcorr = skv() & tsgGrad;
|
||||
|
||||
tcorr.ref().dimensions().reset(vsf.dimensions());
|
||||
|
||||
if (vsf.mesh().relaxField("grad(" + vsf.name() + ")"))
|
||||
{
|
||||
const scalar relax =
|
||||
vsf.mesh().fieldRelaxationFactor("grad(" + vsf.name() + ")");
|
||||
|
||||
// relax*prediction + (1-relax)*old
|
||||
gGrad *= (1.0 - relax);
|
||||
gGrad += relax*fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
gGrad = fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
|
||||
}
|
||||
}
|
||||
|
||||
fv::gaussGrad<Type>::correctBoundaryConditions(vsf, gGrad);
|
||||
|
||||
return tgGrad;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
@ -0,0 +1,166 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 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/>.
|
||||
|
||||
Class
|
||||
Foam::fv::iterativeGaussGrad
|
||||
|
||||
Description
|
||||
A second-order gradient scheme using face-interpolation,
|
||||
Gauss' theorem and iterative skew correction.
|
||||
|
||||
Usage
|
||||
Minimal example by using \c system/fvSchemes:
|
||||
\verbatim
|
||||
gradSchemes
|
||||
{
|
||||
grad(<term>) iterativeGauss <interpolation scheme> <number of iters>;
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
and by using \c system/fvSolution:
|
||||
\verbatim
|
||||
relaxationFactors
|
||||
{
|
||||
fields
|
||||
{
|
||||
grad(<term>) <relaxation factor>;
|
||||
}
|
||||
}
|
||||
\endverbatim
|
||||
|
||||
SourceFiles
|
||||
iterativeGaussGrad.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef iterativeGaussGrad_H
|
||||
#define iterativeGaussGrad_H
|
||||
|
||||
#include "gaussGrad.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace fv
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class iterativeGaussGrad Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Type>
|
||||
class iterativeGaussGrad
|
||||
:
|
||||
public fv::gaussGrad<Type>
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Number of skew-correction iterations
|
||||
label nIter_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- No copy construct
|
||||
iterativeGaussGrad(const iterativeGaussGrad&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const iterativeGaussGrad&) = delete;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
TypeName("iterativeGauss");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from mesh
|
||||
iterativeGaussGrad(const fvMesh& mesh)
|
||||
:
|
||||
gaussGrad<Type>(mesh),
|
||||
nIter_(1)
|
||||
{}
|
||||
|
||||
//- Construct from mesh and Istream
|
||||
iterativeGaussGrad(const fvMesh& mesh, Istream& schemeData)
|
||||
:
|
||||
gaussGrad<Type>(mesh, schemeData),
|
||||
nIter_(readLabel(schemeData))
|
||||
{
|
||||
if (nIter_ <= 0)
|
||||
{
|
||||
FatalIOErrorInFunction(schemeData)
|
||||
<< "nIter = " << nIter_
|
||||
<< " should be > 0"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return the gradient of the given field
|
||||
//- to the gradScheme::grad for optional caching
|
||||
virtual tmp
|
||||
<
|
||||
GeometricField
|
||||
<
|
||||
typename outerProduct<vector, Type>::type,
|
||||
fvPatchField,
|
||||
volMesh
|
||||
>
|
||||
> calcGrad
|
||||
(
|
||||
const GeometricField<Type, fvPatchField, volMesh>& vsf,
|
||||
const word& name
|
||||
) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace fv
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "iterativeGaussGrad.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
@ -0,0 +1,34 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 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 "iterativeGaussGrad.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
makeFvGradScheme(iterativeGaussGrad)
|
||||
|
||||
// ************************************************************************* //
|
Loading…
Reference in New Issue
Block a user