ReactingParcelIO.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) 2011-2021 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 "ReactingParcel.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class ParcelType>
32 Foam::string Foam::ReactingParcel<ParcelType>::propertyList_ =
34 
35 template<class ParcelType>
37 (
38  sizeof(scalar)
39 );
40 
41 
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 
44 template<class ParcelType>
46 (
47  const polyMesh& mesh,
48  Istream& is,
49  bool readFields
50 )
51 :
52  ParcelType(mesh, is, readFields),
53  mass0_(0.0),
54  Y_(0)
55 {
56  if (readFields)
57  {
59 
60  if (is.format() == IOstream::ASCII)
61  {
62  is >> mass0_ >> Ymix;
63  }
64  else
65  {
66  is.read(reinterpret_cast<char*>(&mass0_), sizeofFields_);
67  is >> Ymix;
68  }
69 
70  Y_.transfer(Ymix);
71  }
72 
73  // Check state of Istream
74  is.check
75  (
76  "ReactingParcel<ParcelType>::ReactingParcel"
77  "("
78  "const polyMesh&, "
79  "Istream&, "
80  "bool"
81  ")"
82  );
83 }
84 
85 
86 template<class ParcelType>
87 template<class CloudType>
89 {
91 }
92 
93 
94 template<class ParcelType>
95 template<class CloudType, class CompositionType>
97 (
98  CloudType& c,
99  const CompositionType& compModel
100 )
101 {
102  bool valid = c.size();
103 
105 
106  IOField<scalar> mass0
107  (
108  c.fieldIOobject("mass0", IOobject::MUST_READ),
109  valid
110  );
111  c.checkFieldIOobject(c, mass0);
112 
113  label i = 0;
114  forAllIter(typename CloudType, c, iter)
115  {
116  ReactingParcel<ParcelType>& p = iter();
117  p.mass0_ = mass0[i++];
118  }
119 
120  // Get names and sizes for each Y...
121  const wordList& phaseTypes = compModel.phaseTypes();
122  const label nPhases = phaseTypes.size();
123  wordList stateLabels(nPhases, "");
124  if (compModel.nPhase() == 1)
125  {
126  stateLabels = compModel.stateLabels()[0];
127  }
128 
129 
130  // Set storage for each Y... for each parcel
131  forAllIter(typename CloudType, c, iter)
132  {
133  ReactingParcel<ParcelType>& p = iter();
134  p.Y_.setSize(nPhases, 0.0);
135  }
136 
137  // Populate Y for each parcel
138  forAll(phaseTypes, j)
139  {
141  (
142  c.fieldIOobject
143  (
144  "Y" + phaseTypes[j] + stateLabels[j],
145  IOobject::MUST_READ
146  ),
147  valid
148  );
149 
150  label i = 0;
151  forAllIter(typename CloudType, c, iter)
152  {
153  ReactingParcel<ParcelType>& p = iter();
154  p.Y_[j] = Y[i++];
155  }
156  }
157 }
158 
159 
160 template<class ParcelType>
161 template<class CloudType>
163 {
164  ParcelType::writeFields(c);
165 }
166 
167 
168 template<class ParcelType>
169 template<class CloudType, class CompositionType>
171 (
172  const CloudType& c,
173  const CompositionType& compModel
174 )
175 {
176  ParcelType::writeFields(c, compModel);
177 
178  const label np = c.size();
179 
180  {
181  IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
182 
183  label i = 0;
184  forAllConstIter(typename CloudType, c, iter)
185  {
186  const ReactingParcel<ParcelType>& p = iter();
187  mass0[i++] = p.mass0_;
188  }
189  mass0.write(np > 0);
190 
191  // Write the composition fractions
192  const wordList& phaseTypes = compModel.phaseTypes();
193  wordList stateLabels(phaseTypes.size(), "");
194  if (compModel.nPhase() == 1)
195  {
196  stateLabels = compModel.stateLabels()[0];
197  }
198 
199  forAll(phaseTypes, j)
200  {
202  (
203  c.fieldIOobject
204  (
205  "Y" + phaseTypes[j] + stateLabels[j],
206  IOobject::NO_READ
207  ),
208  np
209  );
210  label i = 0;
211  forAllConstIter(typename CloudType, c, iter)
212  {
213  const ReactingParcel<ParcelType>& p = iter();
214  Y[i++] = p.Y()[j];
215  }
216 
217  Y.write(np > 0);
218  }
219  }
220 }
221 
222 
223 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
224 
225 template<class ParcelType>
226 Foam::Ostream& Foam::operator<<
227 (
228  Ostream& os,
230 )
231 {
232  if (os.format() == IOstream::ASCII)
233  {
234  os << static_cast<const ParcelType&>(p)
235  << token::SPACE << p.mass0()
236  << token::SPACE << p.Y();
237  }
238  else
239  {
240  os << static_cast<const ParcelType&>(p);
241  os.write
242  (
243  reinterpret_cast<const char*>(&p.mass0_),
245  );
246  os << p.Y();
247  }
248 
249  // Check state of Ostream
250  os.check
251  (
252  "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
253  );
254 
255  return os;
256 }
257 
258 
259 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject *> &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
scalarField Y_
Mass fractions of mixture [].
ReactingParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from mesh, coordinates and topology.
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:190
static void writeFields(const CloudType &c, const CompositionType &compModel)
Write.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static void readFields(CloudType &c, const CompositionType &compModel)
Read.
virtual Istream & read(token &)=0
Return next token from stream.
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
PtrList< volScalarField > & Y
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:190
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
Reacting parcel class with one/two-way coupling with the continuous phase.
volScalarField & p
scalar mass0_
Initial mass [kg].
void transfer(List< T > &)
Transfer contents of the argument List into this.
Definition: DynamicListI.H:285
A class for handling character strings derived from std::string.
Definition: string.H:76
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:170
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
const scalarField & Y() const
Return const access to mass fractions of mixture [].