faceMDLimitedGrads.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "faceMDLimitedGrad.H"
27 #include "cellMDLimitedGrad.H"
28 #include "gaussGrad.H"
29 #include "fvMesh.H"
30 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 makeFvGradScheme(faceMDLimitedGrad)
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 template<>
42 (
43  const volScalarField& vsf,
44  const word& name
45 ) const
46 {
47  const fvMesh& mesh = vsf.mesh();
48 
49  tmp<volVectorField> tGrad = basicGradScheme_().calcGrad(vsf, name);
50 
51  if (k_ < small)
52  {
53  return tGrad;
54  }
55 
56  volVectorField& g = tGrad.ref();
57 
58  const labelUList& owner = mesh.owner();
59  const labelUList& neighbour = mesh.neighbour();
60 
61  const volVectorField& C = mesh.C();
62  const surfaceVectorField& Cf = mesh.Cf();
63 
64  scalar rk = (1.0/k_ - 1.0);
65 
66  forAll(owner, facei)
67  {
68  label own = owner[facei];
69  label nei = neighbour[facei];
70 
71  scalar vsfOwn = vsf[own];
72  scalar vsfNei = vsf[nei];
73 
74  scalar maxFace = max(vsfOwn, vsfNei);
75  scalar minFace = min(vsfOwn, vsfNei);
76 
77  if (k_ < 1.0)
78  {
79  scalar maxMinFace = rk*(maxFace - minFace);
80  maxFace += maxMinFace;
81  minFace -= maxMinFace;
82  }
83 
84  // owner side
85  cellMDLimitedGrad<scalar>::limitFace
86  (
87  g[own],
88  maxFace - vsfOwn,
89  minFace - vsfOwn,
90  Cf[facei] - C[own]
91  );
92 
93  // neighbour side
94  cellMDLimitedGrad<scalar>::limitFace
95  (
96  g[nei],
97  maxFace - vsfNei,
98  minFace - vsfNei,
99  Cf[facei] - C[nei]
100  );
101  }
102 
103  const volScalarField::Boundary& bsf = vsf.boundaryField();
104 
105  forAll(bsf, patchi)
106  {
107  const fvPatchScalarField& psf = bsf[patchi];
108 
109  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
110  const vectorField& pCf = Cf.boundaryField()[patchi];
111 
112  if (psf.coupled())
113  {
114  const scalarField psfNei(psf.patchNeighbourField());
115 
116  forAll(pOwner, pFacei)
117  {
118  label own = pOwner[pFacei];
119 
120  scalar vsfOwn = vsf[own];
121  scalar vsfNei = psfNei[pFacei];
122 
123  scalar maxFace = max(vsfOwn, vsfNei);
124  scalar minFace = min(vsfOwn, vsfNei);
125 
126  if (k_ < 1.0)
127  {
128  scalar maxMinFace = rk*(maxFace - minFace);
129  maxFace += maxMinFace;
130  minFace -= maxMinFace;
131  }
132 
133  cellMDLimitedGrad<scalar>::limitFace
134  (
135  g[own],
136  maxFace - vsfOwn,
137  minFace - vsfOwn,
138  pCf[pFacei] - C[own]
139  );
140  }
141  }
142  else if (psf.fixesValue())
143  {
144  forAll(pOwner, pFacei)
145  {
146  label own = pOwner[pFacei];
147 
148  scalar vsfOwn = vsf[own];
149  scalar vsfNei = psf[pFacei];
150 
151  scalar maxFace = max(vsfOwn, vsfNei);
152  scalar minFace = min(vsfOwn, vsfNei);
153 
154  if (k_ < 1.0)
155  {
156  scalar maxMinFace = rk*(maxFace - minFace);
157  maxFace += maxMinFace;
158  minFace -= maxMinFace;
159  }
160 
161  cellMDLimitedGrad<scalar>::limitFace
162  (
163  g[own],
164  maxFace - vsfOwn,
165  minFace - vsfOwn,
166  pCf[pFacei] - C[own]
167  );
168  }
169  }
170  }
171 
172  g.correctBoundaryConditions();
174 
175  return tGrad;
176 }
177 
178 
179 template<>
182 (
183  const volVectorField& vvf,
184  const word& name
185 ) const
186 {
187  const fvMesh& mesh = vvf.mesh();
188 
189  tmp<volTensorField> tGrad = basicGradScheme_().calcGrad(vvf, name);
190 
191  if (k_ < small)
192  {
193  return tGrad;
194  }
195 
196  volTensorField& g = tGrad.ref();
197 
198  const labelUList& owner = mesh.owner();
199  const labelUList& neighbour = mesh.neighbour();
200 
201  const volVectorField& C = mesh.C();
202  const surfaceVectorField& Cf = mesh.Cf();
203 
204  scalar rk = (1.0/k_ - 1.0);
205 
206  forAll(owner, facei)
207  {
208  label own = owner[facei];
209  label nei = neighbour[facei];
210 
211  vector vvfOwn = vvf[own];
212  vector vvfNei = vvf[nei];
213 
214  vector maxFace = max(vvfOwn, vvfNei);
215  vector minFace = min(vvfOwn, vvfNei);
216 
217  if (k_ < 1.0)
218  {
219  vector maxMinFace = rk*(maxFace - minFace);
220  maxFace += maxMinFace;
221  minFace -= maxMinFace;
222  }
223 
224  // owner side
226  (
227  g[own],
228  maxFace - vvfOwn,
229  minFace - vvfOwn,
230  Cf[facei] - C[own]
231  );
232 
233 
234  // neighbour side
236  (
237  g[nei],
238  maxFace - vvfNei,
239  minFace - vvfNei,
240  Cf[facei] - C[nei]
241  );
242  }
243 
244 
245  const volVectorField::Boundary& bvf = vvf.boundaryField();
246 
247  forAll(bvf, patchi)
248  {
249  const fvPatchVectorField& psf = bvf[patchi];
250 
251  const labelUList& pOwner = mesh.boundary()[patchi].faceCells();
252  const vectorField& pCf = Cf.boundaryField()[patchi];
253 
254  if (psf.coupled())
255  {
256  const vectorField psfNei(psf.patchNeighbourField());
257 
258  forAll(pOwner, pFacei)
259  {
260  label own = pOwner[pFacei];
261 
262  vector vvfOwn = vvf[own];
263  vector vvfNei = psfNei[pFacei];
264 
265  vector maxFace = max(vvfOwn, vvfNei);
266  vector minFace = min(vvfOwn, vvfNei);
267 
268  if (k_ < 1.0)
269  {
270  vector maxMinFace = rk*(maxFace - minFace);
271  maxFace += maxMinFace;
272  minFace -= maxMinFace;
273  }
274 
276  (
277  g[own],
278  maxFace - vvfOwn, minFace - vvfOwn,
279  pCf[pFacei] - C[own]
280  );
281  }
282  }
283  else if (psf.fixesValue())
284  {
285  forAll(pOwner, pFacei)
286  {
287  label own = pOwner[pFacei];
288 
289  vector vvfOwn = vvf[own];
290  vector vvfNei = psf[pFacei];
291 
292  vector maxFace = max(vvfOwn, vvfNei);
293  vector minFace = min(vvfOwn, vvfNei);
294 
295  if (k_ < 1.0)
296  {
297  vector maxMinFace = rk*(maxFace - minFace);
298  maxFace += maxMinFace;
299  minFace -= maxMinFace;
300  }
301 
303  (
304  g[own],
305  maxFace - vvfOwn,
306  minFace - vvfOwn,
307  pCf[pFacei] - C[own]
308  );
309  }
310  }
311  }
312 
315 
316  return tGrad;
317 }
318 
319 
320 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Graphite solid properties.
Definition: C.H:51
const GeoMesh & mesh() const
Return mesh.
Generic GeometricBoundaryField class.
Generic GeometricField class.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
void correctBoundaryConditions()
Correct boundary field.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const volVectorField & C() const
Return cell centres.
const labelUList & owner() const
Internal face owner.
Definition: fvMesh.H:490
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
const surfaceVectorField & Cf() const
Return face centres.
const labelUList & neighbour() const
Internal face neighbour.
Definition: fvMesh.H:496
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:90
virtual bool fixesValue() const
Return true if this patch field fixes a value.
Definition: fvPatchField.H:326
virtual bool coupled() const
Return true if this patch field is coupled.
Definition: fvPatchField.H:339
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking) const
Return patchField on the opposite patch of a coupled patch.
Definition: fvPatchField.H:447
cellMDLimitedGrad gradient scheme applied to a runTime selected base gradient scheme.
virtual tmp< VolField< typename outerProduct< vector, Type >::type > > calcGrad(const VolField< Type > &vsf, const word &name) const
Return the gradient of the given field to the gradScheme::grad.
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
makeFvGradScheme(faceMDLimitedGrad)
volScalarField scalarField(fieldObject, mesh)
volVectorField vectorField(fieldObject, mesh)
label patchi
U correctBoundaryConditions()
static const coefficient C("C", dimTemperature, 234.5)
VolField< vector > volVectorField
Definition: volFieldsFwd.H:63
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
VolField< scalar > volScalarField
Definition: volFieldsFwd.H:62
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
SurfaceField< vector > surfaceVectorField
UList< label > labelUList
Definition: UList.H:65
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
fvPatchField< scalar > fvPatchScalarField