ENH: autoLayerDriver: better layering information message
[OpenFOAM-2.0.x.git] / src / lagrangian / molecularDynamics / molecule / mdTools / meanMomentumEnergyAndNMols.H
blobae117cafc5709dea2c18d46f8f94edb110d0637d
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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/>.
24 Global
25     meanMomentumEnergyAndNMols.H
27 Description
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)
58     {
59         const label molId = mol().id();
61         scalar molMass(molecules.constProps(molId).mass());
63         singleStepTotalMass += molMass;
65         //singleStepCentreOfMass += mol().position()*molMass;
66     }
68     // if (singleStepNMols)
69     // {
70     //     singleStepCentreOfMass /= singleStepTotalMass;
71     // }
73     forAllConstIter(IDLList<molecule>, molecules, mol)
74     {
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)
95         {
96             singleStepMaxVelocityMag = mag(molV);
97         }
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();
108     }
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>());
134 if (singleStepNMols)
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 = "
157         <<
158         (
159             singleStepTotalLinearKE
160           + singleStepTotalAngularKE
161           + singleStepTotalPE
162         )
163         /singleStepNMols
164         << endl;
166         // Info<< singleStepNMols << " "
167         //     << singleStepTotalMomentum/singleStepTotalMass << " "
168         //     << singleStepMaxVelocityMag << " "
169         //     << singleStepTotalKE/singleStepNMols << " "
170         //     << singleStepTotalPE/singleStepNMols << " "
171         //     << (singleStepTotalKE + singleStepTotalPE)
172         //        /singleStepNMols << endl;
174 else
176     Info<< "No molecules in system" << endl;
180 // ************************************************************************* //