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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Global
28 meanMomentumEnergyAndNMols.H
29
30Description
31 Calculates and prints the mean momentum and energy in the system
32 and the number of molecules.
33
34\*---------------------------------------------------------------------------*/
35
41scalar singleStepMaxVelocityMag = 0.0;
43scalar singleStepTotalMass = 0.0;
45scalar singleStepTotalLinearKE = 0.0;
47scalar singleStepTotalAngularKE = 0.0;
49scalar singleStepTotalPE = 0.0;
50
51scalar singleStepTotalrDotf = 0.0;
53//vector singleStepCentreOfMass(Zero);
55label singleStepNMols = molecules.size();
56
57label singleStepDOFs = 0;
58
59{
60 for (const molecule& mol : molecules)
61 {
62 const label molId = mol.id();
63
64 scalar molMass(molecules.constProps(molId).mass());
65
66 singleStepTotalMass += molMass;
67
68 //singleStepCentreOfMass += mol.position()*molMass;
69 }
70
71 // if (singleStepNMols)
72 // {
73 // singleStepCentreOfMass /= singleStepTotalMass;
74 // }
75
76 for (const molecule& mol : molecules)
77 {
78 const label molId = mol.id();
79
80 const molecule::constantProperties cP(molecules.constProps(molId));
81
82 scalar molMass(cP.mass());
83
84 const diagTensor& molMoI(cP.momentOfInertia());
85
86 const vector& molV(mol.v());
87
88 const vector molOmega(inv(molMoI) & mol.pi());
89
90 vector molPiGlobal = mol.Q() & mol.pi();
91
92 singleStepTotalLinearMomentum += molV * molMass;
93
94 singleStepTotalAngularMomentum += molPiGlobal;
95 //+((mol.position() - singleStepCentreOfMass) ^ (molV * molMass));
96
97 if (mag(molV) > singleStepMaxVelocityMag)
98 {
99 singleStepMaxVelocityMag = mag(molV);
100 }
101
102 singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
103
104 singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
105
106 singleStepTotalPE += mol.potentialEnergy();
107
108 singleStepTotalrDotf += tr(mol.rf());
109
110 singleStepDOFs += cP.degreesOfFreedom();
111 }
112}
113
114if (Pstream::parRun())
115{
116 reduce(singleStepTotalLinearMomentum, sumOp<vector>());
117
118 reduce(singleStepTotalAngularMomentum, sumOp<vector>());
119
120 reduce(singleStepMaxVelocityMag, maxOp<scalar>());
121
122 reduce(singleStepTotalMass, sumOp<scalar>());
123
124 reduce(singleStepTotalLinearKE, sumOp<scalar>());
125
126 reduce(singleStepTotalAngularKE, sumOp<scalar>());
127
128 reduce(singleStepTotalPE, sumOp<scalar>());
129
130 reduce(singleStepTotalrDotf, sumOp<scalar>());
131
132 reduce(singleStepNMols, sumOp<label>());
133
134 reduce(singleStepDOFs, sumOp<label>());
135}
136
138{
139 Info<< "Number of molecules in system = "
140 << singleStepNMols << nl
141 << "Overall number density = "
143 << "Overall mass density = "
145 << "Average linear momentum per molecule = "
148 << "Average angular momentum per molecule = "
151 << "Maximum |velocity| = "
153 << "Average linear KE per molecule = "
155 << "Average angular KE per molecule = "
157 << "Average PE per molecule = "
159 << "Average TE per molecule = "
160 <<
161 (
165 )
167 << endl;
168
169 // Info<< singleStepNMols << " "
170 // << singleStepTotalMomentum/singleStepTotalMass << " "
171 // << singleStepMaxVelocityMag << " "
172 // << singleStepTotalKE/singleStepNMols << " "
173 // << singleStepTotalPE/singleStepNMols << " "
174 // << (singleStepTotalKE + singleStepTotalPE)
175 // /singleStepNMols << endl;
176}
177else
178{
179 Info<< "No molecules in system" << endl;
180}
181
182
183// ************************************************************************* //
reduce(hasMovingMesh, orOp< bool >())
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
scalar singleStepTotalMass
scalar singleStepTotalPE
label singleStepDOFs
scalar singleStepTotalrDotf
scalar singleStepMaxVelocityMag
scalar singleStepTotalLinearKE
vector singleStepTotalLinearMomentum(Zero)
vector singleStepTotalAngularMomentum(Zero)
label singleStepNMols
scalar singleStepTotalAngularKE
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53