Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
ChemicalProps.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive phases.
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/ArrayStream.hpp>
22 #include <Reaktoro/Common/Matrix.hpp>
23 #include <Reaktoro/Common/Types.hpp>
24 #include <Reaktoro/Core/ChemicalPropsPhase.hpp>
25 #include <Reaktoro/Core/ChemicalSystem.hpp>
26 
27 namespace Reaktoro {
28 
29 // Forward declarations
30 class ChemicalState;
31 
34 {
35 public:
38 
41 
43  explicit ChemicalProps(ChemicalState const& state);
44 
47  auto update(ChemicalState const& state) -> void;
48 
53  auto update(real const& T, real const& P, ArrayXrConstRef n) -> void;
54 
57  auto update(ArrayXrConstRef u) -> void;
58 
61  auto update(ArrayXdConstRef u) -> void;
62 
65  auto updateIdeal(ChemicalState const& state) -> void;
66 
71  auto updateIdeal(real const& T, real const& P, ArrayXrConstRef n) -> void;
72 
75  auto serialize(ArrayStream<real>& stream) const -> void;
76 
79  auto serialize(ArrayStream<double>& stream) const -> void;
80 
83  auto deserialize(const ArrayStream<real>& stream) -> void;
84 
87  auto deserialize(const ArrayStream<double>& stream) -> void;
88 
99  auto stateid() const -> Index;
100 
102  auto system() const -> ChemicalSystem const&;
103 
107 
109  auto extra() const -> const Map<String, Any>&;
110 
112  auto temperature() const -> real;
113 
115  auto pressure() const -> real;
116 
118  auto charge() const -> real;
119 
122  auto chargeInPhase(StringOrIndex phase) const -> real;
123 
126  auto chargeAmongSpecies(Indices const& indices) const -> real;
127 
130  auto elementAmount(StringOrIndex element) const -> real;
131 
135  auto elementAmountInPhase(StringOrIndex element, StringOrIndex phase) const -> real;
136 
140  auto elementAmountAmongSpecies(StringOrIndex element, Indices const& indices) const -> real;
141 
144  auto elementMass(StringOrIndex element) const -> real;
145 
149  auto elementMassInPhase(StringOrIndex element, StringOrIndex phase) const -> real;
150 
154  auto elementMassAmongSpecies(StringOrIndex element, Indices const& indices) const -> real;
155 
157  auto elementAmounts() const -> ArrayXr;
158 
162 
165  auto elementAmountsAmongSpecies(Indices const& indices) const -> ArrayXr;
166 
168  auto componentAmounts() const -> ArrayXr;
169 
173 
176  auto componentAmountsAmongSpecies(Indices const& indices) const -> ArrayXr;
177 
180  auto speciesAmount(StringOrIndex species) const -> real;
181 
184  auto speciesMass(StringOrIndex species) const -> real;
185 
188  auto speciesMoleFraction(StringOrIndex species) const -> real;
189 
192  auto speciesConcentration(StringOrIndex species) const -> real;
193 
196  auto speciesConcentrationLg(StringOrIndex species) const -> real;
197 
200  auto speciesConcentrationLn(StringOrIndex species) const -> real;
201 
205 
209 
213 
216  auto speciesActivity(StringOrIndex species) const -> real;
217 
220  auto speciesActivityLg(StringOrIndex species) const -> real;
221 
224  auto speciesActivityLn(StringOrIndex species) const -> real;
225 
229 
232  auto speciesStandardVolume(StringOrIndex species) const -> real;
233 
236  auto speciesStandardVolumeT(StringOrIndex species) const -> real;
237 
240  auto speciesStandardVolumeP(StringOrIndex species) const -> real;
241 
245 
249 
252  auto speciesStandardEntropy(StringOrIndex species) const -> real;
253 
257 
261 
265 
269 
272 
274  auto speciesMasses() const -> ArrayXr;
275 
278 
281 
284 
287 
290 
293 
296 
299 
302 
305 
308 
311 
314 
317 
320 
323 
327  auto surfaceArea(StringOrIndex const& surface) const -> real;
328 
330  auto surfaceAreas() const -> ArrayXr;
331 
333  auto molarVolume() const -> real;
334 
336  auto molarVolumeT() const -> real;
337 
339  auto molarVolumeP() const -> real;
340 
342  auto molarGibbsEnergy() const -> real;
343 
345  auto molarEnthalpy() const -> real;
346 
348  auto molarEntropy() const -> real;
349 
351  auto molarInternalEnergy() const -> real;
352 
354  auto molarHelmholtzEnergy() const -> real;
355 
357  auto molarHeatCapacityConstP() const -> real;
358 
360  auto molarHeatCapacityConstV() const -> real;
361 
363  auto specificVolume() const -> real;
364 
366  auto specificVolumeT() const -> real;
367 
369  auto specificVolumeP() const -> real;
370 
372  auto specificGibbsEnergy() const -> real;
373 
375  auto specificEnthalpy() const -> real;
376 
378  auto specificEntropy() const -> real;
379 
381  auto specificInternalEnergy() const -> real;
382 
384  auto specificHelmholtzEnergy() const -> real;
385 
388 
391 
393  auto density() const -> real;
394 
396  auto amount() const -> real;
397 
399  auto mass() const -> real;
400 
402  auto volume() const -> real;
403 
405  auto volumeT() const -> real;
406 
408  auto volumeP() const -> real;
409 
411  auto gibbsEnergy() const -> real;
412 
414  auto enthalpy() const -> real;
415 
417  auto entropy() const -> real;
418 
420  auto internalEnergy() const -> real;
421 
423  auto helmholtzEnergy() const -> real;
424 
426  auto heatCapacityConstP() const -> real;
427 
429  auto heatCapacityConstV() const -> real;
430 
433  auto reactionRate(StringOrIndex reaction) const -> real;
434 
436  auto reactionRates() const -> ArrayXr;
437 
440 
442  auto indicesPhasesWithStates(std::initializer_list<StateOfMatter> soms) const -> Indices;
443 
446 
449 
452 
454  auto indicesSpeciesInPhasesWithStates(std::initializer_list<StateOfMatter> soms) const -> Indices;
455 
458 
461 
463  auto output(std::ostream& out) const -> void;
464 
466  auto output(String const& filename) const -> void;
467 
469  operator VectorXr() const;
470 
472  operator VectorXd() const;
473 
474 private:
476  Index mstateid = 0;
477 
479  ChemicalSystem msystem;
480 
482  real T;
483 
485  real P;
486 
488  ArrayXr n;
489 
491  ArrayXr s;
492 
494  ArrayXr Ts;
495 
497  ArrayXr Ps;
498 
500  ArrayXr nsum;
501 
503  ArrayXr msum;
504 
506  ArrayXr x;
507 
509  ArrayXr G0;
510 
512  ArrayXr H0;
513 
515  ArrayXr V0;
516 
518  ArrayXr VT0;
519 
521  ArrayXr VP0;
522 
524  ArrayXr Cp0;
525 
527  ArrayXr Vx;
528 
530  ArrayXr VxT;
531 
533  ArrayXr VxP;
534 
536  ArrayXr Vxi;
537 
539  ArrayXr Gx;
540 
542  ArrayXr Hx;
543 
545  ArrayXr Cpx;
546 
548  ArrayXr ln_g;
549 
551  ArrayXr ln_a;
552 
554  ArrayXr u;
555 
557  Vec<StateOfMatter> som;
558 
562  Map<String, Any> m_extra;
563 
566  auto phasePropsRef(StringOrIndex phase) -> ChemicalPropsPhaseRef;
567 };
568 
570 auto operator<<(std::ostream& out, ChemicalProps const& props) -> std::ostream&;
571 
572 } // namespace Reaktoro
The class used to serialize/deserialize data using array.
Definition: ArrayStream.hpp:28
The base type for chemical properties of a phase and its species.
Definition: ChemicalPropsPhase.hpp:175
The class that computes chemical properties of a chemical system.
Definition: ChemicalProps.hpp:34
auto molarVolume() const -> real
Return the molar volume of the system (in m³/mol).
auto molarVolumeP() const -> real
Return the pressure derivative of the molar volume of the system (in m³/(mol·Pa)).
auto temperature() const -> real
Return the temperature of the system (in K).
auto speciesStandardGibbsEnergy(StringOrIndex species) const -> real
Return the standard partial molar Gibbs energy of formation of a species in the system (in J/mol).
auto speciesStandardVolumesT() const -> ArrayXrConstRef
Return the temperature derivative of the standard molar volumes of the species in the system (in m³/(...
auto specificGibbsEnergy() const -> real
Return the specific Gibbs energy of formation of the system (in J/kg).
auto indicesPhasesWithFluidState() const -> Indices
Return the indices of the phases in liquid, gaseous, or supercritical states.
auto phaseProps(StringOrIndex phase) const -> ChemicalPropsPhaseConstRef
Return the chemical properties of a phase with given index.
auto pressure() const -> real
Return the pressure of the system (in Pa).
auto speciesConcentration(StringOrIndex species) const -> real
Return the concentration (activity divided by activity coefficient) of a species in the system.
auto surfaceArea(StringOrIndex const &surface) const -> real
Return the area of a surface in the system (in m2).
auto volumeT() const -> real
Return the temperature derivative of the volume of the system (in m³/K).
auto speciesStandardHeatCapacityConstP(StringOrIndex species) const -> real
Return the standard partial molar isobaric heat capacity of the species a the system (in J/(mol·K)).
auto speciesStandardEntropy(StringOrIndex species) const -> real
Return the standard partial molar entropy of formation of the species a the system (in J/(mol·K)).
auto updateIdeal(ChemicalState const &state) -> void
Update the chemical properties of the system using ideal activity models.
auto speciesStandardInternalEnergies() const -> ArrayXr
Return the standard partial molar internal energies of formation of the species in the system (in J/m...
auto speciesStandardVolumeP(StringOrIndex species) const -> real
Return the pressure derivative of the standard partial molar volume of a species in the system (in m³...
ChemicalProps()
Construct a default uninitialized ChemicalProps object.
auto mass() const -> real
Return the sum of species masses in the system (in kg).
auto speciesActivity(StringOrIndex species) const -> real
Return the activity of a species in the system.
ChemicalProps(ChemicalState const &state)
Construct a ChemicalProps object with given chemical state of the system.
auto speciesActivitiesLn() const -> ArrayXrConstRef
Return the ln activities of the species in the system.
auto speciesStandardVolumeT(StringOrIndex species) const -> real
Return the temperature derivative of the standard partial molar volume of a species in the system (in...
auto heatCapacityConstP() const -> real
Return the isobaric heat capacity of the system (in J/K).
auto speciesChemicalPotentials() const -> ArrayXrConstRef
Return the chemical potentials of the species in the system (in J/mol).
auto speciesStandardHeatCapacitiesConstP() const -> ArrayXrConstRef
Return the standard partial molar isobaric heat capacities of the species in the system (in J/(mol·K)...
auto speciesMasses() const -> ArrayXr
Return the masses of the species in the system (in kg).
auto speciesStandardEntropies() const -> ArrayXr
Return the standard partial molar entropies of formation of the species in the system (in J/(mol·K)).
auto speciesStandardGibbsEnergies() const -> ArrayXrConstRef
Return the standard partial molar Gibbs energies of formation of the species in the system (in J/mol)...
auto serialize(ArrayStream< double > &stream) const -> void
Serialize the chemical properties into the array stream stream.
auto speciesAmount(StringOrIndex species) const -> real
Return the amount of a species in the system (in mol).
auto chargeAmongSpecies(Indices const &indices) const -> real
Return the amount of electric charge among a group of species in the system (in mol).
auto stateid() const -> Index
Return the state identification number of this ChemicalProps object.
auto indicesPhasesWithSolidState() const -> Indices
Return the indices of the phases in solid states.
auto indicesSpeciesInPhasesWithState(StateOfMatter som) const -> Indices
Return the indices of the phases with a given state of matter.
auto entropy() const -> real
Return the entropy of formation of the system (in J/K).
auto charge() const -> real
Return the amount of electric charge in the system (in mol).
auto specificInternalEnergy() const -> real
Return the specific internal energy of formation of the system (in J/kg).
auto elementAmountAmongSpecies(StringOrIndex element, Indices const &indices) const -> real
Return the amount of an element among a group of species in the system (in mol).
auto extra() const -> const Map< String, Any > &
Return the extra data produced during the evaluation of activity models.
auto speciesStandardHelmholtzEnergy(StringOrIndex species) const -> real
Return the standard partial molar Helmholtz energy of formation of a species in the system (in J/mol)...
auto speciesStandardEnthalpies() const -> ArrayXrConstRef
Return the standard partial molar enthalpies of formation of the species in the system (in J/mol).
auto speciesActivityLg(StringOrIndex species) const -> real
Return the lg activity of a species in the system.
auto speciesConcentrationLg(StringOrIndex species) const -> real
Return the lg concentration (activity divided by activity coefficient) of a species in the system.
auto volume() const -> real
Return the volume of the system (in m³).
auto update(real const &T, real const &P, ArrayXrConstRef n) -> void
Update the chemical properties of the system.
auto molarHeatCapacityConstV() const -> real
Return the molar isochoric heat capacity of the system (in J/(mol·K)).
auto speciesActivityLn(StringOrIndex species) const -> real
Return the ln activity of a species in the system.
auto indicesSpeciesInPhasesWithSolidState() const -> Indices
Return the indices of the phases with solid states.
auto speciesActivityCoefficientsLn() const -> ArrayXrConstRef
Return the ln activity coefficients of the species in the system.
auto elementAmounts() const -> ArrayXr
Return the amounts of the elements in the system (in mol).
auto indicesSpeciesInPhasesWithStates(std::initializer_list< StateOfMatter > soms) const -> Indices
Return the indices of the phases with one of the given states of matter.
auto speciesChemicalPotential(StringOrIndex species) const -> real
Return the chemical potential of a species in the system.
auto speciesStandardVolume(StringOrIndex species) const -> real
Return the standard partial molar volume of a species in the system (in m³/mol).
auto update(ArrayXdConstRef u) -> void
Update the chemical properties of the system with serialized data.
auto output(std::ostream &out) const -> void
Output the chemical properties of the system to a stream.
auto specificVolume() const -> real
Return the specific volume of the system (in m³/kg).
auto speciesStandardVolumes() const -> ArrayXrConstRef
Return the standard partial molar volumes of the species in the system (in m³/mol).
auto specificEnthalpy() const -> real
Return the specific enthalpy of formation of the system (in J/kg).
auto indicesPhasesWithState(StateOfMatter som) const -> Indices
Return the indices of the phases in a given state of matter.
auto speciesAmounts() const -> ArrayXrConstRef
Return the amounts of the species in the system (in mol).
auto specificVolumeT() const -> real
Return the temperature derivative of the specific volume of the system (in m³/(kg·K)).
auto specificHeatCapacityConstV() const -> real
Return the specific isochoric heat capacity of the system (in J/(kg·K)).
auto speciesStandardInternalEnergy(StringOrIndex species) const -> real
Return the standard partial molar internal energy of formation of a species in the system (in J/mol).
auto updateIdeal(real const &T, real const &P, ArrayXrConstRef n) -> void
Update the chemical properties of the system using ideal activity models.
auto speciesPartialMolarVolumes() const -> ArrayXr
Return the partial molar volumes of the species in the system (in m³/mol).
auto speciesStandardEnthalpy(StringOrIndex species) const -> real
Return the standard partial molar enthalpy of formation of a species in the system (in J/mol).
auto specificHeatCapacityConstP() const -> real
Return the specific isobaric heat capacity of the system (in J/(kg·K)).
auto elementMass(StringOrIndex element) const -> real
Return the mass of an element in the system (in kg).
auto componentAmounts() const -> ArrayXr
Return the amounts of the conservative components (elements and charge) in the system (in mol).
auto indicesSpeciesInPhasesWithFluidState() const -> Indices
Return the indices of the phases with liquid, gaseous, or supercritical states.
auto componentAmountsInPhase(StringOrIndex phase) const -> ArrayXr
Return the amounts of the conservative components (elements and charge) in a phase of the system (in ...
auto indicesPhasesWithStates(std::initializer_list< StateOfMatter > soms) const -> Indices
Return the indices of the phases with one of the given states of matter.
auto speciesConcentrationsLn() const -> ArrayXr
Return the ln concentrations (activity divided by activity coefficient) of the species in the system.
auto internalEnergy() const -> real
Return the internal energy of formation of the system (in J).
auto molarGibbsEnergy() const -> real
Return the molar Gibbs energy of formation of the system (in J/mol).
auto elementAmount(StringOrIndex element) const -> real
Return the amount of an element in the system (in mol).
auto molarHeatCapacityConstP() const -> real
Return the molar isobaric heat capacity of the system (in J/(mol·K)).
auto molarHelmholtzEnergy() const -> real
Return the molar Helmholtz energy of formation of the system (in J/mol).
auto speciesStandardHeatCapacityConstV(StringOrIndex species) const -> real
Return the standard partial molar isochoric heat capacity of the species a the system (in J/(mol·K)).
auto elementAmountsInPhase(StringOrIndex phase) const -> ArrayXr
Return the amounts of the elements in a phase of the system (in mol).
auto componentAmountsAmongSpecies(Indices const &indices) const -> ArrayXr
Return the amounts of the conservative components (elements and charge) among a group of species in t...
auto reactionRates() const -> ArrayXr
Return the reaction rates of the kinetic reactions in the system (in mol/s).
ChemicalProps(ChemicalSystem const &system)
Construct an uninitialized ChemicalProps object with given chemical system.
auto system() const -> ChemicalSystem const &
Return the chemical system associated with these chemical properties.
auto specificHelmholtzEnergy() const -> real
Return the specific Helmholtz energy of formation of the system (in J/kg).
auto serialize(ArrayStream< real > &stream) const -> void
Serialize the chemical properties into the array stream stream.
auto speciesActivityCoefficientLn(StringOrIndex species) const -> real
Return the ln activity coefficient of a species in the system.
auto helmholtzEnergy() const -> real
Return the Helmholtz energy of formation of the system (in J).
auto amount() const -> real
Return the sum of species amounts in the system (in mol).
auto elementAmountInPhase(StringOrIndex element, StringOrIndex phase) const -> real
Return the amount of an element in a phase of the system (in mol).
auto molarEntropy() const -> real
Return the molar entropy of formation of the system (in J/(mol·K)).
auto speciesMoleFractions() const -> ArrayXrConstRef
Return the mole fractions of the species in the system relative to the phase where they exist.
auto elementAmountsAmongSpecies(Indices const &indices) const -> ArrayXr
Return the amounts of the elements among a group of species in the system (in mol).
auto speciesActivityCoefficient(StringOrIndex species) const -> real
Return the activity coefficient of a species in the system.
auto speciesMass(StringOrIndex species) const -> real
Return the mass of a species in the system.
auto surfaceAreas() const -> ArrayXr
Return the areas of all surfaces in the system (in m2).
auto update(ChemicalState const &state) -> void
Update the chemical properties of the system.
auto speciesStandardVolumesP() const -> ArrayXrConstRef
Return the pressure derivative of the standard molar volumes of the species in the system (in m³/(mol...
auto heatCapacityConstV() const -> real
Return the isochoric heat capacity of the system (in J/K).
auto molarInternalEnergy() const -> real
Return the molar internal energy of formation of the system (in J/mol).
auto volumeP() const -> real
Return the pressure derivative of the volume of the system (in m³/Pa).
auto elementMassInPhase(StringOrIndex element, StringOrIndex phase) const -> real
Return the mass of an element in the system (in kg).
auto gibbsEnergy() const -> real
Return the Gibbs energy of formation of the system (in J).
auto chargeInPhase(StringOrIndex phase) const -> real
Return the amount of electric charge in a phase of the system (in mol).
auto speciesStandardHeatCapacitiesConstV() const -> ArrayXr
Return the standard partial molar isochoric heat capacities of the species in the system (in J/(mol·K...
auto deserialize(const ArrayStream< double > &stream) -> void
Update the chemical properties of the system using the array stream stream.
auto update(ArrayXrConstRef u) -> void
Update the chemical properties of the system with serialized data.
auto molarVolumeT() const -> real
Return the temperature derivative of the molar volume of the system (in m³/(mol·K)).
auto deserialize(const ArrayStream< real > &stream) -> void
Update the chemical properties of the system using the array stream stream.
auto reactionRate(StringOrIndex reaction) const -> real
Return the rate of a kinetic reaction in the system (in mol/s).
auto speciesConcentrationLn(StringOrIndex species) const -> real
Return the ln concentration (activity divided by activity coefficient) of a species in the system.
auto speciesStandardHelmholtzEnergies() const -> ArrayXr
Return the standard partial molar Helmholtz energies of formation of the species in the system (in J/...
auto enthalpy() const -> real
Return the enthalpy of formation of the system (in J).
auto speciesActivityCoefficientLg(StringOrIndex species) const -> real
Return the lg activity coefficient of a species in the system.
auto specificEntropy() const -> real
Return the specific entropy of formation of the system (in J/(kg·K)).
auto specificVolumeP() const -> real
Return the pressure derivative of the specific volume of the system (in m³/(kg·Pa)).
auto elementMassAmongSpecies(StringOrIndex element, Indices const &indices) const -> real
Return the mass of an element among a group of species in the system (in kg).
auto speciesMoleFraction(StringOrIndex species) const -> real
Return the mole fraction of a species relative to the phase where it exists.
auto density() const -> real
Return the density of the system (in kg/m³).
auto molarEnthalpy() const -> real
Return the molar enthalpy of formation of the system (in J/mol).
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
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
std::vector< T > Vec
Convenient alias for std::vector<T>.
Definition: Types.hpp:66
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
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
autodiff::VectorXreal VectorXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:58
Eigen::Ref< const ArrayXd > ArrayXdConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:105
std::any Any
Convenient alias for std::any.
Definition: Types.hpp:125
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
StateOfMatter
The list of states of matter for phases.
Definition: StateOfMatter.hpp:27
Eigen::Ref< const ArrayXr > ArrayXrConstRef
Convenient alias to Eigen type.
Definition: Matrix.hpp:89
autodiff::ArrayXreal ArrayXr
Convenient alias to Eigen type.
Definition: Matrix.hpp:87
std::unordered_map< Key, T > Map
Convenient alias for std::unordered_map<Key, T>.
Definition: Types.hpp:74