FreeFOAM The Cross-Platform CFD Toolkit
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) 2008-2010 OpenCFD Ltd.
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"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 :
33  phase_(UNKNOWN),
34  stateLabel_("(unknown)"),
35  names_(0),
36  Y_(0),
37  globalIds_(0),
38  globalCarrierIds_(0)
39 {
40  is.check("Foam::phaseProperties::phaseProperties(Istream& is)");
41 
42  dictionaryEntry phaseInfo(dictionary::null, is);
43 
44  phase_ = phaseTypeNames_[phaseInfo.keyword()];
45  stateLabel_ = phaseToStateLabel(phase_);
46 
47  if (phaseInfo.size() > 0)
48  {
49  label nComponents = phaseInfo.size();
50  names_.setSize(nComponents, "unknownSpecie");
51  Y_.setSize(nComponents, 0.0);
52  globalIds_.setSize(nComponents, -1);
53  globalCarrierIds_.setSize(nComponents, -1);
54 
55  label cmptI = 0;
56  forAllConstIter(IDLList<entry>, phaseInfo, iter)
57  {
58  names_[cmptI] = iter().keyword();
59  Y_[cmptI] = readScalar(phaseInfo.lookup(names_[cmptI]));
60  cmptI++;
61  }
62 
63  checkTotalMassFraction();
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
69 
71 {
72  is.check
73  (
74  "Foam::Istream& Foam::operator>>(Istream&, phaseProperties&)"
75  );
76 
77  dictionaryEntry phaseInfo(dictionary::null, is);
78 
79  pp.phase_ = pp.phaseTypeNames_[phaseInfo.keyword()];
80  pp.stateLabel_ = pp.phaseToStateLabel(pp.phase_);
81 
82  if (phaseInfo.size() > 0)
83  {
84  label nComponents = phaseInfo.size();
85 
86  pp.names_.setSize(nComponents, "unknownSpecie");
87  pp.Y_.setSize(nComponents, 0.0);
88  pp.globalIds_.setSize(nComponents, -1);
89  pp.globalCarrierIds_.setSize(nComponents, -1);
90 
91  label cmptI = 0;
92  forAllConstIter(IDLList<entry>, phaseInfo, iter)
93  {
94  pp.names_[cmptI] = iter().keyword();
95  pp.Y_[cmptI] = readScalar(phaseInfo.lookup(pp.names_[cmptI]));
96  cmptI++;
97  }
98 
99  pp.checkTotalMassFraction();
100  }
101 
102  return is;
103 }
104 
105 
106 Foam::Ostream& Foam::operator<<(Ostream& os, const phaseProperties& pp)
107 {
108  os.check
109  (
110  "Foam::Ostream& Foam::operator<<(Ostream&, const phaseProperties&)"
111  );
112 
113  os << pp.phaseTypeNames_[pp.phase_] << nl << token::BEGIN_BLOCK << nl
114  << incrIndent;
115 
116  forAll(pp.names_, cmptI)
117  {
118  os.writeKeyword(pp.names_[cmptI]) << pp.Y_[cmptI]
119  << token::END_STATEMENT << nl;
120  }
121 
122  os << decrIndent << token::END_BLOCK << nl;
123 
124  os.check
125  (
126  "Foam::Ostream& Foam::operator<<(Ostream&, const phaseProperties&)"
127  );
128 
129  return os;
130 }
131 
132 
133 // ************************ vim: set sw=4 sts=4 et: ************************ //