Reaktoro A unified framework for modeling chemically reactive systems
ChemicalState Class Reference

Provides a computational representation of the state of a multiphase chemical system. More...

#include <ChemicalState.hpp>

## Public Member Functions

ChemicalState ()=delete
Disable the default ChemicalState constructor. More...

ChemicalState (const ChemicalSystem &system)
Construct a ChemicalState instance with standard conditions This constructor creates an instance of ChemicalState with temperature 25 °C, pressure 1 bar, and zero mole amounts for the species. More...

ChemicalState (const ChemicalState &other)
Construct a copy of a ChemicalState instance.

virtual ~ChemicalState ()
Destroy the instance.

auto operator= (ChemicalState other) -> ChemicalState &
Assign a ChemicalState instance to this instance.

auto setTemperature (double val) -> void
Set the temperature of the chemical state (in units of K)

auto setTemperature (double val, std::string units) -> void
Set the temperature of the chemical state with given units.

auto setPressure (double val) -> void
Set the pressure of the chemical state (in units of Pa)

auto setPressure (double val, std::string units) -> void
Set the pressure of the chemical state with given units.

auto setSpeciesAmounts (double val) -> void
Set the molar amounts of the species with a single value (in units of mol) More...

auto setSpeciesAmounts (VectorConstRef n) -> void
Set the molar amounts of the species (in units of mol) More...

auto setSpeciesAmounts (VectorConstRef n, const Indices &indices) -> void
Set the molar amounts of species given by their indices (in units of mol) More...

auto setSpeciesAmount (Index index, double amount) -> void
Set the molar amount of a species (in units of mol) More...

auto setSpeciesAmount (std::string name, double amount) -> void
Set the molar amount of a species (in units of mol) More...

auto setSpeciesAmount (Index index, double amount, std::string units) -> void
Set the amount of a species with given units. More...

auto setSpeciesAmount (std::string name, double amount, std::string units) -> void
Set the amount of a species with given units. More...

auto setSpeciesMass (Index index, double mass) -> void
Set the mass of a species (in units of kg) More...

auto setSpeciesMass (std::string name, double mass) -> void
Set the mass of a species (in units of kg) More...

auto setSpeciesMass (Index index, double mass, std::string units) -> void
Set the mass of a species with given units. More...

auto setSpeciesMass (std::string name, double mass, std::string units) -> void
Set the mass of a species with given units. More...

auto setSpeciesDualPotentials (VectorConstRef z) -> void
Set the dual potentials of the species (in units of J/mol). More...

auto setElementDualPotentials (VectorConstRef y) -> void
Set the dual potentials of the elements (in units of J/mol). More...

auto scaleSpeciesAmounts (double scalar) -> void
Scale the molar amounts of the species by a given scalar. More...

auto scaleSpeciesAmountsInPhase (Index index, double scalar) -> void
Scale the molar amounts of the species in a phase by a given scalar. More...

auto scalePhaseVolume (Index index, double volume) -> void
Scale the volume of a phase by adjusting the molar amounts of its species. More...

auto scalePhaseVolume (Index index, double volume, std::string units) -> void
Scale the volume of a phase by adjusting the molar amounts of its species. More...

auto scalePhaseVolume (std::string name, double volume) -> void
Scale the volume of a phase by adjusting the molar amounts of its species. More...

auto scalePhaseVolume (std::string name, double volume, std::string units) -> void
Scale the volume of a phase by adjusting the molar amounts of its species. More...

auto scaleFluidVolume (double volume) -> void
Scale the fluid volume of the chemical system. More...

auto scaleFluidVolume (double volume, std::string units) -> void
Scale the fluid volume of the chemical system with given units. More...

auto scaleSolidVolume (double volume) -> void
Scale the solid volume of the chemical system. More...

auto scaleSolidVolume (double volume, std::string units) -> void
Scale the solid volume of the chemical system with given units. More...

auto scaleVolume (double volume) -> void
Scale the volume of the chemical system by adjusting the molar amounts of all species equally. More...

auto scaleVolume (double volume, std::string units) -> void
Scale the volume of the chemical system by adjusting the molar amounts of all species equally. More...

auto system () const -> const ChemicalSystem &
Return the chemical system instance.

