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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "multiComponentMixture.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class ThermoType>
34 (
35  const dictionary& thermoDict
36 )
37 {
38  forAll(species_, i)
39  {
40  speciesData_.set
41  (
42  i,
43  new ThermoType(thermoDict.subDict(species_[i]))
44  );
45  }
46 
47  return speciesData_[0];
48 }
49 
50 
51 template<class ThermoType>
53 {
54  // Multiplication by 1.0 changes Yt patches to "calculated"
55  volScalarField Yt("Yt", 1.0*Y_[0]);
56 
57  for (label n=1; n<Y_.size(); n++)
58  {
59  Yt += Y_[n];
60  }
61 
62  if (mag(max(Yt).value()) < ROOTVSMALL)
63  {
65  << "Sum of mass fractions is zero for species " << this->species()
66  << exit(FatalError);
67  }
68 
69  forAll(Y_, n)
70  {
71  Y_[n] /= Yt;
72  }
73 }
74 
75 
76 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
77 
78 template<class ThermoType>
80 (
81  const dictionary& thermoDict,
82  const wordList& specieNames,
83  const HashPtrTable<ThermoType>& thermoData,
84  const fvMesh& mesh,
85  const word& phaseName
86 )
87 :
88  basicSpecieMixture(thermoDict, specieNames, mesh, phaseName),
89  speciesData_(species_.size()),
90  mixture_("mixture", *thermoData[specieNames[0]]),
91  mixtureVol_("volMixture", *thermoData[specieNames[0]])
92 {
93  forAll(species_, i)
94  {
95  speciesData_.set
96  (
97  i,
98  new ThermoType(*thermoData[species_[i]])
99  );
100  }
101 
102  correctMassFractions();
103 }
104 
105 
106 template<class ThermoType>
108 (
109  const dictionary& thermoDict,
110  const fvMesh& mesh,
111  const word& phaseName
112 )
113 :
115  (
116  thermoDict,
117  thermoDict.lookup("species"),
118  mesh,
119  phaseName
120  ),
121  speciesData_(species_.size()),
122  mixture_("mixture", constructSpeciesData(thermoDict)),
123  mixtureVol_("volMixture", speciesData_[0])
124 {
125  correctMassFractions();
126 }
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
131 template<class ThermoType>
133 (
134  const label celli
135 ) const
136 {
137  mixture_ = Y_[0][celli]*speciesData_[0];
138 
139  for (label n=1; n<Y_.size(); n++)
140  {
141  mixture_ += Y_[n][celli]*speciesData_[n];
142  }
143 
144  return mixture_;
145 }
146 
147 
148 template<class ThermoType>
150 (
151  const label patchi,
152  const label facei
153 ) const
154 {
155  mixture_ = Y_[0].boundaryField()[patchi][facei]*speciesData_[0];
156 
157  for (label n=1; n<Y_.size(); n++)
158  {
159  mixture_ += Y_[n].boundaryField()[patchi][facei]*speciesData_[n];
160  }
161 
162  return mixture_;
163 }
164 
165 
166 template<class ThermoType>
168 (
169  const scalar p,
170  const scalar T,
171  const label celli
172 ) const
173 {
174  scalar rhoInv = 0.0;
175  forAll(speciesData_, i)
176  {
177  rhoInv += Y_[i][celli]/speciesData_[i].rho(p, T);
178  }
179 
180  mixtureVol_ =
181  Y_[0][celli]/speciesData_[0].rho(p, T)/rhoInv*speciesData_[0];
182 
183  for (label n=1; n<Y_.size(); n++)
184  {
185  mixtureVol_ +=
186  Y_[n][celli]/speciesData_[n].rho(p, T)/rhoInv*speciesData_[n];
187  }
188 
189  return mixtureVol_;
190 }
191 
192 
193 template<class ThermoType>
196 (
197  const scalar p,
198  const scalar T,
199  const label patchi,
200  const label facei
201 ) const
202 {
203  scalar rhoInv = 0.0;
204  forAll(speciesData_, i)
205  {
206  rhoInv +=
207  Y_[i].boundaryField()[patchi][facei]/speciesData_[i].rho(p, T);
208  }
209 
210  mixtureVol_ =
211  Y_[0].boundaryField()[patchi][facei]/speciesData_[0].rho(p, T)/rhoInv
212  * speciesData_[0];
213 
214  for (label n=1; n<Y_.size(); n++)
215  {
216  mixtureVol_ +=
217  Y_[n].boundaryField()[patchi][facei]/speciesData_[n].rho(p,T)
218  / rhoInv*speciesData_[n];
219  }
220 
221  return mixtureVol_;
222 }
223 
224 
225 template<class ThermoType>
227 (
228  const dictionary& thermoDict
229 )
230 {
231  forAll(species_, i)
232  {
233  speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
234  }
235 }
236 
237 
238 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::multiComponentMixture::read
void read(const dictionary &)
Read dictionary.
Definition: multiComponentMixture.C:227
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::basicSpecieMixture
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
Definition: basicSpecieMixture.H:58
Foam::multiComponentMixture::patchFaceVolMixture
const ThermoType & patchFaceVolMixture(const scalar p, const scalar T, const label patchi, const label facei) const
Definition: multiComponentMixture.C:196
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
n
label n
Definition: TABSMDCalcMethod2.H:31
Yt
volScalarField Yt(0.0 *Y[0])
Foam::multiComponentMixture
Foam::multiComponentMixture.
Definition: InterfaceCompositionModel.H:51
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::multiComponentMixture::patchFaceMixture
const ThermoType & patchFaceMixture(const label patchi, const label facei) const
Definition: multiComponentMixture.C:150
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:83
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::multiComponentMixture::cellMixture
const ThermoType & cellMixture(const label celli) const
Definition: multiComponentMixture.C:133
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::HashPtrTable< ThermoType >
Foam::List< word >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
multiComponentMixture.H
Foam::multiComponentMixture::cellVolMixture
const ThermoType & cellVolMixture(const scalar p, const scalar T, const label celli) const
Definition: multiComponentMixture.C:168