CMULESTemplates.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) 2013-2025 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 "CMULES.H"
27 #include "fvcSurfaceIntegrate.H"
28 #include "localEulerDdtScheme.H"
29 
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 template<class RdeltaTType, class RhoType, class SpType>
34 (
35  const RdeltaTType& rDeltaT,
36  const RhoType& rho,
38  const surfaceScalarField& phiCorr,
39  const SpType& Sp
40 )
41 {
42  Info<< "MULES: Correcting " << psi.name() << endl;
43 
44  scalarField psiIf(psi.size(), 0);
45  fvc::surfaceIntegrate(psiIf, phiCorr);
46 
47  psi.primitiveFieldRef() =
48  (
49  (rho.primitiveField()*rDeltaT - Sp.primitiveField())
50  *psi.primitiveField()
51  - psiIf
52  )/(rho.primitiveField()*rDeltaT - Sp.primitiveField());
53 
54  psi.correctBoundaryConditions();
55 }
56 
57 
58 template<class RhoType>
60 (
61  const RhoType& rho,
63  const surfaceScalarField& phiCorr
64 )
65 {
66  correct(rho, psi, phiCorr, zeroField());
67 }
68 
69 
70 template<class RhoType, class SpType>
72 (
73  const RhoType& rho,
75  const surfaceScalarField& phiCorr,
76  const SpType& Sp
77 )
78 {
79  const fvMesh& mesh = psi.mesh();
80 
81  if (fv::localEulerDdt::enabled(mesh))
82  {
83  const volScalarField& rDeltaT = fv::localEulerDdt::localRDeltaT(mesh);
84  correct(rDeltaT, rho, psi, phiCorr, Sp);
85  }
86  else
87  {
88  const scalar rDeltaT = 1.0/mesh.time().deltaTValue();
89  correct(rDeltaT, rho, psi, phiCorr, Sp);
90  }
91 }
92 
93 
94 template<class RhoType, class PsiMaxType, class PsiMinType>
96 (
97  const control& controls,
98  const RhoType& rho,
100  const surfaceScalarField& phiBD,
101  surfaceScalarField& phiCorr,
102  const PsiMaxType& psiMax,
103  const PsiMinType& psiMin
104 )
105 {
106  correct
107  (
108  controls,
109  rho,
110  psi,
111  phiBD,
112  phiCorr,
113  zeroField(),
114  psiMax,
115  psiMin
116  );
117 }
118 
119 
120 template
121 <
122  class RhoType,
123  class SpType,
124  class PsiMaxType,
125  class PsiMinType
126 >
128 (
129  const control& controls,
130  const RhoType& rho,
132  const surfaceScalarField& phiBD,
133  surfaceScalarField& phiCorr,
134  const SpType& Sp,
135  const PsiMaxType& psiMax,
136  const PsiMinType& psiMin
137 )
138 {
139  const fvMesh& mesh = psi.mesh();
140 
141  if (fv::localEulerDdt::enabled(mesh))
142  {
143  const volScalarField& rDeltaT = fv::localEulerDdt::localRDeltaT(mesh);
144 
145  limitCorr
146  (
147  controls,
148  rDeltaT,
149  rho,
150  psi,
151  phiBD,
152  phiCorr,
153  Sp,
154  psiMax,
155  psiMin
156  );
157 
158  correct(rDeltaT, rho, psi, phiCorr, Sp);
159  }
160  else
161  {
162  const scalar rDeltaT = 1.0/mesh.time().deltaTValue();
163 
164  limitCorr
165  (
166  controls,
167  rDeltaT,
168  rho,
169  psi,
170  phiBD,
171  phiCorr,
172  Sp,
173  psiMax,
174  psiMin
175  );
176 
177  correct(rDeltaT, rho, psi, phiCorr, Sp);
178  }
179 }
180 
181 
182 template
183 <
184  class RhoType,
185  class SpType,
186  class PsiMaxType,
187  class PsiMinType
188 >
190 (
191  const control& controls,
192  const RhoType& rho,
194  const surfaceScalarField& phiBD,
196  const SpType& Sp,
197  const PsiMaxType& psiMax,
198  const PsiMinType& psiMin
199 )
200 {
201  const fvMesh& mesh = psi.mesh();
202 
203  surfaceScalarField phiCorr(phiCorrs[0]);
204  for (label i = 1; i<phiCorrs.size(); i++)
205  {
206  phiCorr += phiCorrs[i];
207  }
208 
209  if (fv::localEulerDdt::enabled(mesh))
210  {
211  const volScalarField& rDeltaT = fv::localEulerDdt::localRDeltaT(mesh);
212 
213  limitCorr
214  (
215  controls,
216  rDeltaT,
217  rho,
218  psi,
219  phiBD,
220  phiCorrs,
221  phiCorr,
222  Sp,
223  psiMax,
224  psiMin
225  );
226 
227  correct(rDeltaT, rho, psi, phiCorr, Sp);
228  }
229  else
230  {
231  const scalar rDeltaT = 1.0/mesh.time().deltaTValue();
232 
233  limitCorr
234  (
235  controls,
236  rDeltaT,
237  rho,
238  psi,
239  phiBD,
240  phiCorrs,
241  phiCorr,
242  Sp,
243  psiMax,
244  psiMin
245  );
246 
247  correct(rDeltaT, rho, psi, phiCorr, Sp);
248  }
249 }
250 
251 
252 template
253 <
254  class RdeltaTType,
255  class RhoType,
256  class SpType,
257  class PsiMaxType,
258  class PsiMinType
259 >
261 (
262  const control& controls,
263  const RdeltaTType& rDeltaT,
264  const RhoType& rho,
265  const volScalarField& psi,
266  const surfaceScalarField& phiBD,
267  surfaceScalarField& phiCorr,
268  const SpType& Sp,
269  const PsiMaxType& psiMax,
270  const PsiMinType& psiMin
271 )
272 {
273  const fvMesh& mesh = psi.mesh();
274 
276  (
277  IOobject
278  (
279  "lambda",
280  mesh.time().name(),
281  mesh,
282  IOobject::NO_READ,
283  IOobject::NO_WRITE,
284  false
285  ),
286  mesh,
288  );
289 
290  // Correction equation source
291  scalarField SuCorr
292  (
293  mesh.Vsc()().primitiveField()
294  *(rho.primitiveField()*rDeltaT - Sp.primitiveField())
295  *psi.primitiveField()
296 
297  );
298 
299  limiter
300  (
301  controls,
302  lambda,
303  rDeltaT,
304  rho,
305  psi,
306  SuCorr,
307  phiBD,
308  phiCorr,
309  Sp,
310  psiMax,
311  psiMin
312  );
313 
314  phiCorr *= lambda;
315 }
316 
317 
318 template
319 <
320  class RdeltaTType,
321  class RhoType,
322  class SpType,
323  class PsiMaxType,
324  class PsiMinType
325 >
327 (
328  const control& controls,
329  const RdeltaTType& rDeltaT,
330  const RhoType& rho,
331  const volScalarField& psi,
332  const surfaceScalarField& phiBD,
334  surfaceScalarField& phiCorr,
335  const SpType& Sp,
336  const PsiMaxType& psiMax,
337  const PsiMinType& psiMin
338 )
339 {
340  const fvMesh& mesh = psi.mesh();
341 
343  (
344  IOobject
345  (
346  "lambda",
347  mesh.time().name(),
348  mesh,
349  IOobject::NO_READ,
350  IOobject::NO_WRITE,
351  false
352  ),
353  mesh,
355  );
356 
357  // Correction equation source
358  scalarField SuCorr
359  (
360  mesh.Vsc()().primitiveField()
361  *(rho.primitiveField()*rDeltaT - Sp.primitiveField())
362  *psi.primitiveField()
363 
364  );
365 
366  limiter
367  (
368  controls,
369  lambda,
370  rDeltaT,
371  rho,
372  psi,
373  SuCorr,
374  phiBD,
375  phiCorr,
376  Sp,
377  psiMax,
378  psiMin
379  );
380 
381  forAll(phiCorrs, i)
382  {
383  phiCorrs[i] *= lambda;
384  }
385  phiCorr *= lambda;
386 }
387 
388 
389 template
390 <
391  class RhoType,
392  class SpType,
393  class PsiMaxType,
394  class PsiMinType
395 >
397 (
398  const control& controls,
399  const RhoType& rho,
400  const volScalarField& psi,
401  const surfaceScalarField& phiBD,
402  surfaceScalarField& phiCorr,
403  const SpType& Sp,
404  const PsiMaxType& psiMax,
405  const PsiMinType& psiMin
406 )
407 {
408  const fvMesh& mesh = psi.mesh();
409 
410  if (fv::localEulerDdt::enabled(mesh))
411  {
412  const volScalarField& rDeltaT = fv::localEulerDdt::localRDeltaT(mesh);
413 
414  limitCorr
415  (
416  controls,
417  rDeltaT,
418  rho,
419  psi,
420  phiBD,
421  phiCorr,
422  Sp,
423  psiMax,
424  psiMin
425  );
426  }
427  else
428  {
429  const scalar rDeltaT = 1.0/mesh.time().deltaTValue();
430 
431  limitCorr
432  (
433  controls,
434  rDeltaT,
435  rho,
436  psi,
437  phiBD,
438  phiCorr,
439  Sp,
440  psiMax,
441  psiMin
442  );
443  }
444 }
445 
446 
447 // ************************************************************************* //
CMULES: Multidimensional universal limiter for explicit corrected implicit solution.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
scalar deltaTValue() const
Return time step value.
Definition: TimeStateI.H:34
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
const word & name() const
Return const reference to name.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:433
tmp< DimensionedField< scalar, fvMesh > > Vsc() const
Return sub-cycle cell volumes.
A class representing the concept of a field of 0 used to avoid unnecessary manipulations for objects ...
Definition: zeroField.H:53
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField.
const volScalarField & psi
rho
Definition: pEqn.H:1
dimensionedScalar lambda(viscosity->lookup("lambda"))
void correct(const RdeltaTType &rDeltaT, const RhoType &rho, volScalarField &psi, const surfaceScalarField &phiCorr, const SpType &Sp)
void limitCorr(const control &controls, const RdeltaTType &rDeltaT, const RhoType &rho, const volScalarField &psi, const surfaceScalarField &phiBD, surfaceScalarField &phiCorr, const SpType &Sp, const PsiMaxType &psiMax, const PsiMinType &psiMin)
void limiter(const control &controls, surfaceScalarField &lambda, const RdeltaTType &rDeltaT, const RhoType &rho, const volScalarField &psi, const scalarField &SuCorr, const surfaceScalarField &phi, const surfaceScalarField &phiCorr, const SpType &Sp, const PsiMaxType &psiMax, const PsiMinType &psiMin)
Definition: MULESlimiter.C:42
const dimensionSet dimless
void surfaceIntegrate(Field< Type > &ivf, const SurfaceField< Type > &ssf)
tmp< VolField< Type > > Sp(const volScalarField &sp, const VolField< Type > &vf)
Definition: fvcSup.C:67
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info