Loading...
Searching...
No Matches
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-2023 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,
47 )
48 ),
49 geometryType_(geomType),
50 cloud_(c)
51{}
52
53
54// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55
56template<class CloudType>
58(
59 const bool /* writeOnProc */
60) const
61{
62 return regIOobject::write(cloud_.size() > 0);
63}
64
65
66template<class CloudType>
68{
69 os << cloud_.size() << nl << token::BEGIN_LIST << nl;
70
71 switch (geometryType_)
72 {
74 {
75 for (const auto& p : cloud_)
76 {
77 p.writeCoordinates(os);
78 os << nl;
79 }
80 break;
81 }
82 case cloud::geometryType::POSITIONS:
83 {
84 for (const auto& p : cloud_)
85 {
86 p.writePosition(os);
87 os << nl;
88 }
89 break;
90 }
91 }
92
94
95 return os.good();
96}
97
98
99template<class CloudType>
101{
102 const polyMesh& mesh = c.pMesh();
103
104 token tok(is);
105
106 const bool newFormat = (geometryType_ == cloud::geometryType::COORDINATES);
107
108 if (tok.isLabel())
109 {
110 const label len = tok.labelToken();
111
112 // Read beginning of contents
114
115 for (label i=0; i<len; ++i)
116 {
117 // Read position only
118 c.append
119 (
120 new typename CloudType::particleType
121 (
122 mesh,
123 is,
124 false,
125 newFormat
126 )
127 );
128 }
129
130 // Read end of contents
132 }
133 else if (tok.isPunctuation(token::BEGIN_LIST))
134 {
135 is >> tok;
136 while (!tok.isPunctuation(token::END_LIST))
137 {
138 is.putBack(tok);
139
140 // Read position only
141 c.append
142 (
143 new typename CloudType::particleType(mesh, is, false, newFormat)
144 );
145 is >> tok;
146 }
147 }
148 else
149 {
151 << "incorrect first token, expected <int> or '(', found "
152 << tok.info() << nl
153 << exit(FatalIOError);
154 }
155
157}
158
159
160// ************************************************************************* //
ParticleType particleType
Definition Cloud.H:130
virtual bool writeData(Ostream &os) const
Pure virtual writeData function.
Definition IOPosition.C:60
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Definition IOPosition.C:51
virtual void readData(Istream &, CloudType &)
Definition IOPosition.C:93
IOPosition(const CloudType &c, cloud::geometryType geomType=cloud::geometryType::COORDINATES)
Construct from cloud.
Definition IOPosition.C:26
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const Time & time() const noexcept
Return Time associated with the objectRegistry.
Definition IOobject.C:456
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
char readEndList(const char *funcName)
End read of list data, ends with ')' or '}'.
Definition Istream.C:192
char readBeginList(const char *funcName)
Begin read of list data, starts with '(' or '{'.
Definition Istream.C:171
void putBack(const token &tok)
Put back a token (copy). Only a single put back is permitted.
Definition Istream.C:71
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A cloud is a registry collection of lagrangian particles.
Definition cloud.H:56
geometryType
Cloud geometry type (internal or IO representations).
Definition cloud.H:63
@ COORDINATES
barycentric coordinates
Definition cloud.H:64
@ POSITIONS
positions
Definition cloud.H:65
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
regIOobject(const IOobject &io, const bool isTimeObject=false)
Construct from IOobject. The optional flag adds special handling if the object is the top-level regIO...
Definition regIOobject.C:43
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
A token holds an item read from Istream.
Definition token.H:70
bool isPunctuation() const noexcept
Token is PUNCTUATION.
Definition tokenI.H:650
@ BEGIN_LIST
Begin list [isseparator].
Definition token.H:174
@ END_LIST
End list [isseparator].
Definition token.H:175
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
volScalarField & p
dynamicFvMesh & mesh
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
word timeName
Definition getTimeIndex.H:3
#define FUNCTION_NAME
DSMCCloud< dsmcParcel > CloudType
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50