Reaktoro
A unified framework for modeling chemically reactive systems
EquilibriumProblem.hpp
1 // This file is part of Reaktoro (https://reaktoro.org).
2 //
3 // Reaktoro is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // Reaktoro is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with this library. If not, see <http://www.gnu.org/licenses/>.
15 
16 #pragma once
17 
18 // C++ includes
19 #include <memory>
20 
21 // Reaktoro includes
22 #include <Reaktoro/Math/Matrix.hpp>
23 
24 namespace Reaktoro {
25 
26 // Forward declarations
27 class ChemicalState;
28 class ChemicalSystem;
29 class Partition;
30 
33 {
34 public:
36  explicit EquilibriumProblem(const ChemicalSystem& system);
37 
39  explicit EquilibriumProblem(const Partition& partition);
40 
43 
45  virtual ~EquilibriumProblem();
46 
49 
53 
57  auto setTemperature(double val) -> EquilibriumProblem&;
58 
63  auto setTemperature(double val, std::string units) -> EquilibriumProblem&;
64 
68  auto setPressure(double val) -> EquilibriumProblem&;
69 
74  auto setPressure(double val, std::string units) -> EquilibriumProblem&;
75 
79 
83 
87  auto setElementAmount(Index ielement, double amount) -> EquilibriumProblem&;
88 
92  auto setElementAmount(std::string element, double amount) -> EquilibriumProblem&;
93 
97 
104  auto add(std::string name, double amount, std::string units) -> EquilibriumProblem&;
105 
113  auto add(const ChemicalState& state) -> EquilibriumProblem&;
114 
120  auto addCompound(std::string name, double amount, std::string unit) -> EquilibriumProblem&;
121 
127  auto addSpecies(std::string name, double amount, std::string unit) -> EquilibriumProblem&;
128 
136  auto addState(const ChemicalState& state) -> EquilibriumProblem&;
137 
139  auto system() const -> const ChemicalSystem&;
140 
142  auto partition() const -> const Partition&;
143 
145  auto temperature() const -> double;
146 
148  auto pressure() const -> double;
149 
151  auto elementAmounts() const -> VectorConstRef;
152 
153 private:
154  struct Impl;
155 
156  std::unique_ptr<Impl> pimpl;
157 };
158 
159 } // namespace Reaktoro
auto pressure() const -> double
Return the pressure for the equilibrium calculation (in units of Pa)
Definition: EquilibriumProblem.cpp:268
auto amount(double value, Index nspecies, Index ispecies) -> ChemicalScalarBase< double, decltype(tr(unit(nspecies, ispecies)))>
Return a ChemicalScalar representation of a mole amount of a species.
Definition: ChemicalScalar.hpp:233
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:38
Provides a computational representation of the state of a multiphase chemical system.
Definition: ChemicalState.hpp:61
auto system() const -> const ChemicalSystem &
Return a reference to the ChemicalSystem instance used to create this EquilibriumProblem instance.
Definition: EquilibriumProblem.cpp:253
A type that defines an equilibrium problem.
Definition: EquilibriumProblem.hpp:33
auto addCompound(std::string name, double amount, std::string unit) -> EquilibriumProblem &
Add a given amount of a compound to the equilibrium recipe.
Definition: EquilibriumProblem.cpp:184
auto setPartition(const Partition &partition) -> EquilibriumProblem &
Set the partition of the chemical system.
Definition: EquilibriumProblem.cpp:101
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto setElectricalCharge(double amount) -> EquilibriumProblem &
Set the mole amount of electrical charge.
Definition: EquilibriumProblem.cpp:167
auto setTemperature(double val) -> EquilibriumProblem &
Set the temperature for the equilibrium calculation.
Definition: EquilibriumProblem.cpp:107
virtual ~EquilibriumProblem()
Destroy this EquilibriumProblem instance.
Definition: EquilibriumProblem.cpp:92
auto addState(const ChemicalState &state) -> EquilibriumProblem &
Add the mole amounts of the equilibrium species in a ChemicalState instance to the equilibrium recipe...
Definition: EquilibriumProblem.cpp:246
auto elementAmounts() const -> VectorConstRef
Return the amounts of the elements for the equilibrium calculation (in units of mol)
Definition: EquilibriumProblem.cpp:273
auto setElementAmount(Index ielement, double amount) -> EquilibriumProblem &
Set the mole amount of an element for the equilibrium calculation (in units of mol)
Definition: EquilibriumProblem.cpp:148
auto setElementAmounts(VectorConstRef b) -> EquilibriumProblem &
Set the mole amounts of each element for the equilibrium calculation.
Definition: EquilibriumProblem.cpp:133
EquilibriumProblem(const ChemicalSystem &system)
Construct an EquilibriumProblem instance.
Definition: EquilibriumProblem.cpp:80
auto temperature() const -> double
Return the temperature for the equilibrium calculation (in units of K)
Definition: EquilibriumProblem.cpp:263
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto add(std::string name, double amount, std::string units) -> EquilibriumProblem &
Add a given amount of a compound or species to the equilibrium recipe.
Definition: EquilibriumProblem.cpp:172
auto partition() const -> const Partition &
Return a reference to the Partition instance used to create this EquilibriumProblem instance.
Definition: EquilibriumProblem.cpp:258
Provide a computational representation of the Partition of a chemical system.
Definition: Partition.hpp:56
auto operator=(EquilibriumProblem other) -> EquilibriumProblem &
Assign an EquilibriumProblem instance to this.
Definition: EquilibriumProblem.cpp:95
auto setPressure(double val) -> EquilibriumProblem &
Set the pressure for the equilibrium calculation.
Definition: EquilibriumProblem.cpp:120
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31
auto unit(Index rows, Index i) -> decltype(Vector::Unit(rows, i))
Return an expression of a unit vector.
Definition: Matrix.hxx:47
auto addSpecies(std::string name, double amount, std::string unit) -> EquilibriumProblem &
Add a given amount of a species to the equilibrium recipe The species must be present in the chemical...
Definition: EquilibriumProblem.cpp:217