Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ReactionRate.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/Real.hpp>
22 #include <Reaktoro/Common/NumberTraits.hpp>
23 
24 namespace Reaktoro {
25 
28 {
29 public:
32  {}
33 
35  template<typename T, Requires<isNumeric<T>> = true>
36  ReactionRate(T const& value)
37  : m_value(value) {}
38 
40  static auto enforce(real const& value) -> ReactionRate
41  {
42  ReactionRate res(value);
43  res.m_equation_mode = true;
44  return res;
45  }
46 
48  auto value() const -> real const&
49  {
50  return m_value;
51  }
52 
54  auto onEquationMode() const -> bool
55  {
56  return m_equation_mode;
57  }
58 
60  operator real const&() const
61  {
62  return m_value;
63  }
64 
66  template<typename T, Requires<isNumeric<T>> = true>
67  auto operator=(T const& value) -> ReactionRate&
68  {
69  m_value = value;
70  return *this;
71  }
72 
73  template<typename T, Requires<isNumeric<T>> = true> auto operator+=(T const& scalar) -> ReactionRate& { m_value += scalar; return *this; }
74  template<typename T, Requires<isNumeric<T>> = true> auto operator-=(T const& scalar) -> ReactionRate& { m_value -= scalar; return *this; }
75  template<typename T, Requires<isNumeric<T>> = true> auto operator*=(T const& scalar) -> ReactionRate& { m_value *= scalar; return *this; }
76  template<typename T, Requires<isNumeric<T>> = true> auto operator/=(T const& scalar) -> ReactionRate& { m_value /= scalar; return *this; }
77 
78 private:
80  real m_value = {};
81 
83  bool m_equation_mode = false;
84 };
85 
86 inline auto operator+(ReactionRate const& rate) { return rate; }
87 inline auto operator-(ReactionRate rate) { return rate *= -1.0; }
88 
89 template<typename T, Requires<isNumeric<T>> = true> auto operator+(ReactionRate rate, T const& scalar) { return rate += scalar; }
90 template<typename T, Requires<isNumeric<T>> = true> auto operator-(ReactionRate rate, T const& scalar) { return rate -= scalar; }
91 template<typename T, Requires<isNumeric<T>> = true> auto operator*(ReactionRate rate, T const& scalar) { return rate *= scalar; }
92 template<typename T, Requires<isNumeric<T>> = true> auto operator/(ReactionRate rate, T const& scalar) { return rate /= scalar; }
93 
94 template<typename T, Requires<isNumeric<T>> = true> auto operator+(T const& scalar, ReactionRate rate) { return rate += scalar; }
95 template<typename T, Requires<isNumeric<T>> = true> auto operator-(T const& scalar, ReactionRate rate) { return rate -= scalar; }
96 template<typename T, Requires<isNumeric<T>> = true> auto operator*(T const& scalar, ReactionRate rate) { return rate *= scalar; }
97 template<typename T, Requires<isNumeric<T>> = true> auto operator/(T const& scalar, ReactionRate rate) { return rate /= scalar; }
98 
99 } // namespace Reaktoro
The result of a reaction rate model evaluation.
Definition: ReactionRate.hpp:28
ReactionRate(T const &value)
Construct a ReactionRate object with given rate value.
Definition: ReactionRate.hpp:36
auto operator=(T const &value) -> ReactionRate &
Assign a value to this ReactionRate object.
Definition: ReactionRate.hpp:67
static auto enforce(real const &value) -> ReactionRate
Return a ReactionRate object that represents the residual of an enforced equation f(props) = 0 instea...
Definition: ReactionRate.hpp:40
auto onEquationMode() const -> bool
Return true if this ReactionRate object is in equation mode enabled by enforce.
Definition: ReactionRate.hpp:54
ReactionRate()
Construct a default ReactionRate object.
Definition: ReactionRate.hpp:31
auto value() const -> real const &
Return the underlying real object in the ReactionRate object.
Definition: ReactionRate.hpp:48
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
auto operator/(const Eigen::MatrixBase< DerivedLHS > &lhs, const Eigen::MatrixBase< DerivedRHS > &rhs) -> decltype(lhs.cwiseQuotient(rhs))
Return the component-wise division of two matrices.
Definition: Matrix.hpp:762
auto operator-(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar - mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:786
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
auto operator+(const typename Derived::Scalar &scalar, const Eigen::MatrixBase< Derived > &mat) -> decltype((scalar+mat.array()).matrix())
Return the component-wise division of two matrices.
Definition: Matrix.hpp:774