Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
30
31// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32
33template<class ThermoType>
34const ThermoType& Foam::multiComponentMixture<ThermoType>::constructSpeciesData
35(
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
52template<class ThermoType>
53void Foam::multiComponentMixture<ThermoType>::correctMassFractions()
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
95template<class ThermoType>
96Foam::multiComponentMixture<ThermoType>::multiComponentMixture
97(
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 );
118
119 correctMassFractions();
120}
121
122
123template<class ThermoType>
124Foam::multiComponentMixture<ThermoType>::multiComponentMixture
125(
126 const dictionary& thermoDict,
127 const fvMesh& mesh,
128 const word& phaseName
129)
130:
131 basicSpecieMixture
132 (
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
148template<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];
160
161 return mixture_;
162}
163
164
165template<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];
178
179 return mixture_;
180}
181
182
183template<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];
205
206 return mixtureVol_;
207}
208
209
210template<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];
237
238 return mixtureVol_;
239}
240
241
242template<class ThermoType>
244(
246)
247{
248 forAll(species_, i)
249 {
250 speciesData_[i] = ThermoType(thermoDict.subDict(species_[i]));
251 }
252}
253
254
255// ************************************************************************* //
label n
volScalarField Yt(0.0 *Y[0])
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:171
speciesTable species_
Table of specie names.
PtrList< volScalarField > Y_
Species mass fractions.
basicSpecieMixture(const dictionary &thermoDict, const wordList &specieNames, const fvMesh &mesh, const word &phaseName)
Construct from dictionary, species names, mesh and phase name.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const ThermoType & cellMixture(const label celli) const
const ThermoType & cellVolMixture(const scalar p, const scalar T, const label celli) const
const ThermoType & patchFaceMixture(const label patchi, const label facei) const
const ThermoType & patchFaceVolMixture(const scalar p, const scalar T, const label patchi, const label facei) const
void read(const dictionary &)
Read dictionary.
Lookup type of boundary radiation properties.
Definition lookup.H:60
A class for handling words, derived from Foam::string.
Definition word.H:66
volScalarField & p
const volScalarField & T
const dictionary & thermoDict
Definition EEqn.H:16
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define WarningInFunction
Report a warning using Foam::Warning.
List< word > wordList
List of word.
Definition fileName.H:60
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition Ostream.H:490
Ostream & indent(Ostream &os)
Indent stream.
Definition Ostream.H:481
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
scalar diff(const triad &A, const triad &B)
Return a quantity of the difference between two triads.
Definition triad.C:373
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
HashPtrTable< ThermoType > ReactionTable
Definition Reaction.H:52
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition Ostream.H:499
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299