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-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program 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
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. 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:
64  ChemicalState();
65 
70  explicit ChemicalState(const ChemicalSystem& system);
71 
73  ChemicalState(const ChemicalState& other);
74 
76  virtual ~ChemicalState();
77 
79  auto operator=(ChemicalState other) -> ChemicalState&;
80 
82  auto setTemperature(double val) -> void;
83 
85  auto setTemperature(double val, std::string units) -> void;
86 
88  auto setPressure(double val) -> void;
89 
91  auto setPressure(double val, std::string units) -> void;
92 
95  auto setSpeciesAmounts(double val) -> void;
96 
99  auto setSpeciesAmounts(const Vector& n) -> void;
100 
104  auto setSpeciesAmounts(const Vector& n, const Indices& indices) -> void;
105 
109  auto setSpeciesAmount(Index index, double amount) -> void;
110 
114  auto setSpeciesAmount(std::string name, double amount) -> void;
115 
120  auto setSpeciesAmount(Index index, double amount, std::string units) -> void;
121 
126  auto setSpeciesAmount(std::string name, double amount, std::string units) -> void;
127 
131  auto setSpeciesMass(Index index, double mass) -> void;
132 
136  auto setSpeciesMass(std::string name, double mass) -> void;
137 
142  auto setSpeciesMass(Index index, double mass, std::string units) -> void;
143 
148  auto setSpeciesMass(std::string name, double mass, std::string units) -> void;
149 
157  auto setSpeciesDualPotentials(const Vector& z) -> void;
158 
164  auto setElementDualPotentials(const Vector& y) -> void;
165 
168  auto scaleSpeciesAmounts(double scalar) -> void;
169 
173  auto scaleSpeciesAmountsInPhase(Index index, double scalar) -> void;
174 
178  auto scalePhaseVolume(Index index, double volume) -> void;
179 
184  auto scalePhaseVolume(Index index, double volume, std::string units) -> void;
185 
189  auto scalePhaseVolume(std::string name, double volume) -> void;
190 
195  auto scalePhaseVolume(std::string name, double volume, std::string units) -> void;
196 
202  auto scaleFluidVolume(double volume) -> void;
203 
210  auto scaleFluidVolume(double volume, std::string units) -> void;
211 
217  auto scaleSolidVolume(double volume) -> void;
218 
225  auto scaleSolidVolume(double volume, std::string units) -> void;
226 
229  auto scaleVolume(double volume) -> void;
230 
232  auto system() const -> const ChemicalSystem&;
233 
235  auto temperature() const -> double;
236 
238  auto pressure() const -> double;
239 
241  auto speciesAmounts() const -> const Vector&;
242 
245  auto speciesAmounts(const Indices& indices) const -> Vector;
246 
249  auto speciesAmount(Index index) const -> double;
250 
253  auto speciesAmount(std::string name) const -> double;
254 
258  auto speciesAmount(Index index, std::string units) const -> double;
259 
263  auto speciesAmount(std::string name, std::string units) const -> double;
264 
266  auto speciesDualPotentials() const -> const Vector&;
267 
269  auto elementAmounts() const -> Vector;
270 
273  auto elementAmountsInPhase(Index index) const -> Vector;
274 
277  auto elementAmountsInSpecies(const Indices& indices) const -> Vector;
278 
281  auto elementAmount(Index index) const -> double;
282 
285  auto elementAmount(std::string name) const -> double;
286 
290  auto elementAmount(Index index, std::string units) const -> double;
291 
295  auto elementAmount(std::string name, std::string units) const -> double;
296 
300  auto elementAmountInPhase(Index ielement, Index iphase) const -> double;
301 
305  auto elementAmountInPhase(std::string element, std::string phase) const -> double;
306 
311  auto elementAmountInPhase(Index ielement, Index iphase, std::string units) const -> double;
312 
317  auto elementAmountInPhase(std::string element, std::string phase, std::string units) const -> double;
318 
322  auto elementAmountInSpecies(Index ielement, const Indices& ispecies) const -> double;
323 
328  auto elementAmountInSpecies(Index ielement, const Indices& ispecies, std::string units) const -> double;
329 
331  auto elementDualPotentials() const -> const Vector&;
332 
335  auto phaseAmount(Index index) const -> double;
336 
339  auto phaseAmount(std::string name) const -> double;
340 
344  auto phaseAmount(Index index, std::string units) const -> double;
345 
349  auto phaseAmount(std::string name, std::string units) const -> double;
350 
356  auto phaseStabilityIndices() const -> Vector;
357 
359  auto properties() const -> ChemicalProperties;
360 
362  auto output(std::string filename) -> void;
363 
364 private:
365  struct Impl;
366 
367  std::unique_ptr<Impl> pimpl;
368 };
369 
371 auto operator<<(std::ostream& out, const ChemicalState& state) -> std::ostream&;
372 
374 auto operator+(const ChemicalState& l, const ChemicalState& r) -> ChemicalState;
375 
377 auto operator*(double scalar, const ChemicalState& state) -> ChemicalState;
378 
380 auto operator*(const ChemicalState& state, double scalar) -> ChemicalState;
381 
382 } // namespace Reaktoro
auto amount(double value, Index size, Index index) -> ChemicalScalarBase< double, decltype(unit(size, index))>
Return a ChemicalScalar representation of a mole amount of a species.
Definition: ChemicalScalar.hpp:208
auto elementAmount(Index index) const -> double
Return the molar amount of an element (in units of mol)
Definition: ChemicalState.cpp:686
A class for querying thermodynamic and chemical properties of a chemical system.
Definition: ChemicalProperties.hpp:36
auto phaseAmount(Index index) const -> double
Return the molar amount of a phase (in units of mol)
Definition: ChemicalState.cpp:741
auto operator=(ChemicalState other) -> ChemicalState &
Assign a ChemicalState instance to this instance.
Definition: ChemicalState.cpp:475
auto scaleSpeciesAmounts(double scalar) -> void
Scale the molar amounts of the species by a given scalar.
Definition: ChemicalState.cpp:566
auto properties() const -> ChemicalProperties
Return the chemical properties of the system.
Definition: ChemicalState.cpp:766
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
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
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:47
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:726
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:706
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:681
auto temperature() const -> double
Return the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:626
auto setSpeciesAmounts(double val) -> void
Set the molar amounts of the species with a single value (in units of mol)
Definition: ChemicalState.cpp:501
auto setSpeciesMass(Index index, double mass) -> void
Set the mass of a species (in units of kg)
Definition: ChemicalState.cpp:536
auto setPressure(double val) -> void
Set the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:491
auto elementDualPotentials() const -> const Vector &
Return the dual potentials of the elements (in units of J/mol)
Definition: ChemicalState.cpp:736
auto scaleSolidVolume(double volume) -> void
Scale the solid volume of the chemical system.
Definition: ChemicalState.cpp:606
auto scaleFluidVolume(double volume) -> void
Scale the fluid volume of the chemical system.
Definition: ChemicalState.cpp:596
auto output(std::string filename) -> void
Output the ChemicalState instance to a file.
Definition: ChemicalState.cpp:771
auto elementAmounts() const -> Vector
Return the molar amounts of the elements (in units of mol)
Definition: ChemicalState.cpp:671
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
auto elementAmountsInPhase(Index index) const -> Vector
Return the molar amounts of the elements in a phase (in units of mol)
Definition: ChemicalState.cpp:676
auto setSpeciesDualPotentials(const Vector &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
auto pressure() const -> double
Return the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:631
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 phaseStabilityIndices() const -> Vector
Return the stability indices of the phases with respect to chemical equilibrium.
Definition: ChemicalState.cpp:761
auto setTemperature(double val) -> void
Set the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:481
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
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 speciesAmount(Index index) const -> double
Return the molar mass of a chemical species (in units of mol)
Definition: ChemicalState.cpp:646
virtual ~ChemicalState()
Destroy the instance.
Definition: ChemicalState.cpp:472
auto setElementDualPotentials(const Vector &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
Definition: Units.cpp:38
Provides a computational representation of the state of a multiphase chemical system.
Definition: ChemicalState.hpp:60
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 setSpeciesAmount(Index index, double amount) -> void
Set the molar amount of a species (in units of mol)
Definition: ChemicalState.cpp:516
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto system() const -> const ChemicalSystem &
Return the chemical system instance.
Definition: ChemicalState.cpp:621
auto speciesAmounts() const -> const Vector &
Return the molar amounts of the species (in units of mol)
Definition: ChemicalState.cpp:636
auto speciesDualPotentials() const -> const Vector &
Return the dual potentials of the species (in units of J/mol)
Definition: ChemicalState.cpp:666
ChemicalState()
Construct a default ChemicalState instance.
Definition: ChemicalState.cpp:460
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