Reaktoro
A unified framework for modeling chemically reactive systems
Phase.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <memory>
22 #include <string>
23 
24 // Reaktoro includes
25 #include <Reaktoro/Core/Element.hpp>
26 #include <Reaktoro/Core/Species.hpp>
27 #include <Reaktoro/Thermodynamics/Models/PhaseChemicalModel.hpp>
28 #include <Reaktoro/Thermodynamics/Models/PhaseThermoModel.hpp>
29 
30 namespace Reaktoro {
31 
33 enum class PhaseType
34 {
35  Solid, Liquid, Gas, Plasma
36 };
37 
41 class Phase
42 {
43 public:
45  Phase();
46 
48  Phase(std::string name, PhaseType type);
49 
51  auto setName(std::string name) -> void;
52 
54  auto setType(PhaseType type) -> void;
55 
57  auto setSpecies(const std::vector<Species>& species) -> void;
58 
60  auto setThermoModel(const PhaseThermoModel& model) -> void;
61 
63  auto setChemicalModel(const PhaseChemicalModel& model) -> void;
64 
66  auto numElements() const -> unsigned;
67 
69  auto numSpecies() const -> unsigned;
70 
72  auto name() const -> std::string;
73 
75  auto type() const -> PhaseType;
76 
78  auto elements() const -> const std::vector<Element>&;
79 
81  auto elements() -> std::vector<Element>&;
82 
84  auto species() const -> const std::vector<Species>&;
85 
87  auto species() -> std::vector<Species>&;
88 
90  auto species(Index index) const -> const Species&;
91 
93  auto isFluid() const -> bool;
94 
96  auto isSolid() const -> bool;
97 
100  auto thermoModel() const -> const PhaseThermoModel&;
101 
104  auto chemicalModel() const -> const PhaseChemicalModel&;
105 
109  auto indexSpecies(std::string name) const -> Index;
110 
114  auto indexSpeciesWithError(std::string name) const -> Index;
115 
119  auto indexSpeciesAny(const std::vector<std::string>& names) const -> Index;
120 
124  auto indexSpeciesAnyWithError(const std::vector<std::string>& names) const -> Index;
125 
130  auto properties(PhaseThermoModelResult& res, double T, double P) const -> void;
131 
137  auto properties(PhaseChemicalModelResult& res, double T, double P, VectorConstRef n) const -> void;
138 
139 private:
140  struct Impl;
141 
142  std::shared_ptr<Impl> pimpl;
143 };
144 
146 auto operator<(const Phase& lhs, const Phase& rhs) -> bool;
147 
149 auto operator==(const Phase& lhs, const Phase& rhs) -> bool;
150 
151 } // namespace Reaktoro
std::function< void(PhaseThermoModelResult &, Temperature, Pressure)> PhaseThermoModel
The signature of the chemical model function that calculates the thermodynamic properties of the spec...
Definition: PhaseThermoModel.hpp:59
auto numSpecies() const -> unsigned
Return the number of species in the phase.
Definition: Phase.cpp:109
auto index(const T &value, const std::vector< T > &values) -> Index
Find the index of a value in a container of values.
Definition: SetUtils.hxx:21
auto names(const NamedValues &values) -> std::vector< std::string >
Return the names of the entries in a container.
Definition: Utils.hxx:22
PhaseType
A type to define the possible state of matter of a phase.
Definition: Phase.hpp:34
The result of a chemical model function that calculates the chemical properties of species.
Definition: PhaseChemicalModel.hpp:33
auto name() const -> std::string
Return the name of the phase.
Definition: Phase.cpp:114
auto indexSpeciesAnyWithError(const std::vector< std::string > &names) const -> Index
Return the index of the first species in the phase with any of the given names.
Definition: Phase.cpp:188
auto setChemicalModel(const PhaseChemicalModel &model) -> void
Set the function that calculates the chemical properties of the phase.
Definition: Phase.cpp:99
auto setType(PhaseType type) -> void
Set the type of the phase.
Definition: Phase.cpp:82
auto elements() const -> const std::vector< Element > &
Return the elements of the phase.
Definition: Phase.cpp:124
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto indexSpeciesAny(const std::vector< std::string > &names) const -> Index
Return the index of the first species in the phase with any of the given names.
Definition: Phase.cpp:183
auto thermoModel() const -> const PhaseThermoModel &
Return the thermodynamic model function of the phase.
Definition: Phase.cpp:159
auto properties(PhaseThermoModelResult &res, double T, double P) const -> void
Calculate the standard thermodynamic properties of the species in the phase.
Definition: Phase.cpp:198
auto setName(std::string name) -> void
Set the name of the phase.
Definition: Phase.cpp:77
auto setSpecies(const std::vector< Species > &species) -> void
Set the species of the phase.
Definition: Phase.cpp:87
auto indexSpecies(std::string name) const -> Index
Return the index of a species in the phase.
Definition: Phase.cpp:169
A type used to define a phase and its attributes.
Definition: Phase.hpp:42
auto isSolid() const -> bool
Return true if the phase type is solid.
Definition: Phase.cpp:154
auto indexSpeciesWithError(std::string name) const -> Index
Return the index of a species in the system.
Definition: Phase.cpp:174
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto isFluid() const -> bool
Return true if the state of matter of the phase is fluid, i.e., liquid, gas, or plasma.
Definition: Phase.cpp:149
std::function< void(PhaseChemicalModelResult &, Temperature, Pressure, VectorConstRef)> PhaseChemicalModel
The signature of the chemical model function that calculates the chemical properties of the species i...
Definition: PhaseChemicalModel.hpp:66
A type used to describe a species and its attributes.
Definition: Species.hpp:42
auto chemicalModel() const -> const PhaseChemicalModel &
Return the chemical model function of the phase.
Definition: Phase.cpp:164
Phase()
Construct a default Phase instance.
Definition: Phase.cpp:66
The result of a thermodynamic model function that calculates the thermodynamic properties of species.
Definition: PhaseThermoModel.hpp:32
auto numElements() const -> unsigned
Return the number of elements in the phase.
Definition: Phase.cpp:104
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31
auto type() const -> PhaseType
Return the type of the phase.
Definition: Phase.cpp:119
auto setThermoModel(const PhaseThermoModel &model) -> void
Set the function that calculates the standard thermodynamic properties of the phase.
Definition: Phase.cpp:94
auto species() const -> const std::vector< Species > &
Return the species of the phase.
Definition: Phase.cpp:134