phasePropertiesIO.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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] = readScalar(phaseInfo.lookup(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] = readScalar(phaseInfo.lookup(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  os.writeKeyword(pp.names_[cmptI]) << pp.Y_[cmptI]
116  << token::END_STATEMENT << nl;
117  }
118 
119  os << decrIndent << token::END_BLOCK << nl;
120 
121  os.check
122  (
123  "Foam::Ostream& Foam::operator<<(Ostream&, const phaseProperties&)"
124  );
125 
126  return os;
127 }
128 
129 
130 // ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
const keyType & keyword() const
Return keyword.
Definition: entry.H:123
virtual bool check(const char *operation) const
Check IOstream status for given operation.
Definition: IOstream.C:92
Helper class to manage multi-specie phase properties.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const dictionary null
Null dictionary.
Definition: dictionary.H:202
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
static const NamedEnum< phaseType, 4 > phaseTypeNames
Corresponding word representations for phase type enumerations.
Istream & operator>>(Istream &, directionInfo &)
bool readScalar(const char *buf, doubleScalar &s)
Read whole of buf as a scalar. Return true if succesful.
Definition: doubleScalar.H:63
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:262
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:237
Ostream & writeKeyword(const keyType &)
Write the keyword followed by an appropriate indentation.
Definition: Ostream.C:54
void setSize(const label)
Reset size of List.
Definition: List.C:281
Ostream & operator<<(Ostream &, const ensightPart &)
phaseProperties()
Null constructor.
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:230
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576