Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ActivityModel.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 // C++ includes
21 #include <cmath>
22 
23 // Reaktoro includes
24 #include <Reaktoro/Common/Types.hpp>
25 #include <Reaktoro/Core/ActivityProps.hpp>
26 #include <Reaktoro/Core/Model.hpp>
27 #include <Reaktoro/Core/SpeciesList.hpp>
28 
29 namespace Reaktoro {
30 
34 {
36  real const& T;
37 
39  real const& P;
40 
43 };
44 
45 // Declare this so that Model understands ActivityPropsRef as reference type for ActivityProps instead of ActivityProps&.
46 REAKTORO_DEFINE_REFERENCE_TYPE_OF(ActivityProps, ActivityPropsRef);
47 
50 
54 
57 
60 
62 template<typename... Models>
63 auto chain(ActivityModelGenerator const& model, Models const&... models) -> ActivityModelGenerator
64 {
65  Vec<ActivityModelGenerator> vec = {model, models...};
66  return chain(vec);
67 }
68 
69 } // namespace Reaktoro
70 
71 //=========================================================================
72 // CODE BELOW NEEDED FOR MEMOIZATION TECHNIQUE INVOLVING ACTIVITYMODELARGS
73 //=========================================================================
74 
75 namespace Reaktoro {
76 
77 template<typename T>
78 struct MemoizationTraits;
79 
81 template<>
83 {
84  using Type = ActivityModelArgs;
85 
88 
89  static auto equal(Tuple<real, real, ArrayXr> const& a, ActivityModelArgs const& b)
90  {
91  auto const& [T, P, x] = a;
92  return T == b.T && P == b.P && (x == b.x).all();
93  }
94 
95  static auto assign(Tuple<real, real, ArrayXr>& a, ActivityModelArgs const& b)
96  {
97  auto& [T, P, x] = a;
98  T = b.T;
99  P = b.P;
100  x = b.x;
101  }
102 };
103 
104 } // namespace Reaktoro
Definition: Model.hpp:30
A type used as a collection of species.
Definition: SpeciesList.hpp:29
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Fn< ActivityModel(SpeciesList const &species)> ActivityModelGenerator
The type for functions that construct an ActivityModel for a phase.
Definition: ActivityModel.hpp:53
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
auto chain(const Vec< ActivityModelGenerator > &models) -> ActivityModelGenerator
Return an activity model resulting from chaining other activity models.
Model< ActivityProps(ActivityModelArgs)> ActivityModel
The function type for the calculation of activity and corrective thermodynamic properties of a phase.
Definition: ActivityModel.hpp:49
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
std::tuple< Args... > Tuple
Convenient alias for std::tuple<Args...>.
Definition: Types.hpp:94
std::function< F > Fn
Convenient alias for std::function<R(Args...)>.
Definition: Types.hpp:110
Eigen::Ref< const ArrayXr > ArrayXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:89
ActivityPropsBase< TypeOpIdentity > ActivityProps
The activity and corrective thermodynamic properties of a phase.
Definition: ActivityProps.hpp:159
The arguments in an function for calculation of activity properties of a phase.
Definition: ActivityModel.hpp:34
real const & T
The temperature for the calculation (in K).
Definition: ActivityModel.hpp:36
real const & P
The pressure for the calculation (in Pa).
Definition: ActivityModel.hpp:39
ArrayXrConstRef x
The mole fractions of the species in the phase.
Definition: ActivityModel.hpp:42
The base type for the primary activity and corrective thermodynamic properties of a phase.
Definition: ActivityProps.hpp:59
Tuple< real, real, ArrayXr > CacheType
The type used instead to cache an ActivityModelArgs object.
Definition: ActivityModel.hpp:87
Used to enable function arguments of a type T to be cached in a memoized version of the function.
Definition: Memoization.hpp:30
static auto assign(CacheType &a, const Type &b)
Assign the value of b, of type T, into a, of type CacheType.
Definition: Memoization.hpp:64
static auto equal(const CacheType &a, const Type &b)
Check if a, of type CacheType, is equal to b, of type T.
Definition: Memoization.hpp:56