multiComponentMixture.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2020 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 "multiComponentMixture.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class ThermoType>
33 (
34  const dictionary& thermoDict
35 ) const
36 {
37  PtrList<ThermoType> specieThermos(species_.size());
38 
39  forAll(species_, i)
40  {
41  specieThermos.set
42  (
43  i,
44  new ThermoType(thermoDict.subDict(species_[i]))
45  );
46  }
47 
48  return specieThermos;
49 }
50 
51 
52 template<class ThermoType>
55 (
56  const dictionary& thermoDict,
57  const speciesTable& species
58 ) const
59 {
60  speciesCompositionTable speciesComposition_;
61 
62  // Loop through all species in thermoDict to retrieve
63  // the species composition
64  forAll(species, si)
65  {
66  if (thermoDict.subDict(species[si]).isDict("elements"))
67  {
68  dictionary currentElements
69  (
70  thermoDict.subDict(species[si]).subDict("elements")
71  );
72 
73  wordList currentElementsName(currentElements.toc());
74  List<specieElement> currentComposition(currentElementsName.size());
75 
76  forAll(currentElementsName, eni)
77  {
78  currentComposition[eni].name() = currentElementsName[eni];
79 
80  currentComposition[eni].nAtoms() =
81  currentElements.lookupOrDefault
82  (
83  currentElementsName[eni],
84  0
85  );
86  }
87 
88  // Add current specie composition to the hash table
89  speciesCompositionTable::iterator specieCompositionIter
90  (
91  speciesComposition_.find(species[si])
92  );
93 
94  if (specieCompositionIter != speciesComposition_.end())
95  {
96  speciesComposition_.erase(specieCompositionIter);
97  }
98 
99  speciesComposition_.insert(species[si], currentComposition);
100  }
101  }
102 
103  return speciesComposition_;
104 }
105 
106 
107 template<class ThermoType>
109 {
110  // Multiplication by 1.0 changes Yt patches to "calculated"
111  volScalarField Yt("Yt", 1.0*Y_[0]);
112 
113  for (label n=1; n<Y_.size(); n++)
114  {
115  Yt += Y_[n];
116  }
117 
118  if (mag(max(Yt).value()) < rootVSmall)
119  {
121  << "Sum of mass fractions is zero for species " << this->species()
122  << exit(FatalError);
123  }
124 
125  forAll(Y_, n)
126  {
127  Y_[n] /= Yt;
128  }
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
134 template<class ThermoType>
136 (
137  const dictionary& thermoDict,
138  const fvMesh& mesh,
139  const word& phaseName
140 )
141 :
143  (
144  thermoDict,
145  thermoDict.lookup("species"),
146  mesh,
147  phaseName
148  ),
149  specieThermos_(readSpeciesData(thermoDict)),
150  speciesComposition_(readSpeciesComposition(thermoDict, species())),
151  mixture_("mixture", specieThermos_[0]),
152  mixtureVol_("volMixture", specieThermos_[0])
153 {
154  correctMassFractions();
155 }
156 
157 
158 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
159 
160 template<class ThermoType>
162 (
163  const label celli
164 ) const
165 {
166  mixture_ = Y_[0][celli]*specieThermos_[0];
167 
168  for (label n=1; n<Y_.size(); n++)
169  {
170  mixture_ += Y_[n][celli]*specieThermos_[n];
171  }
172 
173  return mixture_;
174 }
175 
176 
177 template<class ThermoType>
179 (
180  const label patchi,
181  const label facei
182 ) const
183 {
184  mixture_ = Y_[0].boundaryField()[patchi][facei]*specieThermos_[0];
185 
186  for (label n=1; n<Y_.size(); n++)
187  {
188  mixture_ += Y_[n].boundaryField()[patchi][facei]*specieThermos_[n];
189  }
190 
191  return mixture_;
192 }
193 
194 
195 template<class ThermoType>
197 (
198  const scalar p,
199  const scalar T,
200  const label celli
201 ) const
202 {
203  scalar rhoInv = 0.0;
204  forAll(specieThermos_, i)
205  {
206  rhoInv += Y_[i][celli]/specieThermos_[i].rho(p, T);
207  }
208 
209  mixtureVol_ =
210  Y_[0][celli]/specieThermos_[0].rho(p, T)/rhoInv*specieThermos_[0];
211 
212  for (label n=1; n<Y_.size(); n++)
213  {
214  mixtureVol_ +=
215  Y_[n][celli]/specieThermos_[n].rho(p, T)/rhoInv*specieThermos_[n];
216  }
217 
218  return mixtureVol_;
219 }
220 
221 
222 template<class ThermoType>
225 (
226  const scalar p,
227  const scalar T,
228  const label patchi,
229  const label facei
230 ) const
231 {
232  scalar rhoInv = 0.0;
233  forAll(specieThermos_, i)
234  {
235  rhoInv +=
236  Y_[i].boundaryField()[patchi][facei]/specieThermos_[i].rho(p, T);
237  }
238 
239  mixtureVol_ =
240  Y_[0].boundaryField()[patchi][facei]/specieThermos_[0].rho(p, T)/rhoInv
241  * specieThermos_[0];
242 
243  for (label n=1; n<Y_.size(); n++)
244  {
245  mixtureVol_ +=
246  Y_[n].boundaryField()[patchi][facei]/specieThermos_[n].rho(p,T)
247  / rhoInv*specieThermos_[n];
248  }
249 
250  return mixtureVol_;
251 }
252 
253 
254 template<class ThermoType>
256 (
257  const dictionary& thermoDict
258 )
259 {
260  forAll(species_, i)
261  {
262  specieThermos_[i] = ThermoType(thermoDict.subDict(species_[i]));
263  }
264 }
265 
266 
267 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Specialization of basicMixture for a mixture consisting of a number for molecular species...
hashedWordList speciesTable
A table of species as a hashedWordList.
Definition: speciesTable.H:41
const ThermoType & patchFaceVolMixture(const scalar p, const scalar T, const label patchi, const label facei) const
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:934
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
dynamicFvMesh & mesh
A class for handling words, derived from string.
Definition: word.H:59
const ThermoType & patchFaceMixture(const label patchi, const label facei) const
Foam::multiComponentMixture.
HashTable< List< specieElement > > speciesCompositionTable
Definition: chemkinReader.H:65
List< word > wordList
A List of words.
Definition: fileName.H:54
label patchi
const ThermoType & cellMixture(const label celli) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
multiComponentMixture(const dictionary &, const fvMesh &, const word &)
Construct from dictionary, mesh and phase name.
dimensioned< scalar > mag(const dimensioned< Type > &)
label n
const ThermoType & cellVolMixture(const scalar p, const scalar T, const label celli) const
void read(const dictionary &)
Read dictionary.
volScalarField Yt(0.0 *Y[0])
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:812