auto temperature () const -> double
Return the temperature of the chemical state (in units of K)

auto pressure () const -> double
Return the pressure of the chemical state (in units of Pa)

auto speciesAmounts () const -> VectorConstRef
Return the molar amounts of the species (in units of mol)

auto speciesAmounts (const Indices &indices) const -> Vector
Return the molar amounts of given species (in units of mol) More...

auto speciesAmount (Index index) const -> double
Return the molar mass of a chemical species (in units of mol) More...

auto speciesAmount (std::string name) const -> double
Return the molar amount of a chemical species (in units of mol) More...

auto speciesAmount (Index index, std::string units) const -> double
Return the amount of a chemical species with given molar units. More...

auto speciesAmount (std::string name, std::string units) const -> double
Return the amount of a chemical species with given molar units. More...

auto speciesDualPotentials () const -> VectorConstRef
Return the dual potentials of the species (in units of J/mol)

auto elementAmounts () const -> Vector
Return the molar amounts of the elements (in units of mol)

auto elementAmountsInPhase (Index index) const -> Vector
Return the molar amounts of the elements in a phase (in units of mol) More...

auto elementAmountsInSpecies (const Indices &indices) const -> Vector
Return the molar amounts of the elements in a set of species (in units of mol) More...

auto elementAmount (Index index) const -> double
Return the molar amount of an element (in units of mol) More...

auto elementAmount (std::string name) const -> double
Return the molar amount of an element (in units of mol) More...

auto elementAmount (Index index, std::string units) const -> double
Return the amount of an element with given units. More...

auto elementAmount (std::string name, std::string units) const -> double
Return the amount of an element with given units. More...

auto elementAmountInPhase (Index ielement, Index iphase) const -> double
Return the molar amount of an element in a given phase (in units of mol). More...

auto elementAmountInPhase (std::string element, std::string phase) const -> double
Return the molar amount of an element in a given phase (in units of mol). More...

auto elementAmountInPhase (Index ielement, Index iphase, std::string units) const -> double
Return the amount of an element in a given phase with given units. More...

auto elementAmountInPhase (std::string element, std::string phase, std::string units) const -> double
Return the amount of an element in a given phase with given units. More...

auto elementAmountInSpecies (Index ielement, const Indices &ispecies) const -> double
Return the molar amount of an element in a set of species (in units of mol). More...

auto elementAmountInSpecies (Index ielement, const Indices &ispecies, std::string units) const -> double
Return the amount of an element in a set of species with given units. More...

auto elementDualPotentials () const -> VectorConstRef
Return the dual potentials of the elements (in units of J/mol).

auto phaseAmount (Index index) const -> double
Return the molar amount of a phase (in units of mol). More...

auto phaseAmount (std::string name) const -> double
Return the molar amount of a phase (in units of mol). More...

auto phaseAmount (Index index, std::string units) const -> double
Return the molar amount of a phase with given units. More...

auto phaseAmount (std::string name, std::string units) const -> double
Return the molar amount of a phase with given units. More...

auto phaseStabilityIndices () const -> Vector
Return the stability indices of the phases with respect to chemical equilibrium. More...

auto properties () const -> ChemicalProperties
Return the chemical properties of the system.

auto output (std::ostream &out, int precision=6) const -> void
Output the ChemicalState instance to a stream.

auto output (std::string const &filename, int precision=6) const -> void
Output the ChemicalState instance to a file.

## Detailed Description

Provides a computational representation of the state of a multiphase chemical system.

The chemical state of a multiphase system is defined by its temperature $$(T)$$, pressure $$(P)$$, and molar composition $$(\mathbf{n})$$.

Usage

// Create a ChemicalState instance, where system is a ChemicalSystem instance
// Set the temperature and pressure states
state.setTemperature(60.0, "celsius");
state.setPressure( 180.0, "bar");
// Set the amount of some species
state.set( "H2O(l)", 1.0, "kg");
state.set( "Na+", 1.0, "mol");
state.set( "Cl-", 1.0, "mol");
state.set("CO2(aq)", 0.5, "mol");
state.set("Calcite", 10.0, "g");
// Output the chemical state instance
std::cout << state << std::endl;
ChemicalSystem

