1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 meanMomentumEnergyAndNMols.H
28 Calculates and prints the mean momentum and energy in the system
29 and the number of molecules.
31 \*---------------------------------------------------------------------------*/
34 vector singleStepTotalLinearMomentum(vector::zero);
36 vector singleStepTotalAngularMomentum(vector::zero);
38 scalar singleStepMaxVelocityMag = 0.0;
40 scalar singleStepTotalMass = 0.0;
42 scalar singleStepTotalLinearKE = 0.0;
44 scalar singleStepTotalAngularKE = 0.0;
46 scalar singleStepTotalPE = 0.0;
48 scalar singleStepTotalrDotf = 0.0;
50 //vector singleStepCentreOfMass(vector::zero);
52 label singleStepNMols = molecules.size();
54 label singleStepDOFs = 0;
57 forAllConstIter(IDLList<molecule>, molecules, mol)
59 const label molId = mol().id();
61 scalar molMass(molecules.constProps(molId).mass());
63 singleStepTotalMass += molMass;
65 //singleStepCentreOfMass += mol().position()*molMass;
68 // if (singleStepNMols)
70 // singleStepCentreOfMass /= singleStepTotalMass;
73 forAllConstIter(IDLList<molecule>, molecules, mol)
75 const label molId = mol().id();
77 const molecule::constantProperties cP(molecules.constProps(molId));
79 scalar molMass(cP.mass());
81 const diagTensor& molMoI(cP.momentOfInertia());
83 const vector& molV(mol().v());
85 const vector& molOmega(inv(molMoI) & mol().pi());
87 vector molPiGlobal = mol().Q() & mol().pi();
89 singleStepTotalLinearMomentum += molV * molMass;
91 singleStepTotalAngularMomentum += molPiGlobal;
92 //+((mol().position() - singleStepCentreOfMass) ^ (molV * molMass));
94 if (mag(molV) > singleStepMaxVelocityMag)
96 singleStepMaxVelocityMag = mag(molV);
99 singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
101 singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
103 singleStepTotalPE += mol().potentialEnergy();
105 singleStepTotalrDotf += tr(mol().rf());
107 singleStepDOFs += cP.degreesOfFreedom();
111 if (Pstream::parRun())
113 reduce(singleStepTotalLinearMomentum, sumOp<vector>());
115 reduce(singleStepTotalAngularMomentum, sumOp<vector>());
117 reduce(singleStepMaxVelocityMag, maxOp<scalar>());
119 reduce(singleStepTotalMass, sumOp<scalar>());
121 reduce(singleStepTotalLinearKE, sumOp<scalar>());
123 reduce(singleStepTotalAngularKE, sumOp<scalar>());
125 reduce(singleStepTotalPE, sumOp<scalar>());
127 reduce(singleStepTotalrDotf, sumOp<scalar>());
129 reduce(singleStepNMols, sumOp<label>());
131 reduce(singleStepDOFs, sumOp<label>());
136 Info<< "Number of molecules in system = "
137 << singleStepNMols << nl
138 << "Overall number density = "
139 << singleStepNMols/meshVolume << nl
140 << "Overall mass density = "
141 << singleStepTotalMass/meshVolume << nl
142 << "Average linear momentum per molecule = "
143 << singleStepTotalLinearMomentum/singleStepNMols << ' '
144 << mag(singleStepTotalLinearMomentum)/singleStepNMols << nl
145 << "Average angular momentum per molecule = "
146 << singleStepTotalAngularMomentum << ' '
147 << mag(singleStepTotalAngularMomentum)/singleStepNMols << nl
148 << "Maximum |velocity| = "
149 << singleStepMaxVelocityMag << nl
150 << "Average linear KE per molecule = "
151 << singleStepTotalLinearKE/singleStepNMols << nl
152 << "Average angular KE per molecule = "
153 << singleStepTotalAngularKE/singleStepNMols << nl
154 << "Average PE per molecule = "
155 << singleStepTotalPE/singleStepNMols << nl
156 << "Average TE per molecule = "
159 singleStepTotalLinearKE
160 + singleStepTotalAngularKE
166 // Info<< singleStepNMols << " "
167 // << singleStepTotalMomentum/singleStepTotalMass << " "
168 // << singleStepMaxVelocityMag << " "
169 // << singleStepTotalKE/singleStepNMols << " "
170 // << singleStepTotalPE/singleStepNMols << " "
171 // << (singleStepTotalKE + singleStepTotalPE)
172 // /singleStepNMols << endl;
176 Info<< "No molecules in system" << endl;
180 // ************************************************************************* //