basicFluidSolver.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) 2022-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 "basicFluidSolver.H"
27 #include "surfaceFields.H"
28 #include "fvcDiv.H"
29 #include "fvcSurfaceIntegrate.H"
30 #include "fvcVolumeIntegrate.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace solvers
37 {
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
44 
46 {
48 }
49 
50 
52 {
53  solver::read();
54 
55  maxCo =
56  runTime.controlDict().lookupOrDefault<scalar>("maxCo", vGreat);
57 
58  maxDeltaT_ =
59  runTime.controlDict().found("maxDeltaT")
60  ? runTime.controlDict().lookup<scalar>("maxDeltaT", runTime.userUnits())
61  : vGreat;
62 
63  correctPhi = pimple.dict().lookupOrDefault
64  (
65  "correctPhi",
66  mesh.dynamic()
67  );
68 
69  checkMeshCourantNo = pimple.dict().lookupOrDefault
70  (
71  "checkMeshCourantNo",
72  false
73  );
74 
75  return true;
76 }
77 
79 {
81  {
82  const scalarField sumPhi
83  (
84  fvc::surfaceSum(mag(mesh.phi()))().primitiveField()
85  );
86 
87  const scalar meshCoNum
88  (
89  0.5*gMax(sumPhi/mesh.V().primitiveField())*runTime.deltaTValue()
90  );
91 
92  const scalar meanMeshCoNum
93  (
94  0.5
95  *(gSum(sumPhi)/gSum(mesh.V().primitiveField()))
96  *runTime.deltaTValue()
97  );
98 
99  Info<< "Mesh Courant Number mean: " << meanMeshCoNum
100  << " max: " << meshCoNum << endl;
101  }
102 }
103 
104 
105 template<class RhoType>
106 void Foam::solvers::basicFluidSolver::correctCoNum
107 (
108  const RhoType& rho,
109  const surfaceScalarField& phi
110 )
111 {
112  const scalarField sumPhi
113  (
114  fvc::surfaceSum(mag(phi))().primitiveField()/rho.primitiveField()
115  );
116 
117  CoNum_ = 0.5*gMax(sumPhi/mesh.V().primitiveField())*runTime.deltaTValue();
118 
119  const scalar meanCoNum =
120  0.5
121  *(gSum(sumPhi)/gSum(mesh.V().primitiveField()))
122  *runTime.deltaTValue();
123 
124  Info<< "Courant Number mean: " << meanCoNum
125  << " max: " << CoNum << endl;
126 }
127 
128 
129 void Foam::solvers::basicFluidSolver::correctCoNum
130 (
131  const surfaceScalarField& phi
132 )
133 {
134  correctCoNum(geometricOneField(), phi);
135 }
136 
137 
138 void Foam::solvers::basicFluidSolver::correctCoNum
139 (
140  const volScalarField& rho,
141  const surfaceScalarField& phi
142 )
143 {
144  correctCoNum<volScalarField>(rho, phi);
145 }
146 
147 
149 (
150  const surfaceScalarField& phi
151 )
152 {
153  const volScalarField contErr(fvc::div(phi));
154 
155  const scalar sumLocalContErr =
156  runTime.deltaTValue()
157  *mag(contErr)().weightedAverage(mesh.V()).value();
158 
159  const scalar globalContErr =
160  runTime.deltaTValue()
161  *contErr.weightedAverage(mesh.V()).value();
162 
163  Info<< "time step continuity errors : sum local = " << sumLocalContErr
164  << ", global = " << globalContErr;
165 
166  if (pimple.finalPisoIter() && pimple.finalIter())
167  {
169 
170  Info<< ", cumulative = " << cumulativeContErr;
171  }
172 
173  Info<< endl;
174 }
175 
176 
178 (
179  const volScalarField& rho,
180  const volScalarField& thermoRho,
181  const surfaceScalarField& phi
182 )
183 {
184  if (mesh.schemes().steady())
185  {
186  continuityErrors(phi);
187  }
188  else
189  {
190  const dimensionedScalar totalMass = fvc::domainIntegrate(rho);
191 
192  const scalar sumLocalContErr =
193  (fvc::domainIntegrate(mag(rho - thermoRho))/totalMass).value();
194 
195  const scalar globalContErr =
196  (fvc::domainIntegrate(rho - thermoRho)/totalMass).value();
197 
199 
200  Info<< "time step continuity errors : sum local = " << sumLocalContErr
201  << ", global = " << globalContErr
202  << ", cumulative = " << cumulativeContErr
203  << endl;
204  }
205 }
206 
207 
208 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
209 
211 :
212  solver(mesh),
213  maxCo(0),
214  maxDeltaT_(0),
216  CoNum_(0),
217  CoNum(CoNum_)
218 {
219  // Read the controls
220  read();
221 }
222 
223 
224 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
225 
227 {}
228 
229 
230 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
231 
233 {
234  scalar deltaT = min(fvModels().maxDeltaT(), maxDeltaT_);
235 
236  if (maxCo < vGreat && CoNum > small)
237  {
238  deltaT = min(deltaT, maxCo/CoNum*runTime.deltaTValue());
239  }
240 
241  return deltaT;
242 }
243 
244 
245 // ************************************************************************* //
dimensioned< Type > weightedAverage(const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &) const
Calculate and return weighted average.
Generic GeometricField class.
const IOdictionary & controlDict() const
Return the control dict.
Definition: Time.H:275
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:98
const DimensionedField< scalar, fvMesh > & V() const
Return cell volumes.
const surfaceScalarField & phi() const
Return cell face motion fluxes.
const fvSchemes & schemes() const
Return the fvSchemes.
Definition: fvMesh.C:1792
const fvSolution & solution() const
Return the fvSolution.
Definition: fvMesh.C:1803
bool dynamic() const
Is this mesh dynamic?
Definition: fvMesh.C:695
bool steady() const
Return true if the default ddtScheme is steadyState.
Definition: fvSchemes.H:145
A class representing the concept of a GeometricField of 1 used to avoid unnecessary manipulations for...
virtual bool modified() const
Return true if the object's file (or files for objectRegistry)
Abstract base class for run-time selectable region solvers.
Definition: solver.H:56
const Time & runTime
Time.
Definition: solver.H:104
const fvMesh & mesh
Region mesh.
Definition: solver.H:101
virtual bool read()
Read controls.
Definition: solver.C:52
Base solver module for fluid solvers.
basicFluidSolver(fvMesh &mesh)
Construct from region mesh.
void continuityErrors(const surfaceScalarField &phi)
Calculate and print the continuity errors.
virtual bool dependenciesModified() const
Return true if the solver's dependencies have been modified.
virtual scalar maxDeltaT() const
Return the current maximum time-step for stable solution.
void meshCourantNo() const
Check mesh Courant numbers for moving mesh cases.
virtual ~basicFluidSolver()
Destructor.
virtual bool read()
Read controls.
scalar CoNum
scalar meanCoNum
Foam::fvModels & fvModels(Foam::fvModels::New(mesh))
pimpleControl pimple(mesh)
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
scalar maxDeltaT
scalar maxCo
Calculate the divergence of the given field.
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField.
Volume integrate volField creating a volField.
scalar cumulativeContErr
rho
Definition: pEqn.H:1
dimensioned< Type > domainIntegrate(const VolField< Type > &vf)
tmp< VolField< Type > > div(const SurfaceField< Type > &ssf)
Definition: fvcDiv.C:47
tmp< VolInternalField< Type > > surfaceSum(const SurfaceField< Type > &ssf)
defineTypeNameAndDebug(basicFluidSolver, 0)
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
Type gSum(const UList< Type > &f, const label comm)
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Type gMax(const UList< Type > &f, const label comm)
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
checkMeshCourantNo
correctPhi
Foam::surfaceFields.
scalar sumLocalContErr
Definition: volContinuity.H:9
scalar globalContErr
Definition: volContinuity.H:12