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-2023 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 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 template<class ThermoType>
33 (
34  const dictionary& thermoDict
35 ) const
36 {
37  PtrList<ThermoType> specieThermos(species_.size());
38 
39  forAll(species_, i)
40  {
41  specieThermos.set
42  (
43  i,
44  new ThermoType(species_[i], thermoDict.subDict(species_[i]))
45  );
46  }
47 
48  return specieThermos;
49 }
50 
51 
52 template<class ThermoType>
55 (
56  const dictionary& thermoDict
57 ) const
58 {
59  List<List<specieElement>> specieCompositions(species_.size());
60 
61  // Loop through all species in thermoDict to retrieve
62  // the species composition
63  forAll(species_, i)
64  {
65  if (thermoDict.subDict(species_[i]).isDict("elements"))
66  {
67  const dictionary& elements =
68  thermoDict.subDict(species_[i]).subDict("elements");
69 
70  const wordList elementsNames(elements.toc());
71 
72  specieCompositions[i].resize(elementsNames.size());
73 
74  forAll(elementsNames, eni)
75  {
76  specieCompositions[i][eni].name() = elementsNames[eni];
77  specieCompositions[i][eni].nAtoms() =
78  elements.lookupOrDefault(elementsNames[eni], 0);
79  }
80  }
81  }
82 
83  return specieCompositions;
84 }
85 
86 
87 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
88 
89 template<class ThermoType>
91 (
92  const dictionary& thermoDict,
93  const fvMesh& mesh,
94  const word& phaseName
95 )
96 :
98  (
99  thermoDict,
100  thermoDict.lookup("species"),
101  mesh,
102  phaseName
103  ),
104  specieThermos_(readSpeciesData(thermoDict)),
105  specieCompositions_(readSpeciesComposition(thermoDict))
106 {
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 template<class ThermoType>
115 (
116  const dictionary& thermoDict
117 )
118 {
119  specieThermos_ = readSpeciesData(thermoDict);
120  specieCompositions_ = readSpeciesComposition(thermoDict);
121 }
122 
123 
124 template<class ThermoType>
127 (
128  const label speciei
129 ) const
130 {
131  if (specieCompositions_[speciei].empty())
132  {
133  // Spit an error associated with the lookup of this specie's elements
134  refCast<const dictionary>(*this)
135  .subDict(species_[speciei])
136  .subDict("elements");
137  }
138 
139  return specieCompositions_[speciei];
140 }
141 
142 
143 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
Specialisation of basicMixture for a mixture consisting of a number for molecular species.
void correctMassFractions()
Scale the mass fractions to sum to 1.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
Foam::multicomponentMixture.
const List< specieElement > & specieComposition(const label speciei) const
Return composition based on index.
void read(const dictionary &)
Read dictionary.
multicomponentMixture(const dictionary &, const fvMesh &, const word &)
Construct from dictionary, mesh and phase name.
A class for handling words, derived from string.
Definition: word.H:62
List< word > wordList
A List of words.
Definition: fileName.H:54
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