Reaktoro
A unified framework for modeling chemically reactive systems
ChemicalState.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 // C++ includes
21 #include <memory>
22 #include <string>
23 
24 // Reaktoro includes
25 #include <Reaktoro/Math/Matrix.hpp>
26 #include <Reaktoro/Common/ScalarTypes.hpp>
27 
28 namespace Reaktoro {
29 
30 // Forward declarations
31 class ChemicalProperties;
32 class ChemicalSystem;
33 
61 {
62 public:
66  ChemicalState() = delete;
67 
72  explicit ChemicalState(const ChemicalSystem& system);
73 
75  ChemicalState(const ChemicalState& other);
76 
78  virtual ~ChemicalState();
79 
81  auto operator=(ChemicalState other) -> ChemicalState&;
82 
84  auto setTemperature(double val) -> void;
85 
87  auto setTemperature(double val, std::string units) -> void;
88 
90  auto setPressure(double val) -> void;
91 
93  auto setPressure(double val, std::string units) -> void;
94 
97  auto setSpeciesAmounts(double val) -> void;
98 
101  auto setSpeciesAmounts(VectorConstRef n) -> void;
102 
106  auto setSpeciesAmounts(VectorConstRef n, const Indices& indices) -> void;
107 
111  auto setSpeciesAmount(Index index, double amount) -> void;
112 
116  auto setSpeciesAmount(std::string name, double amount) -> void;
117 
122  auto setSpeciesAmount(Index index, double amount, std::string units) -> void;
123 
128  auto setSpeciesAmount(std::string name, double amount, std::string units) -> void;
129 
133  auto setSpeciesMass(Index index, double mass) -> void;
134 
138  auto setSpeciesMass(std::string name, double mass) -> void;
139 
144  auto setSpeciesMass(Index index, double mass, std::string units) -> void;
145 
150  auto setSpeciesMass(std::string name, double mass, std::string units) -> void;
151 
160 
167 
170  auto scaleSpeciesAmounts(double scalar) -> void;
171 
175  auto scaleSpeciesAmountsInPhase(Index index, double scalar) -> void;
176 
180  auto scalePhaseVolume(Index index, double volume) -> void;
181 
186  auto scalePhaseVolume(Index index, double volume, std::string units) -> void;
187 
191  auto scalePhaseVolume(std::string name, double volume) -> void;
192 
197  auto scalePhaseVolume(std::string name, double volume, std::string units) -> void;
198 
204  auto scaleFluidVolume(double volume) -> void;
205 
212  auto scaleFluidVolume(double volume, std::string units) -> void;
213 
219  auto scaleSolidVolume(double volume) -> void;
220 
227  auto scaleSolidVolume(double volume, std::string units) -> void;
228 
231  auto scaleVolume(double volume) -> void;
232 
236  auto scaleVolume(double volume, std::string units) -> void;
237 
239  auto system() const -> const ChemicalSystem&;
240 
242  auto temperature() const -> double;
243 
245  auto pressure() const -> double;
246 
248  auto speciesAmounts() const -> VectorConstRef;
249 
252  auto speciesAmounts(const Indices& indices) const -> Vector;
253 
256  auto speciesAmount(Index index) const -> double;
257 
260  auto speciesAmount(std::string name) const -> double;
261 
265  auto speciesAmount(Index index, std::string units) const -> double;
266 
270  auto speciesAmount(std::string name, std::string units) const -> double;
271 
273  auto speciesDualPotentials() const -> VectorConstRef;
274 
276  auto elementAmounts() const -> Vector;
277 
280  auto elementAmountsInPhase(Index index) const -> Vector;
281 
284  auto elementAmountsInSpecies(const Indices& indices) const -> Vector;
285 
288  auto elementAmount(Index index) const -> double;
289 
292  auto elementAmount(std::string name) const -> double;
293 
297  auto elementAmount(Index index, std::string units) const -> double;
298 
302  auto elementAmount(std::string name, std::string units) const -> double;
303 
307  auto elementAmountInPhase(Index ielement, Index iphase) const -> double;
308 
312  auto elementAmountInPhase(std::string element, std::string phase) const -> double;
313 
318  auto elementAmountInPhase(Index ielement, Index iphase, std::string units) const -> double;
319 
324  auto elementAmountInPhase(std::string element, std::string phase, std::string units) const -> double;
325 
329  auto elementAmountInSpecies(Index ielement, const Indices& ispecies) const -> double;
330 
335  auto elementAmountInSpecies(Index ielement, const Indices& ispecies, std::string units) const -> double;
336 
338  auto elementDualPotentials() const -> VectorConstRef;
339 
342  auto phaseAmount(Index index) const -> double;
343 
346  auto phaseAmount(std::string name) const -> double;
347 
351  auto phaseAmount(Index index, std::string units) const -> double;
352 
356  auto phaseAmount(std::string name, std::string units) const -> double;
357 
363  auto phaseStabilityIndices() const -> Vector;
364 
366  auto properties() const -> ChemicalProperties;
367 
369  auto output(std::string filename) const -> void;
370 
371 private:
372  struct Impl;
373 
374  std::unique_ptr<Impl> pimpl;
375 };
376 
378 auto operator<<(std::ostream& out, const ChemicalState& state) -> std::ostream&;
379 
381 auto operator+(const ChemicalState& l, const ChemicalState& r) -> ChemicalState;
382 
384 auto operator*(double scalar, const ChemicalState& state) -> ChemicalState;
385 
387 auto operator*(const ChemicalState& state, double scalar) -> ChemicalState;
388 
389 } // namespace Reaktoro
auto indices(const std::vector< std::string > &names, const NamedValues &values) -> Indices
Return the indices of some entries in a container.
Definition: SetUtils.hxx:59
auto elementAmountsInPhase(Index index) const -> Vector
Return the molar amounts of the elements in a phase (in units of mol)
Definition: ChemicalState.cpp:681
auto system() const -> const ChemicalSystem &
Return the chemical system instance.
Definition: ChemicalState.cpp:626
auto elementAmounts() const -> Vector
Return the molar amounts of the elements (in units of mol)
Definition: ChemicalState.cpp:676
A class for querying thermodynamic and chemical properties of a chemical system.
Definition: ChemicalProperties.hpp:32
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)
Definition: ChemicalState.cpp:731
auto amount(double value, Index nspecies, Index ispecies) -> ChemicalScalarBase< double, decltype(tr(unit(nspecies, ispecies)))>
Return a ChemicalScalar representation of a mole amount of a species.
Definition: ChemicalScalar.hpp:233
auto scaleSolidVolume(double volume) -> void
Scale the solid volume of the chemical system.
Definition: ChemicalState.cpp:606
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:37
auto phaseAmount(Index index) const -> double
Return the molar amount of a phase (in units of mol)
Definition: ChemicalState.cpp:746
auto elementAmountsInSpecies(const Indices &indices) const -> Vector
Return the molar amounts of the elements in a set of species (in units of mol)
Definition: ChemicalState.cpp:686
auto pressure() const -> double
Return the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:636
auto scaleSpeciesAmounts(double scalar) -> void
Scale the molar amounts of the species by a given scalar.
Definition: ChemicalState.cpp:566
auto setSpeciesMass(Index index, double mass) -> void
Set the mass of a species (in units of kg)
Definition: ChemicalState.cpp:536
auto properties() const -> ChemicalProperties
Return the chemical properties of the system.
Definition: ChemicalState.cpp:771
auto setTemperature(double val) -> void
Set the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:481
auto setElementDualPotentials(VectorConstRef y) -> void
Set the dual potentials of the elements (in units of J/mol) The dual potentials of the elements are t...
Definition: ChemicalState.cpp:561
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:33
auto scaleVolume(double volume) -> void
Scale the volume of the chemical system by adjusting the molar amounts of all species equally...
Definition: ChemicalState.cpp:616
auto setPressure(double val) -> void
Set the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:491
auto phaseStabilityIndices() const -> Vector
Return the stability indices of the phases with respect to chemical equilibrium.
Definition: ChemicalState.cpp:766
auto speciesDualPotentials() const -> VectorConstRef
Return the dual potentials of the species (in units of J/mol)
Definition: ChemicalState.cpp:671
auto scalePhaseVolume(Index index, double volume) -> void
Scale the volume of a phase by adjusting the molar amounts of its species.
Definition: ChemicalState.cpp:576
auto operator=(ChemicalState other) -> ChemicalState &
Assign a ChemicalState instance to this instance.
Definition: ChemicalState.cpp:475
auto temperature() const -> double
Return the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:631
ChemicalState()=delete
Disable the default ChemicalState constructor.
auto speciesAmount(Index index) const -> double
Return the molar mass of a chemical species (in units of mol)
Definition: ChemicalState.cpp:651
auto scaleFluidVolume(double volume) -> void
Scale the fluid volume of the chemical system.
Definition: ChemicalState.cpp:596
auto speciesAmounts() const -> VectorConstRef
Return the molar amounts of the species (in units of mol)
Definition: ChemicalState.cpp:641
auto elementDualPotentials() const -> VectorConstRef
Return the dual potentials of the elements (in units of J/mol)
Definition: ChemicalState.cpp:741
auto elementAmountInPhase(Index ielement, Index iphase) const -> double
Return the molar amount of an element in a given phase (in units of mol)
Definition: ChemicalState.cpp:711
Definition: Units.cpp:38
Provides a computational representation of the state of a multiphase chemical system.
Definition: ChemicalState.hpp:60
auto scaleSpeciesAmountsInPhase(Index index, double scalar) -> void
Scale the molar amounts of the species in a phase by a given scalar.
Definition: ChemicalState.cpp:571
auto output(std::string filename) const -> void
Output the ChemicalState instance to a file.
Definition: ChemicalState.cpp:776
auto setSpeciesAmount(Index index, double amount) -> void
Set the molar amount of a species (in units of mol)
Definition: ChemicalState.cpp:516
auto index(const T &value, const std::vector< T > &values) -> Index
Find the index of a value in a container of values.
Definition: SetUtils.hxx:21
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto elementAmount(Index index) const -> double
Return the molar amount of an element (in units of mol)
Definition: ChemicalState.cpp:691
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...
Definition: ChemicalState.cpp:556
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto setSpeciesAmounts(double val) -> void
Set the molar amounts of the species with a single value (in units of mol)
Definition: ChemicalState.cpp:501
virtual ~ChemicalState()
Destroy the instance.