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,
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_),
236  ThermoParcel<ParcelType>::sizeofFields
237  );
238  }
239 
240  os.check(FUNCTION_NAME);
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)
Write.
Definition: ThermoParcelIO.C:117
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: foamVtkLagrangianWriter.H:61
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:286
Foam::ThermoParcel::writeProperties
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly=false) const
Write individual parcel properties to stream.
Definition: ThermoParcelIO.C:143
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:76
Foam::ThermoParcel::writeObjects
static void writeObjects(const CloudType &c, objectRegistry &obr)
Write particle fields as objects into the obr registry.
Definition: ThermoParcelIO.C:192
Foam::ThermoParcel::sizeofFields
static const std::size_t sizeofFields
Size in bytes of the fields.
Definition: ThermoParcel.H:78
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::IOstream::checkLabelSize
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Definition: IOstream.H:300
Foam::Istream::endRawRead
virtual bool endRawRead()=0
End of low-level raw binary read.
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::ThermoParcel::readObjects
static void readObjects(CloudType &c, const objectRegistry &obr)
Read particle fields as objects from the obr registry.
Definition: ThermoParcelIO.C:166
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:71
Foam::IOstream::checkScalarSize
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Definition: IOstream.H:309
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
T
const volScalarField & T
Definition: createFieldRefs.H:2
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::Istream::beginRawRead
virtual bool beginRawRead()=0
Start of low-level raw binary read.
Foam::ThermoParcel
Thermodynamic parcel class with one/two-way coupling with the continuous phase. Includes Kinematic pa...
Definition: ThermoParcel.H:57
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
Cp
const volScalarField & Cp
Definition: EEqn.H:7
FUNCTION_NAME
#define FUNCTION_NAME
Definition: messageStream.H:295
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
ThermoParcel.H
writeProp
#define writeProp(Name, Value)
Foam::ThermoParcel::ThermoParcel
ThermoParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from mesh, coordinates and topology.
Definition: ThermoParcelI.H:77
Foam::ThermoParcel::readFields
static void readFields(CloudType &c)
Read.
Definition: ThermoParcelIO.C:91
Foam::writeFields
void writeFields(const fvMesh &mesh, const wordHashSet &selectedFields, const bool writeFaceFields)
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.