Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
SmartEquilibriumSolver.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/HashUtils.hpp>
22 #include <Reaktoro/Common/Matrix.hpp>
23 #include <Reaktoro/Common/Types.hpp>
24 #include <Reaktoro/Core/ChemicalState.hpp>
25 #include <Reaktoro/Equilibrium/EquilibriumConditions.hpp>
26 #include <Reaktoro/Equilibrium/EquilibriumPredictor.hpp>
27 #include <Reaktoro/Equilibrium/EquilibriumSensitivity.hpp>
28 #include <Reaktoro/ODML/ClusterConnectivity.hpp>
29 #include <Reaktoro/ODML/PriorityQueue.hpp>
30 
31 namespace Reaktoro {
32 
33 // Forward declarations
34 class ChemicalProps;
35 class ChemicalState;
36 class ChemicalSystem;
37 class EquilibriumRestrictions;
38 class EquilibriumSpecs;
39 struct SmartEquilibriumOptions;
40 struct SmartEquilibriumResult;
41 
44 {
45 public:
47  explicit SmartEquilibriumSolver(ChemicalSystem const& system);
48 
50  explicit SmartEquilibriumSolver(EquilibriumSpecs const& specs);
51 
54 
57 
60 
61  //=================================================================================================================
62  //
63  // CHEMICAL EQUILIBRIUM METHODS
64  //
65  //=================================================================================================================
66 
70 
74  auto solve(ChemicalState& state, EquilibriumRestrictions const& restrictions) -> SmartEquilibriumResult;
75 
80 
85  auto solve(ChemicalState& state, EquilibriumConditions const& conditions, EquilibriumRestrictions const& restrictions) -> SmartEquilibriumResult;
86 
87  //=================================================================================================================
88  //
89  // CHEMICAL EQUILIBRIUM METHODS WITH SENSITIVITY CALCULATION
90  //
91  //=================================================================================================================
92 
97 
103 
109 
115  auto solve(ChemicalState& state, EquilibriumSensitivity& sensitivity, EquilibriumConditions const& conditions, EquilibriumRestrictions const& restrictions) -> SmartEquilibriumResult;
116 
117  //=================================================================================================================
118  //
119  // MISCELLANEOUS METHODS
120  //
121  //=================================================================================================================
122 
124  auto setOptions(SmartEquilibriumOptions const& options) -> void;
125 
127  struct Record
128  {
131 
134 
137 
140  };
141 
143  struct Cluster
144  {
147 
150 
153 
156  };
157 
159  struct Cell
160  {
163 
166 
169  };
170 
172  struct Grid
173  {
179  };
180 
181 private:
182  struct Impl;
183 
184  Ptr<Impl> pimpl;
185 };
186 
187 } // namespace Reaktoro
The chemical state of a chemical system.
Definition: ChemicalState.hpp:41
The class used to represent a chemical system and its attributes and properties.
Definition: ChemicalSystem.hpp:70
Definition: ClusterConnectivity.hpp:28
The class used to define conditions to be satisfied at chemical equilibrium.
Definition: EquilibriumConditions.hpp:32
Used to predict a chemical equilibrium state at given conditions using first-order Taylor approximati...
Definition: EquilibriumPredictor.hpp:33
The class used to define reactivity restrictions in a chemical equilibrium calculation.
Definition: EquilibriumRestrictions.hpp:28
The sensitivity derivatives of a chemical equilibrium state.
Definition: EquilibriumSensitivity.hpp:37
The class used to define conditions to be satisfied at chemical equilibrium.
Definition: EquilibriumSpecs.hpp:281
Definition: PriorityQueue.hpp:27
Used for calculating chemical equilibrium states using an on-demand machine learning (ODML) strategy.
Definition: SmartEquilibriumSolver.hpp:44
SmartEquilibriumSolver(SmartEquilibriumSolver const &other)
Construct a copy of an SmartEquilibriumSolver object.
auto operator=(SmartEquilibriumSolver other) -> SmartEquilibriumSolver &
Assign a copy of an SmartEquilibriumSolver object to this.
auto solve(ChemicalState &state, EquilibriumSensitivity &sensitivity, EquilibriumConditions const &conditions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given constraint conditions and compute sensitivity derivativ...
auto solve(ChemicalState &state) -> SmartEquilibriumResult
Equilibrate a chemical state.
auto setOptions(SmartEquilibriumOptions const &options) -> void
Set the options of the equilibrium solver.
SmartEquilibriumSolver(ChemicalSystem const &system)
Construct an SmartEquilibriumSolver object with given chemical system.
~SmartEquilibriumSolver()
Destroy this SmartEquilibriumSolver object.
auto solve(ChemicalState &state, EquilibriumRestrictions const &restrictions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given reactivity restrictions.
auto solve(ChemicalState &state, EquilibriumConditions const &conditions, EquilibriumRestrictions const &restrictions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given constraint conditions and reactivity restrictions.
auto solve(ChemicalState &state, EquilibriumSensitivity &sensitivity, EquilibriumConditions const &conditions, EquilibriumRestrictions const &restrictions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given constraint conditions and reactivity restrictions and c...
SmartEquilibriumSolver(EquilibriumSpecs const &specs)
Construct an SmartEquilibriumSolver object with given chemical equilibrium specifications.
auto solve(ChemicalState &state, EquilibriumSensitivity &sensitivity, EquilibriumRestrictions const &restrictions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given reactivity restrictions and compute sensitivity derivat...
auto solve(ChemicalState &state, EquilibriumSensitivity &sensitivity) -> SmartEquilibriumResult
Equilibrate a chemical state and compute sensitivity derivatives.
auto solve(ChemicalState &state, EquilibriumConditions const &conditions) -> SmartEquilibriumResult
Equilibrate a chemical state respecting given constraint conditions.
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
std::unique_ptr< T > Ptr
Convenient alias for std::unique_ptr<T>.
Definition: Types.hpp:102
ArrayX< Eigen::Index > ArrayXl
Convenient alias to Eigen type.
Definition: Matrix.hpp:95
std::deque< T > Deque
Convenient alias for std::deque<T>.
Definition: Types.hpp:70
std::unordered_map< Key, T > Map
Convenient alias for std::unordered_map<Key, T>.
Definition: Types.hpp:74
The options for the smart equilibrium calculations.
Definition: SmartEquilibriumOptions.hpp:28
Used to describe the result of a smart chemical equilibrium calculation.
Definition: SmartEquilibriumResult.hpp:102
The collection of clusters containing learned input-output data associated to a temperature-pressure ...
Definition: SmartEquilibriumSolver.hpp:160
PriorityQueue priority
The priority queue for the clusters based on their usage counts.
Definition: SmartEquilibriumSolver.hpp:168
Deque< Cluster > clusters
The clusters containing the learned input-output data points in a temperature-pressure grid cell.
Definition: SmartEquilibriumSolver.hpp:162
ClusterConnectivity connectivity
The connectivity matrix of the clusters to determine how we move from one to another when searching.
Definition: SmartEquilibriumSolver.hpp:165
The cluster storing learned input-output data with same classification.
Definition: SmartEquilibriumSolver.hpp:144
Deque< Record > records
The records stored in this cluster with learning data.
Definition: SmartEquilibriumSolver.hpp:152
ArrayXl iprimary
The indices of the primary species for this cluster.
Definition: SmartEquilibriumSolver.hpp:146
PriorityQueue priority
The priority queue for the records based on their usage count.
Definition: SmartEquilibriumSolver.hpp:155
Index label
The hash of the indices of the primary species for this cluster.
Definition: SmartEquilibriumSolver.hpp:149
The temperature-pressure grid cells containing learned input-output data.
Definition: SmartEquilibriumSolver.hpp:173
Map< Pair< long, long >, Cell > cells
The hash table used to access a temperature-pressure grid cell containing learned computations.
Definition: SmartEquilibriumSolver.hpp:178
The record of the knowledge database containing input, output, and derivatives data.
Definition: SmartEquilibriumSolver.hpp:128
EquilibriumSensitivity sensitivity
The sensitivity derivatives at the calculated chemical equilibrium state.
Definition: SmartEquilibriumSolver.hpp:136
EquilibriumPredictor predictor
The predictor of chemical equilibrium states at given new conditions.
Definition: SmartEquilibriumSolver.hpp:139
EquilibriumConditions conditions
The conditions at which the chemical equilibrium state was calculated.
Definition: SmartEquilibriumSolver.hpp:133
ChemicalState state
The fully calculated chemical equilibrium state.
Definition: SmartEquilibriumSolver.hpp:130