adjustTimeStepToReaction.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) 2023-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 
27 #include "reactionModel.H"
28 #include "solver.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
38 
40  (
44  );
45 }
46 }
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
51 Foam::functionObjects::adjustTimeStepToReaction::propsDictIo
52 (
53  const IOobject::readOption& r
54 ) const
55 {
56  return
57  typeIOobject<timeIOdictionary>
58  (
59  name() + "Properties",
60  obr_.time().name(),
61  "uniform",
62  obr_,
63  r,
65  false
66  );
67 }
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
73 (
74  const word& name,
75  const Time& runTime,
76  const dictionary& dict
77 )
78 :
79  regionFunctionObject(name, runTime, dict),
80  phaseName_(word::null),
81  maxCo_(NaN),
82  extrapolate_(false),
83  haveReactionDeltaT0_(false),
84  reactionDeltaT0_(NaN)
85 {
86  read(dict);
87 }
88 
89 
90 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
91 
93 {}
94 
95 
96 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
97 
99 (
100  const dictionary& dict
101 )
102 {
103  phaseName_ = dict.lookupOrDefault<word>("phase", word::null);
104  maxCo_ = dict.lookupOrDefault<scalar>("maxCo", 1);
105  extrapolate_ = dict.lookupOrDefault<bool>("extrapolate", false);
106 
108  (
109  this->propsDictIo(IOobject::MUST_READ_IF_MODIFIED)
110  );
111 
112  if (propsDictIo.headerOk())
113  {
114  const timeIOdictionary propsDict(propsDictIo);
115 
116  haveReactionDeltaT0_ = true;
117  reactionDeltaT0_ = propsDict.lookup<scalar>("reactionDeltaT");
118  }
119  else
120  {
121  haveReactionDeltaT0_ = false;
122  }
123 
124  return true;
125 }
126 
127 
129 {
130  return true;
131 }
132 
133 
135 {
136  if (extrapolate_ && obr_.time().writeTime())
137  {
139 
140  propsDict.add("reactionDeltaT", reactionDeltaT0_);
141 
142  propsDict.regIOobject::write();
143  }
144 
145  return true;
146 }
147 
148 
149 Foam::scalar
151 {
152  if (!time_.controlDict().lookupOrDefault("adjustTimeStep", false))
153  {
154  return vGreat;
155  }
156 
157  const reactionModel& reaction =
158  obr_.lookupObject<reactionModel>
159  (
161  (
163  phaseName_
164  )
165  );
166 
167  const fluidMulticomponentThermo& thermo = reaction.thermo();
168 
169  // Build a mass turnover rate
170  volScalarField::Internal rhoDotByRho
171  (
173  (
174  "rhoDotByRho",
175  reaction.mesh(),
177  )
178  );
179  forAll(thermo.Y(), i)
180  {
181  if (thermo.solveSpecie(i))
182  {
183  rhoDotByRho += mag(reaction.R(i))/2/thermo.rho()();
184  }
185  }
186 
187  // Convert to a time-scale
188  const scalar reactionDeltaT1 = maxCo_/max(gMax(rhoDotByRho), vSmall);
189 
190  // We want to clip the time-step to the time-scale, but also additionally
191  // reduce the time-step significantly if that time-scale is reducing
192  // rapidly. This helps us catch the onset of reactions. The following does
193  // this by passing the change ratio into a steeply non-linear function.
194  scalar deltaT;
195  if (extrapolate_ && haveReactionDeltaT0_)
196  {
197  const scalar x = min(max(reactionDeltaT1/reactionDeltaT0_, 0), 1);
198  const scalar f = (1 - rootSmall)*(1 - sqrt(1 - sqr(x))) + rootSmall;
199  deltaT = f*reactionDeltaT1;
200  }
201  else
202  {
203  deltaT = reactionDeltaT1;
204  }
205 
206  // Store the latest reaction time-step
207  haveReactionDeltaT0_ = true;
208  reactionDeltaT0_ = reactionDeltaT1;
209 
210  return deltaT;
211 }
212 
213 
214 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static tmp< DimensionedField< Type, GeoMesh, PrimitiveField > > New(const word &name, const GeoMesh &mesh, const dimensionSet &, const PrimitiveField< Type > &)
Return a temporary field constructed from name, mesh,.
@ MUST_READ_IF_MODIFIED
Definition: IOobject.H:119
static word groupName(Name name, const word &group)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return const reference to name.
Base-class for multi-component fluid thermodynamic properties.
Abstract base-class for Time/database functionObjects.
const word & name() const
Return the name of this functionObject.
Returns the minimum bulk reaction time scale.
virtual scalar maxDeltaT() const
Return the minimum reaction time-scale.
adjustTimeStepToReaction(const word &name, const Time &runTime, const dictionary &dict)
Construct from components.
virtual bool read(const dictionary &)
Read and reset the timeStep Function1.
const objectRegistry & obr_
Reference to the objectRegistry.
Specialisation of Foam::functionObject for a region.
const Time & time() const
Return time.
Base class for reaction models.
Definition: reactionModel.H:53
static const word reactionPropertiesName
Default reactionProperties dictionary name.
Definition: reactionModel.H:90
Reaction base-class holding the specie names and coefficients.
Definition: reaction.H:57
timeIOdictionary derived from IOdictionary with globalFile set false to enable writing to processor t...
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:545
A class for handling words, derived from string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:78
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
const dimensionSet & dimless
Definition: dimensions.C:138
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
const dimensionSet & dimTime
Definition: dimensions.C:142
dimensioned< Type > min(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
Type gMax(const UList< Type > &f, const label comm)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
tmp< DimensionedField< scalar, GeoMesh, Field > > mag(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
void sqrt(LagrangianPatchField< scalar > &f, const LagrangianPatchField< scalar > &f1)
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
labelList f(nPoints)
dictionary dict
fluidMulticomponentThermo & thermo
Definition: createFields.H:15
IOdictionary propsDict(systemDict("particleTracksDict", args, runTime))