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 
161 
169 
172  auto scaleSpeciesAmounts(double scalar) -> void;
173 
177  auto scaleSpeciesAmountsInPhase(Index index, double scalar) -> void;
178 
182  auto scalePhaseVolume(Index index, double volume) -> void;
183 
188  auto scalePhaseVolume(Index index, double volume, std::string units) -> void;
189 
193  auto scalePhaseVolume(std::string name, double volume) -> void;
194 
199  auto scalePhaseVolume(std::string name, double volume, std::string units) -> void;
200 
206  auto scaleFluidVolume(double volume) -> void;
207 
214  auto scaleFluidVolume(double volume, std::string units) -> void;
215 
221  auto scaleSolidVolume(double volume) -> void;
222 
229  auto scaleSolidVolume(double volume, std::string units) -> void;
230 
233  auto scaleVolume(double volume) -> void;
234 
238  auto scaleVolume(double volume, std::string units) -> void;
239 
241  auto system() const -> const ChemicalSystem&;
242 
244  auto temperature() const -> double;
245 
247  auto pressure() const -> double;
248 
250  auto speciesAmounts() const -> VectorConstRef;
251 
254  auto speciesAmounts(const Indices& indices) const -> Vector;
255 
258  auto speciesAmount(Index index) const -> double;
259 
262  auto speciesAmount(std::string name) const -> double;
263 
267  auto speciesAmount(Index index, std::string units) const -> double;
268 
272  auto speciesAmount(std::string name, std::string units) const -> double;
273 
275  auto speciesDualPotentials() const -> VectorConstRef;
276 
278  auto elementAmounts() const -> Vector;
279 
282  auto elementAmountsInPhase(Index index) const -> Vector;
283 
286  auto elementAmountsInSpecies(const Indices& indices) const -> Vector;
287 
290  auto elementAmount(Index index) const -> double;
291 
294  auto elementAmount(std::string name) const -> double;
295 
299  auto elementAmount(Index index, std::string units) const -> double;
300 
304  auto elementAmount(std::string name, std::string units) const -> double;
305 
309  auto elementAmountInPhase(Index ielement, Index iphase) const -> double;
310 
314  auto elementAmountInPhase(std::string element, std::string phase) const -> double;
315 
320  auto elementAmountInPhase(Index ielement, Index iphase, std::string units) const -> double;
321 
326  auto elementAmountInPhase(std::string element, std::string phase, std::string units) const -> double;
327 
331  auto elementAmountInSpecies(Index ielement, const Indices& ispecies) const -> double;
332 
337  auto elementAmountInSpecies(Index ielement, const Indices& ispecies, std::string units) const -> double;
338 
340  auto elementDualPotentials() const -> VectorConstRef;
341 
344  auto phaseAmount(Index index) const -> double;
345 
348  auto phaseAmount(std::string name) const -> double;
349 
353  auto phaseAmount(Index index, std::string units) const -> double;
354 
358  auto phaseAmount(std::string name, std::string units) const -> double;
359 
366  auto phaseStabilityIndices() const -> Vector;
367 
369  auto properties() const -> ChemicalProperties;
370 
372  auto output(std::ostream& out, int precision = 6) const -> void;
373 
375  auto output(std::string const& filename, int precision = 6) const -> void;
376 
377 private:
378  struct Impl;
379 
380  std::unique_ptr<Impl> pimpl;
381 };
382 
384 auto operator<<(std::ostream& out, const ChemicalState& state) -> std::ostream&;
385 
387 auto operator+(const ChemicalState& l, const ChemicalState& r) -> ChemicalState;
388 
390 auto operator*(double scalar, const ChemicalState& state) -> ChemicalState;
391 
393 auto operator*(const ChemicalState& state, double scalar) -> ChemicalState;
394 
395 } // namespace Reaktoro
auto properties() const -> ChemicalProperties
Return the chemical properties of the system.
Definition: ChemicalState.cpp:771
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 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
auto speciesDualPotentials() const -> VectorConstRef
Return the dual potentials of the species (in units of J/mol)
Definition: ChemicalState.cpp:671
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
A class to represent a system and its attributes and properties.
Definition: ChemicalSystem.hpp:38
auto scaleFluidVolume(double volume) -> void
Scale the fluid volume of the chemical system.
Definition: ChemicalState.cpp:596
auto setSpeciesAmounts(double val) -> void
Set the molar amounts of the species with a single value (in units of mol)
Definition: ChemicalState.cpp:501
Provides a computational representation of the state of a multiphase chemical system.
Definition: ChemicalState.hpp:61
auto speciesAmount(Index index) const -> double
Return the molar mass of a chemical species (in units of mol)
Definition: ChemicalState.cpp:651
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 elementDualPotentials() const -> VectorConstRef
Return the dual potentials of the elements (in units of J/mol).
Definition: ChemicalState.cpp:741
auto setElementDualPotentials(VectorConstRef y) -> void
Set the dual potentials of the elements (in units of J/mol).
Definition: ChemicalState.cpp:561
auto operator=(ChemicalState other) -> ChemicalState &
Assign a ChemicalState instance to this instance.
Definition: ChemicalState.cpp:475
auto phaseStabilityIndices() const -> Vector
Return the stability indices of the phases with respect to chemical equilibrium.
Definition: ChemicalState.cpp:766
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto setSpeciesMass(Index index, double mass) -> void
Set the mass of a species (in units of kg)
Definition: ChemicalState.cpp:536
auto setSpeciesAmount(Index index, double amount) -> void
Set the molar amount of a species (in units of mol)
Definition: ChemicalState.cpp:516
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
ChemicalState()=delete
Disable the default ChemicalState constructor.
auto speciesAmounts() const -> VectorConstRef
Return the molar amounts of the species (in units of mol)
Definition: ChemicalState.cpp:641
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:33
auto setPressure(double val) -> void
Set the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:491
virtual ~ChemicalState()
Destroy the instance.
auto setTemperature(double val) -> void
Set the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:481
auto output(std::ostream &out, int precision=6) const -> void
Output the ChemicalState instance to a stream.
Definition: ChemicalState.cpp:776
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
auto scaleSpeciesAmounts(double scalar) -> void
Scale the molar amounts of the species by a given scalar.
Definition: ChemicalState.cpp:566
auto system() const -> const ChemicalSystem &
Return the chemical system instance.
Definition: ChemicalState.cpp:626
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
std::vector< Index > Indices
Define a type that represents a collection of indices.
Definition: Index.hpp:29
auto temperature() const -> double
Return the temperature of the chemical state (in units of K)
Definition: ChemicalState.cpp:631
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 elementAmount(Index index) const -> double
Return the molar amount of an element (in units of mol)
Definition: ChemicalState.cpp:691
auto pressure() const -> double
Return the pressure of the chemical state (in units of Pa)
Definition: ChemicalState.cpp:636
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 elementAmountsInPhase(Index index) const -> Vector
Return the molar amounts of the elements in a phase (in units of mol)
Definition: ChemicalState.cpp:681
auto scaleSolidVolume(double volume) -> void
Scale the solid volume of the chemical system.
Definition: ChemicalState.cpp:606
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31
auto phaseAmount(Index index) const -> double
Return the molar amount of a phase (in units of mol).
Definition: ChemicalState.cpp:746
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
auto setSpeciesDualPotentials(VectorConstRef z) -> void
Set the dual potentials of the species (in units of J/mol).
Definition: ChemicalState.cpp:556