FreeFOAM The Cross-Platform CFD Toolkit
meanMomentumEnergyAndNMols.H
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 Global
25  meanMomentumEnergyAndNMols.H
26 
27 Description
28  Calculates and prints the mean momentum and energy in the system
29  and the number of molecules.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 
35 
37 
39 
40 scalar singleStepTotalMass = 0.0;
41 
43 
45 
46 scalar singleStepTotalPE = 0.0;
47 
48 scalar singleStepTotalrDotf = 0.0;
49 
50 //vector singleStepCentreOfMass(vector::zero);
51 
52 label singleStepNMols = molecules.size();
53 
54 label singleStepDOFs = 0;
55 
56 {
57  IDLList<molecule>::iterator mol(molecules.begin());
58 
59  for
60  (
61  mol = molecules.begin();
62  mol != molecules.end();
63  ++mol
64  )
65  {
66  label molId = mol().id();
67 
68  scalar molMass(molecules.constProps(molId).mass());
69 
70  singleStepTotalMass += molMass;
71 
72  //singleStepCentreOfMass += mol().position()*molMass;
73  }
74 
75  // if(singleStepNMols)
76  // {
77  // singleStepCentreOfMass /= singleStepTotalMass;
78  // }
79 
80  for
81  (
82  mol = molecules.begin();
83  mol != molecules.end();
84  ++mol
85  )
86  {
87  label molId = mol().id();
88 
89  const molecule::constantProperties cP(molecules.constProps(molId));
90 
91  scalar molMass(cP.mass());
92 
93  const diagTensor& molMoI(cP.momentOfInertia());
94 
95  const vector& molV(mol().v());
96 
97  const vector& molOmega(inv(molMoI) & mol().pi());
98 
99  vector molPiGlobal = mol().Q() & mol().pi();
100 
101  singleStepTotalLinearMomentum += molV * molMass;
102 
103  singleStepTotalAngularMomentum += molPiGlobal;
104  //+((mol().position() - singleStepCentreOfMass) ^ (molV * molMass));
105 
106  if(mag(molV) > singleStepMaxVelocityMag)
107  {
109  }
110 
111  singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
112 
113  singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
114 
115  singleStepTotalPE += mol().potentialEnergy();
116 
117  singleStepTotalrDotf += tr(mol().rf());
118 
119  singleStepDOFs += cP.degreesOfFreedom();
120  }
121 }
122 
123 if (Pstream::parRun())
124 {
125  reduce(singleStepTotalLinearMomentum, sumOp<vector>());
126 
127  reduce(singleStepTotalAngularMomentum, sumOp<vector>());
128 
129  reduce(singleStepMaxVelocityMag, maxOp<scalar>());
130 
131  reduce(singleStepTotalMass, sumOp<scalar>());
132 
133  reduce(singleStepTotalLinearKE, sumOp<scalar>());
134 
135  reduce(singleStepTotalAngularKE, sumOp<scalar>());
136 
137  reduce(singleStepTotalPE, sumOp<scalar>());
138 
139  reduce(singleStepTotalrDotf, sumOp<scalar>());
140 
141  reduce(singleStepNMols, sumOp<label>());
142 
143  reduce(singleStepDOFs, sumOp<label>());
144 }
145 
146 if (singleStepNMols)
147 {
148  Info<< "Number of molecules in system = "
149  << singleStepNMols << nl
150  << "Overall number density = "
152  << "Overall mass density = "
154  << "Average linear momentum per molecule = "
157  << "Average angular momentum per molecule = "
160  << "Maximum |velocity| = "
162  << "Average linear KE per molecule = "
164  << "Average angular KE per molecule = "
166  << "Average PE per molecule = "
168  << "Average TE per molecule = "
169  <<
170  (
174  )
176  << endl;
177 
178  // Info << singleStepNMols << " "
179  // << singleStepTotalMomentum/singleStepTotalMass << " "
180  // << singleStepMaxVelocityMag << " "
181  // << singleStepTotalKE/singleStepNMols << " "
182  // << singleStepTotalPE/singleStepNMols << " "
183  // << (singleStepTotalKE + singleStepTotalPE)
184  // /singleStepNMols << endl;
185 }
186 else
187 {
188  Info<< "No molecules in system" << endl;
189 }
190 
191 
192 // ************************ vim: set sw=4 sts=4 et: ************************ //