SprayParcelIO.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-2023 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 "SprayParcel.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class ParcelType>
33 (
34  sizeof(SprayParcel<ParcelType>) - sizeof(ParcelType)
35 );
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
40 template<class ParcelType>
42 :
43  ParcelType(is, readFields),
44  d0_(0.0),
45  mass0_(0.0),
46  position0_(Zero),
47  sigma_(0.0),
48  mu_(0.0),
49  liquidCore_(0.0),
50  KHindex_(0.0),
51  y_(0.0),
52  yDot_(0.0),
53  tc_(0.0),
54  ms_(0.0),
55  injector_(-1),
56  tMom_(great)
57 {
58  if (readFields)
59  {
60  if (is.format() == IOstream::ASCII)
61  {
62  d0_ = readScalar(is);
63  mass0_ = readScalar(is);
64  is >> position0_;
65  sigma_ = readScalar(is);
66  mu_ = readScalar(is);
67  liquidCore_ = readScalar(is);
68  KHindex_ = readScalar(is);
69  y_ = readScalar(is);
70  yDot_ = readScalar(is);
71  tc_ = readScalar(is);
72  ms_ = readScalar(is);
73  injector_ = readLabel(is);
74  tMom_ = readScalar(is);
75  }
76  else
77  {
78  is.read(reinterpret_cast<char*>(&d0_), sizeofFields_);
79  }
80  }
81 
82  // Check state of Istream
83  is.check
84  (
85  "SprayParcel<ParcelType>::SprayParcel"
86  "("
87  "const polyMesh, "
88  "Istream&, "
89  "bool"
90  ")"
91  );
92 }
93 
94 
95 template<class ParcelType>
96 template<class CloudType>
98 {
100 }
101 
102 
103 template<class ParcelType>
104 template<class CloudType, class CompositionType>
106 (
107  CloudType& c,
108  const CompositionType& compModel
109 )
110 {
111  bool write = c.size();
112 
113  ParcelType::readFields(c, compModel);
114 
115  IOField<scalar> d0(c.fieldIOobject("d0", IOobject::MUST_READ), write);
116  c.checkFieldIOobject(c, d0);
117 
118  IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::MUST_READ), write);
119  c.checkFieldIOobject(c, mass0);
120 
121  IOField<vector> position0
122  (
123  c.fieldIOobject("position0", IOobject::MUST_READ),
124  write
125  );
126  c.checkFieldIOobject(c, position0);
127 
128  IOField<scalar> sigma(c.fieldIOobject("sigma", IOobject::MUST_READ), write);
129  c.checkFieldIOobject(c, sigma);
130 
131  IOField<scalar> mu(c.fieldIOobject("mu", IOobject::MUST_READ), write);
132  c.checkFieldIOobject(c, mu);
133 
134  IOField<scalar> liquidCore
135  (
136  c.fieldIOobject("liquidCore", IOobject::MUST_READ),
137  write
138  );
139  c.checkFieldIOobject(c, liquidCore);
140 
141  IOField<scalar> KHindex
142  (
143  c.fieldIOobject("KHindex", IOobject::MUST_READ),
144  write
145  );
146  c.checkFieldIOobject(c, KHindex);
147 
149  (
150  c.fieldIOobject("y", IOobject::MUST_READ),
151  write
152  );
153  c.checkFieldIOobject(c, y);
154 
155  IOField<scalar> yDot
156  (
157  c.fieldIOobject("yDot", IOobject::MUST_READ),
158  write
159  );
160  c.checkFieldIOobject(c, yDot);
161 
162  IOField<scalar> tc
163  (
164  c.fieldIOobject("tc", IOobject::MUST_READ),
165  write
166  );
167  c.checkFieldIOobject(c, tc);
168 
169  IOField<scalar> ms
170  (
171  c.fieldIOobject("ms", IOobject::MUST_READ),
172  write
173  );
174  c.checkFieldIOobject(c, ms);
175 
176  IOField<label> injector
177  (
178  c.fieldIOobject("injector", IOobject::MUST_READ),
179  write
180  );
181  c.checkFieldIOobject(c, injector);
182 
183  IOField<scalar> tMom
184  (
185  c.fieldIOobject("tMom", IOobject::MUST_READ),
186  write
187  );
188  c.checkFieldIOobject(c, tMom);
189 
190  label i = 0;
191  forAllIter(typename CloudType, c, iter)
192  {
193  SprayParcel<ParcelType>& p = iter();
194  p.d0_ = d0[i];
195  p.mass0_ = mass0[i];
196  p.position0_ = position0[i];
197  p.sigma_ = sigma[i];
198  p.mu_ = mu[i];
199  p.liquidCore_ = liquidCore[i];
200  p.KHindex_ = KHindex[i];
201  p.y_ = y[i];
202  p.yDot_ = yDot[i];
203  p.tc_ = tc[i];
204  p.ms_ = ms[i];
205  p.injector_ = injector[i];
206  p.tMom_ = tMom[i];
207  i++;
208  }
209 }
210 
211 
212 template<class ParcelType>
213 template<class CloudType>
215 {
216  ParcelType::writeFields(c);
217 }
218 
219 
220 template<class ParcelType>
221 template<class CloudType, class CompositionType>
223 (
224  const CloudType& c,
225  const CompositionType& compModel
226 )
227 {
228  ParcelType::writeFields(c, compModel);
229 
230  label np = c.size();
231 
232  IOField<scalar> d0(c.fieldIOobject("d0", IOobject::NO_READ), np);
233  IOField<scalar> mass0(c.fieldIOobject("mass0", IOobject::NO_READ), np);
234  IOField<vector> position0
235  (
236  c.fieldIOobject("position0", IOobject::NO_READ),
237  np
238  );
239  IOField<scalar> sigma(c.fieldIOobject("sigma", IOobject::NO_READ), np);
240  IOField<scalar> mu(c.fieldIOobject("mu", IOobject::NO_READ), np);
241  IOField<scalar> liquidCore
242  (
243  c.fieldIOobject("liquidCore", IOobject::NO_READ),
244  np
245  );
246  IOField<scalar> KHindex(c.fieldIOobject("KHindex", IOobject::NO_READ), np);
247  IOField<scalar> y(c.fieldIOobject("y", IOobject::NO_READ), np);
248  IOField<scalar> yDot(c.fieldIOobject("yDot", IOobject::NO_READ), np);
249  IOField<scalar> tc(c.fieldIOobject("tc", IOobject::NO_READ), np);
250  IOField<scalar> ms(c.fieldIOobject("ms", IOobject::NO_READ), np);
251  IOField<label> injector
252  (
253  c.fieldIOobject("injector", IOobject::NO_READ),
254  np
255  );
256  IOField<scalar> tMom(c.fieldIOobject("tMom", IOobject::NO_READ), np);
257 
258  label i = 0;
259  forAllConstIter(typename CloudType, c, iter)
260  {
261  const SprayParcel<ParcelType>& p = iter();
262  d0[i] = p.d0_;
263  mass0[i] = p.mass0_;
264  position0[i] = p.position0_;
265  sigma[i] = p.sigma_;
266  mu[i] = p.mu_;
267  liquidCore[i] = p.liquidCore_;
268  KHindex[i] = p.KHindex_;
269  y[i] = p.y_;
270  yDot[i] = p.yDot_;
271  tc[i] = p.tc_;
272  ms[i] = p.ms_;
273  injector[i] = p.injector_;
274  tMom[i] = p.tMom_;
275  i++;
276  }
277 
278  const bool write = np > 0;
279 
280  d0.write(write);
281  mass0.write(write);
282  position0.write(write);
283  sigma.write(write);
284  mu.write(write);
285  liquidCore.write(write);
286  KHindex.write(write);
287  y.write(write);
288  yDot.write(write);
289  tc.write(write);
290  ms.write(write);
291  injector.write(write);
292  tMom.write(write);
293 }
294 
295 
296 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
297 
298 template<class ParcelType>
299 Foam::Ostream& Foam::operator<<
300 (
301  Ostream& os,
303 )
304 {
305  if (os.format() == IOstream::ASCII)
306  {
307  os << static_cast<const ParcelType&>(p)
308  << token::SPACE << p.d0()
309  << token::SPACE << p.mass0()
310  << token::SPACE << p.position0()
311  << token::SPACE << p.sigma()
312  << token::SPACE << p.mu()
313  << token::SPACE << p.liquidCore()
314  << token::SPACE << p.KHindex()
315  << token::SPACE << p.y()
316  << token::SPACE << p.yDot()
317  << token::SPACE << p.tc()
318  << token::SPACE << p.ms()
319  << token::SPACE << p.injector()
320  << token::SPACE << p.tMom();
321  }
322  else
323  {
324  os << static_cast<const ParcelType&>(p);
325  os.write
326  (
327  reinterpret_cast<const char*>(&p.d0_),
328  SprayParcel<ParcelType>::sizeofFields_
329  );
330  }
331 
332  // Check state of Ostream
333  os.check
334  (
335  "Ostream& operator<<(Ostream&, const SprayParcel<ParcelType>&)"
336  );
337 
338  return os;
339 }
340 
341 
342 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
scalar y
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Reaching spray parcel, with added functionality for atomisation and breakup.
Definition: SprayParcel.H:69
SprayParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const label facei)
Construct from mesh, coordinates and topology.
Definition: SprayParcelI.H:110
scalar d0_
Initial droplet diameter [m].
Definition: SprayParcel.H:149
vector position0_
Injection position.
Definition: SprayParcel.H:155
label injector_
Injector id.
Definition: SprayParcel.H:182
scalar mu_
Liquid dynamic viscosity [Pa.s].
Definition: SprayParcel.H:161
scalar sigma_
Liquid surface tension [N/m].
Definition: SprayParcel.H:158
static void writeFields(const CloudType &c, const CompositionType &compModel)
Write.
scalar tMom_
Momentum relaxation time (needed for calculating parcel acc.)
Definition: SprayParcel.H:185
scalar y_
Spherical deviation.
Definition: SprayParcel.H:170
scalar tc_
Characteristic time (used in atomisation and/or breakup model)
Definition: SprayParcel.H:176
scalar KHindex_
Index for KH Breakup.
Definition: SprayParcel.H:167
scalar mass0_
Initial mass [kg].
Definition: SprayParcel.H:152
scalar ms_
Stripped parcel mass due to breakup.
Definition: SprayParcel.H:179
scalar yDot_
Rate of change of spherical deviation.
Definition: SprayParcel.H:173
static void readFields(CloudType &c, const CompositionType &compModel)
Read.
scalar liquidCore_
Part of liquid core ( >0.5=liquid, <0.5=droplet )
Definition: SprayParcel.H:164
virtual bool write(const bool write=true) const
Write using setting from DB.
const dimensionedScalar sigma
Stefan-Boltzmann constant: default SI units: [W/m^2/K^4].
const dimensionedScalar mu
Atomic mass unit.
const dimensionedScalar c
Speed of light in a vacuum.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
static const zero Zero
Definition: zero.H:97
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
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
label readLabel(Istream &is)
Definition: label.H:64
volScalarField & p