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-2023 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  scalar relax = 1;
64  const bool useRelax =
65  vsf.mesh().relaxField("grad(" + vsf.name() + ")", relax);
66 
67  for (label i = 0; i < nIter_; ++i)
68  {
69  tmp<GradSurfFieldType> tsgGrad = linearInterpolate(gGrad);
70 
71  tmp<SurfFieldType> tcorr = skv() & tsgGrad;
72 
73  tcorr.ref().dimensions().reset(vsf.dimensions());
74 
75  if (useRelax)
76  {
77  // relax*prediction + (1-relax)*old
78  gGrad *= (1.0 - relax);
79  gGrad += relax*fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
80  }
81  else
82  {
83  gGrad = fv::gaussGrad<Type>::gradf(tcorr + ssf, name);
84  }
85  }
86 
88 
89  return tgGrad;
90 }
91 
92 
93 // ************************************************************************* //
type
Types of root.
Definition: Roots.H:52
UEqn relax()
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > linearInterpolate(const GeometricField< Type, fvPatchField, volMesh > &vf)
Definition: linear.H:120
cellMask correctBoundaryConditions()
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:118
Generic GeometricField class.
Definition: areaFieldsFwd.H:50
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:45
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
virtual tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh > > calcGrad(const GeometricField< Type, fvPatchField, volMesh > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad for optional caching.
A class for managing temporary objects.
Definition: HashPtrTable.H:50