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-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. 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 
44 using ReactionRateFunction = std::function<ChemicalScalar(const ChemicalProperties&)>;
45 
50 using ReactionRateVectorFunction = std::function<ChemicalVector(const ChemicalProperties&)>;
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 -> const Vector&;
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
A class for querying thermodynamic and chemical properties of a chemical system.
Definition: ChemicalProperties.hpp:36
auto setRate(const ReactionRateFunction &function) -> void
Set the rate function of the reaction (in units of mol/s).
Definition: Reaction.cpp:122
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto name() const -> std::string
Return the name of the reaction.
Definition: Reaction.cpp:127
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:47
virtual ~Reaction()
Destroy this instance.
Definition: Reaction.cpp:103
auto stoichiometries() const -> const Vector &
Return the stoichiometries of the reacting species of the reaction.
Definition: Reaction.cpp:162
auto lnEquilibriumIndex(const ChemicalProperties &properties) const -> ChemicalScalar
Calculate the equilibrium index of the reaction as .
Definition: Reaction.cpp:213
std::function< ChemicalScalar(const ChemicalProperties &)> ReactionRateFunction
The function signature of the rate of a reaction (in units of mol/s).
Definition: Reaction.hpp:44
ChemicalScalarBase< double, Vector > ChemicalScalar
A type that represents a chemical scalar and its derivatives.
Definition: ChemicalScalar.hpp:35
auto setName(std::string name) -> void
Set the name of the reaction.
Definition: Reaction.cpp:112
Provide a computational representation of a chemical reaction.
Definition: Reaction.hpp:59
Reaction()
Construct a default Reaction instance.
Definition: Reaction.cpp:91
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
Define a type that describes the equation of a reaction.
Definition: ReactionEquation.hpp:35
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 species() const -> const std::vector< Species > &
Return the reacting species of the reaction.
Definition: Reaction.cpp:152
auto indices() const -> const Indices &
Return the indices of the reacting species of the reaction.
Definition: Reaction.cpp:157
ThermoScalarBase< double > ThermoScalar
A type that defines a scalar thermo property.
Definition: ScalarTypes.hpp:40
auto lnEquilibriumConstant(const ChemicalProperties &properties) const -> ThermoScalar
Calculate the equilibrium constant of the reaction (in natural log).
Definition: Reaction.cpp:172
auto setEquilibriumConstant(const ThermoScalarFunction &lnk) -> void
Set the equilibrium constant function of the reaction (in natural log scale).
Definition: Reaction.cpp:117
auto stoichiometry(std::string species) const -> double
Return the stoichiometry of a species in the reaction equation.
Definition: Reaction.cpp:167
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
auto operator=(Reaction other) -> Reaction &
Assign a Reaction instance to this instance.
Definition: Reaction.cpp:106
auto equation() const -> const ReactionEquation &
Return the equation of the reaction.
Definition: Reaction.cpp:142
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
auto system() const -> const ChemicalSystem &
Return the chemical system instance of the reaction.
Definition: Reaction.cpp:147