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 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class ThermoType>
33 (
34  const dictionary& dict
35 )
36 {
37  read(dict);
38 }
39 
40 
41 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
42 
43 template<class ThermoType>
45 {
46  wordList result(specieThermos_.size());
47 
48  forAll(specieThermos_, speciei)
49  {
50  result[speciei] = specieThermos_[speciei].name();
51  }
52 
53  return result;
54 }
55 
56 
57 template<class ThermoType>
59 (
60  const dictionary& dict
61 )
62 {
63  const wordList specieNames(dict.lookup("species"));
64 
65  specieThermos_.setSize(specieNames.size());
66  specieCompositions_.setSize(specieNames.size());
67  specieDictLocations_.setSize(specieNames.size());
68 
69  forAll(specieNames, speciei)
70  {
71  const dictionary& specieDict = dict.subDict(specieNames[speciei]);
72 
73  specieThermos_.set
74  (
75  speciei,
76  new ThermoType(specieNames[speciei], specieDict)
77  );
78 
79  if (specieDict.isDict("elements"))
80  {
81  const dictionary& specieElementsDict =
82  specieDict.subDict("elements");
83 
84  const wordList elementsNames(specieElementsDict.toc());
85 
86  specieCompositions_[speciei].resize(elementsNames.size());
87 
88  forAll(elementsNames, eni)
89  {
90  specieCompositions_[speciei][eni].name() = elementsNames[eni];
91  specieCompositions_[speciei][eni].nAtoms() =
92  specieElementsDict.lookupOrDefault(elementsNames[eni], 0);
93  }
94  }
95 
96  specieDictLocations_[speciei] = IOerrorLocation(specieDict);
97  }
98 }
99 
100 
101 template<class ThermoType>
104 (
105  const label speciei
106 ) const
107 {
108  if (specieCompositions_[speciei].empty())
109  {
110  FatalIOErrorInFunction(specieDictLocations_[speciei])
111  << "Elemental composition not specified for specie "
112  << specieThermos_[speciei].name()
113  << exit(FatalIOError);
114  }
115 
116  return specieCompositions_[speciei];
117 }
118 
119 
120 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) 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:797
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:843
wordList toc() const
Return the table of contents.
Definition: dictionary.C:976
const List< specieElement > & specieComposition(const label speciei) const
Return composition based on index.
multicomponentMixture(const dictionary &)
Construct from a dictionary.
void read(const dictionary &)
Read dictionary.
wordList specieNames() const
Return the specie names.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
void read(Istream &, label &, const dictionary &)
In-place read with dictionary lookup.
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