DTRMParticleIO.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) 2017-2019 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "DTRMParticle.H"
29#include "IOstreams.H"
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
35
37(
38 sizeof(DTRMParticle) - sizeof(particle)
39);
40
41
42// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43
45(
46 const polyMesh& mesh,
47 Istream& is,
48 bool readFields,
49 bool newFormat
50)
51:
52 particle(mesh, is, readFields, newFormat),
53 p0_(Zero),
54 p1_(Zero),
55 I0_(0),
56 I_(0),
57 dA_(0),
58 transmissiveId_(-1)
59{
60 if (readFields)
61 {
62 if (is.format() == IOstream::ASCII)
63 {
64 is >> p0_ >> p1_ >> I0_ >> I_ >> dA_ >> transmissiveId_;
65 }
66 else if (!is.checkLabelSize<>() || !is.checkScalarSize<>())
67 {
68 // Non-native label or scalar size
69
70 is.beginRawRead();
71
72 readRawScalar(is, p0_.data(), vector::nComponents);
73 readRawScalar(is, p1_.data(), vector::nComponents);
74 readRawScalar(is, &I0_);
75 readRawScalar(is, &I_);
76 readRawScalar(is, &dA_);
77 readRawLabel(is, &transmissiveId_);
78
79 is.endRawRead();
80 }
81 else
82 {
83 is.read(reinterpret_cast<char*>(&p0_), sizeofFields_);
84 }
85 }
86
87 is.check(FUNCTION_NAME);
88}
89
90
92(
93 Ostream& os,
94 const wordRes& filters,
95 const word& delim,
96 const bool namesOnly
97) const
98{
99 particle::writeProperties(os, filters, delim, namesOnly);
100
101 #undef writeProp
102 #define writeProp(Name, Value) \
103 particle::writeProperty(os, Name, Value, namesOnly, delim, filters)
104
105 writeProp("p0", p0_);
106 writeProp("p1", p1_);
107 writeProp("I0", I0_);
108 writeProp("I", I_);
109 writeProp("dA", dA_);
110 writeProp("transmissiveId", transmissiveId_);
111
112 #undef writeProp
113}
114
115
116Foam::Ostream& Foam::operator<<(Ostream& os, const DTRMParticle& p)
117{
118 if (os.format() == IOstream::ASCII)
119 {
120 os << static_cast<const particle&>(p)
121 << token::SPACE << p.p0_
122 << token::SPACE << p.p1_
123 << token::SPACE << p.I0_
124 << token::SPACE << p.I_
125 << token::SPACE << p.dA_
126 << token::SPACE << p.transmissiveId_;
127 }
128 else
129 {
130 os << static_cast<const particle&>(p);
131 os.write
132 (
133 reinterpret_cast<const char*>(&p.p0_),
135 );
136 }
137
138 // Check state of Ostream
140
141 return os;
142}
143
144
145// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Discrete Transfer Radiation Model (DTRM) particle.
Definition: DTRMParticle.H:65
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: DTRMParticle.H:149
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly=false) const
Write individual parcel properties to stream.
streamFormat format() const noexcept
Get the current stream format.
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
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
static constexpr direction nComponents
Number of components in bool is 1.
Definition: bool.H:98
static string propertyList()
Definition: particle.H:372
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly) const
Write individual particle properties to stream.
Definition: particleIO.C:220
static string propertyList_
String representation of properties.
Definition: particle.H:372
A class for handling character strings derived from std::string.
Definition: string.H:79
@ SPACE
Space [isspace].
Definition: token.H:125
volScalarField & p
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.
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:46