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  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "multiComponentMixture.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 template<class ThermoType>
35 (
36  const dictionary& thermoDict
37 )
38 {
39  forAll(species_, i)
40  {
41  speciesData_.set
42  (
43  i,
44  new ThermoType(thermoDict.subDict(species_[i]))
45  );
46  }
47 
48  return speciesData_[0];
49 }
50 
51 
52 template<class ThermoType>
54 {
55  // Multiplication by 1.0 changes Yt patches to "calculated"
56  volScalarField Yt("Yt", 1.0*Y_[0]);
57 
58  for (label n=1; n<Y_.size(); n++)
59  {
60  Yt += Y_[n];
61  }
62 
63  if (mag(min(Yt).value()) < ROOTVSMALL)
64  {
66  << "Sum of mass fractions is zero for species " << this->species()
67  << exit(FatalError);
68  }
69 
70  if (mag(max(Yt).value()) != scalar(1))
71  {
73  << "Sum of mass fractions is different from one for species "
74  << this->species()
75  << nl;
76  }
77 
78  forAll(Y_, n)
79  {
80  Y_[n] /= Yt;
81  }
82 }
83 
84 
85 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
86 
87 template<class ThermoType>
89 (
90  const dictionary& thermoDict,
91  const wordList& specieNames,
92  const ReactionTable<ThermoType>& thermoData,
93  const fvMesh& mesh,
94  const word& phaseName
95 )
96 :
97  basicSpecieMixture(thermoDict, specieNames, mesh, phaseName),
98  speciesData_(species_.size()),
99  mixture_("mixture", *thermoData[specieNames[0]]),
100  mixtureVol_("volMixture", *thermoData[specieNames[0]])
101 {
102  forAll(species_, i)
103  {
104  speciesData_.set
105  (
106  i,
107  new ThermoType(*thermoData[species_[i]])
108  );
109  }
110 
111  correctMassFractions();
112 }
113 
114 
115 template<class ThermoType>
117 (
118  const dictionary& thermoDict,
119  const fvMesh& mesh,
120  const word& phaseName
121 )
122 :
124  (
125  thermoDict,
126  thermoDict.lookup("species"),
127  mesh,
128  phaseName
129  ),
130  speciesData_(species_.size()),
131  mixture_("mixture", constructSpeciesData(thermoDict)),
132  mixtureVol_("volMixture", speciesData_[0])
133 {
134  correctMassFractions();
135 }
136 
137 
138 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
139 
140 template<class ThermoType>
142 (
143  const label celli
144 ) const
145 {
146  mixture_ = Y_[0][celli]*speciesData_[0];
147 
148  for (label n=1; n<Y_.size(); n++)
149  {
150  mixture_ += Y_[n][celli]*speciesData_[n];
151  }
152 
153  return mixture_;
154 }
155 
156 
157 template<class ThermoType>
159 (
160  const label patchi,
161  const label facei
162 ) const
163 {
164  mixture_ = Y_[0].boundaryField()[patchi][facei]*speciesData_[0];
165 
166  for (label n=1; n<Y_.size(); n++)
167  {
168  mixture_ += Y_[n].boundaryField()[patchi][facei]*speciesData_[n];
169  }
170 
171  return mixture_;
172 }
173 
174 
175 template<class ThermoType>
177 (
178  const scalar p,
179  const scalar T,
180  const label celli
181 ) const
182 {
183  scalar rhoInv = 0.0;
184  forAll(speciesData_, i)
185  {
186  rhoInv += Y_[i][celli]/speciesData_[i].rho(p, T);
187  }
188 
189  mixtureVol_ =
190  Y_[0][celli]/speciesData_[0].rho(p, T)/rhoInv*speciesData_[0];
191 
192  for (label n=1; n<Y_.size(); n++)
193  {
194  mixtureVol_ +=
195  Y_[n][celli]/speciesData_[n].rho(p, T)/rhoInv*speciesData_[n];
196  }
197 
198  return mixtureVol_;
199 }
200 
201 
202 template<class ThermoType>
205 (
206  const scalar p,
207  const scalar T,
208  const label patchi,
209  const label facei
210 ) const
211 {
212  scalar rhoInv = 0.0;
213  forAll(speciesData_, i)
214  {
215  rhoInv +=
216  Y_[i].boundaryField()[patchi][facei]/speciesData_[i].rho(p, T);
217  }
218 
219  mixtureVol_ =
220  Y_[0].boundaryField()[patchi][facei]/speciesData_[0].rho(p, T)/rhoInv
221  * speciesData_[0];
222 
223  for (label n=1; n<Y_.size(); n++)
224  {
225  mixtureVol_ +=
226  Y_[n].boundaryField()[patchi][facei]/speciesData_[n].rho(p,T)
227  / rhoInv*speciesData_[n];
228  }
229 
230  return mixtureVol_;
231 }
232 
233 
234 template<class ThermoType>
236 (
237  const dictionary& thermoDict
238 )
239 {
240  forAll(species_, i)
241  {
242  speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
243  }
244 }
245 
246 
247 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::multiComponentMixture::read
void read(const dictionary &)
Read dictionary.
Definition: multiComponentMixture.C:236
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
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:205
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
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:159
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:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:85
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::multiComponentMixture::cellMixture
const ThermoType & cellMixture(const label celli) const
Definition: multiComponentMixture.C:142
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:453
thermoDict
const dictionary & thermoDict
Definition: EEqn.H:16
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:177
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328