particleIO.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 | Copyright (C) 2011-2015 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, position_)
36 );
37 
38 const std::size_t Foam::particle::sizeofFields_
39 (
40  sizeof(particle) - offsetof(particle, position_)
41 );
42 
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
47 :
48  mesh_(mesh),
49  position_(),
50  cellI_(-1),
51  faceI_(-1),
52  stepFraction_(0.0),
53  tetFaceI_(-1),
54  tetPtI_(-1),
55  origProc_(Pstream::myProcNo()),
56  origId_(-1)
57 {
58  if (is.format() == IOstream::ASCII)
59  {
60  is >> position_ >> cellI_;
61 
62  if (readFields)
63  {
64  is >> faceI_
65  >> stepFraction_
66  >> tetFaceI_
67  >> tetPtI_
68  >> origProc_
69  >> origId_;
70  }
71  }
72  else
73  {
74  if (readFields)
75  {
76  is.read(reinterpret_cast<char*>(&position_), sizeofFields_);
77  }
78  else
79  {
80  is.read(reinterpret_cast<char*>(&position_), sizeofPosition_);
81  }
82  }
83 
84  // Check state of Istream
85  is.check("particle::particle(Istream&, bool)");
86 }
87 
88 
90 {
91  if (os.format() == IOstream::ASCII)
92  {
93  os << position_ << token::SPACE << cellI_;
94  }
95  else
96  {
97  os.write(reinterpret_cast<const char*>(&position_), 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.position_
110  << token::SPACE << p.cellI_
111  << token::SPACE << p.faceI_
112  << token::SPACE << p.stepFraction_
113  << token::SPACE << p.tetFaceI_
114  << token::SPACE << p.tetPtI_
115  << token::SPACE << p.origProc_
116  << token::SPACE << p.origId_;
117  }
118  else
119  {
120  os.write
121  (
122  reinterpret_cast<const char*>(&p.position_),
124  );
125  }
126 
127  return os;
128 }
129 
130 
131 // ************************************************************************* //
Foam::IOstream::format
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Foam::particle::stepFraction_
scalar stepFraction_
Fraction of time-step completed.
Definition: particle.H:149
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
p
p
Definition: pEqn.H:62
Foam::string
A class for handling character strings derived from std::string.
Definition: string.H:74
Foam::particle::faceI_
label faceI_
Face index if the particle is on a face otherwise -1.
Definition: particle.H:146
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::particle::writePosition
void writePosition(Ostream &) const
Write the particle position and cell.
Definition: particleIO.C:89
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::particle::propertyList
static string propertyList()
Definition: particle.H:315
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::particle::propertyList_
static string propertyList_
String representation of properties.
Definition: particle.H:315
Foam::particle::particle
particle(const polyMesh &mesh, const vector &position, const label cellI, const label tetFaceI, const label tetPtI)
Construct from components.
Definition: particle.C:48
Foam::particle::tetPtI_
label tetPtI_
Index of the point on the face that defines the decomposed.
Definition: particle.H:158
Foam::particle::cellI_
label cellI_
Index of the cell it is in.
Definition: particle.H:143
Foam::Pstream
Inter-processor communications stream.
Definition: Pstream.H:53
Foam::particle::position_
vector position_
Position of particle.
Definition: particle.H:140
Foam::particle
Base particle class.
Definition: particle.H:78
particle.H
Foam::particle::tetFaceI_
label tetFaceI_
Index of the face that owns the decomposed tet that the.
Definition: particle.H:153
Foam::particle::sizeofFields_
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: particle.H:88
Foam::particle::origProc_
label origProc_
Originating processor id.
Definition: particle.H:161
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::particle::origId_
label origId_
Local particle id on originating processor.
Definition: particle.H:164
Foam::token::SPACE
@ SPACE
Definition: token.H:95
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.
Foam::particle::sizeofPosition_
static const std::size_t sizeofPosition_
Size in bytes of the position data.
Definition: particle.H:85