ThermoParcelIO.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) 2016-2019 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 "ThermoParcel.H"
30 #include "IOstreams.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 template<class ParcelType>
37 
38 
39 template<class ParcelType>
41 (
42  sizeof(ThermoParcel<ParcelType>)
43  - offsetof(ThermoParcel<ParcelType>, T_)
44 );
45 
46 
47 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48 
49 template<class ParcelType>
51 (
52  const polyMesh& mesh,
53  Istream& is,
54  bool readFields,
55  bool newFormat
56 )
57 :
58  ParcelType(mesh, is, readFields, newFormat),
59  T_(0.0),
60  Cp_(0.0)
61 {
62  if (readFields)
63  {
64  if (is.format() == IOstream::ASCII)
65  {
66  is >> T_ >> Cp_;
67  }
68  else if (!is.checkLabelSize<>() || !is.checkScalarSize<>())
69  {
70  // Non-native label or scalar size
71 
72  is.beginRawRead();
73 
74  readRawScalar(is, &T_);
75  readRawScalar(is, &Cp_);
76 
77  is.endRawRead();
78  }
79  else
80  {
81  is.read(reinterpret_cast<char*>(&T_), sizeofFields);
82  }
83  }
84 
85  is.check(FUNCTION_NAME);
86 }
87 
88 
89 template<class ParcelType>
90 template<class CloudType>
92 {
93  const bool valid = c.size();
94 
96 
97  IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ), valid);
98  c.checkFieldIOobject(c, T);
99 
100  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::MUST_READ), valid);
101  c.checkFieldIOobject(c, Cp);
102 
103 
104  label i = 0;
105  for (ThermoParcel<ParcelType>& p : c)
106  {
107  p.T_ = T[i];
108  p.Cp_ = Cp[i];
109 
110  ++i;
111  }
112 }
113 
114 
115 template<class ParcelType>
116 template<class CloudType>
118 {
120 
121  const label np = c.size();
122  const bool valid = np;
123 
124  IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
125  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::NO_READ), np);
126 
127  label i = 0;
128  for (const ThermoParcel<ParcelType>& p : c)
129  {
130  T[i] = p.T_;
131  Cp[i] = p.Cp_;
132 
133  ++i;
134  }
135 
136  T.write(valid);
137  Cp.write(valid);
138 }
139 
140 
141 template<class ParcelType>
143 (
144  Ostream& os,
145  const wordRes& filters,
146  const word& delim,
147  const bool namesOnly
148 ) const
149 {
150  ParcelType::writeProperties(os, filters, delim, namesOnly);
151 
152  #undef writeProp
153  #define writeProp(Name, Value) \
154  ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters)
155 
156  writeProp("T", T_);
157  writeProp("Cp", Cp_);
158 
159  #undef writeProp
160 }
161 
162 
163 template<class ParcelType>
164 template<class CloudType>
166 (
167  CloudType& c,
168  const objectRegistry& obr
169 )
170 {
172 
173  if (!c.size()) return;
174 
175  auto& T = cloud::lookupIOField<scalar>("T", obr);
176  auto& Cp = cloud::lookupIOField<scalar>("Cp", obr);
177 
178  label i = 0;
179  for (ThermoParcel<ParcelType>& p : c)
180  {
181  p.T_ = T[i];
182  p.Cp_ = Cp[i];
183 
184  ++i;
185  }
186 }
187 
188 
189 template<class ParcelType>
190 template<class CloudType>
192 (
193  const CloudType& c,
194  objectRegistry& obr
195 )
196 {
197  ParcelType::writeObjects(c, obr);
198 
199  const label np = c.size();
200 
201  auto& T = cloud::createIOField<scalar>("T", np, obr);
202  auto& Cp = cloud::createIOField<scalar>("Cp", np, obr);
203 
204  label i = 0;
205  for (const ThermoParcel<ParcelType>& p : c)
206  {
207  T[i] = p.T_;
208  Cp[i] = p.Cp_;
209 
210  ++i;
211  }
212 }
213 
214 
215 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
216 
217 template<class ParcelType>
218 Foam::Ostream& Foam::operator<<
219 (
220  Ostream& os,
221  const ThermoParcel<ParcelType>& p
222 )
223 {
224  if (os.format() == IOstream::ASCII)
225  {
226  os << static_cast<const ParcelType&>(p)
227  << token::SPACE << p.T()
228  << token::SPACE << p.Cp();
229  }
230  else
231  {
232  os << static_cast<const ParcelType&>(p);
233  os.write
234  (
235  reinterpret_cast<const char*>(&p.T_),
237  );
238  }
239 
241  return os;
242 }
243 
244 
245 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::ThermoParcel::writeFields
static void writeFields(const CloudType &c)
Definition: ThermoParcelIO.C:110
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:57
Foam::IOstreamOption::format
streamFormat format() const noexcept
Definition: IOstreamOption.H:282
Foam::ThermoParcel::writeProperties
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly=false) const
Definition: ThermoParcelIO.C:136
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:72
Foam::OBJstream::write
virtual Ostream & write(const char c)
Definition: OBJstream.C:71
Foam::ThermoParcel::writeObjects
static void writeObjects(const CloudType &c, objectRegistry &obr)
Definition: ThermoParcelIO.C:185
Foam::ThermoParcel::sizeofFields
static const std::size_t sizeofFields
Definition: ThermoParcel.H:74
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:56
Foam::ThermoParcel::T_
scalar T_
Definition: ThermoParcel.H:249
Foam::ThermoParcel::Cp_
scalar Cp_
Definition: ThermoParcel.H:252
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:51
Foam::ThermoParcel::readObjects
static void readObjects(CloudType &c, const objectRegistry &obr)
Definition: ThermoParcelIO.C:159
Foam::CloudType
DSMCCloud< dsmcParcel > CloudType
Definition: makeDSMCParcelBinaryCollisionModels.C:31
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:67
Foam::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.C:51
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::readFields
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Definition: ReadFieldsTemplates.C:305
Foam::GeometricField::T
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Definition: GeometricField.C:1039
Foam::IOstreamOption::ASCII
@ ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:68
Foam::ThermoParcel
Thermodynamic parcel class with one/two-way coupling with the continuous phase. Includes Kinematic pa...
Definition: ThermoParcel.H:53
Foam::token::SPACE
@ SPACE
Space [isspace].
Definition: token.H:121
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
Cp
const volScalarField & Cp
Definition: EEqn.H:7
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:302
Foam::constant::universal::c
const dimensionedScalar c
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
ThermoParcel.H
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:184
writeProp
#define writeProp(Name, Value)
Foam::ThermoParcel::ThermoParcel
ThermoParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Definition: ThermoParcelI.H:70
Foam::ThermoParcel::readFields
static void readFields(CloudType &c)
Definition: ThermoParcelIO.C:84
Foam::writeFields
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181