Reaktoro
A unified framework for modeling chemically reactive systems
Reaction.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 <functional>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 // Reaktoro includes
27 #include <Reaktoro/Common/Index.hpp>
28 #include <Reaktoro/Math/Matrix.hpp>
29 #include <Reaktoro/Common/ReactionEquation.hpp>
30 #include <Reaktoro/Common/ScalarTypes.hpp>
31 #include <Reaktoro/Core/Species.hpp>
32 
33 namespace Reaktoro {
34 
35 // Forward declarations
36 class ChemicalSystem;
37 class ChemicalProperties;
38 
45 
51 
59 class Reaction
60 {
61 public:
63  Reaction();
64 
67 
69  Reaction(const Reaction& other);
70 
72  virtual ~Reaction();
73 
75  auto operator=(Reaction other) -> Reaction&;
76 
78  auto setName(std::string name) -> void;
79 
81  auto setEquilibriumConstant(const ThermoScalarFunction& lnk) -> void;
82 
84  auto setRate(const ReactionRateFunction& function) -> void;
85 
87  auto name() const -> std::string;
88 
90  auto equilibriumConstant() const -> const ThermoScalarFunction&;
91 
93  auto rate() const -> const ReactionRateFunction&;
94 
96  auto equation() const -> const ReactionEquation&;
97 
99  auto system() const -> const ChemicalSystem&;
100 
102  auto species() const -> const std::vector<Species>&;
103 
105  auto indices() const -> const Indices&;
106 
108  auto stoichiometries() const -> VectorConstRef;
109 
112  auto stoichiometry(std::string species) const -> double;
113 
116  auto lnEquilibriumConstant(const ChemicalProperties& properties) const -> ThermoScalar;
117 
129  auto lnReactionQuotient(const ChemicalProperties& properties) const -> ChemicalScalar;
130 
132  auto lnEquilibriumIndex(const ChemicalProperties& properties) const -> ChemicalScalar;
133 
136  auto rate(const ChemicalProperties& properties) const -> ChemicalScalar;
137 
138 private:
139  struct Impl;
140 
141  std::unique_ptr<Impl> pimpl;
142 };
143 
145 auto operator<(const Reaction& lhs, const Reaction& rhs) -> bool;
146 
148 auto operator==(const Reaction& lhs, const Reaction& rhs) -> bool;
149 
150 } // namespace Reaktoro
auto lnEquilibriumConstant(const ChemicalProperties &properties) const -> ThermoScalar
Calculate the equilibrium constant of the reaction (in natural log).
Definition: Reaction.cpp:172
auto operator=(Reaction other) -> Reaction &
Assign a Reaction instance to this instance.
Definition: Reaction.cpp:106
auto setEquilibriumConstant(const ThermoScalarFunction &lnk) -> void
Set the equilibrium constant function of the reaction (in natural log scale).
Definition: Reaction.cpp:117
virtual ~Reaction()
Destroy this instance.
Definition: Reaction.cpp:103
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:38
Define a type that describes the equation of a reaction.
Definition: ReactionEquation.hpp:36
auto equation() const -> const ReactionEquation &
Return the equation of the reaction.
Definition: Reaction.cpp:142
auto rate() const -> const ReactionRateFunction &
Return the rate function of the reaction.
Definition: Reaction.cpp:137
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
Reaction()
Construct a default Reaction instance.
Definition: Reaction.cpp:91
auto name() const -> std::string
Return the name of the reaction.
Definition: Reaction.cpp:127
auto setName(std::string name) -> void
Set the name of the reaction.
Definition: Reaction.cpp:112
A class for querying thermodynamic and chemical properties of a chemical system.
Definition: ChemicalProperties.hpp:33
std::function< ChemicalScalar(const ChemicalProperties &)> ReactionRateFunction
The function signature of the rate of a reaction (in units of mol/s).
Definition: Reaction.hpp:44
auto equilibriumConstant() const -> const ThermoScalarFunction &
Return the equilibrium constant function of the reaction.
Definition: Reaction.cpp:132
auto lnReactionQuotient(const ChemicalProperties &properties) const -> ChemicalScalar
Calculate the reaction quotient of the reaction (in natural log scale).
Definition: Reaction.cpp:197
Provide a computational representation of a chemical reaction.
Definition: Reaction.hpp:60
ChemicalScalarBase< double, RowVector > ChemicalScalar
A type that represents a chemical property and its derivatives.
Definition: ChemicalScalar.hpp:35
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto system() const -> const ChemicalSystem &
Return the chemical system instance of the reaction.
Definition: Reaction.cpp:147
ChemicalVectorBase< Vector, Vector, Vector, Matrix > ChemicalVector
A type that represents a vector of chemical properties and their derivatives.
Definition: ChemicalVector.hpp:39
auto species() const -> const std::vector< Species > &
Return the reacting species of the reaction.
Definition: Reaction.cpp:152
auto lnEquilibriumIndex(const ChemicalProperties &properties) const -> ChemicalScalar
Calculate the equilibrium index of the reaction as .
Definition: Reaction.cpp:213
std::function< ChemicalVector(const ChemicalProperties &)> ReactionRateVectorFunction
The function signature of the rates of a collection of reactions (in units of mol/s).
Definition: Reaction.hpp:50
auto setRate(const ReactionRateFunction &function) -> void
Set the rate function of the reaction (in units of mol/s).
Definition: Reaction.cpp:122
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31
auto stoichiometry(std::string species) const -> double
Return the stoichiometry of a species in the reaction equation.
Definition: Reaction.cpp:167
ThermoScalarBase< double > ThermoScalar
A type that defines a scalar thermo property.
Definition: ScalarTypes.hpp:40
auto indices() const -> const Indices &
Return the indices of the reacting species of the reaction.
Definition: Reaction.cpp:157
auto stoichiometries() const -> VectorConstRef
Return the stoichiometries of the reacting species of the reaction.
Definition: Reaction.cpp:162