Reaktoro  v2.11.0
A unified framework for modeling chemically reactive systems
Species.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright © 2014-2024 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 // Reaktoro includes
21 #include <Reaktoro/Common/StringList.hpp>
22 #include <Reaktoro/Common/Types.hpp>
23 #include <Reaktoro/Core/AggregateState.hpp>
24 #include <Reaktoro/Core/ChemicalFormula.hpp>
25 #include <Reaktoro/Core/ElementalComposition.hpp>
26 #include <Reaktoro/Core/FormationReaction.hpp>
27 #include <Reaktoro/Core/SpeciesThermoProps.hpp>
28 #include <Reaktoro/Core/StandardThermoModel.hpp>
29 #include <Reaktoro/Core/StandardThermoProps.hpp>
30 
31 namespace Reaktoro {
32 
34 class Species
35 {
36 public:
38  struct Attribs
39  {
43 
47 
51 
55 
58  double charge = 0.0;
59 
63 
70 
76 
80  };
81 
84 
86  explicit Species(const String& formula);
87 
89  explicit Species(const Attribs& attribs);
90 
92  auto clone() const -> Species;
93 
95  auto withName(String name) const -> Species;
96 
99 
102 
105 
107  auto withCharge(double charge) const -> Species;
108 
111 
118 
127  auto withStandardGibbsEnergy(real const& G0) const -> Species;
128 
136 
138  auto withTags(const StringList& tags) const -> Species;
139 
141  auto withAttachedData(Any data) const -> Species;
142 
144  auto name() const -> String;
145 
147  auto formula() const -> ChemicalFormula;
148 
150  auto repr() const -> String;
151 
153  auto substance() const -> String;
154 
156  auto elements() const -> const ElementalComposition&;
157 
159  auto charge() const -> double;
160 
163 
165  auto reaction() const -> const FormationReaction&;
166 
168  auto standardThermoModel() const -> const StandardThermoModel&;
169 
171  auto tags() const -> const Strings&;
172 
174  auto attachedData() const -> const Any&;
175 
177  auto molarMass() const -> double;
178 
184 
189  auto props(real T, real P) const -> SpeciesThermoProps;
190 
197  auto props(real T, Chars unitT, real P, Chars unitP) const -> SpeciesThermoProps;
198 
199 private:
200  struct Impl;
201 
202  SharedPtr<Impl> pimpl;
203 };
204 
206 auto operator<(const Species& lhs, const Species& rhs) -> bool;
207 
209 auto operator==(const Species& lhs, const Species& rhs) -> bool;
210 
211 } // namespace Reaktoro
212 
213 // Custom specialization of std::hash for Reaktoro::Species
214 namespace std {
215 
216 template<>
217 struct hash<Reaktoro::Species>
218 {
219  std::size_t operator()(const Reaktoro::Species& s) const noexcept
220  {
221  return std::hash<std::string>{}(s.name());
222  }
223 };
224 
225 } // namespace std
A type used to represent the chemical formula of a chemical species.
Definition: ChemicalFormula.hpp:27
A type used to describe the elemental composition of chemical species.
Definition: ElementalComposition.hpp:28
A class to represent a formation reaction of a chemical species.
Definition: FormationReaction.hpp:33
A type used to represent a chemical species and its attributes.
Definition: Species.hpp:35
auto withStandardGibbsEnergy(real const &G0) const -> Species
Return a duplicate of this Species object with new standard thermodynamic model.
auto standardThermoProps(real T, real P) const -> StandardThermoProps
Calculate the primary standard thermodynamic properties of the species.
auto elements() const -> const ElementalComposition &
Return the elements that compose the species and their coefficients.
auto withStandardThermoModel(const StandardThermoModel &model) const -> Species
Return a duplicate of this Species object with new standard thermodynamic model.
auto attachedData() const -> const Any &
Return the attached data of the species whose type is known at runtime only.
auto withCharge(double charge) const -> Species
Return a duplicate of this Species object with new electric charge attribute.
auto molarMass() const -> double
Return the molar mass of the species (in kg/mol).
auto repr() const -> String
Return the name of the species and its chemical formula if name does not contain it (e....
Species(const Attribs &attribs)
Construct a Species object with given attributes.
auto aggregateState() const -> AggregateState
Return the aggregate state of the species.
auto clone() const -> Species
Return a deep copy of this Species object.
auto props(real T, real P) const -> SpeciesThermoProps
Calculate the complete set of standard thermodynamic properties of the species.
auto withElements(ElementalComposition elements) const -> Species
Return a duplicate of this Species object with new elemental composition.
Species()
Construct a default Species object.
auto substance() const -> String
Return the name of the underlying substance of the species if provided, otherwise,...
auto withTags(const StringList &tags) const -> Species
Return a duplicate of this Species object with new tags attribute.
auto withAggregateState(AggregateState option) const -> Species
Return a duplicate of this Species object with new aggregate state.
auto withName(String name) const -> Species
Return a duplicate of this Species object with new name that uniquely identifies this species.
auto reaction() const -> const FormationReaction &
Return the formation reaction of the species.
auto withAttachedData(Any data) const -> Species
Return a duplicate of this Species object with new attached data whose type is known at runtime only.
auto charge() const -> double
Return the electric charge of the species.
auto formula() const -> ChemicalFormula
Return the chemical formula of the species.
auto name() const -> String
Return the name that uniquely identifies this species if provided, otherwise, its formula.
Species(const String &formula)
Construct a Species object with given chemical formula (e.g., H2O, CaCO3, CO3--, CO3-2).
auto standardThermoModel() const -> const StandardThermoModel &
Return the function that computes the standard thermodynamic properties of the species.
auto withSubstance(String substance) const -> Species
Return a duplicate of this Species object with new case insensitive substance name (e....
auto tags() const -> const Strings &
Return the tags of the species (e.g., organic, mineral).
auto withFormula(String formula) const -> Species
Return a duplicate of this Species object with new formula (e.g., H2O, CaCO3, CO3--,...
auto withFormationReaction(const FormationReaction &reaction) const -> Species
Return a duplicate of this Species object with new formation reaction and new standard thermodynamic ...
A class for representing a list of strings with special constructors.
Definition: StringList.hpp:28
The namespace containing all components of the Reaktoro library.
Definition: Algorithms.hpp:29
AggregateState
The aggregate states of substances according to IUPAC.
Definition: AggregateState.hpp:32
@ Undefined
when aggregate state is not explicitly provided (default)
std::string String
Convenient alias for std::string.
Definition: Types.hpp:52
autodiff::real real
The number type used throughout the library.
Definition: Real.hpp:26
std::vector< std::string > Strings
Convenient alias for std::vector<String>.
Definition: Types.hpp:55
const char * Chars
Convenient alias for const char*.
Definition: Types.hpp:49
std::any Any
Convenient alias for std::any.
Definition: Types.hpp:125
std::shared_ptr< T > SharedPtr
Convenient alias for std::shared_ptr<T>.
Definition: Types.hpp:106
The complete set of standard thermodynamic properties of a chemical species.
Definition: SpeciesThermoProps.hpp:33
The attributes of a Species object.
Definition: Species.hpp:39
StandardThermoModel std_thermo_model
The standard thermodynamic model of the species.
Definition: Species.hpp:75
String substance
The underlying substance name (e.g.
Definition: Species.hpp:50
ElementalComposition elements
The elements that compose the species (e.g., {{"H", 2}, {"O", 1}}).
Definition: Species.hpp:54
String name
The name of the species (e.g., CO2(g), CaCO3(aq)).
Definition: Species.hpp:42
FormationReaction formation_reaction
The formation reaction of the species.
Definition: Species.hpp:69
Strings tags
The tags of the species.
Definition: Species.hpp:79
double charge
The electric charge of the species.
Definition: Species.hpp:58
String formula
The chemical formula of the species (e.g., H2O, CaCO3, CO3--, CO3-2).
Definition: Species.hpp:46
AggregateState aggregate_state
The aggregate state of the species.
Definition: Species.hpp:62
The primary standard thermodynamic properties of a chemical species.
Definition: StandardThermoProps.hpp:27