Reaktoro
A unified framework for modeling chemically reactive systems
AqueousMixture.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 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/Thermodynamics/Species/AqueousSpecies.hpp>
22 #include <Reaktoro/Thermodynamics/Mixtures/GeneralMixture.hpp>
23 
24 namespace Reaktoro {
25 
29 {
32 
35 
38 
41 
44 
47 };
48 
59 class AqueousMixture : public GeneralMixture<AqueousSpecies>
60 {
61 public:
64 
67  explicit AqueousMixture(const std::vector<AqueousSpecies>& species);
68 
70  virtual ~AqueousMixture();
71 
73  auto setWaterDensity(const ThermoScalarFunction& rho) -> void;
74 
76  auto setWaterDielectricConstant(const ThermoScalarFunction& epsilon) -> void;
77 
84  auto setInterpolationPoints(const std::vector<double>& temperatures, const std::vector<double>& pressures) -> void;
85 
87  auto numNeutralSpecies() const -> unsigned;
88 
90  auto numChargedSpecies() const -> unsigned;
91 
93  auto indicesNeutralSpecies() const -> const Indices&;
94 
96  auto indicesChargedSpecies() const -> const Indices&;
97 
99  auto indicesCations() const -> const Indices&;
100 
102  auto indicesAnions() const -> const Indices&;
103 
105  auto indexWater() const -> Index;
106 
110  auto indexNeutralSpecies(std::string name) const -> Index;
111 
115  auto indexNeutralSpeciesAny(const std::vector<std::string>& names) const -> Index;
116 
120  auto indexChargedSpecies(std::string name) const -> Index;
121 
125  auto indexChargedSpeciesAny(const std::vector<std::string>& names) const -> Index;
126 
130  auto indexCation(std::string name) const -> Index;
131 
135  auto indexAnion(std::string name) const -> Index;
136 
138  auto namesNeutralSpecies() const -> std::vector<std::string>;
139 
141  auto namesChargedSpecies() const -> std::vector<std::string>;
142 
144  auto namesCations() const -> std::vector<std::string>;
145 
147  auto namesAnions() const -> std::vector<std::string>;
148 
150  auto chargesChargedSpecies() const -> Vector;
151 
153  auto chargesCations() const -> Vector;
154 
156  auto chargesAnions() const -> Vector;
157 
163  auto dissociationMatrix() const -> MatrixConstRef;
164 
168  auto molalities(VectorConstRef n) const -> ChemicalVector;
169 
174 
178  auto effectiveIonicStrength(const ChemicalVector& m) const -> ChemicalScalar;
179 
184 
190 
191 private:
193  Index idx_water;
194 
196  Indices idx_neutral_species;
197 
199  Indices idx_charged_species;
200 
202  Indices idx_cations;
203 
205  Indices idx_anions;
206 
208  Matrix dissociation_matrix;
209 
211  ThermoScalarFunction rho, rho_default;
212 
214  ThermoScalarFunction epsilon, epsilon_default;
215 
217  void initializeIndices(const std::vector<AqueousSpecies>& species);
218 
220  void initializeDissociationMatrix(const std::vector<AqueousSpecies>& species);
221 };
222 
223 } // namespace Reaktoro
auto indicesCations() const -> const Indices &
Return the indices of the cations in the aqueous mixture.
Definition: AqueousMixture.cpp:116
ChemicalScalar Is
The stoichiometric ionic strength of the aqueous mixture and their partial derivatives (in units of m...
Definition: AqueousMixture.hpp:40
Provide a base of implementation for the mixture classes.
Definition: GeneralMixture.hpp:58
ChemicalScalar Ie
The effective ionic strength of the aqueous mixture and their partial derivatives (in units of mol/kg...
Definition: AqueousMixture.hpp:37
auto names(const NamedValues &values) -> std::vector< std::string >
Return the names of the entries in a container.
Definition: Utils.hxx:22
auto state(Temperature T, Pressure P, VectorConstRef n) const -> AqueousMixtureState
Calculate the state of the aqueous mixture.
Definition: AqueousMixture.cpp:284
auto name() const -> std::string
Return the name of the mixture.
Definition: GeneralMixture.hpp:149
auto indicesAnions() const -> const Indices &
Return the indices of the anions in the aqueous mixture.
Definition: AqueousMixture.cpp:121
auto indexNeutralSpeciesAny(const std::vector< std::string > &names) const -> Index
Return the local index of the first neutral species among the neutral species in the aqueous mixture ...
Definition: AqueousMixture.cpp:142
auto indexAnion(std::string name) const -> Index
Return the local index of an anion among the anions in the aqueous mixture.
Definition: AqueousMixture.cpp:166
A type that describes pressure in units of Pa.
Definition: ThermoScalar.hpp:194
auto indexChargedSpeciesAny(const std::vector< std::string > &names) const -> Index
Return the local index of the first charged species among the charged species in the aqueous mixture ...
Definition: AqueousMixture.cpp:154
auto setWaterDielectricConstant(const ThermoScalarFunction &epsilon) -> void
Set a customized dielectric constant function for water.
Definition: AqueousMixture.cpp:85
auto species() const -> const std::vector< AqueousSpecies > &
Return the species that compose the mixture.
Definition: GeneralMixture.hpp:155
auto indexCation(std::string name) const -> Index
Return the local index of a cation among the cations in the aqueous mixture.
Definition: AqueousMixture.cpp:160
auto dissociationMatrix() const -> MatrixConstRef
Return the dissociation matrix of the aqueous complexes into ions.
Definition: AqueousMixture.cpp:131
auto setWaterDensity(const ThermoScalarFunction &rho) -> void
Set a customized density function for water.
Definition: AqueousMixture.cpp:80
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
A type used to describe an aqueous mixture.
Definition: AqueousMixture.hpp:60
auto setInterpolationPoints(const std::vector< double > &temperatures, const std::vector< double > &pressures) -> void
Set the temperature and pressure interpolation points for calculation of water density and water diel...
Definition: AqueousMixture.cpp:90
A type that describes temperature in units of K.
Definition: ThermoScalar.hpp:177
ThermoScalar epsilon
The relative dielectric constant of water (no units)
Definition: AqueousMixture.hpp:34
auto molalities(VectorConstRef n) const -> ChemicalVector
Calculate the molalities of the aqueous species and its molar derivatives.
Definition: AqueousMixture.cpp:207
auto effectiveIonicStrength(const ChemicalVector &m) const -> ChemicalScalar
Calculate the effective ionic strength of the aqueous mixture and its molar derivatives.
Definition: AqueousMixture.cpp:258
ChemicalVector ms
The stoichiometric molalities of the ionic species and their partial derivatives (in units of mol/kg)
Definition: AqueousMixture.hpp:46
A type used to describe the state of a mixture.
Definition: GeneralMixture.hpp:37
ThermoScalar rho
The density of water (in units of kg/m3)
Definition: AqueousMixture.hpp:31
auto indicesNeutralSpecies() const -> const Indices &
Return the indices of the neutral aqueous species in the aqueous mixture.
Definition: AqueousMixture.cpp:106
auto indexChargedSpecies(std::string name) const -> Index
Return the local index of a charged species among the charged species in the aqueous mixture.
Definition: AqueousMixture.cpp:148
auto stoichiometricMolalities(const ChemicalVector &m) const -> ChemicalVector
Calculate the stoichiometric molalities of the ions and its molar derivatives.
Definition: AqueousMixture.cpp:233
auto indicesChargedSpecies() const -> const Indices &
Return the indices of the charged aqueous species in the aqueous mixture.
Definition: AqueousMixture.cpp:111
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
virtual ~AqueousMixture()
Destroy the AqueousMixture instance.
Definition: AqueousMixture.cpp:77
auto namesAnions() const -> std::vector< std::string >
Return the names of the anions in the aqueous mixture.
Definition: AqueousMixture.cpp:187
ChemicalScalarBase< double, RowVector > ChemicalScalar
A type that represents a chemical property and its derivatives.
Definition: ChemicalScalar.hpp:35
auto namesNeutralSpecies() const -> std::vector< std::string >
Return the names of the neutral species in the aqueous mixture.
Definition: AqueousMixture.cpp:172
A type used to describe the state of an aqueous mixture.
Definition: AqueousMixture.hpp:29
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto numChargedSpecies() const -> unsigned
Return the number of charged aqueous species in the aqueous mixture.
Definition: AqueousMixture.cpp:101
Eigen::MatrixXd Matrix
Alias to Eigen type MatrixXd.
Definition: Matrix.hpp:42
ChemicalVectorBase< Vector, Vector, Vector, Matrix > ChemicalVector
A type that represents a vector of chemical properties and their derivatives.
Definition: ChemicalVector.hpp:39
auto namesCations() const -> std::vector< std::string >
Return the names of the cations in the aqueous mixture.
Definition: AqueousMixture.cpp:182
auto chargesAnions() const -> Vector
Return the charges of the anions in the aqueous mixture.
Definition: AqueousMixture.cpp:202
auto namesChargedSpecies() const -> std::vector< std::string >
Return the names of the charged species in the aqueous mixture.
Definition: AqueousMixture.cpp:177
auto numNeutralSpecies() const -> unsigned
Return the number of neutral aqueous species in the aqueous mixture.
Definition: AqueousMixture.cpp:96
Eigen::Ref< const Eigen::MatrixXd > MatrixConstRef
Alias to Eigen type Ref<const MatrixXd>.
Definition: Matrix.hpp:44
auto indexWater() const -> Index
Return the index of the water species ..
Definition: AqueousMixture.cpp:126
AqueousMixture()
Construct a default AqueousMixture instance.
Definition: AqueousMixture.cpp:58
auto chargesCations() const -> Vector
Return the charges of the cations in the aqueous mixture.
Definition: AqueousMixture.cpp:197
auto chargesChargedSpecies() const -> Vector
Return the charges of the charged species in the aqueous mixture.
Definition: AqueousMixture.cpp:192
ChemicalVector m
The molalities of the aqueous species and their partial derivatives (in units of mol/kg)
Definition: AqueousMixture.hpp:43
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31
auto stoichiometricIonicStrength(const ChemicalVector &ms) const -> ChemicalScalar
Calculate the stoichiometric ionic strength of the aqueous mixture and its molar derivatives.
Definition: AqueousMixture.cpp:271
auto indexNeutralSpecies(std::string name) const -> Index
Return the local index of a neutral species among the neutral species in the aqueous mixture.
Definition: AqueousMixture.cpp:136