IOPosition.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 "IOPosition.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class CloudType>
32 :
34  (
35  IOobject
36  (
37  "positions",
38  c.time().timeName(),
39  c,
40  IOobject::MUST_READ,
41  IOobject::NO_WRITE
42  )
43  ),
44  cloud_(c)
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
50 template<class CloudType>
52 {
53  if (cloud_.size())
54  {
55  return regIOobject::write();
56  }
57  else
58  {
59  return true;
60  }
61 }
62 
63 
64 template<class CloudType>
66 {
67  os << cloud_.size() << nl << token::BEGIN_LIST << nl;
68 
69  forAllConstIter(typename CloudType, cloud_, iter)
70  {
71  iter().writePosition(os);
72  os << nl;
73  }
74 
75  os << token::END_LIST << endl;
76 
77  return os.good();
78 }
79 
80 
81 template<class CloudType>
83 {
84  const polyMesh& mesh = c.pMesh();
85 
86  Istream& is = readStream(checkClass ? typeName : "");
87 
88  token firstToken(is);
89 
90  if (firstToken.isLabel())
91  {
92  label s = firstToken.labelToken();
93 
94  // Read beginning of contents
95  is.readBeginList("IOPosition<CloudType>::readData(CloudType, bool)");
96 
97  for (label i=0; i<s; i++)
98  {
99  // Read position only
100  c.append(new typename CloudType::particleType(mesh, is, false));
101  }
102 
103  // Read end of contents
104  is.readEndList("IOPosition<CloudType>::readData(CloudType, bool)");
105  }
106  else if (firstToken.isPunctuation())
107  {
108  if (firstToken.pToken() != token::BEGIN_LIST)
109  {
111  (
112  "void IOPosition<CloudType>::readData(CloudType&, bool)",
113  is
114  ) << "incorrect first token, '(', found "
115  << firstToken.info() << exit(FatalIOError);
116  }
117 
118  token lastToken(is);
119  while
120  (
121  !(
122  lastToken.isPunctuation()
123  && lastToken.pToken() == token::END_LIST
124  )
125  )
126  {
127  is.putBack(lastToken);
128 
129  // Write position only
130  c.append(new typename CloudType::particleType(mesh, is, false));
131  is >> lastToken;
132  }
133  }
134  else
135  {
137  (
138  "void IOPosition<ParticleType>::readData(CloudType&, bool)",
139  is
140  ) << "incorrect first token, expected <int> or '(', found "
141  << firstToken.info() << exit(FatalIOError);
142  }
143 
144  // Check state of IOstream
145  is.check
146  (
147  "void IOPosition<CloudType>::readData(CloudType&, bool)"
148  );
149 }
150 
151 
152 // ************************************************************************* //
bool isLabel() const
Definition: tokenI.H:262
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 ))
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
IOPosition(const CloudType &)
Construct from cloud.
Definition: IOPosition.C:31
char readBeginList(const char *funcName)
Definition: Istream.C:131
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
bool isPunctuation() const
Definition: tokenI.H:203
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void append(link *)
Add at tail of list.
Definition: DLListBase.C:73
dynamicFvMesh & mesh
const polyMesh & pMesh() const
Return the polyMesh reference.
Definition: Cloud.H:170
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
virtual bool write() const
Write using setting from DB.
static const char nl
Definition: Ostream.H:260
virtual void readData(CloudType &c, bool checkClass)
Definition: IOPosition.C:82
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOerror FatalIOError
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
void putBack(const token &)
Put back token.
Definition: Istream.C:30
InfoProxy< token > info() const
Return info proxy.
Definition: token.H:372
char readEndList(const char *funcName)
Definition: Istream.C:152
bool good() const
Return true if next operation might succeed.
Definition: IOstream.H:333
A token holds items read from Istream.
Definition: token.H:67
virtual bool write() const
Write using setting from DB.
Definition: IOPosition.C:51
label labelToken() const
Definition: tokenI.H:267
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
label size() const
Definition: Cloud.H:175
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const dimensionedScalar c
Speed of light in a vacuum.
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:68
punctuationToken pToken() const
Definition: tokenI.H:208
ParcelType particleType
Definition: Cloud.H:114
Istream & readStream(const word &)
Return Istream and check object type against that given.
virtual bool writeData(Ostream &os) const
Pure virtual writaData function.
Definition: IOPosition.C:65
#define FatalIOErrorIn(functionName, ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:325
word timeName
Definition: getTimeIndex.H:3