cellMDLimitedGrads.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) 2011-2016 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 "cellMDLimitedGrad.H"
29 #include "gaussGrad.H"
30 #include "fvMesh.H"
31 #include "volMesh.H"
32 #include "surfaceMesh.H"
33 #include "volFields.H"
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 
38 makeFvGradScheme(cellMDLimitedGrad)
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 template<>
45 (
46  const volScalarField& vsf,
47  const word& name
48 ) const
49 {
50  const fvMesh& mesh = vsf.mesh();
51 
52  tmp<volVectorField> tGrad = basicGradScheme_().calcGrad(vsf, name);
53 
54  if (k_ < SMALL)
55  {
56  return tGrad;
57  }
58 
59  volVectorField& g = tGrad.ref();
60 
61  const labelUList& owner = mesh.owner();
62  const labelUList& neighbour = mesh.neighbour();
63 
64  const volVectorField& C = mesh.C();
65  const surfaceVectorField& Cf = mesh.Cf();
66 
67  scalarField maxVsf(vsf.primitiveField());
68  scalarField minVsf(vsf.primitiveField());
69 
70  forAll(owner, facei)
71  {
72  label own = owner[facei];
73  label nei = neighbour[facei];
74 
75  scalar vsfOwn = vsf[own];
76  scalar vsfNei = vsf[nei];
77 
78  maxVsf[own] = max(maxVsf[own], vsfNei);
79  minVsf[own] = min(minVsf[own], vsfNei);
80 
81  maxVsf[nei] = max(maxVsf[nei], vsfOwn);
82  minVsf[nei] = min(minVsf[nei], vsfOwn);
83  }
84 
85 
86  const volScalarField::Boundary& bsf = vsf.boundaryField();
87 
88  forAll(bsf, patchi)
89  {
90  const fvPatchScalarField& psf = bsf[patchi];
91 
92  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
93 
94  if (psf.coupled())
95  {
96  const scalarField psfNei(psf.patchNeighbourField());
97 
98  forAll(pOwner, pFacei)
99  {
100  label own = pOwner[pFacei];
101  scalar vsfNei = psfNei[pFacei];
102 
103  maxVsf[own] = max(maxVsf[own], vsfNei);
104  minVsf[own] = min(minVsf[own], vsfNei);
105  }
106  }
107  else
108  {
109  forAll(pOwner, pFacei)
110  {
111  label own = pOwner[pFacei];
112  scalar vsfNei = psf[pFacei];
113 
114  maxVsf[own] = max(maxVsf[own], vsfNei);
115  minVsf[own] = min(minVsf[own], vsfNei);
116  }
117  }
118  }
119 
120  maxVsf -= vsf;
121  minVsf -= vsf;
122 
123  if (k_ < 1.0)
124  {
125  const scalarField maxMinVsf((1.0/k_ - 1.0)*(maxVsf - minVsf));
126  maxVsf += maxMinVsf;
127  minVsf -= maxMinVsf;
128 
129  //maxVsf *= 1.0/k_;
130  //minVsf *= 1.0/k_;
131  }
132 
133 
134  forAll(owner, facei)
135  {
136  label own = owner[facei];
137  label nei = neighbour[facei];
138 
139  // owner side
140  limitFace
141  (
142  g[own],
143  maxVsf[own],
144  minVsf[own],
145  Cf[facei] - C[own]
146  );
147 
148  // neighbour side
149  limitFace
150  (
151  g[nei],
152  maxVsf[nei],
153  minVsf[nei],
154  Cf[facei] - C[nei]
155  );
156  }
157 
158 
159  forAll(bsf, patchi)
160  {
161  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
162  const vectorField& pCf = Cf.boundaryField()[patchi];
163 
164  forAll(pOwner, pFacei)
165  {
166  label own = pOwner[pFacei];
167 
168  limitFace
169  (
170  g[own],
171  maxVsf[own],
172  minVsf[own],
173  pCf[pFacei] - C[own]
174  );
175  }
176  }
177 
178  g.correctBoundaryConditions();
180 
181  return tGrad;
182 }
183 
184 
185 template<>
188 (
189  const volVectorField& vsf,
190  const word& name
191 ) const
192 {
193  const fvMesh& mesh = vsf.mesh();
194 
195  tmp<volTensorField> tGrad = basicGradScheme_().calcGrad(vsf, name);
196 
197  if (k_ < SMALL)
198  {
199  return tGrad;
200  }
201 
202  volTensorField& g = tGrad.ref();
203 
204  const labelUList& owner = mesh.owner();
205  const labelUList& neighbour = mesh.neighbour();
206 
207  const volVectorField& C = mesh.C();
208  const surfaceVectorField& Cf = mesh.Cf();
209 
210  vectorField maxVsf(vsf.primitiveField());
211  vectorField minVsf(vsf.primitiveField());
212 
213  forAll(owner, facei)
214  {
215  label own = owner[facei];
216  label nei = neighbour[facei];
217 
218  const vector& vsfOwn = vsf[own];
219  const vector& vsfNei = vsf[nei];
220 
221  maxVsf[own] = max(maxVsf[own], vsfNei);
222  minVsf[own] = min(minVsf[own], vsfNei);
223 
224  maxVsf[nei] = max(maxVsf[nei], vsfOwn);
225  minVsf[nei] = min(minVsf[nei], vsfOwn);
226  }
227 
228 
229  const volVectorField::Boundary& bsf = vsf.boundaryField();
230 
231  forAll(bsf, patchi)
232  {
233  const fvPatchVectorField& psf = bsf[patchi];
234  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
235 
236  if (psf.coupled())
237  {
238  const vectorField psfNei(psf.patchNeighbourField());
239 
240  forAll(pOwner, pFacei)
241  {
242  label own = pOwner[pFacei];
243  const vector& vsfNei = psfNei[pFacei];
244 
245  maxVsf[own] = max(maxVsf[own], vsfNei);
246  minVsf[own] = min(minVsf[own], vsfNei);
247  }
248  }
249  else
250  {
251  forAll(pOwner, pFacei)
252  {
253  label own = pOwner[pFacei];
254  const vector& vsfNei = psf[pFacei];
255 
256  maxVsf[own] = max(maxVsf[own], vsfNei);
257  minVsf[own] = min(minVsf[own], vsfNei);
258  }
259  }
260  }
261 
262  maxVsf -= vsf;
263  minVsf -= vsf;
264 
265  if (k_ < 1.0)
266  {
267  const vectorField maxMinVsf((1.0/k_ - 1.0)*(maxVsf - minVsf));
268  maxVsf += maxMinVsf;
269  minVsf -= maxMinVsf;
270 
271  //maxVsf *= 1.0/k_;
272  //minVsf *= 1.0/k_;
273  }
274 
275 
276  forAll(owner, facei)
277  {
278  label own = owner[facei];
279  label nei = neighbour[facei];
280 
281  // owner side
282  limitFace
283  (
284  g[own],
285  maxVsf[own],
286  minVsf[own],
287  Cf[facei] - C[own]
288  );
289 
290  // neighbour side
291  limitFace
292  (
293  g[nei],
294  maxVsf[nei],
295  minVsf[nei],
296  Cf[facei] - C[nei]
297  );
298  }
299 
300 
301  forAll(bsf, patchi)
302  {
303  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
304  const vectorField& pCf = Cf.boundaryField()[patchi];
305 
306  forAll(pOwner, pFacei)
307  {
308  label own = pOwner[pFacei];
309 
310  limitFace
311  (
312  g[own],
313  maxVsf[own],
314  minVsf[own],
315  pCf[pFacei] - C[own]
316  );
317  }
318  }
319 
320  g.correctBoundaryConditions();
322 
323  return tGrad;
324 }
325 
326 
327 // ************************************************************************* //
Foam::fvPatchField< vector >
Foam::fvPatchScalarField
fvPatchField< scalar > fvPatchScalarField
Definition: fvPatchFieldsFwd.H:40
volFields.H
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
makeFvGradScheme
makeFvGradScheme(cellMDLimitedGrad)
Definition: cellMDLimitedGrads.C:38
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
volMesh.H
Foam::GeometricField::primitiveField
const Internal::FieldType & primitiveField() const
Return a const-reference to the internal field.
Definition: GeometricFieldI.H:53
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()
Foam::fvPatchField::coupled
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:331
gaussGrad.H
Foam::tmp::ref
T & ref() const
Definition: tmpI.H:228
Foam::Field< vector >
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
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
surfaceMesh.H
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
fvMesh.H
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:24
Foam::fvPatchField::patchNeighbourField
virtual tmp< Field< Type > > patchNeighbourField() const
Return patchField on the opposite patch of a coupled patch.
Definition: fvPatchField.H:434
Foam::volVectorField
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:62
Foam::fv::cellMDLimitedGrad::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::Vector< scalar >
fixedValueFvPatchFields.H
Foam::UList< label >
Foam::labelUList
UList< label > labelUList
A UList of labels.
Definition: UList.H:80
Foam::C
Graphite solid properties.
Definition: C.H:50
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:59
Foam::GeometricField< vector, fvPatchField, volMesh >
cellMDLimitedGrad.H
Foam::GeometricField::boundaryField
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Definition: GeometricFieldI.H:62