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-------------------------------------------------------------------------------
11License
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
34template<class ParcelType>
37
38
39template<class ParcelType>
41(
42 sizeof(ThermoParcel<ParcelType>)
43 - offsetof(ThermoParcel<ParcelType>, T_)
44);
45
46
47// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
48
49template<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
86}
87
88
89template<class ParcelType>
90template<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
115template<class ParcelType>
116template<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
141template<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
163template<class ParcelType>
164template<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
189template<class ParcelType>
190template<class CloudType>
192(
193 const CloudType& c,
194 objectRegistry& obr
195)
196{
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
217template<class ParcelType>
218Foam::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_),
237 );
238 }
239
241 return os;
242}
243
244
245// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field)
A primitive field of type <T> with automated input and output.
Definition: IOField.H:58
streamFormat format() const noexcept
Get the current stream format.
std::enable_if< std::is_integral< T >::value, bool >::type checkLabelSize() const noexcept
Definition: IOstream.H:300
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
std::enable_if< std::is_floating_point< T >::value, bool >::type checkScalarSize() const noexcept
Definition: IOstream.H:309
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
virtual bool endRawRead()=0
End of low-level raw binary read.
virtual bool beginRawRead()=0
Start of low-level raw binary read.
virtual Istream & read(token &)=0
Return next token from stream.
virtual Ostream & write(const char c)
Write character.
Definition: OBJstream.C:78
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Thermodynamic parcel class with one/two-way coupling with the continuous phase. Includes Kinematic pa...
Definition: ThermoParcel.H:74
scalar Cp_
Specific heat capacity [J/(kg.K)].
Definition: ThermoParcel.H:256
static const std::size_t sizeofFields
Size in bytes of the fields.
Definition: ThermoParcel.H:78
static void readObjects(CloudType &c, const objectRegistry &obr)
Read particle fields as objects from the obr registry.
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly=false) const
Write individual parcel properties to stream.
scalar T_
Temperature [K].
Definition: ThermoParcel.H:253
static void readFields(CloudType &c)
Read.
Reads fields from the time directories and adds them to the mesh database for further post-processing...
Definition: readFields.H:158
Allows specification of different writing frequency of objects registered to the database.
Definition: writeObjects.H:142
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly) const
Write individual parcel properties to stream.
Registry of regIOobjects.
static string propertyList()
Definition: particle.H:372
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
virtual bool write(const bool valid=true) const
Write using setting from DB.
A class for handling character strings derived from std::string.
Definition: string.H:79
@ SPACE
Space [isspace].
Definition: token.H:125
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
A class for handling words, derived from Foam::string.
Definition: word.H:68
volScalarField & p
const volScalarField & T
const volScalarField & Cp
Definition: EEqn.H:7
dynamicFvMesh & mesh
OBJstream os(runTime.globalPath()/outputName)
#define writeProp(Name, Value)
#define FUNCTION_NAME
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const wordHashSet &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the templated type.