iterativeGaussGrad.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "iterativeGaussGrad.H"
29 #include "skewCorrectionVectors.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type>
35 <
37  <
41  >
42 >
44 (
45  const GeometricField<Type, fvPatchField, volMesh>& vsf,
46  const word& name
47 ) const
48 {
49  typedef typename outerProduct<vector, Type>::type GradType;
50  typedef GeometricField<GradType, fvPatchField, volMesh> GradFieldType;
51  typedef GeometricField<GradType, fvsPatchField, surfaceMesh>
52  GradSurfFieldType;
53  typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfFieldType;
54 
55  tmp<SurfFieldType> tssf = linearInterpolate(vsf);
56  const SurfFieldType& ssf = tssf.cref();
57 
58  tmp<GradFieldType> tgGrad = fv::gaussGrad<Type>::gradf(ssf, name);
59  GradFieldType& gGrad = tgGrad.ref();
60 
61  const skewCorrectionVectors& skv = skewCorrectionVectors::New(vsf.mesh());
62 
63  for (label i = 0; i < nIter_; ++i)
64  {
65  tmp<GradSurfFieldType> tsgGrad = linearInterpolate(gGrad);
66 
67  tmp<SurfFieldType> tcorr = skv() & tsgGrad;
68 
69  tcorr.ref().dimensions().reset(vsf.dimensions());
70 
71  if (vsf.mesh().relaxField("grad(" + vsf.name() + ")"))
72  {
73  const scalar relax =
74  vsf.mesh().fieldRelaxationFactor("grad(" + vsf.name() + ")");
75 
76  // relax*prediction + (1-relax)*old
77  gGrad *= (1.0 - relax);
78  gGrad += relax*fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
79  }
80  else
81  {
82  gGrad = fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
83  }
84  }
85 
87 
88  return tgGrad;
89 }
90 
91 
92 // ************************************************************************* //
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:47
skewCorrectionVectors.H
iterativeGaussGrad.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:57
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:45
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
correctBoundaryConditions
cellMask correctBoundaryConditions()
Foam::fv::iterativeGaussGrad::calcGrad
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Definition: DimensionedFieldReuseFunctions.H:100
Foam::linearInterpolate
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:108
Foam::roots::type
type
Definition: Roots.H:52
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:49
relax
UEqn relax()