Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Material.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 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 // Reaktoro includes
21 #include <Reaktoro/Common/Matrix.hpp>
22 #include <Reaktoro/Common/Types.hpp>
23 #include <Reaktoro/Core/ChemicalFormula.hpp>
24 #include <Reaktoro/Core/ChemicalState.hpp>
25 #include <Reaktoro/Core/ChemicalSystem.hpp>
26 #include <Reaktoro/Equilibrium/EquilibriumOptions.hpp>
27 #include <Reaktoro/Equilibrium/EquilibriumRestrictions.hpp>
28 #include <Reaktoro/Equilibrium/EquilibriumResult.hpp>
29 
30 namespace Reaktoro {
31 
33 class Material
34 {
35 public:
38 
43  auto addSpeciesAmount(StringOrIndex const& species, double amount) -> void;
44 
50  auto addSpeciesAmount(StringOrIndex const& species, double amount, Chars unit) -> void;
51 
57  auto addSpeciesMass(StringOrIndex const& species, double mass, Chars unit) -> void;
58 
62  auto addSubstanceAmount(ChemicalFormula const& substance, double amount) -> void;
63 
68  auto addSubstanceAmount(ChemicalFormula const& substance, double amount, Chars unit) -> void;
69 
74  auto addSubstanceMass(ChemicalFormula const& substance, double mass, Chars unit) -> void;
75 
80  auto addMaterialAmount(Material const& material, double amount) -> void;
81 
87  auto addMaterialAmount(Material const& material, double amount, Chars unit) -> void;
88 
94  auto addMaterialMass(Material const& material, double mass, Chars unit) -> void;
95 
101  auto add(String const& substance, double value, Chars unit) -> void;
102 
108  auto add(Material const& material, double value, Chars unit) -> void;
109 
115  auto scaleAmount(double value, Chars unit) -> void;
116 
122  auto scaleMass(double value, Chars unit) -> void;
123 
129  auto scale(double value, Chars unit) -> void;
130 
134  auto with(double value, Chars unit) const -> Material;
135 
137  auto system() const -> const ChemicalSystem&;
138 
140  auto substances() const -> const Pairs<ChemicalFormula, double>&;
141 
143  auto species() const -> const Pairs<Index, double>&;
144 
146  auto componentAmounts() const -> ArrayXd;
147 
149  auto elementAmounts() const -> ArrayXd;
150 
152  auto charge() const -> double;
153 
155  auto amount() const -> double;
156 
158  auto mass() const -> double;
159 
161  auto molarMass() const -> double;
162 
165 
168 
170  auto equilibrate(const EquilibriumRestrictions& restrictions) -> ChemicalState;
171 
173  auto equilibrate(const EquilibriumRestrictions& restrictions, const EquilibriumOptions& options) -> ChemicalState;
174 
176  auto equilibrate(double T, Chars unitT, double P, Chars unitP) -> ChemicalState;
177 
179  auto equilibrate(double T, Chars unitT, double P, Chars unitP, const EquilibriumOptions& options) -> ChemicalState;
180 
182  auto equilibrate(double T, Chars unitT, double P, Chars unitP, const EquilibriumRestrictions& restrictions) -> ChemicalState;
183 
185  auto equilibrate(double T, Chars unitT, double P, Chars unitP, const EquilibriumRestrictions& restrictions, const EquilibriumOptions& options) -> ChemicalState;
186 
188  auto result() const -> const EquilibriumResult&;
189 
196  auto initialState(double T, double P) const -> ChemicalState;
197 
201  auto operator()(double value, Chars unit) const -> Material;
202 
203 private:
205  ChemicalSystem m_system;
206 
208  Pairs<ChemicalFormula, double> m_substances;
209 
211  Pairs<Index, double> m_species;
212 
214  EquilibriumResult m_result;
215 };
216 
218 auto operator+(const Material& l, const Material& r) -> Material;
219 
221 auto operator<<(std::ostream& out, const Material& material) -> std::ostream&;
222 
223 } // namespace Reaktoro
A type used to represent the chemical formula of a chemical species.
Definition: ChemicalFormula.hpp:27
The chemical state of a chemical system.
Definition: ChemicalState.hpp:41
The class used to represent a chemical system and its attributes and properties.
Definition: ChemicalSystem.hpp:70
The class used to define reactivity restrictions in a chemical equilibrium calculation.
Definition: EquilibriumRestrictions.hpp:28
A type used to represent a material composed of one or more substances.
Definition: Material.hpp:34
auto addMaterialAmount(Material const &material, double amount) -> void
Add a given amount of another material in this material.
auto molarMass() const -> double
Return the molar mass of the material as the ratio of its mass and amount (in kg/mol).
auto addSpeciesAmount(StringOrIndex const &species, double amount, Chars unit) -> void
Add a given amount of an existing species in the chemical system to the material.
Material(ChemicalSystem const &system)
Construct a Material object.
auto addSubstanceMass(ChemicalFormula const &substance, double mass, Chars unit) -> void
Add a given mass of a substance to the material.
auto scaleAmount(double value, Chars unit) -> void
Scale the amount of the material to a desired value.
auto addMaterialAmount(Material const &material, double amount, Chars unit) -> void
Add a given amount of another material in this material.
auto mass() const -> double
Return the mass of the material as the sum of its substance masses (in kg).
auto amount() const -> double
Return the amount of the material as the sum of its substance amounts (in mol).
auto species() const -> const Pairs< Index, double > &
Return the chemical species (as indices) and their amounts in this material.
auto result() const -> const EquilibriumResult &
Return the result of the chemical equilibrium calculation performed by equilibrate.
auto addSubstanceAmount(ChemicalFormula const &substance, double amount, Chars unit) -> void
Add a given amount of a substance to the material.
auto elementAmounts() const -> ArrayXd
Return the accumulated amounts of elements in the material.
auto add(String const &substance, double value, Chars unit) -> void
Add a given amount or mass of a substance or existing species to the material.
auto addMaterialMass(Material const &material, double mass, Chars unit) -> void
Add a given mass of another material in this material.
auto scaleMass(double value, Chars unit) -> void
Scale the mass of the material to a desired value.
auto addSpeciesAmount(StringOrIndex const &species, double amount) -> void
Add a given amount of an existing species in the chemical system to the material.
auto substances() const -> const Pairs< ChemicalFormula, double > &
Return the substances and their amounts in this material.
auto charge() const -> double
Return the accumulated electric charge in the material.
auto initialState(double T, double P) const -> ChemicalState
Return the initial chemical state that is used in the chemical equilibrium calculation performed by e...
auto add(Material const &material, double value, Chars unit) -> void
Add a given amount or mass of another material in this material.
auto with(double value, Chars unit) const -> Material
Return a copy of this material with scaled amount or mass.
auto componentAmounts() const -> ArrayXd
Return the accumulated amounts of elements and electric charge in the material.
auto addSpeciesMass(StringOrIndex const &species, double mass, Chars unit) -> void
Add a given mass of an existing species in the chemical system to the material.
auto scale(double value, Chars unit) -> void
Scale the amount or mass of the material to a desired value.
auto equilibrate() -> ChemicalState
Perform a chemical equilibrium calculation on this material at 25 °C and 1 bar.
auto system() const -> const ChemicalSystem &
Return the underlying chemical system in this material.
auto addSubstanceAmount(ChemicalFormula const &substance, double amount) -> void
Add a given amount of a substance to the material.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Vec< Pair< T, U > > Pairs
Convenient alias for std::vector<std::pair<T, U>>.
Definition: Types.hpp:90
auto unit(Index rows, Index i) -> decltype(VectorXd::Unit(rows, i))
Return an expression of a unit vector.
Definition: Matrix.hpp:546
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
std::variant< Index, int, std::string > StringOrIndex
The type used to accept either a name or an index.
Definition: Types.hpp:58
const char * Chars
Convenient alias for const char*.
Definition: Types.hpp:49
Eigen::ArrayXd ArrayXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:103
The options for the equilibrium calculations.
Definition: EquilibriumOptions.hpp:43
A type used to describe the result of an equilibrium calculation.
Definition: EquilibriumResult.hpp:28