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-2022 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
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 
36 const std::size_t Foam::DTRMParticle::sizeofFields_
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() == IOstreamOption::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 
117 {
118  if (os.format() == IOstreamOption::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
139  os.check(FUNCTION_NAME);
140 
141  return os;
142 }
143 
144 
145 // ************************************************************************* //
static string propertyList_
String representation of properties.
Definition: particle.H:455
"ascii" (normal default)
DTRMParticle(const polyMesh &mesh, const vector &position, const vector &targetPosition, const scalar I, const label cellI, const scalar dA, const label transmissiveId)
Construct from components, with searching for tetFace and.
#define writeProp(Name, Value)
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
dynamicFvMesh & mesh
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const NameMatchPredicate &selectedFields, DynamicList< regIOobject *> &storedObjects)
Read the selected GeometricFields of the templated type and store on the objectRegistry.
Space [isspace].
Definition: token.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
label readRawLabel(Istream &is)
Read raw label from binary stream.
Definition: label.C:39
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: DTRMParticle.H:168
volScalarField & p
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly) const
Write individual particle properties to stream.
Definition: particleIO.C:213
A class for handling character strings derived from std::string.
Definition: string.H:72
void writeProperties(Ostream &os, const wordRes &filters, const word &delim, const bool namesOnly=false) const
Write individual parcel properties to stream.
static string propertyList()
Definition: particle.H:455
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127