## ◆ ChemicalState() [1/2]

 ChemicalState ( )
delete

Disable the default ChemicalState constructor.

This is to enforce the initialization of a ChemicalState instance with a ChemicalSystem instance.

## ◆ ChemicalState() [2/2]

 ChemicalState ( const ChemicalSystem & system )
explicit

Construct a ChemicalState instance with standard conditions This constructor creates an instance of ChemicalState with temperature 25 °C, pressure 1 bar, and zero mole amounts for the species.

Parameters
 system The chemical system instance

## ◆ setSpeciesAmounts() [1/3]

 auto setSpeciesAmounts ( double val ) -> void

Set the molar amounts of the species with a single value (in units of mol)

Parameters
 val The single molar amounts of the species

## ◆ setSpeciesAmounts() [2/3]

 auto setSpeciesAmounts ( VectorConstRef n ) -> void

Set the molar amounts of the species (in units of mol)

Parameters
 n The vector of molar amounts of the species

## ◆ setSpeciesAmounts() [3/3]

 auto setSpeciesAmounts ( VectorConstRef n, const Indices & indices ) -> void

Set the molar amounts of species given by their indices (in units of mol)

Parameters
 n The vector of molar amounts of the species indices The indices of the species to be set

## ◆ setSpeciesAmount() [1/4]

 auto setSpeciesAmount ( Index index, double amount ) -> void

Set the molar amount of a species (in units of mol)

Parameters
 index The index of the species amount The molar amount of the species

## ◆ setSpeciesAmount() [2/4]

 auto setSpeciesAmount ( std::string name, double amount ) -> void

Set the molar amount of a species (in units of mol)

Parameters
 name The name of the species amount The amount of the species

## ◆ setSpeciesAmount() [3/4]

 auto setSpeciesAmount ( Index index, double amount, std::string units ) -> void

Set the amount of a species with given units.

Parameters
 index The index of the species amount The amount of the species units The units of the amount (must be convertible to either mol or gram)

## ◆ setSpeciesAmount() [4/4]

 auto setSpeciesAmount ( std::string name, double amount, std::string units ) -> void

Set the amount of a species with given units.

Parameters
 name The name of the species amount The amount of the species units The units of the amount (must be convertible to either mol or gram)

## ◆ setSpeciesMass() [1/4]

 auto setSpeciesMass ( Index index, double mass ) -> void

Set the mass of a species (in units of kg)

Parameters
 index The index of the species mass The mass of the species

## ◆ setSpeciesMass() [2/4]

 auto setSpeciesMass ( std::string name, double mass ) -> void

Set the mass of a species (in units of kg)

Parameters
 name The name of the species mass The mass of the species

## ◆ setSpeciesMass() [3/4]

 auto setSpeciesMass ( Index index, double mass, std::string units ) -> void

Set the mass of a species with given units.

Parameters
 index The index of the species mass The mass of the species units The units of the mass

## ◆ setSpeciesMass() [4/4]

 auto setSpeciesMass ( std::string name, double mass, std::string units ) -> void

Set the mass of a species with given units.

Parameters
 name The name of the species mass The mass of the species units The units of the mass

## ◆ setSpeciesDualPotentials()

 auto setSpeciesDualPotentials ( VectorConstRef z ) -> void

Set the dual potentials of the species (in units of J/mol).

The dual potentials of the species are the Lagrange multipliers with respect to the positive bound constraints on the molar amounts of the species in a chemical equilibrium calculation. They can be seen as measures of stability of a species at equilibrium, with values closer to zero meaning more stability.

Parameters
 z The Lagrange multipliers with respect to the positive constraints.

## ◆ setElementDualPotentials()

 auto setElementDualPotentials ( VectorConstRef y ) -> void

Set the dual potentials of the elements (in units of J/mol).

The dual potentials of the elements are the Lagrange multipliers with respect to the balance constraints on the molar amounts of the elements. They can be seen as a dual chemical potential of elements.

Parameters
 values The Lagrange multipliers with respect to the balance constraints.

## ◆ scaleSpeciesAmounts()

 auto scaleSpeciesAmounts ( double scalar ) -> void

Scale the molar amounts of the species by a given scalar.

Parameters
 scalar The scale factor of the molar amounts

