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 | Copyright (C) 2011-2015 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_(tensor::zero),
49  v_(vector::zero),
50  a_(vector::zero),
51  pi_(vector::zero),
52  tau_(vector::zero),
53  specialPosition_(vector::zero),
54  potentialEnergy_(0.0),
55  rf_(tensor::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  if (!mC.size())
97  {
98  return;
99  }
100 
102 
104  mC.checkFieldIOobject(mC, Q);
105 
107  mC.checkFieldIOobject(mC, v);
108 
110  mC.checkFieldIOobject(mC, a);
111 
113  mC.checkFieldIOobject(mC, pi);
114 
116  mC.checkFieldIOobject(mC, tau);
117 
119  (
120  mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
121  );
123 
125  mC.checkFieldIOobject(mC, special);
126 
128  mC.checkFieldIOobject(mC, id);
129 
130  label i = 0;
131  forAllIter(moleculeCloud, mC, iter)
132  {
133  molecule& mol = iter();
134 
135  mol.Q_ = Q[i];
136  mol.v_ = v[i];
137  mol.a_ = a[i];
138  mol.pi_ = pi[i];
139  mol.tau_ = tau[i];
141  mol.special_ = special[i];
142  mol.id_ = id[i];
143  i++;
144  }
145 }
146 
147 
149 {
151 
152  label np = mC.size();
153 
158  IOField<vector> tau(mC.fieldIOobject("tau", IOobject::NO_READ), np);
159  IOField<vector> specialPosition
160  (
161  mC.fieldIOobject("specialPosition", IOobject::NO_READ),
162  np
163  );
164  IOField<label> special(mC.fieldIOobject("special", IOobject::NO_READ), np);
166 
167  // Post processing fields
168 
169  IOField<vector> piGlobal
170  (
171  mC.fieldIOobject("piGlobal", IOobject::NO_READ),
172  np
173  );
174 
175  IOField<vector> tauGlobal
176  (
177  mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
178  np
179  );
180 
181  IOField<vector> orientation1
182  (
183  mC.fieldIOobject("orientation1", IOobject::NO_READ),
184  np
185  );
186 
187  IOField<vector> orientation2
188  (
189  mC.fieldIOobject("orientation2", IOobject::NO_READ),
190  np
191  );
192 
193  IOField<vector> orientation3
194  (
195  mC.fieldIOobject("orientation3", IOobject::NO_READ),
196  np
197  );
198 
199  label i = 0;
200  forAllConstIter(moleculeCloud, mC, iter)
201  {
202  const molecule& mol = iter();
203 
204  Q[i] = mol.Q_;
205  v[i] = mol.v_;
206  a[i] = mol.a_;
207  pi[i] = mol.pi_;
208  tau[i] = mol.tau_;
209  specialPosition[i] = mol.specialPosition_;
210  special[i] = mol.special_;
211  id[i] = mol.id_;
212 
213  piGlobal[i] = mol.Q_ & mol.pi_;
214  tauGlobal[i] = mol.Q_ & mol.tau_;
215 
216  orientation1[i] = mol.Q_ & vector(1,0,0);
217  orientation2[i] = mol.Q_ & vector(0,1,0);
218  orientation3[i] = mol.Q_ & vector(0,0,1);
219 
220  i++;
221  }
222 
223  Q.write();
224  v.write();
225  a.write();
226  pi.write();
227  tau.write();
228  specialPosition.write();
229  special.write();
230  id.write();
231 
232  piGlobal.write();
233  tauGlobal.write();
234 
235  orientation1.write();
236  orientation2.write();
237  orientation3.write();
238 
239  Info<< "writeFields " << mC.name() << endl;
240 
241  if (isA<moleculeCloud>(mC))
242  {
243  const moleculeCloud& m = dynamic_cast<const moleculeCloud&>(mC);
244 
245  m.writeXYZ
246  (
247  m.mesh().time().timePath()/cloud::prefix/"moleculeCloud.xmol"
248  );
249  }
250 }
251 
252 
253 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
254 
256 {
257  if (os.format() == IOstream::ASCII)
258  {
259  os << token::SPACE << static_cast<const particle&>(mol)
260  << token::SPACE << mol.Q_
261  << token::SPACE << mol.v_
262  << token::SPACE << mol.a_
263  << token::SPACE << mol.pi_
264  << token::SPACE << mol.tau_
267  << token::SPACE << mol.rf_
268  << token::SPACE << mol.special_
269  << token::SPACE << mol.id_
270  << token::SPACE << mol.siteForces_
271  << token::SPACE << mol.sitePositions_;
272  }
273  else
274  {
275  os << static_cast<const particle&>(mol);
276  os.write
277  (
278  reinterpret_cast<const char*>(&mol.Q_),
280  );
281  os << mol.siteForces_ << mol.sitePositions_;
282  }
283 
284  // Check state of Ostream
285  os.check
286  (
287  "Foam::Ostream& Foam::operator<<"
288  "(Foam::Ostream&, const Foam::molecule&)"
289  );
290 
291  return os;
292 }
293 
294 
295 // ************************************************************************* //
Foam::molecule::sizeofFields_
static const std::size_t sizeofFields_
Size in bytes of the fields.
Definition: molecule.H:63
Foam::IOstream::format
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Foam::molecule::rf_
tensor rf_
Definition: molecule.H:203
Foam::molecule::writeFields
static void writeFields(const Cloud< molecule > &mC)
Definition: moleculeIO.C:148
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
forAllIter
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:431
Foam::IOField
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50
Foam::molecule::siteForces_
List< vector > siteForces_
Definition: molecule.H:209
Foam::molecule::v
const vector & v() const
Definition: moleculeI.H:478
Foam::molecule::id_
label id_
Definition: molecule.H:207
Foam::objectRegistry::time
const Time & time() const
Return time.
Definition: objectRegistry.H:117
Foam::Cloud::checkFieldIOobject
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:215
Foam::Q::write
virtual void write()
Calculate the Q and write.
Definition: Q.C:154
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::molecule::id
label id() const
Definition: moleculeI.H:598
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::readFields
This function object reads fields from the time directories and adds them to the mesh database for fu...
Definition: readFields.H:104
Foam::Cloud::fieldIOobject
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:195
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
Foam::molecule::tau
const vector & tau() const
Definition: moleculeI.H:514
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
Foam::Q
This function object calculates and outputs the second invariant of the velocity gradient tensor [1/s...
Definition: Q.H:119
Foam::molecule::Q_
tensor Q_
Definition: molecule.H:188
Foam::molecule::special
label special() const
Definition: moleculeI.H:586
Foam::IOstream::ASCII
@ ASCII
Definition: IOstream.H:88
Foam::molecule::Q
const tensor & Q() const
Definition: moleculeI.H:466
moleculeCloud.H
Foam::label
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
Foam::molecule::tau_
vector tau_
Definition: molecule.H:196
Foam::molecule
Foam::molecule.
Definition: molecule.H:56
Foam::molecule::a
const vector & a() const
Definition: moleculeI.H:490
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
Foam::molecule::special_
label special_
Definition: molecule.H:205
Foam::Ostream::write
virtual Ostream & write(const token &)=0
Write next token to stream.
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::Info
messageStream Info
Foam::Time::timePath
fileName timePath() const
Return current time path.
Definition: Time.H:297
Foam::Cloud::size
label size() const
Definition: Cloud.H:175
Foam::moleculeCloud::mesh
const polyMesh & mesh() const
Definition: moleculeCloudI.H:344
Foam::molecule::v_
vector v_
Definition: molecule.H:190
Foam::operator<<
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:130
Foam::molecule::molecule
molecule(const polyMesh &mesh, const vector &position, 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
Foam::moleculeCloud::writeXYZ
void writeXYZ(const fileName &fName) const
Write molecule sites in XYZ format.
Definition: moleculeCloud.C:1231
Foam::IOstream::check
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Foam::molecule::potentialEnergy_
scalar potentialEnergy_
Definition: molecule.H:200
Foam::molecule::sitePositions_
List< vector > sitePositions_
Definition: molecule.H:211
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
readScalar
#define readScalar
Definition: doubleScalar.C:38
Foam::molecule::pi_
vector pi_
Definition: molecule.H:194
Foam::molecule::specialPosition_
vector specialPosition_
Definition: molecule.H:198
Foam::cloud::prefix
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:71
Foam::molecule::readFields
static void readFields(Cloud< molecule > &mC)
Definition: moleculeIO.C:94
Foam::moleculeCloud
Definition: moleculeCloud.H:56
Foam::molecule::specialPosition
const vector & specialPosition() const
Definition: moleculeI.H:550
Foam::particle
Base particle class.
Definition: particle.H:78
Foam::Cloud< molecule >
Foam::readLabel
label readLabel(Istream &is)
Definition: label.H:64
Foam::constant::mathematical::pi
const scalar pi(M_PI)
Foam::particle::readFields
static void readFields(CloudType &c)
Read the fields associated with the owner cloud.
Definition: particleTemplates.C:129
molecule.H
Foam::molecule::a_
vector a_
Definition: molecule.H:192
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::particle::writeFields
static void writeFields(const CloudType &c)
Write the fields associated with the owner cloud.
Definition: particleTemplates.C:159
Foam::molecule::pi
const vector & pi() const
Definition: moleculeI.H:502
Foam::token::SPACE
@ SPACE
Definition: token.H:95
Foam::Istream::read
virtual Istream & read(token &)=0
Return next token from stream.