particleIO.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 "particle.H"
27 #include "IOstreams.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
32 
33 const std::size_t Foam::particle::sizeofPosition_
34 (
35  offsetof(particle, facei_) - offsetof(particle, coordinates_)
36 );
37 
38 const std::size_t Foam::particle::sizeofFields_
39 (
40  sizeof(particle) - offsetof(particle, coordinates_)
41 );
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 :
48  coordinates_(),
49  celli_(-1),
50  tetFacei_(-1),
51  tetPti_(-1),
52  facei_(-1),
53  stepFraction_(0),
54  stepFractionBehind_(0),
55  nTracksBehind_(0),
56  origProc_(Pstream::myProcNo()),
57  origId_(-1)
58 {
59  if (is.format() == IOstream::ASCII)
60  {
61  is >> coordinates_ >> celli_ >> tetFacei_ >> tetPti_;
62 
63  if (readFields)
64  {
65  is >> facei_ >> stepFraction_ >> stepFractionBehind_
66  >> nTracksBehind_ >> origProc_ >> origId_;
67  }
68  }
69  else
70  {
71  if (readFields)
72  {
73  is.read(reinterpret_cast<char*>(&coordinates_), sizeofFields_);
74  }
75  else
76  {
77  is.read(reinterpret_cast<char*>(&coordinates_), sizeofPosition_);
78  }
79  }
80 
81  // Check state of Istream
82  is.check("particle::particle(Istream&, bool)");
83 }
84 
85 
87 {
88  if (os.format() == IOstream::ASCII)
89  {
90  os << coordinates_
91  << token::SPACE << celli_
92  << token::SPACE << tetFacei_
93  << token::SPACE << tetPti_;
94  }
95  else
96  {
97  os.write(reinterpret_cast<const char*>(&coordinates_), sizeofPosition_);
98  }
99 
100  // Check state of Ostream
101  os.check("particle::writePosition(Ostream& os, bool) const");
102 }
103 
104 
106 {
107  if (os.format() == IOstream::ASCII)
108  {
109  os << p.coordinates_
110  << token::SPACE << p.celli_
111  << token::SPACE << p.tetFacei_
112  << token::SPACE << p.tetPti_
113  << token::SPACE << p.facei_
114  << token::SPACE << p.stepFraction_
115  << token::SPACE << p.stepFractionBehind_
116  << token::SPACE << p.nTracksBehind_
117  << token::SPACE << p.origProc_
118  << token::SPACE << p.origId_;
119  }
120  else
121  {
122  os.write
123  (
124  reinterpret_cast<const char*>(&p.coordinates_),
125  particle::sizeofFields_
126  );
127  }
128 
129  return os;
130 }
131 
132 
133 // ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
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
virtual Ostream & write(const char)=0
Write character.
Inter-processor communications stream.
Definition: Pstream.H:56
Base particle class.
Definition: particle.H:83
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const label facei)
Construct from components.
Definition: particle.C:375
static string propertyList()
Definition: particle.H:327
void writePosition(Ostream &) const
Write the particle position and cell.
Definition: particleIO.C:86
static string propertyList_
String representation of properties.
Definition: particle.H:327
A class for handling character strings derived from std::string.
Definition: string.H:79
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
Ostream & operator<<(Ostream &os, const fvConstraints &constraints)
volScalarField & p