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];
140  mol.specialPosition_ = specialPosition[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 
160  (
161  mC.fieldIOobject("specialPosition", IOobject::NO_READ),
162  np
163  );
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_
265  << token::SPACE << mol.specialPosition_
266  << token::SPACE << mol.potentialEnergy_
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_),
279  molecule::sizeofFields_
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 // ************************************************************************* //
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:71
#define readScalar
Definition: doubleScalar.C:38
const vector & v() const
Definition: moleculeI.H:480
const vector & tau() const
Definition: moleculeI.H:516
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual Istream & read(token &)=0
Return next token from stream.
#define forAllIter(Container, container, iter)
Definition: UList.H:440
virtual void write()
Calculate the Q and write.
Definition: Q.C:153
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
messageStream Info
const vector & a() const
Definition: moleculeI.H:492
const vector & pi() const
Definition: moleculeI.H:504
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
label readLabel(Istream &is)
Definition: label.H:64
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
label id() const
Definition: moleculeI.H:600
static void readFields(CloudType &c)
Read the fields associated with the owner cloud.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static void writeFields(const CloudType &c)
Write the fields associated with the owner cloud.
streamFormat format() const
Return current stream format.
Definition: IOstream.H:377
Base particle class.
Definition: particle.H:78
virtual Ostream & write(const token &)=0
Write next token to stream.
const tensor & Q() const
Definition: moleculeI.H:468
const polyMesh & mesh() const
label special() const
Definition: moleculeI.H:588
const word & name() const
Return name.
Definition: IOobject.H:260
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
void checkFieldIOobject(const Cloud< ParticleType > &c, const IOField< DataType > &data) const
Check lagrangian data field.
Definition: CloudIO.C:215
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
label size() const
Definition: Cloud.H:175
fileName timePath() const
Return current time path.
Definition: Time.H:297
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
static void writeFields(const Cloud< molecule > &mC)
Definition: moleculeIO.C:148
const Time & time() const
Return time.
Foam::molecule.
Definition: molecule.H:56
This function object calculates and outputs the second invariant of the velocity gradient tensor [1/s...
Definition: Q.H:66
static void readFields(Cloud< molecule > &mC)
Definition: moleculeIO.C:94
void writeXYZ(const fileName &fName) const
Write molecule sites in XYZ format.
const vector & specialPosition() const
Definition: moleculeI.H:552
IOobject fieldIOobject(const word &fieldName, const IOobject::readOption r) const
Helper to construct IOobject for field and current time.
Definition: CloudIO.C:195
A primitive field of type <T> with automated input and output.
Definition: IOField.H:50