FreeFOAM The Cross-Platform CFD Toolkit
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) 2008-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 "molecule.H"
27 #include <OpenFOAM/IOstreams.H>
28 #include <molecule/moleculeCloud.H>
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
33 (
34  const Cloud<molecule>& cloud,
35  Istream& is,
36  bool readFields
37 )
38 :
39  Particle<molecule>(cloud, is, readFields),
40  Q_(tensor::zero),
41  v_(vector::zero),
42  a_(vector::zero),
43  pi_(vector::zero),
44  tau_(vector::zero),
45  specialPosition_(vector::zero),
46  potentialEnergy_(0.0),
47  rf_(tensor::zero),
48  special_(0),
49  id_(0),
50  siteForces_(0),
51  sitePositions_(0)
52 {
53  if (readFields)
54  {
55  if (is.format() == IOstream::ASCII)
56  {
57  is >> Q_;
58  is >> v_;
59  is >> a_;
60  is >> pi_;
61  is >> tau_;
62  is >> siteForces_;
63  is >> sitePositions_;
64  is >> specialPosition_;
65  potentialEnergy_ = readScalar(is);
66  is >> rf_;
67  special_ = readLabel(is);
68  id_ = readLabel(is);
69  }
70  else
71  {
72  is.read
73  (
74  reinterpret_cast<char*>(&Q_),
75  sizeof(Q_)
76  + sizeof(v_)
77  + sizeof(a_)
78  + sizeof(pi_)
79  + sizeof(tau_)
80  + sizeof(specialPosition_)
81  + sizeof(potentialEnergy_)
82  + sizeof(rf_)
83  + sizeof(special_)
84  + sizeof(id_)
85  );
86 
87  is >> siteForces_ >> sitePositions_;
88  }
89  }
90 
91  // Check state of Istream
92  is.check
93  (
94  "Foam::molecule::molecule"
95  "(const Cloud<molecule>& cloud, Foam::Istream&), bool"
96  );
97 }
98 
99 
101 {
102  if (!mC.size())
103  {
104  return;
105  }
106 
108 
110  mC.checkFieldIOobject(mC, Q);
111 
113  mC.checkFieldIOobject(mC, v);
114 
116  mC.checkFieldIOobject(mC, a);
117 
119  mC.checkFieldIOobject(mC, pi);
120 
122  mC.checkFieldIOobject(mC, tau);
123 
125  (
126  mC.fieldIOobject("specialPosition", IOobject::MUST_READ)
127  );
129 
131  mC.checkFieldIOobject(mC, special);
132 
134  mC.checkFieldIOobject(mC, id);
135 
136  label i = 0;
137  forAllIter(moleculeCloud, mC, iter)
138  {
139  molecule& mol = iter();
140 
141  mol.Q_ = Q[i];
142  mol.v_ = v[i];
143  mol.a_ = a[i];
144  mol.pi_ = pi[i];
145  mol.tau_ = tau[i];
146  mol.specialPosition_ = specialPosition[i];
147  mol.special_ = special[i];
148  mol.id_ = id[i];
149  i++;
150  }
151 }
152 
153 
155 {
157 
158  label np = mC.size();
159 
164  IOField<vector> tau(mC.fieldIOobject("tau", IOobject::NO_READ), np);
165  IOField<vector> specialPosition
166  (
167  mC.fieldIOobject("specialPosition", IOobject::NO_READ),
168  np
169  );
170  IOField<label> special(mC.fieldIOobject("special", IOobject::NO_READ), np);
172 
173  // Post processing fields
174 
175  IOField<vector> piGlobal
176  (
177  mC.fieldIOobject("piGlobal", IOobject::NO_READ),
178  np
179  );
180 
181  IOField<vector> tauGlobal
182  (
183  mC.fieldIOobject("tauGlobal", IOobject::NO_READ),
184  np
185  );
186 
187  IOField<vector> orientation1
188  (
189  mC.fieldIOobject("orientation1", IOobject::NO_READ),
190  np
191  );
192 
193  IOField<vector> orientation2
194  (
195  mC.fieldIOobject("orientation2", IOobject::NO_READ),
196  np
197  );
198 
199  IOField<vector> orientation3
200  (
201  mC.fieldIOobject("orientation3", IOobject::NO_READ),
202  np
203  );
204 
205  label i = 0;
206  forAllConstIter(moleculeCloud, mC, iter)
207  {
208  const molecule& mol = iter();
209 
210  Q[i] = mol.Q_;
211  v[i] = mol.v_;
212  a[i] = mol.a_;
213  pi[i] = mol.pi_;
214  tau[i] = mol.tau_;
215  specialPosition[i] = mol.specialPosition_;
216  special[i] = mol.special_;
217  id[i] = mol.id_;
218 
219  piGlobal[i] = mol.Q_ & mol.pi_;
220  tauGlobal[i] = mol.Q_ & mol.tau_;
221 
222  orientation1[i] = mol.Q_ & vector(1,0,0);
223  orientation2[i] = mol.Q_ & vector(0,1,0);
224  orientation3[i] = mol.Q_ & vector(0,0,1);
225 
226  i++;
227  }
228 
229  Q.write();
230  v.write();
231  a.write();
232  pi.write();
233  tau.write();
234  specialPosition.write();
235  special.write();
236  id.write();
237 
238  piGlobal.write();
239  tauGlobal.write();
240 
241  orientation1.write();
242  orientation2.write();
243  orientation3.write();
244 
245  const moleculeCloud& m = dynamic_cast<const moleculeCloud&>(mC);
246  m.writeXYZ
247  (
248  m.mesh().time().timePath() + "/lagrangian" + "/moleculeCloud.xmol"
249  );
250 }
251 
252 
253 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
254 
256 {
257  if (os.format() == IOstream::ASCII)
258  {
259  os << token::SPACE << static_cast<const Particle<molecule>&>(mol)
260  << token::SPACE << mol.face()
261  << token::SPACE << mol.stepFraction()
262  << token::SPACE << mol.Q_
263  << token::SPACE << mol.v_
264  << token::SPACE << mol.a_
265  << token::SPACE << mol.pi_
266  << token::SPACE << mol.tau_
267  << token::SPACE << mol.specialPosition_
268  << token::SPACE << mol.potentialEnergy_
269  << token::SPACE << mol.rf_
270  << token::SPACE << mol.special_
271  << token::SPACE << mol.id_
272  << token::SPACE << mol.siteForces_
273  << token::SPACE << mol.sitePositions_;
274  }
275  else
276  {
277  os << static_cast<const Particle<molecule>&>(mol);
278  os.write
279  (
280  reinterpret_cast<const char*>(&mol.Q_),
281  sizeof(mol.Q_)
282  + sizeof(mol.v_)
283  + sizeof(mol.a_)
284  + sizeof(mol.pi_)
285  + sizeof(mol.tau_)
286  + sizeof(mol.specialPosition_)
287  + sizeof(mol.potentialEnergy_)
288  + sizeof(mol.rf_)
289  + sizeof(mol.special_)
290  + sizeof(mol.id_)
291  );
292  os << mol.siteForces_ << mol.sitePositions_;
293  }
294 
295  // Check state of Ostream
296  os.check
297  (
298  "Foam::Ostream& Foam::operator<<"
299  "(Foam::Ostream&, const Foam::molecule&)"
300  );
301 
302  return os;
303 }
304 
305 
306 // ************************ vim: set sw=4 sts=4 et: ************************ //