Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Utils.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/Types.hpp>
22 #include <Reaktoro/Common/Matrix.hpp>
23 
24 namespace Reaktoro {
25 
26 // Forward declarations
27 class ChemicalFormula;
28 class ChemicalSystem;
29 class ElementList;
30 class Phase;
31 class PhaseList;
32 class Reaction;
33 class ReactionList;
34 class SpeciesList;
35 class Surface;
36 class SurfaceList;
37 
38 namespace detail {
39 
40 //=================================================================================================
41 // AUXILIARY METHODS RELATED TO SPECIES AMOUNTS
42 //=================================================================================================
43 
45 auto molarMasses(SpeciesList const& species) -> ArrayXd;
46 
52 auto computeSpeciesAmount(ChemicalSystem const& system, Index ispecies, real value, Chars unit) -> real;
53 
54 //=================================================================================================
55 // AUXILIARY INDEX RESOLUTION METHODS THAT DO NOT RAISE ERROR
56 //=================================================================================================
57 
59 auto resolveElementIndex(ElementList const& elementlist, StringOrIndex const& element) -> Index;
60 
62 auto resolveElementIndex(ChemicalSystem const& system, StringOrIndex const& element) -> Index;
63 
65 auto resolveElementIndex(Phase const& phase, StringOrIndex const& element) -> Index;
66 
68 auto resolveSpeciesIndex(SpeciesList const& specieslist, StringOrIndex const& species) -> Index;
69 
71 auto resolveSpeciesIndex(ChemicalSystem const& system, StringOrIndex const& species) -> Index;
72 
74 auto resolveSpeciesIndex(Phase const& phase, StringOrIndex const& species) -> Index;
75 
77 auto resolvePhaseIndex(PhaseList const& phaselist, StringOrIndex const& phase) -> Index;
78 
80 auto resolvePhaseIndex(ChemicalSystem const& system, StringOrIndex const& phase) -> Index;
81 
83 auto resolveReactionIndex(ReactionList const& reactionlist, StringOrIndex const& reaction) -> Index;
84 
86 auto resolveReactionIndex(ChemicalSystem const& system, StringOrIndex const& reaction) -> Index;
87 
89 auto resolveSurfaceIndex(SurfaceList const& surfacelist, StringOrIndex const& surface) -> Index;
90 
92 auto resolveSurfaceIndex(ChemicalSystem const& system, StringOrIndex const& surface) -> Index;
93 
94 //=================================================================================================
95 // AUXILIARY INDEX RESOLUTION METHODS THAT RAISE ERROR
96 //=================================================================================================
97 
101 auto resolveElementIndexOrRaiseError(ElementList const& elementlist, StringOrIndex const& element, String const& errormsg = "") -> Index;
102 
106 auto resolveElementIndexOrRaiseError(ChemicalSystem const& system, StringOrIndex const& element, String const& errormsg = "") -> Index;
107 
111 auto resolveElementIndexOrRaiseError(Phase const& phase, StringOrIndex const& element, String const& errormsg = "") -> Index;
112 
116 auto resolveSpeciesIndexOrRaiseError(SpeciesList const& specieslist, StringOrIndex const& species, String const& errormsg = "") -> Index;
117 
121 auto resolveSpeciesIndexOrRaiseError(ChemicalSystem const& system, StringOrIndex const& species, String const& errormsg = "") -> Index;
122 
126 auto resolveSpeciesIndexOrRaiseError(Phase const& phase, StringOrIndex const& species, String const& errormsg = "") -> Index;
127 
131 auto resolvePhaseIndexOrRaiseError(PhaseList const& phaselist, StringOrIndex const& phase, String const& errormsg = "") -> Index;
132 
136 auto resolvePhaseIndexOrRaiseError(ChemicalSystem const& system, StringOrIndex const& phase, String const& errormsg = "") -> Index;
137 
141 auto resolveReactionIndexOrRaiseError(ReactionList const& reactionlist, StringOrIndex const& reaction, String const& errormsg = "") -> Index;
142 
146 auto resolveReactionIndexOrRaiseError(ChemicalSystem const& system, StringOrIndex const& reaction, String const& errormsg = "") -> Index;
147 
151 auto resolveSurfaceIndexOrRaiseError(SurfaceList const& surfacelist, StringOrIndex const& surface, String const& errormsg = "") -> Index;
152 
156 auto resolveSurfaceIndexOrRaiseError(ChemicalSystem const& system, StringOrIndex const& surface, String const& errormsg = "") -> Index;
157 
158 //=================================================================================================
159 // AUXILIARY FORMULA MATRIX/VECTOR METHODS
160 //=================================================================================================
161 
163 auto assembleFormulaVector(ChemicalFormula const& susbtance, ElementList const& elements) -> VectorXd;
164 
166 auto assembleFormulaMatrix(SpeciesList const& species, ElementList const& elements) -> MatrixXd;
167 
169 auto assembleStoichiometricMatrix(ReactionList const& reactions, SpeciesList const& species) -> MatrixXd;
170 
171 //=================================================================================================
172 // AUXILIARY EXTRACT NAME METHODS
173 //=================================================================================================
174 
176 auto extractNames(SpeciesList const& list) -> Strings;
177 
179 auto extractNames(ElementList const& list) -> Strings;
180 
182 auto extractNames(PhaseList const& list) -> Strings;
183 
184 //=================================================================================================
185 // AUXILIARY METHODS FOR IDENTIFICATION OF REACTIVE INTERPHASE SURFACES
186 //=================================================================================================
187 
193 auto determineReactingPhaseInterfacesInReaction(Reaction const& reaction, PhaseList const& phases) -> Pairs<Index, Index>;
194 
196 auto determineReactingPhaseInterfacesInReactions(Vec<Reaction> const& reactions, PhaseList const& phases) -> Pairs<Index, Index>;
197 
199 auto createSurfacesForReactingPhaseInterfacesInReactions(Vec<Reaction> const& reactions, PhaseList const& phases) -> Vec<Surface>;
200 
201 } // namespace detail
202 } // namespace Reaktoro
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
auto unit(Index rows, Index i) -> decltype(VectorXd::Unit(rows, i))
Return an expression of a unit vector.
Definition: Matrix.hpp:546
Eigen::MatrixXd MatrixXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:137
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
std::vector< std::string > Strings
Convenient alias for std::vector<String>.
Definition: Types.hpp:55
Eigen::VectorXd VectorXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:74
std::variant< Index, int, std::string > StringOrIndex
The type used to accept either a name or an index.
Definition: Types.hpp:58
const char * Chars
Convenient alias for const char*.
Definition: Types.hpp:49
Eigen::ArrayXd ArrayXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:103