IOPosition.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-2020 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 "IOPosition.H"
27 #include "polyMesh.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class CloudType>
33 :
35  (
36  IOobject
37  (
38  "positions",
39  c.time().timeName(),
40  c,
41  IOobject::MUST_READ,
42  IOobject::NO_WRITE
43  )
44  ),
45  cloud_(c)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 template<class CloudType>
53 {
54  return regIOobject::write(cloud_.size());
55 }
56 
57 
58 template<class CloudType>
60 {
61  os << cloud_.size() << nl << token::BEGIN_LIST << nl;
62 
63  forAllConstIter(typename CloudType, cloud_, iter)
64  {
65  iter().writePosition(os);
66  os << nl;
67  }
68 
69  os << token::END_LIST << endl;
70 
71  return os.good();
72 }
73 
74 
75 template<class CloudType>
77 {
78  const polyMesh& mesh = c.pMesh();
79 
80  token firstToken(is);
81 
82  if (firstToken.isLabel())
83  {
84  label s = firstToken.labelToken();
85 
86  // Read beginning of contents
87  is.readBeginList
88  (
89  "IOPosition<CloudType>::readData(Istream&, CloudType&)"
90  );
91 
92  for (label i=0; i<s; i++)
93  {
94  // Read position only
95  c.append(new typename CloudType::particleType(mesh, is, false));
96  }
97 
98  // Read end of contents
99  is.readEndList("IOPosition<CloudType>::readData(Istream&, CloudType&)");
100  }
101  else if (firstToken.isPunctuation())
102  {
103  if (firstToken.pToken() != token::BEGIN_LIST)
104  {
106  (
107  is
108  ) << "incorrect first token, '(', found "
109  << firstToken.info() << exit(FatalIOError);
110  }
111 
112  token lastToken(is);
113  while
114  (
115  !(
116  lastToken.isPunctuation()
117  && lastToken.pToken() == token::END_LIST
118  )
119  )
120  {
121  is.putBack(lastToken);
122 
123  // Read position only
124  c.append(new typename CloudType::particleType(mesh, is, false));
125  is >> lastToken;
126  }
127  }
128  else
129  {
131  (
132  is
133  ) << "incorrect first token, expected <int> or '(', found "
134  << firstToken.info() << exit(FatalIOError);
135  }
136 
137  // Check state of IOstream
138  is.check
139  (
140  "void IOPosition<CloudType>::readData(Istream&, CloudType&)"
141  );
142 }
143 
144 
145 // ************************************************************************* //
ParcelType particleType
Definition: Cloud.H:128
bool isLabel() const
Definition: tokenI.H:392
punctuationToken pToken() const
Definition: tokenI.H:248
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
char readEndList(const char *funcName)
Definition: Istream.C:148
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:391
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A token holds items read from Istream.
Definition: token.H:72
void putBack(const token &)
Put back token.
Definition: Istream.C:30
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:190
fvMesh & mesh
const dimensionedScalar c
Speed of light in a vacuum.
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:330
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
virtual bool write(const bool write=true) const
Write using setting from DB.
Definition: IOPosition.C:52
virtual bool writeData(Ostream &os) const
Pure virtual writaData function.
Definition: IOPosition.C:59
word timeName
Definition: getTimeIndex.H:3
char readBeginList(const char *funcName)
Definition: Istream.C:127
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
static const char nl
Definition: Ostream.H:260
IOPosition(const CloudType &)
Construct from cloud.
Definition: IOPosition.C:32
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
label labelToken() const
Definition: tokenI.H:397
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
virtual bool write(const bool write=true) const
Write using setting from DB.
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:165
virtual void readData(Istream &, CloudType &)
Definition: IOPosition.C:76
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:98
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
bool isPunctuation() const
Definition: tokenI.H:243
IOerror FatalIOError