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-2018 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  << "Sum of mass fractions is zero for species " << this->species()
64  << exit(FatalError);
65  }
66 
67  forAll(Y_, n)
68  {
69  Y_[n] /= Yt;
70  }
71 }
72 
73 
74 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
75 
76 template<class ThermoType>
78 (
79  const dictionary& thermoDict,
80  const wordList& specieNames,
81  const HashPtrTable<ThermoType>& thermoData,
82  const fvMesh& mesh,
83  const word& phaseName
84 )
85 :
86  basicSpecieMixture(thermoDict, specieNames, mesh, phaseName),
87  speciesData_(species_.size()),
88  mixture_("mixture", *thermoData[specieNames[0]]),
89  mixtureVol_("volMixture", *thermoData[specieNames[0]])
90 {
91  forAll(species_, i)
92  {
93  speciesData_.set
94  (
95  i,
96  new ThermoType(*thermoData[species_[i]])
97  );
98  }
99 
100  correctMassFractions();
101 }
102 
103 
104 template<class ThermoType>
106 (
107  const dictionary& thermoDict,
108  const fvMesh& mesh,
109  const word& phaseName
110 )
111 :
113  (
114  thermoDict,
115  thermoDict.lookup("species"),
116  mesh,
117  phaseName
118  ),
119  speciesData_(species_.size()),
120  mixture_("mixture", constructSpeciesData(thermoDict)),
121  mixtureVol_("volMixture", speciesData_[0])
122 {
123  correctMassFractions();
124 }
125 
126 
127 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
128 
129 template<class ThermoType>
131 (
132  const label celli
133 ) const
134 {
135  mixture_ = Y_[0][celli]*speciesData_[0];
136 
137  for (label n=1; n<Y_.size(); n++)
138  {
139  mixture_ += Y_[n][celli]*speciesData_[n];
140  }
141 
142  return mixture_;
143 }
144 
145 
146 template<class ThermoType>
148 (
149  const label patchi,
150  const label facei
151 ) const
152 {
153  mixture_ = Y_[0].boundaryField()[patchi][facei]*speciesData_[0];
154 
155  for (label n=1; n<Y_.size(); n++)
156  {
157  mixture_ += Y_[n].boundaryField()[patchi][facei]*speciesData_[n];
158  }
159 
160  return mixture_;
161 }
162 
163 
164 template<class ThermoType>
166 (
167  const scalar p,
168  const scalar T,
169  const label celli
170 ) const
171 {
172  scalar rhoInv = 0.0;
173  forAll(speciesData_, i)
174  {
175  rhoInv += Y_[i][celli]/speciesData_[i].rho(p, T);
176  }
177 
178  mixtureVol_ =
179  Y_[0][celli]/speciesData_[0].rho(p, T)/rhoInv*speciesData_[0];
180 
181  for (label n=1; n<Y_.size(); n++)
182  {
183  mixtureVol_ +=
184  Y_[n][celli]/speciesData_[n].rho(p, T)/rhoInv*speciesData_[n];
185  }
186 
187  return mixtureVol_;
188 }
189 
190 
191 template<class ThermoType>
194 (
195  const scalar p,
196  const scalar T,
197  const label patchi,
198  const label facei
199 ) const
200 {
201  scalar rhoInv = 0.0;
202  forAll(speciesData_, i)
203  {
204  rhoInv +=
205  Y_[i].boundaryField()[patchi][facei]/speciesData_[i].rho(p, T);
206  }
207 
208  mixtureVol_ =
209  Y_[0].boundaryField()[patchi][facei]/speciesData_[0].rho(p, T)/rhoInv
210  * speciesData_[0];
211 
212  for (label n=1; n<Y_.size(); n++)
213  {
214  mixtureVol_ +=
215  Y_[n].boundaryField()[patchi][facei]/speciesData_[n].rho(p,T)
216  / rhoInv*speciesData_[n];
217  }
218 
219  return mixtureVol_;
220 }
221 
222 
223 template<class ThermoType>
225 (
226  const dictionary& thermoDict
227 )
228 {
229  forAll(species_, i)
230  {
231  speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
232  }
233 }
234 
235 
236 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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:137
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
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:692
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
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.
label patchi
const ThermoType & cellMixture(const label celli) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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:576