From adf6869bbaa807679478c237f6f45ef9ebdb8635 Mon Sep 17 00:00:00 2001 From: Kutalmis Bercin Date: Fri, 26 Nov 2021 09:16:22 +0000 Subject: [PATCH] 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() iterativeGauss ; } --- src/finiteVolume/Make/files | 1 + .../iterativeGaussGrad/iterativeGaussGrad.C | 92 ++++++++++ .../iterativeGaussGrad/iterativeGaussGrad.H | 166 ++++++++++++++++++ .../iterativeGaussGrad/iterativeGaussGrads.C | 34 ++++ 4 files changed, 293 insertions(+) create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.C create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.H create mode 100644 src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrads.C diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index 69b9e9f830..855fb1fd6f 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -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 diff --git a/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.C b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.C new file mode 100644 index 0000000000..2cb9c875c1 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.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 . + +\*---------------------------------------------------------------------------*/ + +#include "iterativeGaussGrad.H" +#include "skewCorrectionVectors.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +template +Foam::tmp +< + Foam::GeometricField + < + typename Foam::outerProduct::type, + Foam::fvPatchField, + Foam::volMesh + > +> +Foam::fv::iterativeGaussGrad::calcGrad +( + const GeometricField& vsf, + const word& name +) const +{ + typedef typename outerProduct::type GradType; + typedef GeometricField GradFieldType; + typedef GeometricField + GradSurfFieldType; + typedef GeometricField SurfFieldType; + + tmp tssf = linearInterpolate(vsf); + const SurfFieldType& ssf = tssf.cref(); + + tmp tgGrad = fv::gaussGrad::gradf(ssf, name); + GradFieldType& gGrad = tgGrad.ref(); + + const skewCorrectionVectors& skv = skewCorrectionVectors::New(vsf.mesh()); + + for (label i = 0; i < nIter_; ++i) + { + tmp tsgGrad = linearInterpolate(gGrad); + + tmp 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::gradf(tcorr + ssf, name); + } + else + { + gGrad = fv::gaussGrad::gradf(tcorr + ssf, name); + } + } + + fv::gaussGrad::correctBoundaryConditions(vsf, gGrad); + + return tgGrad; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.H b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.H new file mode 100644 index 0000000000..209bfc89e2 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrad.H @@ -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 . + +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() iterativeGauss ; + } + \endverbatim + + and by using \c system/fvSolution: + \verbatim + relaxationFactors + { + fields + { + grad() ; + } + } + \endverbatim + +SourceFiles + iterativeGaussGrad.C + +\*---------------------------------------------------------------------------*/ + +#ifndef iterativeGaussGrad_H +#define iterativeGaussGrad_H + +#include "gaussGrad.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace fv +{ + +/*---------------------------------------------------------------------------*\ + Class iterativeGaussGrad Declaration +\*---------------------------------------------------------------------------*/ + +template +class iterativeGaussGrad +: + public fv::gaussGrad +{ + // 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(mesh), + nIter_(1) + {} + + //- Construct from mesh and Istream + iterativeGaussGrad(const fvMesh& mesh, Istream& schemeData) + : + gaussGrad(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::type, + fvPatchField, + volMesh + > + > calcGrad + ( + const GeometricField& vsf, + const word& name + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace fv + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "iterativeGaussGrad.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrads.C b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrads.C new file mode 100644 index 0000000000..36fd9868a1 --- /dev/null +++ b/src/finiteVolume/finiteVolume/gradSchemes/iterativeGaussGrad/iterativeGaussGrads.C @@ -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 . + +\*---------------------------------------------------------------------------*/ + +#include "iterativeGaussGrad.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +makeFvGradScheme(iterativeGaussGrad) + +// ************************************************************************* //