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 | Copyright (C) 2011-2015 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 "ThermoParcel.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 template<class ParcelType>
34 
35 template<class ParcelType>
37 (
38  offsetof(ThermoParcel<ParcelType>, Tc_)
39  - offsetof(ThermoParcel<ParcelType>, T_)
40 );
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
45 template<class ParcelType>
47 (
48  const polyMesh& mesh,
49  Istream& is,
50  bool readFields
51 )
52 :
53  ParcelType(mesh, is, readFields),
54  T_(0.0),
55  Cp_(0.0),
56  Tc_(0.0),
57  Cpc_(0.0)
58 {
59  if (readFields)
60  {
61  if (is.format() == IOstream::ASCII)
62  {
63  T_ = readScalar(is);
64  Cp_ = readScalar(is);
65  }
66  else
67  {
68  is.read(reinterpret_cast<char*>(&T_), sizeofFields_);
69  }
70  }
71 
72  // Check state of Istream
73  is.check
74  (
75  "ThermoParcel::ThermoParcel(const polyMesh&, Istream&, bool)"
76  );
77 }
78 
79 
80 template<class ParcelType>
81 template<class CloudType>
83 {
84  if (!c.size())
85  {
86  return;
87  }
88 
90 
91  IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ));
92  c.checkFieldIOobject(c, T);
93 
94  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::MUST_READ));
95  c.checkFieldIOobject(c, Cp);
96 
97 
98  label i = 0;
99  forAllIter(typename Cloud<ThermoParcel<ParcelType> >, c, iter)
100  {
101  ThermoParcel<ParcelType>& p = iter();
102 
103  p.T_ = T[i];
104  p.Cp_ = Cp[i];
105  i++;
106  }
107 }
108 
109 
110 template<class ParcelType>
111 template<class CloudType>
113 {
114  ParcelType::writeFields(c);
115 
116  label np = c.size();
117 
118  IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
119  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::NO_READ), np);
120 
121  label i = 0;
123  {
124  const ThermoParcel<ParcelType>& p = iter();
125 
126  T[i] = p.T_;
127  Cp[i] = p.Cp_;
128  i++;
129  }
130 
131  T.write();
132  Cp.write();
133 }
134 
135 
136 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
137 
138 template<class ParcelType>
139 Foam::Ostream& Foam::operator<<
140 (
141  Ostream& os,
143 )
144 {
145  if (os.format() == IOstream::ASCII)
146  {
147  os << static_cast<const ParcelType&>(p)
148  << token::SPACE << p.T()
149  << token::SPACE << p.Cp();
150  }
151  else
152  {
153  os << static_cast<const ParcelType&>(p);
154  os.write
155  (
156  reinterpret_cast<const char*>(&p.T_),
158  );
159  }
160 
161  // Check state of Ostream
162  os.check
163  (
164  "Ostream& operator<<(Ostream&, const ThermoParcel<ParcelType>&)"
165  );
166 
167  return os;
168 }
169 
170 
171 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
p
p
Definition: pEqn.H:62
Foam::ThermoParcel::writeFields
static void writeFields(const CloudType &c)
Write.
Definition: ThermoParcelIO.C:112
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::label
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
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::ThermoParcel::T_
scalar T_
Temperature [K].
Definition: ThermoParcel.H:230
Foam::ThermoParcel::Cp_
scalar Cp_
Specific heat capacity [J/(kg.K)].
Definition: ThermoParcel.H:233
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Foam::DSMCCloud
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::ThermoParcel::ThermoParcel
ThermoParcel(const polyMesh &mesh, const vector &position, const label cellI, const label tetFaceI, const label tetPtI)
Construct from owner, position, and cloud owner.
Definition: ThermoParcelI.H:75
Foam::ThermoParcel
Thermodynamic parcel class with one/two-way coupling with the continuous phase. Includes Kinematic pa...
Definition: ThermoParcel.H:51
Foam::readScalar
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
readFields
void readFields(const boolList &haveMesh, const fvMesh &mesh, const autoPtr< fvMeshSubset > &subsetterPtr, IOobjectList &allObjects, PtrList< GeoField > &fields)
Definition: redistributePar.C:589
Foam::Cloud
Base cloud calls templated on particle type.
Definition: Cloud.H:52
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::ThermoParcel::sizeofFields_
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: ThermoParcel.H:72
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
ThermoParcel.H
Foam::ThermoParcel::readFields
static void readFields(CloudType &c)
Read.
Definition: ThermoParcelIO.C:82
Foam::token::SPACE
@ SPACE
Definition: token.H:95