cellLimitedGrad.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) 2018 OpenFOAM Foundation
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 "cellLimitedGrad.H"
29 #include "gaussGrad.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 template<class Type, class Limiter>
35 (
36  const Field<scalar>& limiter,
37  Field<vector>& gIf
38 ) const
39 {
40  gIf *= limiter;
41 }
42 
43 
44 template<class Type, class Limiter>
46 (
47  const Field<vector>& limiter,
48  Field<tensor>& gIf
49 ) const
50 {
51  forAll(gIf, celli)
52  {
53  gIf[celli] = tensor
54  (
55  cmptMultiply(limiter[celli], gIf[celli].x()),
56  cmptMultiply(limiter[celli], gIf[celli].y()),
57  cmptMultiply(limiter[celli], gIf[celli].z())
58  );
59  }
60 }
61 
62 
63 template<class Type, class Limiter>
65 <
67  <
71  >
72 >
74 (
75  const GeometricField<Type, fvPatchField, volMesh>& vsf,
76  const word& name
77 ) const
78 {
79  const fvMesh& mesh = vsf.mesh();
80 
81  tmp
82  <
83  GeometricField
84  <typename outerProduct<vector, Type>::type, fvPatchField, volMesh>
85  > tGrad = basicGradScheme_().calcGrad(vsf, name);
86 
87  if (k_ < SMALL)
88  {
89  return tGrad;
90  }
91 
92  GeometricField
93  <
95  fvPatchField,
96  volMesh
97  >& g = tGrad.ref();
98 
99  const labelUList& owner = mesh.owner();
100  const labelUList& neighbour = mesh.neighbour();
101 
102  const volVectorField& C = mesh.C();
103  const surfaceVectorField& Cf = mesh.Cf();
104 
105  Field<Type> maxVsf(vsf.primitiveField());
106  Field<Type> minVsf(vsf.primitiveField());
107 
108  forAll(owner, facei)
109  {
110  label own = owner[facei];
111  label nei = neighbour[facei];
112 
113  const Type& vsfOwn = vsf[own];
114  const Type& vsfNei = vsf[nei];
115 
116  maxVsf[own] = max(maxVsf[own], vsfNei);
117  minVsf[own] = min(minVsf[own], vsfNei);
118 
119  maxVsf[nei] = max(maxVsf[nei], vsfOwn);
120  minVsf[nei] = min(minVsf[nei], vsfOwn);
121  }
122 
123 
124  const typename GeometricField<Type, fvPatchField, volMesh>::Boundary& bsf =
125  vsf.boundaryField();
126 
127  forAll(bsf, patchi)
128  {
129  const fvPatchField<Type>& psf = bsf[patchi];
130  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
131 
132  if (psf.coupled())
133  {
134  const Field<Type> psfNei(psf.patchNeighbourField());
135 
136  forAll(pOwner, pFacei)
137  {
138  label own = pOwner[pFacei];
139  const Type& vsfNei = psfNei[pFacei];
140 
141  maxVsf[own] = max(maxVsf[own], vsfNei);
142  minVsf[own] = min(minVsf[own], vsfNei);
143  }
144  }
145  else
146  {
147  forAll(pOwner, pFacei)
148  {
149  label own = pOwner[pFacei];
150  const Type& vsfNei = psf[pFacei];
151 
152  maxVsf[own] = max(maxVsf[own], vsfNei);
153  minVsf[own] = min(minVsf[own], vsfNei);
154  }
155  }
156  }
157 
158  maxVsf -= vsf;
159  minVsf -= vsf;
160 
161  if (k_ < 1.0)
162  {
163  const Field<Type> maxMinVsf((1.0/k_ - 1.0)*(maxVsf - minVsf));
164  maxVsf += maxMinVsf;
165  minVsf -= maxMinVsf;
166  }
167 
168 
169  // Create limiter initialized to 1
170  // Note: the limiter is not permitted to be > 1
171  Field<Type> limiter(vsf.primitiveField().size(), pTraits<Type>::one);
172 
173  forAll(owner, facei)
174  {
175  label own = owner[facei];
176  label nei = neighbour[facei];
177 
178  // owner side
179  limitFace
180  (
181  limiter[own],
182  maxVsf[own],
183  minVsf[own],
184  (Cf[facei] - C[own]) & g[own]
185  );
186 
187  // neighbour side
188  limitFace
189  (
190  limiter[nei],
191  maxVsf[nei],
192  minVsf[nei],
193  (Cf[facei] - C[nei]) & g[nei]
194  );
195  }
196 
197  forAll(bsf, patchi)
198  {
199  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
200  const vectorField& pCf = Cf.boundaryField()[patchi];
201 
202  forAll(pOwner, pFacei)
203  {
204  label own = pOwner[pFacei];
205 
206  limitFace
207  (
208  limiter[own],
209  maxVsf[own],
210  minVsf[own],
211  ((pCf[pFacei] - C[own]) & g[own])
212  );
213  }
214  }
215 
216  if (fv::debug)
217  {
218  Info<< "gradient limiter for: " << vsf.name()
219  << " max = " << gMax(limiter)
220  << " min = " << gMin(limiter)
221  << " average: " << gAverage(limiter) << endl;
222  }
223 
224  limitGradient(limiter, g);
225  g.correctBoundaryConditions();
227 
228  return tGrad;
229 }
230 
231 
232 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::fvPatchField
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: volSurfaceMapping.H:50
Foam::cmptMultiply
dimensioned< Type > cmptMultiply(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
Foam::volMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: volMesh.H:50
Foam::outerProduct::type
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:114
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
C
volScalarField & C
Definition: readThermalProperties.H:102
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::vectorField
Field< vector > vectorField
Specialisation of Field<T> for vector.
Definition: primitiveFieldsFwd.H:54
correctBoundaryConditions
cellMask correctBoundaryConditions()
gaussGrad.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:24
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:60
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::roots::type
type
Types of root.
Definition: Roots.H:54
Foam::fv::cellLimitedGrad::calcGrad
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.
Foam::gMin
Type gMin(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:593
cellLimitedGrad.H
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:57
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::limiter
tmp< areaScalarField > limiter(const areaScalarField &phi)
Definition: faNVDscheme.C:37
Foam::tensor
Tensor< scalar > tensor
Tensor of scalars, i.e. Tensor<scalar>.
Definition: symmTensor.H:61
Foam::gMax
Type gMax(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:592
Foam::fv::cellLimitedGrad
cellLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
Definition: cellLimitedGrad.H:63
y
scalar y
Definition: LISASMDCalcMethod1.H:14