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 RdeltaTType,
185  class RhoType,
186  class SpType,
187  class PsiMaxType,
188  class PsiMinType
189 >
191 (
192  const control& controls,
193  const RdeltaTType& rDeltaT,
194  const RhoType& rho,
195  const volScalarField& psi,
196  const surfaceScalarField& phiBD,
197  surfaceScalarField& phiCorr,
198  const SpType& Sp,
199  const PsiMaxType& psiMax,
200  const PsiMinType& psiMin
201 )
202 {
203  const fvMesh& mesh = psi.mesh();
204 
206  (
207  IOobject
208  (
209  "lambda",
210  mesh.time().name(),
211  mesh,
212  IOobject::NO_READ,
213  IOobject::NO_WRITE,
214  false
215  ),
216  mesh,
218  );
219 
220  // Correction equation source
221  scalarField SuCorr
222  (
223  mesh.Vsc()().primitiveField()
224  *(rho.primitiveField()*rDeltaT - Sp.primitiveField())
225  *psi.primitiveField()
226 
227  );
228 
229  limiter
230  (
231  controls,
232  lambda,
233  rDeltaT,
234  rho,
235  psi,
236  SuCorr,
237  phiBD,
238  phiCorr,
239  Sp,
240  psiMax,
241  psiMin
242  );
243 
244  phiCorr *= lambda;
245 }
246 
247 
248 template
249 <
250  class RhoType,
251  class SpType,
252  class PsiMaxType,
253  class PsiMinType
254 >
256 (
257  const control& controls,
258  const RhoType& rho,
259  const volScalarField& psi,
260  const surfaceScalarField& phiBD,
261  surfaceScalarField& phiCorr,
262  const SpType& Sp,
263  const PsiMaxType& psiMax,
264  const PsiMinType& psiMin
265 )
266 {
267  const fvMesh& mesh = psi.mesh();
268 
269  if (fv::localEulerDdt::enabled(mesh))
270  {
271  const volScalarField& rDeltaT = fv::localEulerDdt::localRDeltaT(mesh);
272 
273  limitCorr
274  (
275  controls,
276  rDeltaT,
277  rho,
278  psi,
279  phiBD,
280  phiCorr,
281  Sp,
282  psiMax,
283  psiMin
284  );
285  }
286  else
287  {
288  const scalar rDeltaT = 1.0/mesh.time().deltaTValue();
289 
290  limitCorr
291  (
292  controls,
293  rDeltaT,
294  rho,
295  psi,
296  phiBD,
297  phiCorr,
298  Sp,
299  psiMax,
300  psiMin
301  );
302  }
303 }
304 
305 
306 // ************************************************************************* //
CMULES: Multidimensional universal limiter for explicit corrected implicit solution.
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
const word & name() const
Return const reference to name.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:96
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:420
tmp< DimensionedField< scalar, volMesh > > 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
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
void surfaceIntegrate(Field< Type > &ivf, const SurfaceField< Type > &ssf)
tmp< VolField< Type > > Sp(const volScalarField &sp, const VolField< Type > &vf)
Definition: fvcSup.C:67
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
const dimensionSet dimless
messageStream Info