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 
234  auto scaleVolume(double volume, std::string units) -> void;
235 
237  auto system() const -> const ChemicalSystem&;
238 
240  auto temperature() const -> double;
241 
243  auto pressure() const -> double;
244 
246  auto speciesAmounts() const -> const Vector&;
247 
250  auto speciesAmounts(const Indices& indices) const -> Vector;
251 
254  auto speciesAmount(Index index) const -> double;
255 
258  auto speciesAmount(std::string name) const -> double;
259 
263  auto speciesAmount(Index index, std::string units) const -> double;
264 
268  auto speciesAmount(std::string name, std::string units) const -> double;
269 
271  auto speciesDualPotentials() const -> const Vector&;
272 
274  auto elementAmounts() const -> Vector;
275 
278  auto elementAmountsInPhase(Index index) const -> Vector;
279 
282  auto elementAmountsInSpecies(const Indices& indices) const -> Vector;
283 
286  auto elementAmount(Index index) const -> double;
287 
290  auto elementAmount(std::string name) const -> double;
291 
295  auto elementAmount(Index index, std::string units) const -> double;
296 
300  auto elementAmount(std::string name, std::string units) const -> double;
301 
305  auto elementAmountInPhase(Index ielement, Index iphase) const -> double;
306 
310  auto elementAmountInPhase(std::string element, std::string phase) const -> double;
311 
316  auto elementAmountInPhase(Index ielement, Index iphase, std::string units) const -> double;
317 
322  auto elementAmountInPhase(std::string element, std::string phase, std::string units) const -> double;
323 
327  auto elementAmountInSpecies(Index ielement, const Indices& ispecies) const -> double;
328 
333  auto elementAmountInSpecies(Index ielement, const Indices& ispecies, std::string units) const -> double;
334 
336  auto elementDualPotentials() const -> const Vector&;
337 
340  auto phaseAmount(Index index) const -> double;
341 
344  auto phaseAmount(std::string name) const -> double;
345 
349  auto phaseAmount(Index index, std::string units) const -> double;
350 
354  auto phaseAmount(std::string name, std::string units) const -> double;
355 
361  auto phaseStabilityIndices() const -> Vector;
362 
364  auto properties() const -> ChemicalProperties;
365 
367  auto output(std::string filename) -> void;
368 
369 private:
370  struct Impl;
371 
372  std::unique_ptr<Impl> pimpl;
373 };
374 
376 auto operator<<(std::ostream& out, const ChemicalState& state) -> std::ostream&;
377 
379 auto operator+(const ChemicalState& l, const ChemicalState& r) -> ChemicalState;
380 
382 auto operator*(double scalar, const ChemicalState& state) -> ChemicalState;
383 
385 auto operator*(const ChemicalState& state, double scalar) -> ChemicalState;
386 
387 } // 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:697
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:752
auto operator=(ChemicalState other) -> ChemicalState &
Assign a ChemicalState instance to this instance.
Definition: ChemicalState.cpp:481
auto scaleSpeciesAmounts(double scalar) -> void
Scale the molar amounts of the species by a given scalar.
Definition: ChemicalState.cpp:572
auto properties() const -> ChemicalProperties
Return the chemical properties of the system.
Definition: ChemicalState.cpp:777
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:737
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:717
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:692
auto temperature() const -> double
Return the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:637
auto setSpeciesAmounts(double val) -> void
Set the molar amounts of the species with a single value (in units of mol)
Definition: ChemicalState.cpp:507
auto setSpeciesMass(Index index, double mass) -> void
Set the mass of a species (in units of kg)
Definition: ChemicalState.cpp:542
auto setPressure(double val) -> void
Set the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:497
auto elementDualPotentials() const -> const Vector &
Return the dual potentials of the elements (in units of J/mol)
Definition: ChemicalState.cpp:747
auto scaleSolidVolume(double volume) -> void
Scale the solid volume of the chemical system.
Definition: ChemicalState.cpp:612
auto scaleFluidVolume(double volume) -> void
Scale the fluid volume of the chemical system.
Definition: ChemicalState.cpp:602
auto output(std::string filename) -> void
Output the ChemicalState instance to a file.
Definition: ChemicalState.cpp:782
auto elementAmounts() const -> Vector
Return the molar amounts of the elements (in units of mol)
Definition: ChemicalState.cpp:682
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:687
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:562
auto pressure() const -> double
Return the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:642
auto scaleVolume(double volume) -> void
Scale the volume of the chemical system by adjusting the molar amounts of all species equally...
Definition: ChemicalState.cpp:622
auto phaseStabilityIndices() const -> Vector
Return the stability indices of the phases with respect to chemical equilibrium.
Definition: ChemicalState.cpp:772
auto setTemperature(double val) -> void
Set the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:487
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:577
auto speciesAmount(Index index) const -> double
Return the molar mass of a chemical species (in units of mol)
Definition: ChemicalState.cpp:657
virtual ~ChemicalState()
Destroy the instance.
Definition: ChemicalState.cpp:478
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:567
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:522
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:632
auto speciesAmounts() const -> const Vector &
Return the molar amounts of the species (in units of mol)
Definition: ChemicalState.cpp:647
auto speciesDualPotentials() const -> const Vector &
Return the dual potentials of the species (in units of J/mol)
Definition: ChemicalState.cpp:677
ChemicalState()
Construct a default ChemicalState instance.
Definition: ChemicalState.cpp:466
auto scalePhaseVolume(Index index, double volume) -> void
Scale the volume of a phase by adjusting the molar amounts of its species.
Definition: ChemicalState.cpp:582