Loading...
Searching...
No Matches
moleculeIO.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) 2016-2022 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#include "molecule.H"
30#include "IOstreams.H"
31#include "moleculeCloud.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35const std::size_t Foam::molecule::sizeofFields
37 offsetof(molecule, siteForces_) - offsetof(molecule, Q_)
38);
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
44(
45 const polyMesh& mesh,
46 Istream& is,
47 bool readFields,
48 bool newFormat
49)
50:
51 particle(mesh, is, readFields, newFormat),
52 Q_(Zero),
53 v_(Zero),
54 a_(Zero),
55 pi_(Zero),
56 tau_(Zero),
57 specialPosition_(Zero),
58 potentialEnergy_(0.0),
59 rf_(Zero),
60 special_(0),
61 id_(0),
62 siteForces_(),
63 sitePositions_()
64{
65 if (readFields)
66 {
67 if (is.format() == IOstreamOption::ASCII)
68 {
69 is >> Q_
70 >> v_
71 >> a_
72 >> pi_
73 >> tau_
74 >> specialPosition_
75 >> potentialEnergy_
76 >> rf_
77 >> special_
78 >> id_;
79 }
80 else
81 {
82 // No non-native streaming
84
85 is.read(reinterpret_cast<char*>(&Q_), sizeofFields);
86 }
87
88 is >> siteForces_ >> sitePositions_;
89 }
90
92}
93
94
95void Foam::molecule::readFields(Cloud<molecule>& mC)
96{
97 const bool readOnProc = mC.size();
98
100
101 IOField<tensor> Q(mC.newIOobject("Q", IOobject::MUST_READ), readOnProc);
102 mC.checkFieldIOobject(mC, Q);
103
104 IOField<vector> v(mC.newIOobject("v", IOobject::MUST_READ), readOnProc);
105 mC.checkFieldIOobject(mC, v);
106
107 IOField<vector> a(mC.newIOobject("a", IOobject::MUST_READ), readOnProc);
108 mC.checkFieldIOobject(mC, a);
109
110 IOField<vector> pi(mC.newIOobject("pi", IOobject::MUST_READ), readOnProc);
111 mC.checkFieldIOobject(mC, pi);
112
113 IOField<vector> tau
114 (
115 mC.newIOobject("tau", IOobject::MUST_READ),
116 readOnProc
117 );
118 mC.checkFieldIOobject(mC, tau);
119
120 IOField<vector> specialPosition
121 (
122 mC.newIOobject("specialPosition", IOobject::MUST_READ),
123 readOnProc
124 );
125 mC.checkFieldIOobject(mC, specialPosition);
126
127 IOField<label> special
128 (
129 mC.newIOobject("special", IOobject::MUST_READ),
130 readOnProc
131 );
132 mC.checkFieldIOobject(mC, special);
133
134 IOField<label> id(mC.newIOobject("id", IOobject::MUST_READ), readOnProc);
135 mC.checkFieldIOobject(mC, id);
136
137 label i = 0;
138 for (molecule& mol : mC)
139 {
140 mol.Q_ = Q[i];
141 mol.v_ = v[i];
142 mol.a_ = a[i];
143 mol.pi_ = pi[i];
144 mol.tau_ = tau[i];
145 mol.specialPosition_ = specialPosition[i];
146 mol.special_ = special[i];
147 mol.id_ = id[i];
148
149 ++i;
150 }
151}
152
153
154void Foam::molecule::writeFields(const Cloud<molecule>& mC)
155{
157
158 const label np = mC.size();
159 const bool writeOnProc = mC.size();
160
161 IOField<tensor> Q(mC.newIOobject("Q", IOobject::NO_READ), np);
162 IOField<vector> v(mC.newIOobject("v", IOobject::NO_READ), np);
163 IOField<vector> a(mC.newIOobject("a", IOobject::NO_READ), np);
164 IOField<vector> pi(mC.newIOobject("pi", IOobject::NO_READ), np);
165 IOField<vector> tau(mC.newIOobject("tau", IOobject::NO_READ), np);
166 IOField<vector> specialPosition
167 (
168 mC.newIOobject("specialPosition", IOobject::NO_READ),
169 np
170 );
171 IOField<label> special(mC.newIOobject("special", IOobject::NO_READ), np);
172 IOField<label> id(mC.newIOobject("id", IOobject::NO_READ), np);
173
174 // Post processing fields
175
176 IOField<vector> piGlobal
177 (
178 mC.newIOobject("piGlobal", IOobject::NO_READ),
179 np
180 );
181
182 IOField<vector> tauGlobal
183 (
184 mC.newIOobject("tauGlobal", IOobject::NO_READ),
185 np
186 );
187
188 IOField<vector> orientation1
189 (
190 mC.newIOobject("orientation1", IOobject::NO_READ),
191 np
192 );
193
194 IOField<vector> orientation2
195 (
196 mC.newIOobject("orientation2", IOobject::NO_READ),
197 np
198 );
199
200 IOField<vector> orientation3
201 (
202 mC.newIOobject("orientation3", IOobject::NO_READ),
203 np
204 );
205
206 label i = 0;
207 for (const molecule& mol : mC)
208 {
209 Q[i] = mol.Q_;
210 v[i] = mol.v_;
211 a[i] = mol.a_;
212 pi[i] = mol.pi_;
213 tau[i] = mol.tau_;
214 specialPosition[i] = mol.specialPosition_;
215 special[i] = mol.special_;
216 id[i] = mol.id_;
217
218 piGlobal[i] = mol.Q_ & mol.pi_;
219 tauGlobal[i] = mol.Q_ & mol.tau_;
220
221 orientation1[i] = mol.Q_ & vector(1,0,0);
222 orientation2[i] = mol.Q_ & vector(0,1,0);
223 orientation3[i] = mol.Q_ & vector(0,0,1);
224
225 ++i;
226 }
227
228 Q.write(writeOnProc);
229 v.write(writeOnProc);
230 a.write(writeOnProc);
231 pi.write(writeOnProc);
232 tau.write(writeOnProc);
233 specialPosition.write(writeOnProc);
234 special.write(writeOnProc);
235 id.write(writeOnProc);
236
237 piGlobal.write(writeOnProc);
238 tauGlobal.write(writeOnProc);
239
240 orientation1.write(writeOnProc);
241 orientation2.write(writeOnProc);
242 orientation3.write(writeOnProc);
243
244 Info<< "writeFields " << mC.name() << endl;
245
246 if (isA<moleculeCloud>(mC))
247 {
248 const moleculeCloud& m = dynamic_cast<const moleculeCloud&>(mC);
249
250 m.writeXYZ
251 (
252 m.mesh().time().timePath()/cloud::prefix/"moleculeCloud.xmol"
253 );
254 }
255}
256
257
258// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
259
260Foam::Ostream& Foam::operator<<(Ostream& os, const molecule& mol)
261{
263 {
265 << token::SPACE << mol.Q_
266 << token::SPACE << mol.v_
267 << token::SPACE << mol.a_
268 << token::SPACE << mol.pi_
269 << token::SPACE << mol.tau_
270 << token::SPACE << mol.specialPosition_
271 << token::SPACE << mol.potentialEnergy_
272 << token::SPACE << mol.rf_
273 << token::SPACE << mol.special_
274 << token::SPACE << mol.id_
275 << token::SPACE << mol.siteForces_
276 << token::SPACE << mol.sitePositions_;
277 }
278 else
279 {
281 os.write
282 (
283 reinterpret_cast<const char*>(&mol.Q_),
285 );
286 os << mol.siteForces_ << mol.sitePositions_;
287 }
288
290 return os;
291}
292
293
294// ************************************************************************* //
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
constexpr scalar pi(M_PI)
Base cloud calls templated on particle type.
Definition Cloud.H:64
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition CloudIO.C:174
label size() const noexcept
The number of elements in table.
Definition HashTable.H:358
A primitive field of type <T> with automated input and output.
Definition IOField.H:53
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
streamFormat format() const noexcept
Get the current stream format.
@ ASCII
"ascii" (normal default)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:45
bool fatalCheckNativeSizes(const char *operation) const
Assert that the label/scalar byte-size associated with the stream are the native label/scalar sizes.
Definition IOstream.C:67
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
virtual Istream & read(token &)=0
Return next token from stream.
virtual Ostream & write(const char c) override
Write character.
Definition OBJstream.C:69
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
fileName timePath() const
Return current time path = path/timeName.
Definition Time.H:512
static const word prefix
The prefix to local: lagrangian.
Definition cloud.H:79
void writeXYZ(const fileName &fName) const
Write molecule sites in XYZ format.
const polyMesh & mesh() const noexcept
Foam::molecule.
Definition molecule.H:65
const tensor & Q() const
Definition moleculeI.H:502
const vector & v() const
Definition moleculeI.H:514
const vector & a() const
Definition moleculeI.H:526
const vector & specialPosition() const
Definition moleculeI.H:586
label special() const
Definition moleculeI.H:622
static const std::size_t sizeofFields
Size in bytes of the fields.
Definition molecule.H:71
const vector & tau() const
Definition moleculeI.H:550
molecule(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti, const tensor &Q, const vector &v, const vector &a, const vector &pi, const vector &tau, const vector &specialPosition, const constantProperties &constProps, const label special, const label id)
Construct from components.
Definition moleculeI.H:219
static void writeFields(const Cloud< molecule > &mC)
Definition moleculeIO.C:147
const vector & pi() const
Definition moleculeI.H:538
static void readFields(Cloud< molecule > &mC)
Definition moleculeIO.C:88
label id() const
Definition moleculeI.H:634
const Time & time() const noexcept
Return time registry.
IOobject newIOobject(const word &name, IOobjectOption ioOpt) const
Create an IOobject at the current time instance (timeName) with the specified options.
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
const polyMesh & mesh() const noexcept
Return the mesh database.
Definition particleI.H:110
particle(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label tetFacei, const label tetPti)
Construct from components.
Definition particle.C:507
static void writeFields(const TrackCloudType &c)
Write the fields associated with the owner cloud.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
@ SPACE
Space [isspace].
Definition token.H:144
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
Vector< scalar > vector
Definition vector.H:57