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 -------------------------------------------------------------------------------
11 License
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 
27 Global
28  meanMomentumEnergyAndNMols.H
29 
30 Description
31  Calculates and prints the mean momentum and energy in the system
32  and the number of molecules.
33 
34 \*---------------------------------------------------------------------------*/
35 
36 
38 
40 
41 scalar singleStepMaxVelocityMag = 0.0;
42 
43 scalar singleStepTotalMass = 0.0;
44 
45 scalar singleStepTotalLinearKE = 0.0;
46 
47 scalar singleStepTotalAngularKE = 0.0;
48 
49 scalar singleStepTotalPE = 0.0;
50 
51 scalar singleStepTotalrDotf = 0.0;
52 
53 //vector singleStepCentreOfMass(Zero);
54 
55 label singleStepNMols = molecules.size();
56 
57 label 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  {
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 
114 if (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 
137 if (singleStepNMols)
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 }
177 else
178 {
179  Info<< "No molecules in system" << endl;
180 }
181 
182 
183 // ************************************************************************* //
scalar singleStepTotalrDotf
vector singleStepTotalAngularMomentum(Zero)
DiagTensor< scalar > diagTensor
DiagTensor of scalars, i.e. DiagTensor<scalar>.
Definition: diagTensor.H:49
label singleStepNMols
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
dimensionedSphericalTensor inv(const dimensionedSphericalTensor &dt)
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
scalar singleStepTotalMass
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Vector< scalar > vector
Definition: vector.H:57
label singleStepDOFs
void reduce(const List< UPstream::commsStruct > &comms, T &value, const BinaryOp &bop, const int tag, const label comm)
Reduce inplace (cf. MPI Allreduce) using specified communication schedule.
messageStream Info
Information stream (stdout output on master, null elsewhere)
scalar singleStepMaxVelocityMag
scalar singleStepTotalLinearKE
vector singleStepTotalLinearMomentum(Zero)
scalar singleStepTotalPE
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
scalar singleStepTotalAngularKE
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:133