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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2017-2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30
31template<class CloudType>
33(
34 const CloudType& c,
35 cloud::geometryType geomType
36)
37:
39 (
41 (
42 cloud::geometryTypeNames[geomType],
43 c.time().timeName(),
44 c,
45 IOobject::MUST_READ,
46 IOobject::NO_WRITE
47 )
48 ),
49 geometryType_(geomType),
50 cloud_(c)
51{}
52
53
54// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55
56template<class CloudType>
57bool Foam::IOPosition<CloudType>::write(const bool valid) const
58{
59 return regIOobject::write(cloud_.size());
60}
61
62
63template<class CloudType>
65{
66 os << cloud_.size() << nl << token::BEGIN_LIST << nl;
67
68 switch (geometryType_)
69 {
71 {
72 forAllConstIters(cloud_, iter)
73 {
74 iter().writeCoordinates(os);
75 os << nl;
76 }
77 break;
78 }
80 {
81 forAllConstIters(cloud_, iter)
82 {
83 iter().writePosition(os);
84 os << nl;
85 }
86 break;
87 }
88 }
89
91
92 return os.good();
93}
94
95
96template<class CloudType>
98{
99 const polyMesh& mesh = c.pMesh();
100
101 token tok(is);
102
103 const bool newFormat = (geometryType_ == cloud::geometryType::COORDINATES);
104
105 if (tok.isLabel())
106 {
107 const label len = tok.labelToken();
108
109 // Read beginning of contents
111
112 for (label i=0; i<len; ++i)
113 {
114 // Read position only
115 c.append
116 (
117 new typename CloudType::particleType
118 (
119 mesh,
120 is,
121 false,
122 newFormat
123 )
124 );
125 }
126
127 // Read end of contents
129 }
130 else if (tok.isPunctuation(token::BEGIN_LIST))
131 {
132 is >> tok;
133 while (!tok.isPunctuation(token::END_LIST))
134 {
135 is.putBack(tok);
136
137 // Read position only
138 c.append
139 (
140 new typename CloudType::particleType(mesh, is, false, newFormat)
141 );
142 is >> tok;
143 }
144 }
145 else
146 {
148 << "incorrect first token, expected <int> or '(', found "
149 << tok.info() << nl
150 << exit(FatalIOError);
151 }
152
154}
155
156
157// ************************************************************************* //
ParticleType particleType
Definition: Cloud.H:114
Templated base class for dsmc cloud.
Definition: DSMCCloud.H:75
Helper IO class to read and write particle coordinates (positions).
Definition: IOPosition.H:56
virtual void readData(Istream &, CloudType &)
Definition: IOPosition.C:97
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:58
bool good() const noexcept
True if next operation might succeed.
Definition: IOstream.H:233
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition: Istream.C:169
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition: Istream.C:148
void putBack(const token &tok)
Put back a token. Only a single put back is permitted.
Definition: Istream.C:70
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A cloud is a registry collection of lagrangian particles.
Definition: cloud.H:60
geometryType
Cloud geometry type (internal or IO representations)
Definition: cloud.H:75
@ COORDINATES
barycentric coordinates
virtual bool write()
Write the output fields.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:76
A token holds an item read from Istream.
Definition: token.H:69
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition: tokenI.H:459
@ BEGIN_LIST
Begin list [isseparator].
Definition: token.H:155
@ END_LIST
End list [isseparator].
Definition: token.H:156
bool isLabel() const noexcept
Token is LABEL.
Definition: tokenI.H:497
label labelToken() const
Return label value.
Definition: tokenI.H:513
InfoProxy< token > info() const
Return info proxy for printing token information to a stream.
Definition: token.H:586
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
OBJstream os(runTime.globalPath()/outputName)
word timeName
Definition: getTimeIndex.H:3
#define FUNCTION_NAME
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
Definition: stdFoam.H:278