moleculeIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 "molecule.H"
27 #include "IOstreams.H"
28 #include "moleculeCloud.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 const std::size_t Foam::molecule::sizeofFields_
33 (
34  offsetof(molecule, siteForces_) - offsetof(molecule, Q_)
35 );
36 
37 
38 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 
41 (
42  const polyMesh& mesh,
43  Istream& is,
44  bool readFields
45 )
46 :
47  particle(mesh, is, readFields),
48  Q_(Zero),
49  v_(Zero),
50  a_(Zero),
51  pi_(Zero),
52  tau_(Zero),
53  specialPosition_(Zero),
54  potentialEnergy_(0.0),
55  rf_(Zero),
56  special_(0),
57  id_(0),
58  siteForces_(0),
59  sitePositions_(0)
60 {
61  if (readFields)
62  {
63  if (is.format() == IOstream::ASCII)
64  {
65  is >> Q_;
66  is >> v_;
67  is >> a_;
68  is >> pi_;
69  is >> tau_;
70  is >> specialPosition_;
71  potentialEnergy_ = readScalar(is);
72  is >> rf_;
73  special_ = readLabel(is);
74  id_ = readLabel(is);
75  is >> siteForces_;
76  is >> sitePositions_;
77  }
78  else
79  {
80  is.read(reinterpret_cast<char*>(&Q_), sizeofFields_);
81  is >> siteForces_ >> sitePositions_;
82  }
83  }
84 
85  // Check state of Istream
86  is.check
87  (
88  "Foam::molecule::molecule"
89  "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
90  );
91 }
92 
93 
95 {
96  bool write = mC.size();
97 
99 
101  mC.checkFieldIOobject(mC, Q);
102 
104  mC.checkFieldIOobject(mC, v);
105 
107  mC.checkFieldIOobject(mC, a);
108 
110  mC.checkFieldIOobject(mC, pi);
111 
113  mC.checkFieldIOobject(mC, tau);
114 
116  (
117  mC.fieldIOobject("specialPosition", IOobject::MUST_READ),
118  write
119  );
121 
123  (
124  mC.fieldIOobject("special", IOobject::MUST_READ),
125  write
126  );
127  mC.checkFieldIOobject(mC, special);
128 
130  mC.checkFieldIOobject(mC, id);
131 
132  label i = 0;
133  forAllIter(moleculeCloud, mC, iter)
134  {
135  molecule& mol = iter();
136 
137  mol.Q_ = Q[i];
138  mol.v_ = v[i];
139  mol.a_ = a[i];
140  mol.pi_ = pi[i];
141  mol.tau_ = tau[i];
142  mol.specialPosition_ = specialPosition[i];
143  mol.special_ = special[i];
144  mol.id_ = id[i];
145  i++;
146  }
147 }
148 
149 
151 {
153 
154  label np = mC.size();
155 
162  (
163  mC.fieldIOobject("specialPosition", IOobject::NO_READ),
164  np
165  );
168 
169  // Post processing fields
170 
171  IOField<vector> piGlobal
172  (
173  mC.fieldIOobject("piGlobal", IOobject::NO_READ),
174  np
175  );
176 
177  IOField<vector> tauGlobal
178  (
179  mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
180  np
181  );
182 
183  IOField<vector> orientation1
184  (
185  mC.fieldIOobject("orientation1", IOobject::NO_READ),
186  np
187  );
188 
189  IOField<vector> orientation2
190  (
191  mC.fieldIOobject("orientation2", IOobject::NO_READ),
192  np
193  );
194 
195  IOField<vector> orientation3
196  (
197  mC.fieldIOobject("orientation3", IOobject::NO_READ),
198  np
199  );
200 
201  label i = 0;
202  forAllConstIter(moleculeCloud, mC, iter)
203  {
204  const molecule& mol = iter();
205 
206  Q[i] = mol.Q_;
207  v[i] = mol.v_;
208  a[i] = mol.a_;
209  pi[i] = mol.pi_;
210  tau[i] = mol.tau_;
211  specialPosition[i] = mol.specialPosition_;
212  special[i] = mol.special_;
213  id[i] = mol.id_;
214 
215  piGlobal[i] = mol.Q_ & mol.pi_;
216  tauGlobal[i] = mol.Q_ & mol.tau_;
217 
218  orientation1[i] = mol.Q_ & vector(1,0,0);
219  orientation2[i] = mol.Q_ & vector(0,1,0);
220  orientation3[i] = mol.Q_ & vector(0,0,1);
221 
222  i++;
223  }
224 
225  const bool write = np > 0;
226 
227  Q.write(write);
228  v.write(write);
229  a.write(write);
230  pi.write(write);
231  tau.write(write);
232  specialPosition.write(write);
233  special.write(write);
234  id.write(write);
235 
236  piGlobal.write(write);
237  tauGlobal.write(write);
238 
239  orientation1.write(write);
240  orientation2.write(write);
241  orientation3.write(write);
242 
243  Info<< "writeFields " << mC.name() << endl;
244 
245  if (isA<moleculeCloud>(mC))
246  {
247  const moleculeCloud& m = dynamic_cast<const moleculeCloud&>(mC);
248 
249  m.writeXYZ
250  (
251  m.mesh().time().timePath()/cloud::prefix/"moleculeCloud.xmol"
252  );
253  }
254 }
255 
256 
257 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
258 
260 {
261  if (os.format() == IOstream::ASCII)
262  {
263  os << token::SPACE << static_cast<const particle&>(mol)
264  << token::SPACE << mol.Q_
265  << token::SPACE << mol.v_
266  << token::SPACE << mol.a_
267  << token::SPACE << mol.pi_
268  << token::SPACE << mol.tau_
269  << token::SPACE << mol.specialPosition_
270  << token::SPACE << mol.potentialEnergy_
271  << token::SPACE << mol.rf_
272  << token::SPACE << mol.special_
273  << token::SPACE << mol.id_
274  << token::SPACE << mol.siteForces_
275  << token::SPACE << mol.sitePositions_;
276  }
277  else
278  {
279  os << static_cast<const particle&>(mol);
280  os.write
281  (
282  reinterpret_cast<const char*>(&mol.Q_),
283  molecule::sizeofFields_
284  );
285  os << mol.siteForces_ << mol.sitePositions_;
286  }
287 
288  // Check state of Ostream
289  os.check
290  (
291  "Foam::Ostream& Foam::operator<<"
292  "(Foam::Ostream&, const Foam::molecule&)"
293  );
294 
295  return os;
296 }
297 
298 
299 // ************************************************************************* //
#define readScalar
Definition: doubleScalar.C:38
void writeXYZ(const fileName &fName) const
Write molecule sites in XYZ format.
const tensor & Q() const
Definition: moleculeI.H:501
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
const word & name() const
Return name.
Definition: IOobject.H:295
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
fileName timePath() const
Return current time path.
Definition: Time.H:282
label special() const
Definition: moleculeI.H:621
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const vector & pi() const
Definition: moleculeI.H:537
label size() const
Return the number of particles in the cloud.
Definition: Cloud.H:151
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
static void writeFields(const Cloud< molecule > &mC)
Definition: moleculeIO.C:150
static void readFields(Cloud< molecule > &mC)
Definition: moleculeIO.C:94
Base particle class.
Definition: particle.H:84
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
const vector & a() const
Definition: moleculeI.H:525
virtual Istream & read(token &)=0
Return next token from stream.
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:221
static const zero Zero
Definition: zero.H:97
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
label readLabel(Istream &is)
Definition: label.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
const Time & time() const
Return time.
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:62
static void readFields(TrackCloudType &c)
Read the fields associated with the owner cloud.
static void writeFields(const TrackCloudType &c)
Write the fields associated with the owner cloud.
Ostream & operator<<(Ostream &, const ensightPart &)
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:187
messageStream Info
Foam::molecule.
Definition: molecule.H:64
virtual Ostream & write(const token &)=0
Write next token to stream.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const polyMesh & mesh() const
label id() const
Definition: moleculeI.H:633
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:167
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
const vector & tau() const
Definition: moleculeI.H:549
const vector & specialPosition() const
Definition: moleculeI.H:585
const vector & v() const
Definition: moleculeI.H:513