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-2022 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  << nl
68  << incrIndent << indent
69  << "Min of mass fraction sum " << min(Yt).value()
70  << decrIndent
71  << exit(FatalError);
72  }
73 
74  const scalar diff(mag(max(Yt).value()) - scalar(1));
75 
76  if (diff > ROOTVSMALL)
77  {
79  << "Sum of mass fractions is different from one for species "
80  << this->species()
81  << nl << incrIndent << indent
82  << "Max of mass fraction sum differs from 1 by " << diff
83  << decrIndent << nl;
84  }
85 
86  forAll(Y_, n)
87  {
88  Y_[n] /= Yt;
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
94 
95 template<class ThermoType>
97 (
98  const dictionary& thermoDict,
99  const wordList& specieNames,
100  const ReactionTable<ThermoType>& thermoData,
101  const fvMesh& mesh,
102  const word& phaseName
103 )
104 :
105  basicSpecieMixture(thermoDict, specieNames, mesh, phaseName),
106  speciesData_(species_.size()),
107  mixture_("mixture", *thermoData[specieNames[0]]),
108  mixtureVol_("volMixture", *thermoData[specieNames[0]])
109 {
110  forAll(species_, i)
111  {
112  speciesData_.set
113  (
114  i,
115  new ThermoType(*thermoData[species_[i]])
116  );
117  }
119  correctMassFractions();
120 }
121 
122 
123 template<class ThermoType>
125 (
126  const dictionary& thermoDict,
127  const fvMesh& mesh,
128  const word& phaseName
129 )
130 :
132  (
133  thermoDict,
134  thermoDict.lookup("species"),
135  mesh,
136  phaseName
137  ),
138  speciesData_(species_.size()),
139  mixture_("mixture", constructSpeciesData(thermoDict)),
140  mixtureVol_("volMixture", speciesData_[0])
141 {
142  correctMassFractions();
143 }
144 
145 
146 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
147 
148 template<class ThermoType>
150 (
151  const label celli
152 ) const
153 {
154  mixture_ = Y_[0][celli]*speciesData_[0];
155 
156  for (label n=1; n<Y_.size(); n++)
157  {
158  mixture_ += Y_[n][celli]*speciesData_[n];
159  }
161  return mixture_;
162 }
163 
164 
165 template<class ThermoType>
167 (
168  const label patchi,
169  const label facei
170 ) const
171 {
172  mixture_ = Y_[0].boundaryField()[patchi][facei]*speciesData_[0];
173 
174  for (label n=1; n<Y_.size(); n++)
175  {
176  mixture_ += Y_[n].boundaryField()[patchi][facei]*speciesData_[n];
177  }
179  return mixture_;
180 }
181 
182 
183 template<class ThermoType>
185 (
186  const scalar p,
187  const scalar T,
188  const label celli
189 ) const
190 {
191  scalar rhoInv = 0.0;
192  forAll(speciesData_, i)
193  {
194  rhoInv += Y_[i][celli]/speciesData_[i].rho(p, T);
195  }
196 
197  mixtureVol_ =
198  Y_[0][celli]/speciesData_[0].rho(p, T)/rhoInv*speciesData_[0];
199 
200  for (label n=1; n<Y_.size(); n++)
201  {
202  mixtureVol_ +=
203  Y_[n][celli]/speciesData_[n].rho(p, T)/rhoInv*speciesData_[n];
204  }
205 
206  return mixtureVol_;
207 }
208 
209 
210 template<class ThermoType>
213 (
214  const scalar p,
215  const scalar T,
216  const label patchi,
217  const label facei
218 ) const
219 {
220  scalar rhoInv = 0.0;
221  forAll(speciesData_, i)
222  {
223  rhoInv +=
224  Y_[i].boundaryField()[patchi][facei]/speciesData_[i].rho(p, T);
225  }
226 
227  mixtureVol_ =
228  Y_[0].boundaryField()[patchi][facei]/speciesData_[0].rho(p, T)/rhoInv
229  * speciesData_[0];
230 
231  for (label n=1; n<Y_.size(); n++)
232  {
233  mixtureVol_ +=
234  Y_[n].boundaryField()[patchi][facei]/speciesData_[n].rho(p,T)
235  / rhoInv*speciesData_[n];
236  }
238  return mixtureVol_;
239 }
240 
241 
242 template<class ThermoType>
244 (
245  const dictionary& thermoDict
246 )
247 {
248  forAll(species_, i)
249  {
250  speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
251  }
252 }
253 
254 
255 // ************************************************************************* //
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition: triad.C:373
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:493
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Specialization of basicMultiComponentMixture for a mixture consisting of a number for molecular speci...
Lookup type of boundary radiation properties.
Definition: lookup.H:57
const ThermoType & patchFaceVolMixture(const scalar p, const scalar T, const label patchi, const label facei) const
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:441
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:81
speciesTable species_
Table of specie names.
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
const ThermoType & patchFaceMixture(const label patchi, const label facei) const
Foam::multiComponentMixture.
const dictionary & thermoDict
Definition: EEqn.H:16
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: PtrList.H:159
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:511
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define WarningInFunction
Report a warning using Foam::Warning.
const ThermoType & cellMixture(const label celli) const
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label n
volScalarField & p
const ThermoType & cellVolMixture(const scalar p, const scalar T, const label celli) const
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:502
void read(const dictionary &)
Read dictionary.
volScalarField Yt(0.0 *Y[0])