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-2018 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 
31 Foam::string Foam::particle::propertyList_ = Foam::particle::propertyList();
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  mesh_(mesh),
49  coordinates_(),
50  celli_(-1),
51  tetFacei_(-1),
52  tetPti_(-1),
53  facei_(-1),
54  stepFraction_(0.0),
55  origProc_(Pstream::myProcNo()),
56  origId_(-1)
57 {
58  if (is.format() == IOstream::ASCII)
59  {
60  is >> coordinates_ >> celli_ >> tetFacei_ >> tetPti_;
61 
62  if (readFields)
63  {
64  is >> facei_ >> stepFraction_ >> origProc_ >> origId_;
65  }
66  }
67  else
68  {
69  if (readFields)
70  {
71  is.read(reinterpret_cast<char*>(&coordinates_), sizeofFields_);
72  }
73  else
74  {
75  is.read(reinterpret_cast<char*>(&coordinates_), sizeofPosition_);
76  }
77  }
78 
79  // Check state of Istream
80  is.check("particle::particle(Istream&, bool)");
81 }
82 
83 
85 {
86  if (os.format() == IOstream::ASCII)
87  {
88  os << coordinates_
89  << token::SPACE << celli_
90  << token::SPACE << tetFacei_
91  << token::SPACE << tetPti_;
92  }
93  else
94  {
95  os.write(reinterpret_cast<const char*>(&coordinates_), sizeofPosition_);
96  }
97 
98  // Check state of Ostream
99  os.check("particle::writePosition(Ostream& os, bool) const");
100 }
101 
102 
104 {
105  if (os.format() == IOstream::ASCII)
106  {
107  os << p.coordinates_
108  << token::SPACE << p.celli_
109  << token::SPACE << p.tetFacei_
110  << token::SPACE << p.tetPti_
111  << token::SPACE << p.facei_
112  << token::SPACE << p.stepFraction_
113  << token::SPACE << p.origProc_
114  << token::SPACE << p.origId_;
115  }
116  else
117  {
118  os.write
119  (
120  reinterpret_cast<const char*>(&p.coordinates_),
121  particle::sizeofFields_
122  );
123  }
124 
125  return os;
126 }
127 
128 
129 // ************************************************************************* //
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
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:57
Base particle class.
Definition: particle.H:84
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
virtual Istream & read(token &)=0
Return next token from stream.
dynamicFvMesh & mesh
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
Definition: particle.C:510
Inter-processor communications stream.
Definition: Pstream.H:53
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
void writePosition(Ostream &) const
Write the particle position and cell.
Definition: particleIO.C:84
Ostream & operator<<(Ostream &, const ensightPart &)
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
A class for handling character strings derived from std::string.
Definition: string.H:74
static string propertyList()
Definition: particle.H:349