Loading...
Searching...
No Matches
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-2022 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>)
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() == IOstreamOption::ASCII)
65 {
66 is >> T_ >> Cp_;
67 }
68 else
69 {
70 // No non-native streaming
72
73 is.read(reinterpret_cast<char*>(&T_), sizeofFields);
74 }
75 }
78}
79
80
81template<class ParcelType>
82template<class CloudType>
84{
85 const bool readOnProc = c.size();
86
87 ParcelType::readFields(c);
88
89 IOField<scalar> T(c.newIOobject("T", IOobject::MUST_READ), readOnProc);
90 c.checkFieldIOobject(c, T);
91
92 IOField<scalar> Cp(c.newIOobject("Cp", IOobject::MUST_READ), readOnProc);
93 c.checkFieldIOobject(c, Cp);
94
95
96 label i = 0;
98 {
99 p.T_ = T[i];
100 p.Cp_ = Cp[i];
101
102 ++i;
103 }
104}
105
106
107template<class ParcelType>
108template<class CloudType>
110{
111 ParcelType::writeFields(c);
112
113 const label np = c.size();
114 const bool writeOnProc = c.size();
115
116 IOField<scalar> T(c.newIOobject("T", IOobject::NO_READ), np);
117 IOField<scalar> Cp(c.newIOobject("Cp", IOobject::NO_READ), np);
118
119 label i = 0;
120 for (const ThermoParcel<ParcelType>& p : c)
121 {
122 T[i] = p.T_;
123 Cp[i] = p.Cp_;
124
125 ++i;
126 }
128 T.write(writeOnProc);
129 Cp.write(writeOnProc);
130}
131
132
133template<class ParcelType>
135(
136 Ostream& os,
137 const wordRes& filters,
138 const word& delim,
139 const bool namesOnly
140) const
141{
142 ParcelType::writeProperties(os, filters, delim, namesOnly);
143
144 #undef writeProp
145 #define writeProp(Name, Value) \
146 ParcelType::writeProperty(os, Name, Value, namesOnly, delim, filters)
147
148 writeProp("T", T_);
149 writeProp("Cp", Cp_);
151 #undef writeProp
152}
153
154
155template<class ParcelType>
156template<class CloudType>
158(
159 CloudType& c,
160 const objectRegistry& obr
161)
162{
163 ParcelType::readFields(c);
164
165 if (!c.size()) return;
166
167 auto& T = cloud::lookupIOField<scalar>("T", obr);
168 auto& Cp = cloud::lookupIOField<scalar>("Cp", obr);
169
170 label i = 0;
171 for (ThermoParcel<ParcelType>& p : c)
172 {
173 p.T_ = T[i];
174 p.Cp_ = Cp[i];
175
176 ++i;
177 }
178}
179
180
181template<class ParcelType>
182template<class CloudType>
184(
185 const CloudType& c,
186 objectRegistry& obr
187)
188{
189 ParcelType::writeObjects(c, obr);
190
191 const label np = c.size();
192
193 auto& T = cloud::createIOField<scalar>("T", np, obr);
194 auto& Cp = cloud::createIOField<scalar>("Cp", np, obr);
195
196 label i = 0;
197 for (const ThermoParcel<ParcelType>& p : c)
198 {
199 T[i] = p.T_;
200 Cp[i] = p.Cp_;
201
202 ++i;
203 }
204}
205
206
207// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
208
209template<class ParcelType>
210Foam::Ostream& Foam::operator<<
211(
212 Ostream& os,
214)
215{
217 {
219 << token::SPACE << p.T()
220 << token::SPACE << p.Cp();
221 }
222 else
223 {
225 os.write
226 (
227 reinterpret_cast<const char*>(&p.T_),
229 );
230 }
231
233 return os;
234}
235
236
237// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
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:53
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
streamFormat format() const noexcept
Get the current stream format.
@ ASCII
"ascii" (normal default)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
bool fatalCheckNativeSizes(const char *operation) const
Assert that the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.C:67
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.
virtual Ostream & write(const char c) override
Write character.
Definition OBJstream.C:69
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Thermodynamic parcel class with one/two-way coupling with the continuous phase. Includes Kinematic pa...
scalar Cp() const
Return const access to specific heat capacity.
scalar T() const
Return const access to temperature.
scalar Cp_
Specific heat capacity [J/(kg.K)].
static void writeObjects(const CloudType &c, objectRegistry &obr)
Write particle fields as objects into the obr registry.
static const std::size_t sizeofFields
Size in bytes of the fields.
ThermoParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from mesh, coordinates and topology.
static void readObjects(CloudType &c, const objectRegistry &obr)
Read particle fields as objects from the obr registry.
static void writeFields(const CloudType &c)
Write.
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].
static void readFields(CloudType &c)
Read.
static const IOField< Type > & lookupIOField(const word &fieldName, const objectRegistry &obr)
Lookup an IOField within object registry.
Definition cloud.H:202
static IOField< Type > & createIOField(const word &fieldName, const label nParticle, objectRegistry &obr)
Helper to construct IOField on a supplied object registry.
Registry of regIOobjects.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
A class for handling character strings derived from std::string.
Definition string.H:76
@ SPACE
Space [isspace].
Definition token.H:144
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
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
DSMCCloud< dsmcParcel > CloudType
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)