OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

meanMomentumEnergyAndNMols.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2008-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Global
00026     meanMomentumEnergyAndNMols.H
00027 
00028 Description
00029     Calculates and prints the mean momentum and energy in the system
00030     and the number of molecules.
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 
00035 vector singleStepTotalLinearMomentum(vector::zero);
00036 
00037 vector singleStepTotalAngularMomentum(vector::zero);
00038 
00039 scalar singleStepMaxVelocityMag = 0.0;
00040 
00041 scalar singleStepTotalMass = 0.0;
00042 
00043 scalar singleStepTotalLinearKE = 0.0;
00044 
00045 scalar singleStepTotalAngularKE = 0.0;
00046 
00047 scalar singleStepTotalPE = 0.0;
00048 
00049 scalar singleStepTotalrDotf = 0.0;
00050 
00051 //vector singleStepCentreOfMass(vector::zero);
00052 
00053 label singleStepNMols = molecules.size();
00054 
00055 label singleStepDOFs = 0;
00056 
00057 {
00058     IDLList<molecule>::iterator mol(molecules.begin());
00059 
00060     for
00061     (
00062         mol = molecules.begin();
00063         mol != molecules.end();
00064         ++mol
00065     )
00066     {
00067         label molId = mol().id();
00068 
00069         scalar molMass(molecules.constProps(molId).mass());
00070 
00071         singleStepTotalMass += molMass;
00072 
00073         //singleStepCentreOfMass += mol().position()*molMass;
00074     }
00075 
00076     // if(singleStepNMols)
00077     // {
00078     //     singleStepCentreOfMass /= singleStepTotalMass;
00079     // }
00080 
00081     for
00082     (
00083         mol = molecules.begin();
00084         mol != molecules.end();
00085         ++mol
00086     )
00087     {
00088         label molId = mol().id();
00089 
00090         const molecule::constantProperties cP(molecules.constProps(molId));
00091 
00092         scalar molMass(cP.mass());
00093 
00094         const diagTensor& molMoI(cP.momentOfInertia());
00095 
00096         const vector& molV(mol().v());
00097 
00098         const vector& molOmega(inv(molMoI) & mol().pi());
00099 
00100         vector molPiGlobal = mol().Q() & mol().pi();
00101 
00102         singleStepTotalLinearMomentum += molV * molMass;
00103 
00104         singleStepTotalAngularMomentum += molPiGlobal;
00105         //+((mol().position() - singleStepCentreOfMass) ^ (molV * molMass));
00106 
00107         if(mag(molV) > singleStepMaxVelocityMag)
00108         {
00109             singleStepMaxVelocityMag = mag(molV);
00110         }
00111 
00112         singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
00113 
00114         singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
00115 
00116         singleStepTotalPE += mol().potentialEnergy();
00117 
00118         singleStepTotalrDotf += tr(mol().rf());
00119 
00120         singleStepDOFs += cP.degreesOfFreedom();
00121     }
00122 }
00123 
00124 if (Pstream::parRun())
00125 {
00126     reduce(singleStepTotalLinearMomentum, sumOp<vector>());
00127 
00128     reduce(singleStepTotalAngularMomentum, sumOp<vector>());
00129 
00130     reduce(singleStepMaxVelocityMag, maxOp<scalar>());
00131 
00132     reduce(singleStepTotalMass, sumOp<scalar>());
00133 
00134     reduce(singleStepTotalLinearKE, sumOp<scalar>());
00135 
00136     reduce(singleStepTotalAngularKE, sumOp<scalar>());
00137 
00138     reduce(singleStepTotalPE, sumOp<scalar>());
00139 
00140     reduce(singleStepTotalrDotf, sumOp<scalar>());
00141 
00142     reduce(singleStepNMols, sumOp<label>());
00143 
00144     reduce(singleStepDOFs, sumOp<label>());
00145 }
00146 
00147 if (singleStepNMols)
00148 {
00149     Info<< "Number of molecules in system = "
00150         << singleStepNMols << nl
00151         << "Overall number density = "
00152         << singleStepNMols/meshVolume << nl
00153         << "Overall mass density = "
00154         << singleStepTotalMass/meshVolume << nl
00155         << "Average linear momentum per molecule = "
00156         << singleStepTotalLinearMomentum/singleStepNMols << ' '
00157         << mag(singleStepTotalLinearMomentum)/singleStepNMols << nl
00158         << "Average angular momentum per molecule = "
00159         << singleStepTotalAngularMomentum << ' '
00160         << mag(singleStepTotalAngularMomentum)/singleStepNMols << nl
00161         << "Maximum |velocity| = "
00162         << singleStepMaxVelocityMag << nl
00163         << "Average linear KE per molecule = "
00164         << singleStepTotalLinearKE/singleStepNMols << nl
00165         << "Average angular KE per molecule = "
00166         << singleStepTotalAngularKE/singleStepNMols << nl
00167         << "Average PE per molecule = "
00168         << singleStepTotalPE/singleStepNMols << nl
00169         << "Average TE per molecule = "
00170         <<
00171         (
00172             singleStepTotalLinearKE
00173           + singleStepTotalAngularKE
00174           + singleStepTotalPE
00175         )
00176         /singleStepNMols
00177         << endl;
00178 
00179         // Info << singleStepNMols << " "
00180         //     << singleStepTotalMomentum/singleStepTotalMass << " "
00181         //     << singleStepMaxVelocityMag << " "
00182         //     << singleStepTotalKE/singleStepNMols << " "
00183         //     << singleStepTotalPE/singleStepNMols << " "
00184         //     << (singleStepTotalKE + singleStepTotalPE)
00185         //        /singleStepNMols << endl;
00186 }
00187 else
00188 {
00189     Info<< "No molecules in system" << endl;
00190 }
00191 
00192 
00193 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd