FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 Global
00025     meanMomentumEnergyAndNMols.H
00026 
00027 Description
00028     Calculates and prints the mean momentum and energy in the system
00029     and the number of molecules.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 
00034 vector singleStepTotalLinearMomentum(vector::zero);
00035 
00036 vector singleStepTotalAngularMomentum(vector::zero);
00037 
00038 scalar singleStepMaxVelocityMag = 0.0;
00039 
00040 scalar singleStepTotalMass = 0.0;
00041 
00042 scalar singleStepTotalLinearKE = 0.0;
00043 
00044 scalar singleStepTotalAngularKE = 0.0;
00045 
00046 scalar singleStepTotalPE = 0.0;
00047 
00048 scalar singleStepTotalrDotf = 0.0;
00049 
00050 //vector singleStepCentreOfMass(vector::zero);
00051 
00052 label singleStepNMols = molecules.size();
00053 
00054 label singleStepDOFs = 0;
00055 
00056 {
00057     IDLList<molecule>::iterator mol(molecules.begin());
00058 
00059     for
00060     (
00061         mol = molecules.begin();
00062         mol != molecules.end();
00063         ++mol
00064     )
00065     {
00066         label molId = mol().id();
00067 
00068         scalar molMass(molecules.constProps(molId).mass());
00069 
00070         singleStepTotalMass += molMass;
00071 
00072         //singleStepCentreOfMass += mol().position()*molMass;
00073     }
00074 
00075     // if(singleStepNMols)
00076     // {
00077     //     singleStepCentreOfMass /= singleStepTotalMass;
00078     // }
00079 
00080     for
00081     (
00082         mol = molecules.begin();
00083         mol != molecules.end();
00084         ++mol
00085     )
00086     {
00087         label molId = mol().id();
00088 
00089         const molecule::constantProperties cP(molecules.constProps(molId));
00090 
00091         scalar molMass(cP.mass());
00092 
00093         const diagTensor& molMoI(cP.momentOfInertia());
00094 
00095         const vector& molV(mol().v());
00096 
00097         const vector& molOmega(inv(molMoI) & mol().pi());
00098 
00099         vector molPiGlobal = mol().Q() & mol().pi();
00100 
00101         singleStepTotalLinearMomentum += molV * molMass;
00102 
00103         singleStepTotalAngularMomentum += molPiGlobal;
00104         //+((mol().position() - singleStepCentreOfMass) ^ (molV * molMass));
00105 
00106         if(mag(molV) > singleStepMaxVelocityMag)
00107         {
00108             singleStepMaxVelocityMag = mag(molV);
00109         }
00110 
00111         singleStepTotalLinearKE += 0.5*molMass*magSqr(molV);
00112 
00113         singleStepTotalAngularKE += 0.5*(molOmega & molMoI & molOmega);
00114 
00115         singleStepTotalPE += mol().potentialEnergy();
00116 
00117         singleStepTotalrDotf += tr(mol().rf());
00118 
00119         singleStepDOFs += cP.degreesOfFreedom();
00120     }
00121 }
00122 
00123 if (Pstream::parRun())
00124 {
00125     reduce(singleStepTotalLinearMomentum, sumOp<vector>());
00126 
00127     reduce(singleStepTotalAngularMomentum, sumOp<vector>());
00128 
00129     reduce(singleStepMaxVelocityMag, maxOp<scalar>());
00130 
00131     reduce(singleStepTotalMass, sumOp<scalar>());
00132 
00133     reduce(singleStepTotalLinearKE, sumOp<scalar>());
00134 
00135     reduce(singleStepTotalAngularKE, sumOp<scalar>());
00136 
00137     reduce(singleStepTotalPE, sumOp<scalar>());
00138 
00139     reduce(singleStepTotalrDotf, sumOp<scalar>());
00140 
00141     reduce(singleStepNMols, sumOp<label>());
00142 
00143     reduce(singleStepDOFs, sumOp<label>());
00144 }
00145 
00146 if (singleStepNMols)
00147 {
00148     Info<< "Number of molecules in system = "
00149         << singleStepNMols << nl
00150         << "Overall number density = "
00151         << singleStepNMols/meshVolume << nl
00152         << "Overall mass density = "
00153         << singleStepTotalMass/meshVolume << nl
00154         << "Average linear momentum per molecule = "
00155         << singleStepTotalLinearMomentum/singleStepNMols << ' '
00156         << mag(singleStepTotalLinearMomentum)/singleStepNMols << nl
00157         << "Average angular momentum per molecule = "
00158         << singleStepTotalAngularMomentum << ' '
00159         << mag(singleStepTotalAngularMomentum)/singleStepNMols << nl
00160         << "Maximum |velocity| = "
00161         << singleStepMaxVelocityMag << nl
00162         << "Average linear KE per molecule = "
00163         << singleStepTotalLinearKE/singleStepNMols << nl
00164         << "Average angular KE per molecule = "
00165         << singleStepTotalAngularKE/singleStepNMols << nl
00166         << "Average PE per molecule = "
00167         << singleStepTotalPE/singleStepNMols << nl
00168         << "Average TE per molecule = "
00169         <<
00170         (
00171             singleStepTotalLinearKE
00172           + singleStepTotalAngularKE
00173           + singleStepTotalPE
00174         )
00175         /singleStepNMols
00176         << endl;
00177 
00178         // Info << singleStepNMols << " "
00179         //     << singleStepTotalMomentum/singleStepTotalMass << " "
00180         //     << singleStepMaxVelocityMag << " "
00181         //     << singleStepTotalKE/singleStepNMols << " "
00182         //     << singleStepTotalPE/singleStepNMols << " "
00183         //     << (singleStepTotalKE + singleStepTotalPE)
00184         //        /singleStepNMols << endl;
00185 }
00186 else
00187 {
00188     Info<< "No molecules in system" << endl;
00189 }
00190 
00191 
00192 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines