moleFractions.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "moleFractions.H"
27 #include "basicThermo.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class ThermoType>
33 {
34  const ThermoType& thermo =
35  mesh_.lookupObject<ThermoType>(basicThermo::dictName);
36 
37  const PtrList<volScalarField>& Y = thermo.composition().Y();
38 
39  const volScalarField W(thermo.composition().W());
40 
41  forAll(Y, i)
42  {
43  X_[i] = W*Y[i]/thermo.composition().W(i);
44  }
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 template<class ThermoType>
52 (
53  const word& name,
54  const Time& runTime,
55  const dictionary& dict
56 )
57 :
58  fvMeshFunctionObject(name, runTime, dict)
59 {
60  if (mesh_.foundObject<ThermoType>(basicThermo::dictName))
61  {
62  const ThermoType& thermo =
63  mesh_.lookupObject<ThermoType>(basicThermo::dictName);
64 
65  const PtrList<volScalarField>& Y = thermo.composition().Y();
66 
67  X_.setSize(Y.size());
68 
69  forAll(Y, i)
70  {
71  X_.set
72  (
73  i,
74  new volScalarField
75  (
76  IOobject
77  (
78  "X_" + Y[i].name(),
79  mesh_.time().timeName(),
80  mesh_,
81  IOobject::NO_READ,
82  IOobject::AUTO_WRITE
83  ),
84  mesh_,
85  dimensionedScalar("X", dimless, 0)
86  )
87  );
88  }
89 
90  calculateMoleFractions();
91  }
92  else
93  {
95  << "Cannot find thermodynamics model of type "
96  << ThermoType::typeName
97  << exit(FatalError);
98  }
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
103 
104 template<class ThermoType>
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class ThermoType>
113 (
114  const dictionary& dict
115 )
116 {
117  return true;
118 }
119 
120 
121 template<class ThermoType>
123 {
124  calculateMoleFractions();
125  return true;
126 }
127 
128 
129 template<class ThermoType>
131 {
132  return true;
133 }
134 
135 
136 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual ~moleFractions()
Destructor.
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
const ObjectType & lookupObject(const word &fieldName) const
Lookup object from the objectRegistry.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
A class for handling words, derived from string.
Definition: word.H:59
virtual bool write()
The mole-fraction fields auto-write.
const word dictName("particleTrackDict")
This function object calculates mole-fraction fields from the mass-fraction fields of the psi/rhoReac...
Definition: moleFractions.H:74
void setSize(const label)
Reset size of PtrList. If extending the PtrList, new entries are.
Definition: PtrList.C:131
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
virtual bool execute()
Calculate the mole-fraction fields.
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual bool read(const dictionary &)
Read the moleFractions data.