## ◆ scaleSpeciesAmountsInPhase()

 auto scaleSpeciesAmountsInPhase ( Index index, double scalar ) -> void

Scale the molar amounts of the species in a phase by a given scalar.

Parameters
 index The index of the phase scalar The scale factor of the molar amounts

## ◆ scalePhaseVolume() [1/4]

 auto scalePhaseVolume ( Index index, double volume ) -> void

Scale the volume of a phase by adjusting the molar amounts of its species.

Parameters
 index The index of the phase volume The volume of the phase (in units of m3)

## ◆ scalePhaseVolume() [2/4]

 auto scalePhaseVolume ( Index index, double volume, std::string units ) -> void

Scale the volume of a phase by adjusting the molar amounts of its species.

Parameters
 index The index of the phase volume The volume of the phase units The units of the volume of the phase

## ◆ scalePhaseVolume() [3/4]

 auto scalePhaseVolume ( std::string name, double volume ) -> void

Scale the volume of a phase by adjusting the molar amounts of its species.

Parameters
 name The name of the phase volume The volume of the phase (in units of m3)

## ◆ scalePhaseVolume() [4/4]

 auto scalePhaseVolume ( std::string name, double volume, std::string units ) -> void

Scale the volume of a phase by adjusting the molar amounts of its species.

Parameters
 name The name of the phase volume The volume of the phase units The units of the volume of the phase

## ◆ scaleFluidVolume() [1/2]

 auto scaleFluidVolume ( double volume ) -> void

Scale the fluid volume of the chemical system.

This method scales each fluid phase by the same factor. This factor is defined as the prescribed volume divided by the current volume of the fluid phases.

Parameters
 volume The scaled fluid volume (in units of m3)

## ◆ scaleFluidVolume() [2/2]

 auto scaleFluidVolume ( double volume, std::string units ) -> void

Scale the fluid volume of the chemical system with given units.

This method scales each fluid phase by the same factor. This factor is defined as the prescribed volume divided by the current volume of the fluid phases.

Parameters
 volume The scaled fluid volume units The volume units

## ◆ scaleSolidVolume() [1/2]

 auto scaleSolidVolume ( double volume ) -> void

Scale the solid volume of the chemical system.

This method scales each solid phase by the same factor. This factor is defined as the prescribed volume divided by the current volume of the solid phases.

Parameters
 volume The scaled solid volume (in units of m3)

## ◆ scaleSolidVolume() [2/2]

 auto scaleSolidVolume ( double volume, std::string units ) -> void

Scale the solid volume of the chemical system with given units.

This method scales each solid phase by the same factor. This factor is defined as the prescribed volume divided by the current volume of the solid phases.

Parameters
 volume The scaled solid volume units The volume units

## ◆ scaleVolume() [1/2]

 auto scaleVolume ( double volume ) -> void

Scale the volume of the chemical system by adjusting the molar amounts of all species equally.

Parameters
 volume The volume of the chemical system (in units of m3)

## ◆ scaleVolume() [2/2]

 auto scaleVolume ( double volume, std::string units ) -> void

Scale the volume of the chemical system by adjusting the molar amounts of all species equally.

Parameters
 volume The volume of the chemical system units The volume units

## ◆ speciesAmounts()

 auto speciesAmounts ( const Indices & indices ) const -> Vector

Return the molar amounts of given species (in units of mol)

Parameters
 indices The indices of the species

## ◆ speciesAmount() [1/4]

 auto speciesAmount ( Index index ) const -> double

Return the molar mass of a chemical species (in units of mol)

Parameters
 index The index of the species

## ◆ speciesAmount() [2/4]

 auto speciesAmount ( std::string name ) const -> double

Return the molar amount of a chemical species (in units of mol)

Parameters
 name The name of the species

## ◆ speciesAmount() [3/4]

 auto speciesAmount ( Index index, std::string units ) const -> double

Return the amount of a chemical species with given molar units.

Parameters
 index The index of the species units The units of the species amount

## ◆ speciesAmount() [4/4]

 auto speciesAmount ( std::string name, std::string units ) const -> double

Return the amount of a chemical species with given molar units.

Parameters
 name The name of the species units The units of the species amount

