Reaktoro  v2.13.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 
253 
256  auto speciesStandardEntropy(StringOrIndex species) const -> real;
257 
261 
265 
269 
273 
276 
278  auto speciesMasses() const -> ArrayXr;
279 
282 
285 
288 
291 
294 
297 
300 
303 
306 
309 
312 
315 
318 
321 
324 
327 
331  auto surfaceArea(StringOrIndex const& surface) const -> real;
332 
334  auto surfaceAreas() const -> ArrayXr;
335 
337  auto molarVolume() const -> real;
338 
340  auto molarVolumeT() const -> real;
341 
343  auto molarVolumeP() const -> real;
344 
346  auto molarGibbsEnergy() const -> real;
347 
349  auto molarEnthalpy() const -> real;
350 
352  auto molarEntropy() const -> real;
353 
355  auto molarInternalEnergy() const -> real;
356 
358  auto molarHelmholtzEnergy() const -> real;
359 
361  auto molarHeatCapacityConstP() const -> real;
362 
364  auto molarHeatCapacityConstV() const -> real;
365 
367  auto specificVolume() const -> real;
368 
370  auto specificVolumeT() const -> real;
371 
373  auto specificVolumeP() const -> real;
374 
376  auto specificGibbsEnergy() const -> real;
377 
379  auto specificEnthalpy() const -> real;
380 
382  auto specificEntropy() const -> real;
383 
385  auto specificInternalEnergy() const -> real;
386 
388  auto specificHelmholtzEnergy() const -> real;
389 
392 
395 
397  auto density() const -> real;
398 
400  auto amount() const -> real;
401 
403  auto mass() const -> real;
404 
406  auto volume() const -> real;
407 
409  auto volumeT() const -> real;
410 
412  auto volumeP() const -> real;
413 
415  auto gibbsEnergy() const -> real;
416 
418  auto enthalpy() const -> real;
419 
421  auto entropy() const -> real;
422 
424  auto internalEnergy() const -> real;
425 
427  auto helmholtzEnergy() const -> real;
428 
430  auto heatCapacityConstP() const -> real;
431 
433  auto heatCapacityConstV() const -> real;
434 
437  auto reactionRate(StringOrIndex reaction) const -> real;
438 
440  auto reactionRates() const -> ArrayXr;
441 
444 
446  auto indicesPhasesWithStates(std::initializer_list<StateOfMatter> soms) const -> Indices;
447 
450 
453 
456 
458  auto indicesSpeciesInPhasesWithStates(std::initializer_list<StateOfMatter> soms) const -> Indices;
459 
462 
465 
467  auto output(std::ostream& out) const -> void;
468 
470  auto output(String const& filename) const -> void;
471 
473  operator VectorXr() const;
474 
476  operator VectorXd() const;
477 
478 private:
480  Index mstateid = 0;
481 
483  ChemicalSystem msystem;
484 
486  real T;
487 
489  real P;
490 
492  ArrayXr n;
493 
495  ArrayXr s;
496 
498  ArrayXr Ts;
499 
501  ArrayXr Ps;
502 
504  ArrayXr nsum;
505 
507  ArrayXr msum;
508 
510  ArrayXr x;
511 
513  ArrayXr G0;
514 
516  ArrayXr H0;
517 
519  ArrayXr V0;
520 
522  ArrayXr VT0;
523 
525  ArrayXr VP0;
526 
528  ArrayXr Cp0;
529 
531  ArrayXr Vx;
532 
534  ArrayXr VxT;
535 
537  ArrayXr VxP;
538 
540  ArrayXr Vxi;
541 
543  ArrayXr Gx;
544 
546  ArrayXr Hx;
547 
549  ArrayXr Cpx;
550 
552  ArrayXr ln_g;
553 
555  ArrayXr ln_a;
556 
558  ArrayXr u;
559 
561  Vec<StateOfMatter> som;
562 
566  Map<String, Any> m_extra;
567 
570  auto phasePropsRef(StringOrIndex phase) -> ChemicalPropsPhaseRef;
571 };
572 
574 auto operator<<(std::ostream& out, ChemicalProps const& props) -> std::ostream&;
575 
576 } // 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 speciesCorrectiveMolarVolume(StringOrIndex species) const -> real
Return the derivatives of the corrective molar volume of each phase in the system with respect to spe...
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