ThermoParcelIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 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  sizeof(ThermoParcel<ParcelType>)
39  - offsetof(ThermoParcel<ParcelType>, T_)
40 );
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
45 template<class ParcelType>
47 :
48  ParcelType(is, readFields),
49  T_(0.0),
50  Cp_(0.0)
51 {
52  if (readFields)
53  {
54  if (is.format() == IOstream::ASCII)
55  {
56  T_ = readScalar(is);
57  Cp_ = readScalar(is);
58  }
59  else
60  {
61  is.read(reinterpret_cast<char*>(&T_), sizeofFields_);
62  }
63  }
64 
65  // Check state of Istream
66  is.check
67  (
68  "ThermoParcel::ThermoParcel(const polyMesh&, Istream&, bool)"
69  );
70 }
71 
72 
73 template<class ParcelType>
74 template<class CloudType>
76 {
77  bool valid = c.size();
78 
80 
81  IOField<scalar> T(c.fieldIOobject("T", IOobject::MUST_READ), valid);
82  c.checkFieldIOobject(c, T);
83 
84  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::MUST_READ), valid);
85  c.checkFieldIOobject(c, Cp);
86 
87 
88  label i = 0;
89  forAllIter(typename CloudType, c, iter)
90  {
91  ThermoParcel<ParcelType>& p = iter();
92 
93  p.T_ = T[i];
94  p.Cp_ = Cp[i];
95  i++;
96  }
97 }
98 
99 
100 template<class ParcelType>
101 template<class CloudType>
103 {
104  ParcelType::writeFields(c);
105 
106  label np = c.size();
107 
108  IOField<scalar> T(c.fieldIOobject("T", IOobject::NO_READ), np);
109  IOField<scalar> Cp(c.fieldIOobject("Cp", IOobject::NO_READ), np);
110 
111  label i = 0;
112  forAllConstIter(typename CloudType, c, iter)
113  {
114  const ThermoParcel<ParcelType>& p = iter();
115 
116  T[i] = p.T_;
117  Cp[i] = p.Cp_;
118  i++;
119  }
120 
121  T.write(np > 0);
122  Cp.write(np > 0);
123 }
124 
125 
126 template<class ParcelType>
127 template<class CloudType, class CompositionType>
129 (
130  const CloudType& c,
131  const CompositionType& compModel
132 )
133 {
135 }
136 
137 
138 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
139 
140 template<class ParcelType>
141 Foam::Ostream& Foam::operator<<
142 (
143  Ostream& os,
145 )
146 {
147  if (os.format() == IOstream::ASCII)
148  {
149  os << static_cast<const ParcelType&>(p)
150  << token::SPACE << p.T()
151  << token::SPACE << p.Cp();
152  }
153  else
154  {
155  os << static_cast<const ParcelType&>(p);
156  os.write
157  (
158  reinterpret_cast<const char*>(&p.T_),
159  ThermoParcel<ParcelType>::sizeofFields_
160  );
161  }
162 
163  // Check state of Ostream
164  os.check
165  (
166  "Ostream& operator<<(Ostream&, const ThermoParcel<ParcelType>&)"
167  );
168 
169  return os;
170 }
171 
172 
173 // ************************************************************************* //
scalar Cp(const scalar p, const scalar T) const
Definition: EtoHthermo.H:2
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:80
tmp< GeometricField< Type, PatchField, GeoMesh > > T() const
Return transpose (only if it is a tensor field)
A primitive field of type <Type> with automated input and output.
Definition: IOField.H:53
streamFormat format() const
Return current stream format.
Definition: IOstream.H:374
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
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.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
Thermodynamic parcel class with one/two-way coupling with the continuous phase.
Definition: ThermoParcel.H:77
scalar Cp_
Specific heat capacity [J/kg/K].
Definition: ThermoParcel.H:271
static void writeFields(const CloudType &c)
Write.
scalar T_
Temperature [K].
Definition: ThermoParcel.H:268
static void readFields(CloudType &c)
Read.
ThermoParcel(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const label facei)
Construct from mesh, coordinates and topology.
Definition: ThermoParcelI.H:77
A class for handling character strings derived from std::string.
Definition: string.H:79
bool valid(const PtrList< ModelType > &l)
const dimensionedScalar c
Speed of light in a vacuum.
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
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject * > &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if successful.
Definition: doubleScalar.H:75
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
volScalarField & p