Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
EquilibriumSetup.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 ChemicalProps;
28 class ChemicalState;
29 class ChemicalSystem;
30 class EquilibriumConditions;
31 class EquilibriumDims;
32 class EquilibriumProps;
33 class EquilibriumRestrictions;
34 class EquilibriumSpecs;
35 struct EquilibriumOptions;
36 
39 {
40 public:
42  explicit EquilibriumSetup(EquilibriumSpecs const& specs);
43 
46 
49 
52 
54  auto setOptions(EquilibriumOptions const& options) -> void;
55 
57  auto dims() const -> EquilibriumDims const&;
58 
60  auto options() const -> EquilibriumOptions const&;
61 
63  auto Aex() const -> MatrixXdConstRef;
64 
66  auto Aen() const -> MatrixXdConstRef;
67 
69  auto Aeq() const -> MatrixXdConstRef;
70 
72  auto Aep() const -> MatrixXdConstRef;
73 
77  auto assembleLowerBoundsVector(EquilibriumRestrictions const& restrictions, ChemicalState const& state0) const -> VectorXd;
78 
82  auto assembleUpperBoundsVector(EquilibriumRestrictions const& restrictions, ChemicalState const& state0) const -> VectorXd;
83 
89 
92  auto updateGradX(VectorXlConstRef ibasicvars) -> void;
93 
95  auto updateGradP() -> void;
96 
98  auto updateGradW() -> void;
99 
101  auto getGibbsEnergy() -> real;
102 
105 
108 
111 
114 
117 
120 
123 
126 
129 
132 
144 
149 
151  auto equilibriumProps() const -> EquilibriumProps const&;
152 
154  auto chemicalProps() const -> ChemicalProps const&;
155 
156 private:
157  struct Impl;
158 
159  Ptr<Impl> pimpl;
160 };
161 
162 } // namespace Reaktoro
The class that computes chemical properties of a chemical system.
Definition: ChemicalProps.hpp:34
The chemical state of a chemical system.
Definition: ChemicalState.hpp:41
The class that computes chemical properties of a system during equilibrium calculations.
Definition: EquilibriumProps.hpp:35
The class used to define reactivity restrictions in a chemical equilibrium calculation.
Definition: EquilibriumRestrictions.hpp:28
Used to construct the optimization problem for a chemical equilibrium calculation.
Definition: EquilibriumSetup.hpp:39
auto assembleLowerBoundsVector(EquilibriumRestrictions const &restrictions, ChemicalState const &state0) const -> VectorXd
Assemble the lower bound vector xlower in the optimization problem where x = (n, q).
auto updateGradW() -> void
Update the derivatives of the chemical potentials and residuals of the equilibrium constraints with r...
auto usingDiagonalApproxDerivatives() -> bool
Return true if a diagonal structure is adopted for the Hessian matrix Hxx.
auto options() const -> EquilibriumOptions const &
Return the options for the solution of the equilibrium problem.
auto getGibbsHessianC() -> MatrixXdConstRef
Get the updated Hessian matrix of the Gibbs energy with respect to c.
auto setOptions(EquilibriumOptions const &options) -> void
Set the options for the solution of the equilibrium problem.
auto equilibriumProps() const -> EquilibriumProps const &
Return the current chemical properties of the system as an EquilibriumProps object.
auto getGibbsGradX() -> VectorXdConstRef
Get the updated gradient vector of the Gibbs energy with respect to x.
auto updateGradX(VectorXlConstRef ibasicvars) -> void
Update the derivatives of the chemical potentials and residuals of the equilibrium constraints with r...
auto Aex() const -> MatrixXdConstRef
Return the coefficient matrix Aex in the optimization problem.
auto Aep() const -> MatrixXdConstRef
Return the coefficient matrix Aep in the optimization problem.
auto updateGradP() -> void
Update the derivatives of the chemical potentials and residuals of the equilibrium constraints with r...
auto assembleChemicalPropsJacobianEnd() -> void
Disable recording of derivatives of the chemical properties with respect to *(n, p,...
auto assembleUpperBoundsVector(EquilibriumRestrictions const &restrictions, ChemicalState const &state0) const -> VectorXd
Assemble the upper bound vector xupper in the optimization problem where x = (n, q).
auto chemicalProps() const -> ChemicalProps const &
Return the current chemical properties of the system as a ChemicalProps object.
auto getGibbsEnergy() -> real
Get the updated Gibbs energy value.
auto update(VectorXrConstRef x, VectorXrConstRef p, VectorXrConstRef w) -> void
Update the chemical potentials and residuals of the equilibrium constraints.
auto usingPartiallyExactDerivatives() -> bool
Return true if partially exact derivatives are adopted for the Hessian matrix Hxx.
auto Aen() const -> MatrixXdConstRef
Return the block Aen corresponding to variables n in the coefficient matrix Aex = [Aen Aeq] of the op...
~EquilibriumSetup()
Destroy this EquilibriumSetup object.
EquilibriumSetup(EquilibriumSetup const &other)
Construct a copy of an EquilibriumSetup object.
auto operator=(EquilibriumSetup other) -> EquilibriumSetup &
Assign a copy of an EquilibriumSetup object to this.
auto assembleChemicalPropsJacobianBegin() -> void
Enable recording of derivatives of the chemical properties with respect to *(n, p,...
auto getGibbsHessianX() -> MatrixXdConstRef
Get the updated Hessian matrix of the Gibbs energy with respect to x.
auto Aeq() const -> MatrixXdConstRef
Return the block Aeq corresponding to variables n in the coefficient matrix Aex = [Aen Aeq] of the op...
auto dims() const -> EquilibriumDims const &
Return the dimensions of the variables in the equilibrium problem.
auto getGibbsHessianP() -> MatrixXdConstRef
Get the updated Hessian matrix of the Gibbs energy with respect to p.
auto getConstraintResidualsGradC() -> MatrixXdConstRef
Get the updated Jacobian of the equilibrium constraints with respect to c.
auto getConstraintResidualsGradX() -> MatrixXdConstRef
Get the updated Jacobian of the equilibrium constraints with respect to x.
auto getConstraintResidualsGradP() -> MatrixXdConstRef
Get the updated Jacobian of the equilibrium constraints with respect to p.
EquilibriumSetup(EquilibriumSpecs const &specs)
Construct an EquilibriumSetup object with given specifications.
auto getConstraintResiduals() -> MatrixXdConstRef
Get the updated residuals of the equilibrium constraints.
The class used to define conditions to be satisfied at chemical equilibrium.
Definition: EquilibriumSpecs.hpp:281
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
Eigen::Ref< const VectorXl > VectorXlConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:68
Eigen::Ref< const VectorXr > VectorXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:60
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
std::unique_ptr< T > Ptr
Convenient alias for std::unique_ptr<T>.
Definition: Types.hpp:102
Eigen::Ref< const VectorXd > VectorXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:76
Eigen::VectorXd VectorXd
Convenient alias to Eigen type.
Definition: Matrix.hpp:74
Eigen::Ref< const MatrixXd > MatrixXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:139
The dimensions of the variables in a chemical equilibrium problem.
Definition: EquilibriumDims.hpp:47
The options for the equilibrium calculations.
Definition: EquilibriumOptions.hpp:43