Home
Downloads
Documentation
Installation
User Guide
man-pages
API Documentation
README
Release Notes
Changes
License
Support
SourceForge Project
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
src
lagrangian
basic
IOPosition
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) 1991-2010 OpenCFD Ltd.
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 <
lagrangian/IOPosition.H
>
27
28
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29
30
template
<
class
ParticleType>
31
Foam::IOPosition<ParticleType>::IOPosition
32
(
33
const
Cloud<ParticleType>
& c
34
)
35
:
36
regIOobject
37
(
38
IOobject
39
(
40
"positions"
,
41
c.
time
().timeName(),
42
c,
43
IOobject::MUST_READ,
44
IOobject::NO_WRITE
45
)
46
),
47
cloud_(c)
48
{}
49
50
51
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52
53
template
<
class
ParticleType>
54
bool
Foam::IOPosition<ParticleType>::write
()
const
55
{
56
if
(cloud_.size())
57
{
58
return
regIOobject::write();
59
}
60
else
61
{
62
return
true
;
63
}
64
}
65
66
67
template
<
class
ParticleType>
68
bool
Foam::IOPosition<ParticleType>::writeData
(
Ostream
& os)
const
69
{
70
os<< cloud_.size() <<
nl
<< token::BEGIN_LIST <<
nl
;
71
72
forAllConstIter
(
typename
Cloud<ParticleType>
, cloud_, iter)
73
{
74
// Prevent writing additional fields
75
static_cast<
const
Particle<ParticleType>
&
>
(iter()).write
76
(
77
os,
78
false
79
);
80
os <<
nl
;
81
}
82
83
os<< token::END_LIST <<
endl
;
84
85
return
os.
good
();
86
}
87
88
89
template
<
class
ParticleType>
90
void
Foam::IOPosition<ParticleType>::readData
91
(
92
Cloud<ParticleType>
& c,
93
bool
checkClass
94
)
95
{
96
Istream
& is = readStream(checkClass ? typeName :
""
);
97
98
token
firstToken(is);
99
100
if
(firstToken.
isLabel
())
101
{
102
label s = firstToken.
labelToken
();
103
104
// Read beginning of contents
105
is.
readBeginList
(
"Cloud<ParticleType>"
);
106
107
for
(label i=0; i<s; i++)
108
{
109
// Do not read any fields, position only
110
c.
append
(
new
ParticleType(c, is,
false
));
111
}
112
113
// Read end of contents
114
is.
readEndList
(
"Cloud<ParticleType>"
);
115
}
116
else
if
(firstToken.
isPunctuation
())
117
{
118
if
(firstToken.
pToken
() != token::BEGIN_LIST)
119
{
120
FatalIOErrorIn
121
(
122
"void IOPosition<ParticleType>::readData"
123
"(Cloud<ParticleType>&, bool)"
,
124
is
125
) <<
"incorrect first token, '(', found "
126
<< firstToken.
info
()
127
<<
exit
(
FatalIOError
);
128
}
129
130
token
lastToken(is);
131
while
132
(
133
!(
134
lastToken.
isPunctuation
()
135
&& lastToken.
pToken
() == token::END_LIST
136
)
137
)
138
{
139
is.
putBack
(lastToken);
140
// Do not read any fields, position only
141
c.
append
(
new
ParticleType(c, is,
false
));
142
is >> lastToken;
143
}
144
}
145
else
146
{
147
FatalIOErrorIn
148
(
149
"void IOPosition<ParticleType>::readData"
150
"(Cloud<ParticleType>&, bool)"
,
151
is
152
) <<
"incorrect first token, expected <int> or '(', found "
153
<< firstToken.
info
()
154
<<
exit
(
FatalIOError
);
155
}
156
157
// Check state of IOstream
158
is.
check
159
(
160
"void IOPosition<ParticleType>::readData(Cloud<ParticleType>&, bool)"
161
);
162
}
163
164
165
// ************************ vim: set sw=4 sts=4 et: ************************ //