ReactingCloud.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "ReactingCloud.H"
30 #include "CompositionModel.H"
31 #include "PhaseChangeModel.H"
32 
33 // * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
34 
35 template<class CloudType>
37 {
38  compositionModel_.reset
39  (
41  (
42  this->subModelProperties(),
43  *this
44  ).ptr()
45  );
46 
47  phaseChangeModel_.reset
48  (
50  (
51  this->subModelProperties(),
52  *this
53  ).ptr()
54  );
55 }
56 
57 
58 template<class CloudType>
60 (
61  const scalarField& YSupplied,
62  const scalarField& Y,
63  const word& YName
64 )
65 {
66  if (YSupplied.size() != Y.size())
67  {
69  << YName << " supplied, but size is not compatible with "
70  << "parcel composition: " << nl << " "
71  << YName << "(" << YSupplied.size() << ") vs required composition "
72  << YName << "(" << Y.size() << ")" << nl
73  << abort(FatalError);
74  }
75 }
76 
77 
78 template<class CloudType>
80 {
81  CloudType::cloudReset(c);
82 
83  compositionModel_.reset(c.compositionModel_.ptr());
84  phaseChangeModel_.reset(c.phaseChangeModel_.ptr());
85 }
86 
87 
88 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
89 
90 template<class CloudType>
92 (
93  const word& cloudName,
94  const volScalarField& rho,
95  const volVectorField& U,
96  const dimensionedVector& g,
97  const SLGThermo& thermo,
98  bool readFields
99 )
100 :
101  CloudType(cloudName, rho, U, g, thermo, false),
102  reactingCloud(),
103  cloudCopyPtr_(nullptr),
104  constProps_(this->particleProperties()),
105  compositionModel_(nullptr),
106  phaseChangeModel_(nullptr),
107  rhoTrans_(thermo.carrier().species().size())
108 {
109  if (this->solution().active())
110  {
111  setModels();
112 
113  if (readFields)
114  {
115  parcelType::readFields(*this, this->composition());
116  this->deleteLostParticles();
117  }
118  }
119 
120  // Set storage for mass source fields and initialise to zero
121  forAll(rhoTrans_, i)
122  {
123  const word& specieName = thermo.carrier().species()[i];
124  rhoTrans_.set
125  (
126  i,
128  (
129  IOobject
130  (
131  this->name() + ":rhoTrans_" + specieName,
132  this->db().time().timeName(),
133  this->db(),
134  IOobject::READ_IF_PRESENT,
135  IOobject::AUTO_WRITE
136  ),
137  this->mesh(),
139  )
140  );
141  }
142 
143  if (this->solution().resetSourcesOnStartup())
144  {
145  resetSourceTerms();
146  }
147 }
148 
149 
150 template<class CloudType>
152 (
154  const word& name
155 )
156 :
157  CloudType(c, name),
158  reactingCloud(),
159  cloudCopyPtr_(nullptr),
160  constProps_(c.constProps_),
161  compositionModel_(c.compositionModel_->clone()),
162  phaseChangeModel_(c.phaseChangeModel_->clone()),
163  rhoTrans_(c.rhoTrans_.size())
164 {
165  forAll(c.rhoTrans_, i)
166  {
167  const word& specieName = this->thermo().carrier().species()[i];
168  rhoTrans_.set
169  (
170  i,
172  (
173  IOobject
174  (
175  this->name() + ":rhoTrans_" + specieName,
176  this->db().time().timeName(),
177  this->db(),
178  IOobject::NO_READ,
179  IOobject::NO_WRITE,
180  false
181  ),
182  c.rhoTrans_[i]
183  )
184  );
185  }
186 }
187 
188 
189 template<class CloudType>
191 (
192  const fvMesh& mesh,
193  const word& name,
195 )
196 :
197  CloudType(mesh, name, c),
198  reactingCloud(),
199  cloudCopyPtr_(nullptr),
200  constProps_(),
201  compositionModel_(c.compositionModel_->clone()),
202  phaseChangeModel_(nullptr),
203  rhoTrans_(0)
204 {}
205 
206 
207 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
208 
209 template<class CloudType>
211 (
212  parcelType& parcel,
213  const scalar lagrangianDt
214 )
215 {
216  CloudType::setParcelThermoProperties(parcel, lagrangianDt);
217 
218  parcel.Y() = composition().YMixture0();
219 }
220 
221 
222 template<class CloudType>
224 (
225  parcelType& parcel,
226  const scalar lagrangianDt,
227  const bool fullyDescribed
228 )
229 {
230  CloudType::checkParcelProperties(parcel, lagrangianDt, fullyDescribed);
231 
232  if (fullyDescribed)
233  {
234  checkSuppliedComposition
235  (
236  parcel.Y(),
237  composition().YMixture0(),
238  "YMixture"
239  );
240  }
241 
242  // derived information - store initial mass
243  parcel.mass0() = parcel.mass();
244 }
245 
246 
247 template<class CloudType>
249 {
250  cloudCopyPtr_.reset
251  (
252  static_cast<ReactingCloud<CloudType>*>
253  (
254  clone(this->name() + "Copy").ptr()
255  )
256  );
257 }
258 
259 
260 template<class CloudType>
262 {
263  cloudReset(cloudCopyPtr_());
264  cloudCopyPtr_.clear();
265 }
266 
267 
268 template<class CloudType>
270 {
271  CloudType::resetSourceTerms();
272  forAll(rhoTrans_, i)
273  {
274  rhoTrans_[i].field() = 0.0;
275  }
276 }
277 
278 
279 template<class CloudType>
281 (
282  const ReactingCloud<CloudType>& cloudOldTime
283 )
284 {
285  CloudType::relaxSources(cloudOldTime);
286 
287  typedef volScalarField::Internal dsfType;
288 
289  forAll(rhoTrans_, fieldi)
290  {
291  dsfType& rhoT = rhoTrans_[fieldi];
292  const dsfType& rhoT0 = cloudOldTime.rhoTrans()[fieldi];
293  this->relax(rhoT, rhoT0, "rho");
294  }
295 }
296 
297 
298 template<class CloudType>
300 {
301  CloudType::scaleSources();
302 
303  typedef volScalarField::Internal dsfType;
304 
305  forAll(rhoTrans_, fieldi)
306  {
307  dsfType& rhoT = rhoTrans_[fieldi];
308  this->scale(rhoT, "rho");
309  }
310 }
311 
312 
313 template<class CloudType>
315 {
316  if (this->solution().canEvolve())
317  {
318  typename parcelType::trackingData td(*this);
319 
320  this->solve(*this, td);
321  }
322 }
323 
324 
325 template<class CloudType>
327 {
329 
330  this->updateMesh();
331 }
332 
333 
334 template<class CloudType>
336 {
337  CloudType::info();
338 
339  this->phaseChange().info(Info);
340 }
341 
342 
343 template<class CloudType>
345 {
346  if (compositionModel_)
347  {
349  }
350 }
351 
352 
353 template<class CloudType>
355 {
356  CloudType::particleType::writeObjects(*this, this->composition(), obr);
357 }
358 
359 
360 // ************************************************************************* //
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::PhaseChangeModel
Templated phase change model class.
Definition: ReactingCloud.H:61
Foam::ReactingCloud::resetSourceTerms
void resetSourceTerms()
Reset the cloud source terms.
Definition: ReactingCloud.C:269
Foam::ReactingCloud::writeFields
virtual void writeFields() const
Write the field data for the cloud.
Definition: ReactingCloud.C:344
Foam::solution
Selector class for relaxation factors, solver type and solution.
Definition: solution.H:51
cloudName
const word cloudName(propsDict.get< word >("cloud"))
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::SLGThermo
Thermo package for (S)olids (L)iquids and (G)ases Takes reference to thermo package,...
Definition: SLGThermo.H:64
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::ReactingCloud::evolve
void evolve()
Evolve the cloud.
Definition: ReactingCloud.C:314
thermo
psiReactionThermo & thermo
Definition: createFields.H:28
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::Cloud::parcelType
ParticleType parcelType
Parcels are just particles.
Definition: Cloud.H:116
PhaseChangeModel.H
rho
rho
Definition: readInitialConditions.H:88
composition
basicSpecieMixture & composition
Definition: createFieldRefs.H:6
solve
CEqn solve()
Foam::ReactingCloud::scaleSources
void scaleSources()
Apply scaling to (transient) cloud sources.
Definition: ReactingCloud.C:299
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::CompositionModel
Templated reacting parcel composition model class Consists of carrier species (via thermo package),...
Definition: ReactingCloud.H:58
Foam::Field< scalar >
Foam::ReactingCloud::rhoTrans
volScalarField::Internal & rhoTrans(const label i)
Mass.
Definition: ReactingCloudI.H:80
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::writeFields
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields)
Foam::ReactingCloud::setModels
void setModels()
Set cloud sub-models.
Definition: ReactingCloud.C:36
Foam::reactingCloud
Virtual abstract base class for templated ReactingCloud.
Definition: reactingCloud.H:50
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
Foam::CloudType
DSMCCloud< dsmcParcel > CloudType
Definition: makeDSMCParcelBinaryCollisionModels.C:38
Foam::ReactingCloud::storeState
void storeState()
Store the current cloud state.
Definition: ReactingCloud.C:248
timeName
word timeName
Definition: getTimeIndex.H:3
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::dimensioned< vector >
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:24
Foam::dimMass
const dimensionSet dimMass(1, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:52
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Y
PtrList< volScalarField > & Y
Definition: createFieldRefs.H:7
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.
Definition: ReadFieldsTemplates.C:312
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
U
U
Definition: pEqn.H:72
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
CompositionModel.H
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:54
Foam::ReactingCloud::autoMap
virtual void autoMap(const mapPolyMesh &)
Remap the cells of particles corresponding to the.
Definition: ReactingCloud.C:326
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::ReactingCloud::restoreState
void restoreState()
Reset the current cloud to the previously stored state.
Definition: ReactingCloud.C:261
Foam::ReactingCloud::checkParcelProperties
void checkParcelProperties(parcelType &parcel, const scalar lagrangianDt, const bool fullyDescribed)
Check parcel properties.
Definition: ReactingCloud.C:224
Foam::ReactingCloud::info
void info()
Print cloud information.
Definition: ReactingCloud.C:335
ReactingCloud.H
Foam::ReactingCloud::setParcelThermoProperties
void setParcelThermoProperties(parcelType &parcel, const scalar lagrangianDt)
Set parcel thermo properties.
Definition: ReactingCloud.C:211
Foam::ReactingCloud::writeObjects
virtual void writeObjects(objectRegistry &obr) const
Write particle fields as objects into the obr registry.
Definition: ReactingCloud.C:354
Foam::ReactingCloud::relaxSources
void relaxSources(const ReactingCloud< CloudType > &cloudOldTime)
Apply relaxation to (steady state) cloud sources.
Definition: ReactingCloud.C:281
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::ReactingCloud::checkSuppliedComposition
void checkSuppliedComposition(const scalarField &YSupplied, const scalarField &Y, const word &YName)
Check that size of a composition field is valid.
Definition: ReactingCloud.C:60
Foam::DimensionedField
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: DimensionedField.H:54
Foam::ReactingCloud
Templated base class for reacting cloud.
Definition: ReactingCloud.H:68
Foam::ReactingCloud::cloudReset
void cloudReset(ReactingCloud< CloudType > &c)
Reset state of cloud.
Definition: ReactingCloud.C:79
relax
UEqn relax()