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-2026 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 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class ThermoType>
33 (
34  const dictionary& dict
35 )
36 :
37  species_(dict.lookup("species"))
38 {
39  read(dict);
40 }
41 
42 
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 
45 template<class ThermoType>
47 (
48  const dictionary& dict
49 )
50 {
51  specieThermos_.setSize(species_.size());
52  specieCompositions_.setSize(species_.size());
53  specieDictLocations_.setSize(species_.size());
54  active_.setSize(species_.size(), true);
55 
56  forAll(species_, speciei)
57  {
58  const dictionary& specieDict = dict.subDict(species_[speciei]);
59 
60  specieThermos_.set
61  (
62  speciei,
63  new ThermoType(species_[speciei], specieDict)
64  );
65 
66  if (specieDict.isDict("elements"))
67  {
68  const dictionary& specieElementsDict =
69  specieDict.subDict("elements");
70 
71  const wordList elementsNames(specieElementsDict.toc());
72 
73  specieCompositions_[speciei].resize(elementsNames.size());
74 
75  forAll(elementsNames, eni)
76  {
77  specieCompositions_[speciei][eni].name() = elementsNames[eni];
78  specieCompositions_[speciei][eni].nAtoms() =
79  specieElementsDict.lookupOrDefault(elementsNames[eni], 0);
80  }
81  }
82 
83  specieDictLocations_[speciei] = IOerrorLocation(specieDict);
84  }
85 }
86 
87 
88 template<class ThermoType>
91 (
92  const label speciei
93 ) const
94 {
95  if (specieCompositions_[speciei].empty())
96  {
97  FatalIOErrorInFunction(specieDictLocations_[speciei])
98  << "Elemental composition not specified for specie "
99  << specieThermos_[speciei].name()
100  << exit(FatalIOError);
101  }
102 
103  return specieCompositions_[speciei];
104 }
105 
106 
107 template<class ThermoType>
108 const Foam::boolList&
110 {
111  return active_;
112 }
113 
114 
115 template<class ThermoType>
117 {
118  return active_;
119 }
120 
121 
122 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &) const
Find and return a T, if not found return the given default.
bool isDict(const word &) const
Check if entry is a sub-dictionary.
Definition: dictionary.C:732
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:778
wordList toc() const
Return the table of contents.
Definition: dictionary.C:981
const List< specieElement > & specieComposition(const label speciei) const
Return composition based on index.
const boolList & speciesActive() const
Access the specie active flags.
multicomponentMixture(const dictionary &)
Construct from a dictionary.
void read(const dictionary &)
Read dictionary.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
const unitSet & lookup(const word &unitName)
Lookup and return the named unit from the table.
Definition: units.C:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
IOerror FatalIOError
dictionary dict