multiComponentMixture.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) 2011-2015 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>
32 (
33  const dictionary& thermoDict
34 )
35 {
36  forAll(species_, i)
37  {
38  speciesData_.set
39  (
40  i,
41  new ThermoType(thermoDict.subDict(species_[i]))
42  );
43  }
44 
45  return speciesData_[0];
46 }
47 
48 
49 template<class ThermoType>
51 {
52  // Multiplication by 1.0 changes Yt patches to "calculated"
53  volScalarField Yt("Yt", 1.0*Y_[0]);
54 
55  for (label n=1; n<Y_.size(); n++)
56  {
57  Yt += Y_[n];
58  }
59 
60  if (mag(max(Yt).value()) < ROOTVSMALL)
61  {
63  (
64  "void Foam::multiComponentMixture<ThermoType>::"
65  "correctMassFractions()"
66  )
67  << "Sum of mass fractions is zero for species " << this->species()
68  << exit(FatalError);
69  }
70 
71  forAll(Y_, n)
72  {
73  Y_[n] /= Yt;
74  }
75 }
76 
77 
78 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
79 
80 template<class ThermoType>
82 (
83  const dictionary& thermoDict,
84  const wordList& specieNames,
85  const HashPtrTable<ThermoType>& thermoData,
86  const fvMesh& mesh,
87  const word& phaseName
88 )
89 :
90  basicSpecieMixture(thermoDict, specieNames, mesh, phaseName),
91  speciesData_(species_.size()),
92  mixture_("mixture", *thermoData[specieNames[0]]),
93  mixtureVol_("volMixture", *thermoData[specieNames[0]])
94 {
95  forAll(species_, i)
96  {
97  speciesData_.set
98  (
99  i,
100  new ThermoType(*thermoData[species_[i]])
101  );
102  }
103 
104  correctMassFractions();
105 }
106 
107 
108 template<class ThermoType>
110 (
111  const dictionary& thermoDict,
112  const fvMesh& mesh,
113  const word& phaseName
114 )
115 :
117  (
118  thermoDict,
119  thermoDict.lookup("species"),
120  mesh,
121  phaseName
122  ),
123  speciesData_(species_.size()),
124  mixture_("mixture", constructSpeciesData(thermoDict)),
125  mixtureVol_("volMixture", speciesData_[0])
126 {
127  correctMassFractions();
128 }
129 
130 
131 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 
133 template<class ThermoType>
135 (
136  const label celli
137 ) const
138 {
139  mixture_ = Y_[0][celli]/speciesData_[0].W()*speciesData_[0];
140 
141  for (label n=1; n<Y_.size(); n++)
142  {
143  mixture_ += Y_[n][celli]/speciesData_[n].W()*speciesData_[n];
144  }
145 
146  return mixture_;
147 }
148 
149 
150 template<class ThermoType>
152 (
153  const label patchi,
154  const label facei
155 ) const
156 {
157  mixture_ =
158  Y_[0].boundaryField()[patchi][facei]
159  /speciesData_[0].W()*speciesData_[0];
160 
161  for (label n=1; n<Y_.size(); n++)
162  {
163  mixture_ +=
164  Y_[n].boundaryField()[patchi][facei]
165  /speciesData_[n].W()*speciesData_[n];
166  }
167 
168  return mixture_;
169 }
170 
171 
172 template<class ThermoType>
174 (
175  const scalar p,
176  const scalar T,
177  const label celli
178 ) const
179 {
180  scalar rhoInv = 0.0;
181  forAll(speciesData_, i)
182  {
183  rhoInv += Y_[i][celli]/speciesData_[i].rho(p, T);
184  }
185 
186  mixtureVol_ =
187  Y_[0][celli]/speciesData_[0].rho(p, T)/rhoInv*speciesData_[0];
188 
189  for (label n=1; n<Y_.size(); n++)
190  {
191  mixtureVol_ +=
192  Y_[n][celli]/speciesData_[n].rho(p, T)/rhoInv*speciesData_[n];
193  }
194 
195  return mixtureVol_;
196 }
197 
198 
199 template<class ThermoType>
202 (
203  const scalar p,
204  const scalar T,
205  const label patchi,
206  const label facei
207 ) const
208 {
209  scalar rhoInv = 0.0;
210  forAll(speciesData_, i)
211  {
212  rhoInv +=
213  Y_[i].boundaryField()[patchi][facei]/speciesData_[i].rho(p, T);
214  }
215 
216  mixtureVol_ =
217  Y_[0].boundaryField()[patchi][facei]/speciesData_[0].rho(p, T)/rhoInv
218  * speciesData_[0];
219 
220  for (label n=1; n<Y_.size(); n++)
221  {
222  mixtureVol_ +=
223  Y_[n].boundaryField()[patchi][facei]/speciesData_[n].rho(p,T)
224  / rhoInv*speciesData_[n];
225  }
226 
227  return mixtureVol_;
228 }
229 
230 
231 template<class ThermoType>
233 (
234  const dictionary& thermoDict
235 )
236 {
237  forAll(species_, i)
238  {
239  speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
240  }
241 }
242 
243 
244 // ************************************************************************* //
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
dimensioned< scalar > mag(const dimensioned< Type > &)
const ThermoType & cellVolMixture(const scalar p, const scalar T, const label celli) const
volScalarField Yt(0.0 *Y[0])
A class for handling words, derived from string.
Definition: word.H:59
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
const ThermoType & cellMixture(const label celli) const
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
const ThermoType & patchFaceVolMixture(const scalar p, const scalar T, const label patchi, const label facei) const
const ThermoType & patchFaceMixture(const label patchi, const label facei) const
label n
void read(const dictionary &)
Read dictionary.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define forAll(list, i)
Definition: UList.H:421
label patchi
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Foam::multiComponentMixture.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...