initial commit for version 1.5.x patch release
[OpenFOAM-1.5.x.git] / src / lagrangian / intermediate / submodels / Reacting / CompositionModel / SingleMixtureFraction / SingleMixtureFraction.C
blob350546b5fe78a5b2f5caf7c6b96fe8fdce58e280
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2008 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "SingleMixtureFraction.H"
29 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
31 template<class CloudType>
32 Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction
34     const dictionary& dict,
35     CloudType& owner
38     CompositionModel<CloudType>(dict, owner, typeName),
40     gasNames_(this->coeffDict().lookup("gasNames")),
41     gasGlobalIds_(gasNames_.size(), -1),
42     YGas0_(this->coeffDict().lookup("YGas0")),
43     YGasTot0_(readScalar(this->coeffDict().lookup("YGasTot0"))),
45     liquidNames_(this->coeffDict().lookup("liquidNames")),
46     liquidGlobalIds_(liquidNames_.size(), -1),
47     YLiquid0_(this->coeffDict().lookup("YLiquid0")),
48     YLiquidTot0_(readScalar(this->coeffDict().lookup("YLiquidTot0"))),
50     solidNames_(this->coeffDict().lookup("solidNames")),
51     solidGlobalIds_(solidNames_.size(), -1),
52     YSolid0_(this->coeffDict().lookup("YSolid0")),
53     YSolidTot0_(readScalar(this->coeffDict().lookup("YSolidTot0"))),
55     YMixture0_(3)
57     // Construct gasGlobalIds_ list
58     forAll(gasNames_, i)
59     {
60         forAll (this->carrierThermo().composition().Y(), j)
61         {
62             word specieName(this->carrierThermo().composition().Y()[j].name());
64             if (specieName == gasNames_[i])
65             {
66                 gasGlobalIds_[i] = j;
67                 break;
68             }
69         }
70         if (gasGlobalIds_[i] == -1)
71         {
72             Info<< "\nThermo package species composition comprises:" << endl;
73             forAll (this->carrierThermo().composition().Y(), k)
74             {
75                 Info<< this->carrierThermo().composition().Y()[k].name()
76                     << endl;
77             }
79             FatalErrorIn
80             (
81                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
82                 "(const dictionary&, CloudType&)"
83             )   << "Could not find gas species " << gasNames_[i]
84                 << " in species list" <<  exit(FatalError);
85         }
86     }
88     // Construct liquidGlobalIds_ list
89     forAll(liquidNames_, i)
90     {
91         forAll (this->liquids().components(), j)
92         {
93             word specieName(this->liquids().components()[j]);
95             if (specieName == liquidNames_[i])
96             {
97                 liquidGlobalIds_[i] = j;
98                 break;
99             }
100         }
101         if (liquidGlobalIds_[i] == -1)
102         {
103             Info<< "\nLiquid mixture species composition comprises:" << endl;
104             forAll (this->liquids().components(), k)
105             {
106                 Info<< this->liquids().components()[k] << endl;
107             }
109             FatalErrorIn
110             (
111                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
112                 "(const dictionary&, CloudType&)"
113             )   << "Could not find liquid species " << liquidNames_[i]
114                 << " in species list" <<  exit(FatalError);
115         }
116     }
118     // Construct solidGlobalIds_ list
119     forAll(solidNames_, i)
120     {
121         forAll (this->solids().components(), j)
122         {
123             word specieName(this->solids().components()[j]);
125             if (specieName == solidNames_[i])
126             {
127                 solidGlobalIds_[i] = j;
128                 break;
129             }
130         }
131         if (solidGlobalIds_[i] == -1)
132         {
133             Info<< "\nSolid mixture species composition comprises:" << endl;
134             forAll (this->solids().components(), k)
135             {
136                 Info<< this->solids().components()[k] << endl;
137             }
139             FatalErrorIn
140             (
141                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
142                 "(const dictionary&, CloudType&)"
143             )   << "Could not find solid species " << solidNames_[i]
144                 << " in species list" <<  exit(FatalError);
145         }
146     }
148     // Set mixture fractions
149     YMixture0_[0] = YGasTot0_;
150     YMixture0_[1] = YLiquidTot0_;
151     YMixture0_[2] = YSolidTot0_;
153     // Check that total mass fractions = 1
155     if (YGas0_.size())
156     {
157         if (mag(sum(YGas0_) - 1) > SMALL)
158         {
159             FatalErrorIn
160             (
161                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
162                 "(const dictionary&, CloudType&)"
163             )<< "Mass fractions of YGas0 must sum to unity"
164              <<  exit(FatalError);
165         }
166     }
167     else
168     {
169         YMixture0_[0] = 0.0;
170     }
172     if (YLiquid0_.size())
173     {
174         if (mag(sum(YLiquid0_) - 1) > SMALL)
175         {
176             FatalErrorIn
177             (
178                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
179                 "(const dictionary&, CloudType&)"
180             )<< "Mass fractions of YLiquid0 must sum to unity"
181              <<  exit(FatalError);
182         }
183     }
184     else
185     {
186         YMixture0_[1] = 0.0;
187     }
189     if (YSolid0_.size())
190     {
191         if (mag(sum(YSolid0_) - 1) > SMALL)
192         {
193             FatalErrorIn
194             (
195                 "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
196                 "(const dictionary&, CloudType&)"
197             )<< "Mass fractions of YSolid0 must sum to unity"
198              <<  exit(FatalError);
199         }
200     }
201     else
202     {
203         YMixture0_[2] = 0.0;
204     }
206     // Check total mixture fraction sums to 1
207     if (mag(sum(YMixture0_) - 1) > SMALL)
208     {
209         FatalErrorIn
210         (
211             "Foam::SingleMixtureFraction<CloudType>::SingleMixtureFraction"
212             "(const dictionary&, CloudType&)"
213         )   << "Mass fractions YGasTot0 + YSolidTot0 + YSolidTot0 must sum "
214             << "to unity" <<  exit(FatalError);
215     }
219 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
221 template<class CloudType>
222 Foam::SingleMixtureFraction<CloudType>::~SingleMixtureFraction()
226 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
228 template<class CloudType>
229 const Foam::wordList
230 Foam::SingleMixtureFraction<CloudType>::compositionNames() const
232     wordList names(3);
233     names[0] = "Gas";
234     names[1] = "Liquid";
235     names[2] = "Solid";
236     return names;
239 template<class CloudType>
240 const Foam::wordList&
241 Foam::SingleMixtureFraction<CloudType>::gasNames() const
243      return gasNames_;
247 template<class CloudType>
248 Foam::label
249 Foam::SingleMixtureFraction<CloudType>::gasLocalId(const word& gasName) const
251     forAll(gasNames_, i)
252     {
253         if (gasName == gasNames_[i])
254         {
255             return i;
256         }
257     }
259     WarningIn
260     (
261         "Foam::label SingleMixtureFraction<CloudType>::"
262         "gasLocalId(const word& gasName) const"
263     )<< "Gas name " << gasName << " not found in gasNames_"
264      << endl;
266     return -1;
270 template<class CloudType>
271 Foam::label
272 Foam::SingleMixtureFraction<CloudType>::gasGlobalId(const word& gasName) const
274     forAll(gasNames_, i)
275     {
276         if (gasName == gasNames_[i])
277         {
278             return gasGlobalIds_[i];
279         }
280     }
282     WarningIn
283     (
284         "Foam::label SingleMixtureFraction<CloudType>::"
285         "gasGlobalId(const word& gasName) const"
286     )<< "Gas name " << gasName << " not found in gasNames_"
287      << endl;
289     return -1;
293 template<class CloudType>
294 const Foam::labelList&
295 Foam::SingleMixtureFraction<CloudType>::gasGlobalIds() const
297     return gasGlobalIds_;
301 template<class CloudType>
302 const Foam::scalarField&
303 Foam::SingleMixtureFraction<CloudType>::YGas0() const
305     return YGas0_;
309 template<class CloudType>
310 Foam::scalar Foam::SingleMixtureFraction<CloudType>::YGasTot0() const
312     return YGasTot0_;
316 template<class CloudType>
317 const Foam::wordList&
318 Foam::SingleMixtureFraction<CloudType>::liquidNames() const
320      return liquidNames_;
324 template<class CloudType>
325 Foam::label Foam::SingleMixtureFraction<CloudType>::liquidLocalId
327     const word& liquidName
328 ) const
330     forAll(liquidNames_, i)
331     {
332         if (liquidName == liquidNames_[i])
333         {
334             return i;
335         }
336     }
338     WarningIn
339     (
340         "Foam::label SingleMixtureFraction<CloudType>::"
341         "liquidLocalId(const word& liquidName) const"
342     )<< "Liquid name " << liquidName << " not found in liquidNames_"
343      << endl;
345     return -1;
349 template<class CloudType>
350 Foam::label Foam::SingleMixtureFraction<CloudType>::liquidGlobalId
352     const word& liquidName
353 ) const
355     forAll(liquidNames_, i)
356     {
357         if (liquidName == liquidNames_[i])
358         {
359             return liquidGlobalIds_[i];
360         }
361     }
363     WarningIn
364     (
365         "Foam::label SingleMixtureFraction<CloudType>::"
366         "liquidGlobalId(const word& liquidName) const"
367     )<< "Liquid name " << liquidName << " not found in liquidNames_"
368      << endl;
370     return -1;
374 template<class CloudType>
375 const Foam::labelList&
376 Foam::SingleMixtureFraction<CloudType>::liquidGlobalIds() const
378     return liquidGlobalIds_;
382 template<class CloudType>
383 const Foam::scalarField&
384 Foam::SingleMixtureFraction<CloudType>::YLiquid0() const
386     return YLiquid0_;
390 template<class CloudType>
391 Foam::scalar Foam::SingleMixtureFraction<CloudType>::YLiquidTot0() const
393     return YLiquidTot0_;
397 template<class CloudType>
398 const Foam::wordList&
399 Foam::SingleMixtureFraction<CloudType>::solidNames() const
401     return solidNames_;
405 template<class CloudType>
406 Foam::label Foam::SingleMixtureFraction<CloudType>::solidLocalId
408     const word& solidName
409 ) const
411     forAll(solidNames_, i)
412     {
413         if (solidName == solidNames_[i])
414         {
415             return i;
416         }
417     }
419     WarningIn
420     (
421         "Foam::label SingleMixtureFraction<CloudType>::"
422         "SolididLocalId(const word& solidName) const"
423     )<< "Solid name " << solidName << " not found in solidNames_"
424      << endl;
426     return -1;
430 template<class CloudType>
431 Foam::label
432 Foam::SingleMixtureFraction<CloudType>::solidGlobalId
434     const word& solidName
435 ) const
437     forAll(solidNames_, i)
438     {
439         if (solidName == solidNames_[i])
440         {
441             return solidGlobalIds_[i];
442         }
443     }
445     WarningIn
446     (
447         "Foam::label SingleMixtureFraction<CloudType>::"
448         "solidGlobalId(const word& solidName) const"
449     )<< "Solid name " << solidName << " not found in solidNames_"
450      << endl;
452     return -1;
456 template<class CloudType>
457 const Foam::labelList&
458 Foam::SingleMixtureFraction<CloudType>::solidGlobalIds() const
460     return solidGlobalIds_;
464 template<class CloudType>
465 const Foam::scalarField&
466 Foam::SingleMixtureFraction<CloudType>::YSolid0() const
468     return YSolid0_;
472 template<class CloudType>
473 Foam::scalar
474 Foam::SingleMixtureFraction<CloudType>::YSolidTot0() const
476     return YSolidTot0_;
480 template<class CloudType>
481 const Foam::scalarField&
482 Foam::SingleMixtureFraction<CloudType>::YMixture0() const
484     return YMixture0_;
488 template<class CloudType>
489 Foam::scalar Foam::SingleMixtureFraction<CloudType>::RGas
491     const scalarField& YGas
492 ) const
494     scalar RGasMixture = 0.0;
495     forAll(YGas, i)
496     {
497         label id = gasGlobalIds_[i];
498         RGasMixture += YGas[i]*this->gases()[id].R();
499     }
500     return RGasMixture;
504 template<class CloudType>
505 Foam::scalar Foam::SingleMixtureFraction<CloudType>::HGas
507     const scalarField& YGas,
508     const scalar T
510 const
512     scalar HMixture = 0.0;
513     forAll(YGas, i)
514     {
515         label id = gasGlobalIds_[i];
516         HMixture += YGas[i]*this->gases()[id].H(T);
517     }
518     return HMixture;
522 template<class CloudType>
523 Foam::scalar Foam::SingleMixtureFraction<CloudType>::cpGas
525     const scalarField& YGas,
526     const scalar T
528 const
530     scalar cpMixture = 0.0;
531     forAll(YGas, i)
532     {
533         label id = gasGlobalIds_[i];
534         cpMixture += YGas[i]*this->gases()[id].Cp(T);
535     }
536     return cpMixture;
540 template<class CloudType>
541 Foam::scalar Foam::SingleMixtureFraction<CloudType>::cpLiquid
543     const scalarField& YLiquid,
544     const scalar p,
545     const scalar T
547 const
549     scalar cpMixture = 0.0;
550     forAll(YLiquid, i)
551     {
552         label id = liquidGlobalIds_[i];
553         cpMixture += YLiquid[i]*this->liquids().properties()[id].cp(p, T);
554     }
556     return cpMixture;
560 template<class CloudType>
561 Foam::scalar Foam::SingleMixtureFraction<CloudType>::cpSolid
563     const scalarField& YSolid
565 const
567     scalar cpMixture = 0.0;
568     forAll(YSolid, i)
569     {
570         label id = solidGlobalIds_[i];
571         cpMixture += YSolid[i]*this->solids().properties()[id].cp();
572     }
574     return cpMixture;
578 // ************************************************************************* //