1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 meanMomentumEnergyAndNMols.H
29 Calculates and prints the mean momentum and energy in the system
30 and the number of molecules.
32 \*---------------------------------------------------------------------------*/
35 vector singleStepTotalLinearMomentum(vector::zero);
37 vector singleStepTotalAngularMomentum(vector::zero);
39 scalar singleStepMaxVelocityMag = 0.0;
41 scalar singleStepTotalMass = 0.0;
43 scalar singleStepTotalLinearKE = 0.0;
45 scalar singleStepTotalAngularKE = 0.0;
47 scalar singleStepTotalPE = 0.0;
49 scalar singleStepTotalrDotf = 0.0;
51 //vector singleStepCentreOfMass(vector::zero);
53 label singleStepNMols = molecules.size();
55 label singleStepDOFs = 0;
58 IDLList<molecule>::iterator mol(molecules.begin());
62 mol = molecules.begin();
63 mol != molecules.end();
67 label molId = mol().id();
69 scalar molMass(molecules.constProps(molId).mass());
71 singleStepTotalMass += molMass;
73 //singleStepCentreOfMass += mol().position()*molMass;
76 // if(singleStepNMols)
78 // singleStepCentreOfMass /= singleStepTotalMass;
83 mol = molecules.begin();
84 mol != molecules.end();
88 label molId = mol().id();
90 const molecule::constantProperties cP(molecules.constProps(molId));
92 scalar molMass(cP.mass());
94 const diagTensor& molMoI(cP.momentOfInertia());
96 const vector& molV(mol().v());
98 const vector& molOmega(inv(molMoI) & mol().pi());
100 vector molPiGlobal = mol().Q() & mol().pi();
102 singleStepTotalLinearMomentum += molV * molMass;
104 singleStepTotalAngularMomentum += molPiGlobal;
105 //+((mol().position() - singleStepCentreOfMass) ^ (molV * molMass));
107 if(mag(molV) > singleStepMaxVelocityMag)
109 singleStepMaxVelocityMag = mag(molV);
112 singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
114 singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
116 singleStepTotalPE += mol().potentialEnergy();
118 singleStepTotalrDotf += tr(mol().rf());
120 singleStepDOFs += cP.degreesOfFreedom();
124 if (Pstream::parRun())
126 reduce(singleStepTotalLinearMomentum, sumOp<vector>());
128 reduce(singleStepTotalAngularMomentum, sumOp<vector>());
130 reduce(singleStepMaxVelocityMag, maxOp<scalar>());
132 reduce(singleStepTotalMass, sumOp<scalar>());
134 reduce(singleStepTotalLinearKE, sumOp<scalar>());
136 reduce(singleStepTotalAngularKE, sumOp<scalar>());
138 reduce(singleStepTotalPE, sumOp<scalar>());
140 reduce(singleStepTotalrDotf, sumOp<scalar>());
142 reduce(singleStepNMols, sumOp<label>());
144 reduce(singleStepDOFs, sumOp<label>());
149 Info<< "Number of molecules in system = "
150 << singleStepNMols << nl
151 << "Overall number density = "
152 << singleStepNMols/meshVolume << nl
153 << "Overall mass density = "
154 << singleStepTotalMass/meshVolume << nl
155 << "Average linear momentum per molecule = "
156 << singleStepTotalLinearMomentum/singleStepNMols << ' '
157 << mag(singleStepTotalLinearMomentum)/singleStepNMols << nl
158 << "Average angular momentum per molecule = "
159 << singleStepTotalAngularMomentum << ' '
160 << mag(singleStepTotalAngularMomentum)/singleStepNMols << nl
161 << "Maximum |velocity| = "
162 << singleStepMaxVelocityMag << nl
163 << "Average linear KE per molecule = "
164 << singleStepTotalLinearKE/singleStepNMols << nl
165 << "Average angular KE per molecule = "
166 << singleStepTotalAngularKE/singleStepNMols << nl
167 << "Average PE per molecule = "
168 << singleStepTotalPE/singleStepNMols << nl
169 << "Average TE per molecule = "
172 singleStepTotalLinearKE
173 + singleStepTotalAngularKE
179 // Info << singleStepNMols << " "
180 // << singleStepTotalMomentum/singleStepTotalMass << " "
181 // << singleStepMaxVelocityMag << " "
182 // << singleStepTotalKE/singleStepNMols << " "
183 // << singleStepTotalPE/singleStepNMols << " "
184 // << (singleStepTotalKE + singleStepTotalPE)
185 // /singleStepNMols << endl;
189 Info<< "No molecules in system" << endl;
193 // ************************************************************************* //