phasePropertiesIO.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-2020 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 "phaseProperties.H"
27 #include "dictionaryEntry.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 :
33  phase_(UNKNOWN),
34  stateLabel_("(unknown)"),
35  names_(0),
36  Y_(0),
37  carrierIds_(0)
38 {
39  is.check("Foam::phaseProperties::phaseProperties(Istream& is)");
40 
41  dictionaryEntry phaseInfo(dictionary::null, is);
42 
43  phase_ = phaseTypeNames[phaseInfo.keyword()];
44  stateLabel_ = phaseToStateLabel(phase_);
45 
46  if (phaseInfo.size() > 0)
47  {
48  label nComponents = phaseInfo.size();
49  names_.setSize(nComponents, "unknownSpecie");
50  Y_.setSize(nComponents, 0.0);
51  carrierIds_.setSize(nComponents, -1);
52 
53  label cmptI = 0;
54  forAllConstIter(IDLList<entry>, phaseInfo, iter)
55  {
56  names_[cmptI] = iter().keyword();
57  Y_[cmptI] = phaseInfo.template lookup<scalar>(names_[cmptI]);
58  cmptI++;
59  }
60 
61  checkTotalMassFraction();
62  }
63 }
64 
65 
66 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
67 
69 {
70  is.check
71  (
72  "Foam::Istream& Foam::operator>>(Istream&, phaseProperties&)"
73  );
74 
75  dictionaryEntry phaseInfo(dictionary::null, is);
76 
77  pp.phase_ = pp.phaseTypeNames[phaseInfo.keyword()];
78  pp.stateLabel_ = pp.phaseToStateLabel(pp.phase_);
79 
80  if (phaseInfo.size() > 0)
81  {
82  label nComponents = phaseInfo.size();
83 
84  pp.names_.setSize(nComponents, "unknownSpecie");
85  pp.Y_.setSize(nComponents, 0.0);
86  pp.carrierIds_.setSize(nComponents, -1);
87 
88  label cmptI = 0;
89  forAllConstIter(IDLList<entry>, phaseInfo, iter)
90  {
91  pp.names_[cmptI] = iter().keyword();
92  pp.Y_[cmptI] = phaseInfo.template lookup<scalar>(pp.names_[cmptI]);
93  cmptI++;
94  }
95 
96  pp.checkTotalMassFraction();
97  }
98 
99  return is;
100 }
101 
102 
104 {
105  os.check
106  (
107  "Foam::Ostream& Foam::operator<<(Ostream&, const phaseProperties&)"
108  );
109 
110  os << pp.phaseTypeNames[pp.phase_] << nl << token::BEGIN_BLOCK << nl
111  << incrIndent;
112 
113  forAll(pp.names_, cmptI)
114  {
115  writeEntry(os, pp.names_[cmptI], pp.Y_[cmptI]);
116  }
117 
118  os << decrIndent << token::END_BLOCK << nl;
119 
120  os.check
121  (
122  "Foam::Ostream& Foam::operator<<(Ostream&, const phaseProperties&)"
123  );
124 
125  return os;
126 }
127 
128 
129 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
Template class for intrusive linked lists.
Definition: ILList.H:67
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:60
void setSize(const label)
Reset size of List.
Definition: List.C:281
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
A keyword and a list of tokens is a 'dictionaryEntry'.
static const dictionary null
Null dictionary.
Definition: dictionary.H:242
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
Helper class to manage multi-specie phase properties.
static const NamedEnum< phaseType, 4 > phaseTypeNames
Corresponding word representations for phase type enumerations.
phaseProperties()
Null constructor.
@ BEGIN_BLOCK
Definition: token.H:110
@ END_BLOCK
Definition: token.H:111
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:235
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
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:228
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
Istream & operator>>(Istream &, directionInfo &)
Ostream & operator<<(Ostream &, const ensightPart &)
static const char nl
Definition: Ostream.H:260