Reaktoro 
A unified framework for modeling chemically reactive systems
EquilibriumInverseProblem.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <memory>
22 
23 // Reaktoro includes
24 #include <Reaktoro/Math/Matrix.hpp>
25 
26 namespace Reaktoro {
27 
28 // Forward declarations
29 class ChemicalSystem;
30 class ChemicalState;
31 class Partition;
32 struct EquilibriumResult;
33 
36 {
39 
42 
45 };
46 
57 {
58 public:
60  explicit EquilibriumInverseProblem(const ChemicalSystem& system);
61 
64 
66  virtual ~EquilibriumInverseProblem();
67 
69  auto operator=(EquilibriumInverseProblem other) -> EquilibriumInverseProblem&;
70 
73  auto setPartition(const Partition& partition) -> EquilibriumInverseProblem&;
74 
78  auto setTemperature(double val) -> EquilibriumInverseProblem&;
79 
84  auto setTemperature(double val, std::string units) -> EquilibriumInverseProblem&;
85 
89  auto setPressure(double val) -> EquilibriumInverseProblem&;
90 
95  auto setPressure(double val, std::string units) -> EquilibriumInverseProblem&;
96 
99  auto setElementInitialAmounts(const Vector& values) -> EquilibriumInverseProblem&;
100 
105  auto add(std::string name, double amount, std::string units) -> EquilibriumInverseProblem&;
106 
111  auto fixSpeciesAmount(std::string species, double value, std::string units) -> EquilibriumInverseProblem&;
112 
118  auto fixSpeciesAmount(std::string species, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
119 
124  auto fixSpeciesMass(std::string species, double value, std::string units) -> EquilibriumInverseProblem&;
125 
131  auto fixSpeciesMass(std::string species, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
132 
136  auto fixSpeciesActivity(std::string species, double value) -> EquilibriumInverseProblem&;
137 
142  auto fixSpeciesActivity(std::string species, double value, std::string titrant) -> EquilibriumInverseProblem&;
143 
149  auto fixSpeciesActivity(std::string species, double value, std::string titrant1, std::string titrant2) -> EquilibriumInverseProblem&;
150 
155  auto fixSpeciesFugacity(std::string species, double value, std::string units) -> EquilibriumInverseProblem&;
156 
162  auto fixSpeciesFugacity(std::string species, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
163 
169  auto fixPhaseAmount(std::string phase, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
170 
176  auto fixPhaseMass(std::string phase, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
177 
183  auto fixPhaseVolume(std::string phase, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
184 
190  auto fixPhaseSetVolume(const std::vector<std::string>& phases, double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
191 
194  auto pH(double value) -> EquilibriumInverseProblem&;
195 
199  auto pH(double value, std::string titrant) -> EquilibriumInverseProblem&;
200 
205  auto pH(double value, std::string titrant1, std::string titrant2) -> EquilibriumInverseProblem&;
206 
209  auto pE(double value) -> EquilibriumInverseProblem&;
210 
214  auto pE(double value, std::string titrant) -> EquilibriumInverseProblem&;
215 
218  auto Eh(double value, std::string units) -> EquilibriumInverseProblem&;
219 
224  auto Eh(double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
225 
230  auto alkalinity(double value, std::string units, std::string titrant) -> EquilibriumInverseProblem&;
231 
233  auto system() const -> const ChemicalSystem&;
234 
236  auto partition() const -> const Partition&;
237 
239  auto temperature() const -> double;
240 
242  auto pressure() const -> double;
243 
245  auto numConstraints() const -> Index;
246 
248  auto numTitrants() const -> Index;
249 
254  auto formulaMatrixTitrants() const -> Matrix;
255 
259  auto elementInitialAmounts() const -> Vector;
260 
262  auto titrantInitialAmounts() const -> Vector;
263 
267  auto residualEquilibriumConstraints(const Vector& x, const ChemicalState& state) const -> ResidualEquilibriumConstraints;
268 
271  auto solve(ChemicalState& state) -> EquilibriumResult;
272 
273 private:
274  struct Impl;
275 
276  std::unique_ptr<Impl> pimpl;
277 };
278 
279 } // namespace Reaktoro
Eigen::MatrixXd Matrix
Define an alias to the matrix type of the Eigen library.
Definition: Matrix.hpp:387
auto amount(double value, Index size, Index index) -> ChemicalScalarBase< double, decltype(unit(size, index))>
Return a ChemicalScalar representation of a mole amount of a species.
Definition: ChemicalScalar.hpp:208
Matrix ddx
The partial derivatives of the residuals w.r.t. titrant amounts x.
Definition: EquilibriumInverseProblem.hpp:41
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:47
A type used to define the result of the evaluation of a system of equilibrium constraints.
Definition: EquilibriumInverseProblem.hpp:35
A class used for defining an inverse equilibrium problem.
Definition: EquilibriumInverseProblem.hpp:56
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
A type used to describe the result of an equilibrium calculation.
Definition: EquilibriumResult.hpp:27
Provide a computational representation of the Partition of a chemical system.
Definition: Partition.hpp:55
Vector val
The residual values of the equilibrium constraints.
Definition: EquilibriumInverseProblem.hpp:38
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
Definition: Units.cpp:38
Provides a computational representation of the state of a multiphase chemical system.
Definition: ChemicalState.hpp:60
Matrix ddn
The partial derivatives of the residuals w.r.t. species amounts n.
Definition: EquilibriumInverseProblem.hpp:44
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24