age.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) 2018-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 "age.H"
27 #include "fvmDiv.H"
28 #include "fvmLaplacian.H"
29 #include "fvModels.H"
30 #include "fvConstraints.H"
31 #include "momentumTransportModel.H"
33 #include "wallFvPatch.H"
36 
37 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 namespace functionObjects
42 {
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 Foam::wordList Foam::functionObjects::age::patchTypes() const
52 {
53  wordList result
54  (
55  mesh_.boundary().size(),
57  );
58 
60  {
61  if (isA<wallFvPatch>(mesh_.boundary()[patchi]))
62  {
64  }
65  }
66 
67  return result;
68 }
69 
70 
71 bool Foam::functionObjects::age::converged
72 (
73  const int nCorr,
74  const scalar initialResidual
75 ) const
76 {
77  if (initialResidual < tolerance_)
78  {
79  Info<< "Field " << typeName
80  << " converged in " << nCorr << " correctors\n" << endl;
81 
82  return true;
83  }
84  else
85  {
86  return false;
87  }
88 }
89 
90 
91 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
92 
94 (
95  const word& name,
96  const Time& runTime,
97  const dictionary& dict
98 )
99 :
100  fvMeshFunctionObject(name, runTime, dict)
101 {
102  read(dict);
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
116  phiName_ = dict.lookupOrDefault<word>("phi", "phi");
117  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
118  schemesField_ = dict.lookupOrDefault<word>("schemesField", typeName);
119  solverField_ = dict.lookupOrDefault<word>("solverField", typeName);
120  diffusion_ = dict.lookupOrDefault<Switch>("diffusion", false);
121  tolerance_ = dict.lookupOrDefault<scalar>("tolerance", 1e-5);
122 
123  return true;
124 }
125 
126 
128 {
129  return wordList{phiName_, rhoName_};
130 }
131 
132 
134 {
136  (
137  new volScalarField
138  (
139  IOobject
140  (
141  typeName,
142  time_.name(),
143  mesh_,
146  false
147  ),
148  mesh_,
150  patchTypes()
151  )
152  );
153  volScalarField& age = tage.ref();
154 
155  const word divScheme("div(phi," + schemesField_ + ")");
156 
157  const int nCorr =
158  mesh_.solution().solverDict(solverField_)
159  .lookupOrDefaultBackwardsCompatible<label>
160  (
161  {"nCorrectors", "nCorr"},
162  5
163  );
164 
165  // Set under-relaxation coeff
166  scalar relaxCoeff = 0.0;
167  if (mesh_.solution().relaxEquation(solverField_))
168  {
169  relaxCoeff = mesh_.solution().equationRelaxationFactor(solverField_);
170  }
171 
174  (
176  );
177 
178  const surfaceScalarField& phi =
179  mesh_.lookupObject<surfaceScalarField>(phiName_);
180 
181  if (phi.dimensions() == dimMass/dimTime)
182  {
183  const volScalarField& rho =
184  mesh_.lookupObject<volScalarField>(rhoName_);
185 
186  const word laplacianScheme("laplacian(muEff," + schemesField_ + ")");
187 
188  tmp<volScalarField> tnuEff;
189  if (diffusion_)
190  {
191  tnuEff = mesh_.lookupType<momentumTransportModel>().nuEff();
192  }
193 
194  for (int i=0; i<=nCorr; i++)
195  {
196  fvScalarMatrix ageEqn
197  (
198  fvm::div(phi, age, divScheme) == rho + fvModels.source(rho, age)
199  );
200 
201  if (diffusion_)
202  {
203  ageEqn -= fvm::laplacian(rho*tnuEff(), age, laplacianScheme);
204  }
205 
206  ageEqn.relax(relaxCoeff);
207 
208  fvConstraints.constrain(ageEqn);
209 
210  if (converged(i, ageEqn.solve(solverField_).initialResidual()))
211  {
212  break;
213  };
214 
216  }
217  }
218  else
219  {
220  tmp<volScalarField> tnuEff;
221  word laplacianScheme;
222 
223  if (diffusion_)
224  {
225  tnuEff = mesh_.lookupType<momentumTransportModel>().nuEff();
226 
227  laplacianScheme =
228  "laplacian(" + tnuEff().name() + ',' + schemesField_ + ")";
229  }
230 
231  for (int i=0; i<=nCorr; i++)
232  {
233  fvScalarMatrix ageEqn
234  (
235  fvm::div(phi, age, divScheme)
237  );
238 
239  if (diffusion_)
240  {
241  ageEqn -= fvm::laplacian(tnuEff(), age, laplacianScheme);
242  }
243 
244  ageEqn.relax(relaxCoeff);
245 
246  fvConstraints.constrain(ageEqn);
247 
248  if (converged(i, ageEqn.solve(solverField_).initialResidual()))
249  {
250  break;
251  }
252 
254  }
255  }
256 
257  Info<< "Min/max age:" << min(age).value()
258  << ' ' << max(age).value() << endl;
259 
260  store(tage);
261 
262  return true;
263 }
264 
265 
267 {
268  return writeObject(typeName);
269 }
270 
271 
272 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
static fvModels & New(const word &name, const fvMesh &mesh)
Construct and return the named DemandDrivenMeshObject.
const dimensionSet & dimensions() const
Return dimensions.
static const char *const typeName
Definition: Field.H:106
Generic GeometricField class.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:61
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Calculates and writes out the time taken for a particle to travel from an inlet to the location....
Definition: age.H:139
age(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: age.C:94
virtual wordList fields() const
Return the list of fields required.
Definition: age.C:127
virtual ~age()
Destructor.
Definition: age.C:108
virtual bool execute()
Execute.
Definition: age.C:133
virtual bool write()
Write.
Definition: age.C:266
virtual bool read(const dictionary &)
Read the data.
Definition: age.C:114
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
Finite volume constraints.
Definition: fvConstraints.H:68
bool constrain(fvMatrix< Type > &eqn) const
Apply constraints to an equation.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:118
void relax(const scalar alpha)
Relax matrix (for steady-state solution).
Definition: fvMatrix.C:602
SolverPerformance< Type > solve(const dictionary &)
Solve segregated or coupled returning the solution statistics.
Definition: fvMatrixSolve.C:58
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:934
Finite volume models.
Definition: fvModels.H:69
tmp< fvMatrix< Type > > source(const VolField< Type > &field) const
Return source for an equation.
Abstract base class for momentum transport models (RAS, LES and laminar).
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
Template function which returns the un-mangled name of a given type. Useful for types which do not ha...
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvConstraints & fvConstraints(Foam::fvConstraints::New(mesh))
Foam::fvModels & fvModels(Foam::fvModels::New(mesh))
const scalar nuEff
Calculate the matrix for the divergence of the given field and flux.
Calculate the matrix for the laplacian of the field.
label patchi
rho
Definition: pEqn.H:1
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
tmp< fvMatrix< Type > > laplacian(const VolField< Type > &vf, const word &name)
Definition: fvmLaplacian.C:47
tmp< fvMatrix< Type > > div(const surfaceScalarField &flux, const VolField< Type > &vf, const word &name)
Definition: fvmDiv.C:48
Namespace for OpenFOAM.
List< word > wordList
A List of words.
Definition: fileName.H:54
const doubleScalar e
Definition: doubleScalar.H:106
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
const dimensionSet & dimMass
Definition: dimensions.C:275
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
messageStream Info
const dimensionSet & dimTime
Definition: dimensions.C:277
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
wordList patchTypes(nPatches)
dictionary dict