## ◆ elementAmountsInPhase()

 auto elementAmountsInPhase ( Index index ) const -> Vector

Return the molar amounts of the elements in a phase (in units of mol)

Parameters
 index The index of the phase

## ◆ elementAmountsInSpecies()

 auto elementAmountsInSpecies ( const Indices & indices ) const -> Vector

Return the molar amounts of the elements in a set of species (in units of mol)

Parameters
 indices The indices of the species

## ◆ elementAmount() [1/4]

 auto elementAmount ( Index index ) const -> double

Return the molar amount of an element (in units of mol)

Parameters
 index The index of the element

## ◆ elementAmount() [2/4]

 auto elementAmount ( std::string name ) const -> double

Return the molar amount of an element (in units of mol)

Parameters
 name The name of the element

## ◆ elementAmount() [3/4]

 auto elementAmount ( Index index, std::string units ) const -> double

Return the amount of an element with given units.

Parameters
 index The index of the element units The units of the element amount

## ◆ elementAmount() [4/4]

 auto elementAmount ( std::string name, std::string units ) const -> double

Return the amount of an element with given units.

Parameters
 name The name of the element units The units of the element amount

## ◆ elementAmountInPhase() [1/4]

 auto elementAmountInPhase ( Index ielement, Index iphase ) const -> double

Return the molar amount of an element in a given phase (in units of mol).

Parameters
 ielement The index of the element iphase The index of the phase

## ◆ elementAmountInPhase() [2/4]

 auto elementAmountInPhase ( std::string element, std::string phase ) const -> double

Return the molar amount of an element in a given phase (in units of mol).

Parameters
 element The name of the element phase The name of the phase

## ◆ elementAmountInPhase() [3/4]

 auto elementAmountInPhase ( Index ielement, Index iphase, std::string units ) const -> double

Return the amount of an element in a given phase with given units.

Parameters
 ielement The index of the element iphase The index of the phase units The units of the element amount

## ◆ elementAmountInPhase() [4/4]

 auto elementAmountInPhase ( std::string element, std::string phase, std::string units ) const -> double

Return the amount of an element in a given phase with given units.

Parameters
 element The name of the element phase The name of the phase units The units of the element amount

## ◆ elementAmountInSpecies() [1/2]

 auto elementAmountInSpecies ( Index ielement, const Indices & ispecies ) const -> double

Return the molar amount of an element in a set of species (in units of mol).

Parameters
 ielement The index of the element ispecies The indices of the species

## ◆ elementAmountInSpecies() [2/2]

 auto elementAmountInSpecies ( Index ielement, const Indices & ispecies, std::string units ) const -> double

Return the amount of an element in a set of species with given units.

Parameters
 ielement The index of the element ispecies The indices of the species units The units of the element amount

## ◆ phaseAmount() [1/4]

 auto phaseAmount ( Index index ) const -> double

Return the molar amount of a phase (in units of mol).

Parameters
 index The index of the phase

## ◆ phaseAmount() [2/4]

 auto phaseAmount ( std::string name ) const -> double

Return the molar amount of a phase (in units of mol).

Parameters
 name The name of the phase

## ◆ phaseAmount() [3/4]

 auto phaseAmount ( Index index, std::string units ) const -> double

Return the molar amount of a phase with given units.

Parameters
 index The index of the phase units The units of the phase amount

## ◆ phaseAmount() [4/4]

 auto phaseAmount ( std::string name, std::string units ) const -> double

Return the molar amount of a phase with given units.

Parameters
 name The name of the phase units The units of the phase amount

## ◆ phaseStabilityIndices()

 auto phaseStabilityIndices ( ) const -> Vector

Return the stability indices of the phases with respect to chemical equilibrium.

The stability index of a stable phase at chemical equilibrium should be zero or very close to zero. A negative stability index indicates that the corresponding phase is under-saturated, while a positive index indicates the phase is over-saturated.

The documentation for this class was generated from the following files:
ChemicalState()=delete
Disable the default ChemicalState constructor.
auto setPressure(double val) -> void
Set the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:491
auto setTemperature(double val) -> void
Set the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:481
auto system() const -> const ChemicalSystem &
Return the chemical system instance.
Definition: ChemicalState.cpp:626