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-2018 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 Cloud<ReactingParcel<ParcelType>>, 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 Cloud<ReactingParcel<ParcelType>>, 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 Cloud<ReactingParcel<ParcelType>>, 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);
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;
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;
212  (
214  c,
215  iter
216  )
217  {
218  const ReactingParcel<ParcelType>& p = iter();
219  Y[i++] = p.Y()[j];
220  }
221 
222  Y.write(np > 0);
223  }
224  }
225 }
226 
227 
228 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
229 
230 template<class ParcelType>
231 Foam::Ostream& Foam::operator<<
232 (
233  Ostream& os,
235 )
236 {
237  if (os.format() == IOstream::ASCII)
238  {
239  os << static_cast<const ParcelType&>(p)
240  << token::SPACE << p.mass0()
241  << token::SPACE << p.Y();
242  }
243  else
244  {
245  os << static_cast<const ParcelType&>(p);
246  os.write
247  (
248  reinterpret_cast<const char*>(&p.mass0_),
250  );
251  os << p.Y();
252  }
253 
254  // Check state of Ostream
255  os.check
256  (
257  "Ostream& operator<<(Ostream&, const ReactingParcel<ParcelType>&)"
258  );
259 
260  return os;
261 }
262 
263 
264 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
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 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:163
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:151
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.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
Base cloud calls templated on particle type.
Definition: Cloud.H:52
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
PtrList< volScalarField > & Y
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:187
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
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:74
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:69
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:167
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 [].