diff --git a/ThermoFun/Database.cpp b/ThermoFun/Database.cpp index b53ae193..2e2e51b2 100644 --- a/ThermoFun/Database.cpp +++ b/ThermoFun/Database.cpp @@ -46,16 +46,14 @@ struct Database::Impl { //jsonio::FJson file (filename); //type_ = file.Type(); - fromFile( filename ); - if (elements_map.size()>0) - setDBElements( elements_map ); + fromFile(filename); + setDBElements(elements_map); } Impl(std::vector<std::string> jsons, std::string _label) { fromJSONs(jsons, _label); - if (elements_map.size()>0) - setDBElements( elements_map ); + setDBElements(elements_map); } template<typename Key, typename Value> @@ -68,15 +66,18 @@ struct Database::Impl return collection; } - auto setDBElements(ElementsMap elements ) -> void + auto setDBElement(Element& element) -> void { - thfun_logger->debug("Database::setDBElements() elements {}", elements.size()); - ChemicalFun::ElementValues eldata; - for (auto& e : elements) - { - auto elkey = e.second.toElementKey(eldata); - all_elements.addElement(elkey, eldata); + auto elkey = element.toElementKey(eldata); + all_elements.addElement(elkey, eldata); + } + + auto setDBElements(ElementsMap elements) -> void + { + thfun_logger->debug("Database::setDBElements() elements {}", elements.size()); + for (auto& e : elements) { + setDBElement(e.second); } } @@ -91,12 +92,14 @@ struct Database::Impl auto addElement(const Element& element) -> void { elements_map.insert({element.symbol(), element}); + setDBElement(elements_map[element.symbol()]); } auto setElement(const Element& element) -> void { checkIfSymbolExists(elements_map, "element", element.symbol()); elements_map[element.symbol()] = element; + setDBElement(elements_map[element.symbol()]); } auto addSubstance(const Substance& substance) -> void @@ -113,6 +116,7 @@ struct Database::Impl auto addMapElements(const ElementsMap& elements) -> void { elements_map = elements; + setDBElements(elements_map); } auto addMapSubstances(const SubstancesMap& substances) -> void @@ -166,28 +170,70 @@ struct Database::Impl return reactions_map.size(); } - auto getElement(std::string symbol) -> Element& + auto getElement(std::string symbol) -> const Element& { - if(elements_map.count(symbol) == 0) + if(!containsElement(symbol)) { errorNonExistent("element", symbol, __LINE__); - - return elements_map.find(symbol)->second; + } + return elements_map[symbol]; } - auto getSubstance(std::string symbol) -> Substance& + auto getSubstance(std::string symbol) -> const Substance& { - if(substances_map.count(symbol) == 0) + if(!containsSubstance(symbol)) { errorNonExistent("substance", symbol, __LINE__); - - return substances_map.find(symbol)->second; + } + return substances_map[symbol]; } - auto getReaction(std::string symbol) -> Reaction& + auto getReaction(std::string symbol) -> const Reaction& { - if(reactions_map.count(symbol) == 0) + if(!containsReaction(symbol)) { errorNonExistent("reaction", symbol, __LINE__); + } + return reactions_map[symbol]; + } + + auto element(std::string symbol) -> Element& + { + if(!containsElement(symbol)) { // try restore data from defaults + auto el_key =ChemicalFun::ElementKey(symbol,0); + Element empty_element; + if( all_elements.elements().find(el_key) != all_elements.elements().end()) { + empty_element = elementKeyToElement(el_key); + } + else { + empty_element.setSymbol(symbol); + empty_element.setName(symbol); + } + elements_map[symbol] = empty_element; + } + return elements_map[symbol]; + } - return reactions_map.at(symbol); + auto substance(std::string symbol) -> Substance& + { + if(!containsSubstance(symbol)) { + Substance empty_subst; + empty_subst.setSymbol(symbol); + empty_subst.setName(symbol); + // ... set other default data + substances_map[symbol]=empty_subst; + } + return substances_map[symbol]; + } + + auto reaction(std::string symbol) -> Reaction& + { + if(!containsReaction(symbol)) + { + Reaction empty_react; + empty_react.setSymbol(symbol); + empty_react.setName(symbol); + // ... set other default data + reactions_map[symbol]=empty_react; + } + return reactions_map[symbol]; } auto mapElements() -> ElementsMap& @@ -466,6 +512,22 @@ auto Database::getReaction(std::string symbol) const -> const Reaction& return pimpl->getReaction(symbol); } +auto Database::element(std::string symbol) -> Element& +{ + return pimpl->element(symbol); +} + +auto Database::substance(std::string symbol) -> Substance& +{ + return pimpl->substance(symbol); +} + +auto Database::reaction(std::string symbol) -> Reaction& +{ + return pimpl->reaction(symbol); +} + + auto Database::mapElements() const -> const ElementsMap& { return pimpl->mapElements(); @@ -496,6 +558,38 @@ auto Database::getReactions() const -> std::vector<Reaction> return pimpl->getReactions(); } +// Return all elements in the database +auto Database::getElementsList() const -> std::vector<std::string> +{ + std::vector<std::string> list; + for(const auto& item: pimpl->elements_map) { + list.push_back(item.first); + } + return list; +} + +// Return all substances in the database +auto Database::getSubstancesList() const -> std::vector<std::string> +{ + std::vector<std::string> list; + for(const auto& item: pimpl->substances_map) { + list.push_back(item.first); + } + return list; +} + +// Return all reactions in the database +auto Database::getReactionsList() const -> std::vector<std::string> +{ + std::vector<std::string> list; + for(const auto& item: pimpl->reactions_map) { + list.push_back(item.first); + } + return list; +} + + + auto Database::numberOfElements() const -> size_t { return pimpl->numberOfElements(); @@ -531,7 +625,7 @@ auto Database::parseSubstanceFormula(std::string formula_) const -> std::map<Ele std::map<Element, double> map; ChemicalFun::FormulaToken formula(formula_); // ??? Do we need props, do not save - auto props = formula.properties(pimpl->all_elements.elements()); + //auto props = formula.properties(pimpl->all_elements.elements()); for (const auto& element : formula.getStoichCoefficients()) { diff --git a/ThermoFun/Database.h b/ThermoFun/Database.h index 77205275..bb70f183 100644 --- a/ThermoFun/Database.h +++ b/ThermoFun/Database.h @@ -139,6 +139,15 @@ class Database /// Return all reactions in the database auto getReactions() const -> std::vector<Reaction>; + /// Return list of all elements in the database + auto getElementsList() const -> std::vector<std::string>; + + /// Return list of all substances in the database + auto getSubstancesList() const -> std::vector<std::string>; + + /// Return list og all reactions in the database + auto getReactionsList() const -> std::vector<std::string>; + /// Returns the map of elements in the database auto mapElements() const -> const ElementsMap&; @@ -166,6 +175,15 @@ class Database /// Return a reactions in the database auto getReaction(std::string symbol) const -> const Reaction&; + /// Reference to the element in the database + auto element(std::string symbol) -> Element&; + + /// Reference to the substance in the database + auto substance(std::string symbol) -> Substance&; + + /// Reference to the reaction in the database + auto reaction(std::string symbol) -> Reaction&; + /// Check if the database contains a given element /// @param symbol The name of the element auto containsElement(std::string symbol) const -> bool; diff --git a/ThermoFun/Element.cpp b/ThermoFun/Element.cpp index a6bbb61a..b11e98e9 100644 --- a/ThermoFun/Element.cpp +++ b/ThermoFun/Element.cpp @@ -1,3 +1,4 @@ +#include <iostream> #include "Element.h" #include "ChemicalFun/FormulaParser/ChemicalData.h" #include "Common/ParseJsonToData.h" @@ -206,7 +207,7 @@ ChemicalFun::ElementKey Element::toElementKey(ChemicalFun::ElementValues &eldata eldata.number = number(); eldata.name = symbol(); // was e.name(); - return ChemicalFun::ElementKey(symbol(), class_(), isotopeMass() ); + return ChemicalFun::ElementKey(symbol(), class_(), isotopeMass()); } auto operator<(const Element& lhs, const Element& rhs) -> bool @@ -265,4 +266,22 @@ auto operator==(const Element& lhs, const Element& rhs) -> bool (lhs.isotopeMass() == rhs.isotopeMass()); } + +auto operator<<(std::ostream& stream, const Element& element) -> std::ostream& +{ + stream << "Element(\n"; + stream << " name: " << element.name() << "\n"; + stream << " symbol: " << element.symbol() << "\n"; + stream << " molarMass: " << element.molarMass() << "\n"; + stream << " entropy: " << element.entropy() << "\n"; + stream << " heatCapacity: " << element.heatCapacity() << "\n"; + stream << " volume: " << element.volume() << "\n"; + stream << " valence: " << element.valence() << "\n"; + stream << " class: " << element.class_() << "\n"; + stream << " isotopeMass: " << element.isotopeMass() << "\n"; + stream << " number: " << element.number() << "\n)" << std::endl; + return stream; +} + + } // namespace ThermoFun diff --git a/ThermoFun/Element.h b/ThermoFun/Element.h index 521fc7ed..c36709fd 100644 --- a/ThermoFun/Element.h +++ b/ThermoFun/Element.h @@ -120,6 +120,8 @@ auto operator<(const Element& lhs, const Element& rhs) -> bool; /// Compare two Element instances for equality auto operator==(const Element& lhs, const Element& rhs) -> bool; +auto operator<<(std::ostream& stream, const Element& element) -> std::ostream&; + } // namespace ThermoFun #endif // ELEMENT_H diff --git a/ThermoFun/GlobalVariables.h b/ThermoFun/GlobalVariables.h index e4419de8..09726a90 100644 --- a/ThermoFun/GlobalVariables.h +++ b/ThermoFun/GlobalVariables.h @@ -775,6 +775,18 @@ static const char * reacFMcoeff = "dr_marshall_franck_coeffs.values"; //typedef std::vector<struct ReactionData> Reactions; +/// Output a array instance +template<typename V> +auto operator<<(std::ostream& out, const std::vector<V>& array) -> std::ostream& +{ + out << std::string("[ "); + for(const auto& val: array) { + out << val << " "; + } + out << std::string("]"); + return out; +} + } ///@endcond diff --git a/ThermoFun/Reaction.cpp b/ThermoFun/Reaction.cpp index 715ec252..8a641828 100644 --- a/ThermoFun/Reaction.cpp +++ b/ThermoFun/Reaction.cpp @@ -519,7 +519,73 @@ auto Reaction::calc_logK_fT_coefficients() -> vd // setThermoParameters(th_param); } +auto operator<<(std::ostream& stream, const ThermoPropertiesReaction& data) -> std::ostream& +{ + stream << "( " << data.ln_equilibrium_constant << ", " << data.log_equilibrium_constant << ", " + << data.reaction_gibbs_energy << ", "<< data.reaction_helmholtz_energy << ", " + << data.reaction_internal_energy << ", "<< data.reaction_enthalpy << ", " + << data.reaction_entropy << ", "<< data.reaction_volume << ", " + << data.reaction_heat_capacity_cp << ", "<< data.reaction_heat_capacity_cv << " )"; + return stream; +} + +auto operator<<(std::ostream& stream, const ThermoParametersReaction& data) -> std::ostream& +{ + if( !data.temperature_intervals.empty() ) { + stream << " temperature_intervals: " << data.temperature_intervals << "\n"; + } + if( !data.pressure_intervals.empty() ) { + stream << " pressure_intervals: " << data.pressure_intervals << "\n"; + } + if( !data.reaction_logK_fT_coeff.empty() ) { + stream << " reaction_logK_fT_coeff: " << data.reaction_logK_fT_coeff << "\n"; + } + if( !data.logK_TP_array.empty() ) { + stream << " logK_TP_array: " << data.logK_TP_array << "\n"; + } + if( !data.reaction_Cp_fT_coeff.empty() ) { + stream << " reaction_Cp_fT_coeff: " << data.reaction_Cp_fT_coeff << "\n"; + } + if( !data.reaction_V_fT_coeff.empty() ) { + stream << " reaction_V_fT_coeff: " << data.reaction_V_fT_coeff << "\n"; + } + if( !data.reaction_RB_coeff.empty() ) { + stream << " reaction_RB_coeff: " << data.reaction_RB_coeff << "\n"; + } + if( !data.reaction_RB_coeff.empty() ) { + stream << " reaction_RB_coeff: " << data.reaction_RB_coeff << "\n"; + } + if( !data.reaction_FM_coeff.empty() ) { + stream << " reaction_FM_coeff: " << data.reaction_FM_coeff << "\n"; + } + if( !data.reaction_DM10_coeff.empty() ) { + stream << " reaction_DM10_coeff: " << data.reaction_DM10_coeff << "\n"; + } + return stream; +} +auto operator<<(std::ostream& stream, const Reaction& react) -> std::ostream& +{ + stream << "Reaction(\n"; + stream << " name: " << react.name() << "\n"; + stream << " symbol: " << react.symbol() << "\n"; + stream << " equation: " << react.equation() << "\n"; + stream << " reactants: "; + stream << std::string("[ "); + for(const auto& val: react.reactants()) { + stream << "( " << val.first << " : " << val.second << " ) "; + } + stream << std::string("]\n"); + stream << " thermoReferenceProperties: " << react.thermoReferenceProperties() << "\n"; + stream << " thermo_ref_prop: " << react.thermo_ref_prop() << "\n"; + stream << " thermoParameters: \n" << react.thermoParameters(); + stream << " T: ( " << react.referenceT() << ", " << react.lowerT() << ", " << react.upperT() << " )\n"; + stream << " P: ( " << react.referenceP() << ", " << react.lowerP() << ", " << react.upperP() << " )\n"; + stream << " methodGenEOS: " << react.methodGenEOS() << "\n"; + stream << " method_T: " << react.method_T() << "\n"; + stream << " method_P: " << react.method_P() << "\n)" << std::endl; + return stream; +} } // namespace ThermoFun diff --git a/ThermoFun/Reaction.h b/ThermoFun/Reaction.h index f4a297f0..4cd14df6 100644 --- a/ThermoFun/Reaction.h +++ b/ThermoFun/Reaction.h @@ -172,6 +172,8 @@ class Reaction }; +auto operator<<(std::ostream& stream, const Reaction& react) -> std::ostream&; + } // namespace ThermoFun #endif // REACTION_H diff --git a/ThermoFun/Substance.cpp b/ThermoFun/Substance.cpp index c8164e49..a17c8e19 100644 --- a/ThermoFun/Substance.cpp +++ b/ThermoFun/Substance.cpp @@ -364,5 +364,83 @@ auto operator==(const Substance& lhs, const Substance& rhs) -> bool (lhs.name() == rhs.name()); } + +auto operator<<(std::ostream& stream, const ThermoPropertiesSubstance& data) -> std::ostream& +{ + stream << "( " << data.gibbs_energy << ", " << data.helmholtz_energy << ", " + << data.internal_energy << ", "<< data.enthalpy << ", " + << data.entropy << ", "<< data.volume << ", " + << data.heat_capacity_cp << ", "<< data.heat_capacity_cv << " )"; + return stream; +} + +auto operator<<(std::ostream& stream, const ThermoParametersSubstance& data) -> std::ostream& +{ + stream << "( " << data.isothermal_compresibility << ", " << data.isobaric_expansivity << " )\n"; + if( !data.temperature_intervals.empty() ) { + stream << " temperature_intervals: " << data.temperature_intervals << "\n"; + } + if( !data.pressure_intervals.empty() ) { + stream << " pressure_intervals: " << data.pressure_intervals << "\n"; + } + if( !data.Cp_coeff.empty() ) { + stream << " Cp_coeff: " << data.Cp_coeff << "\n"; + } + if( !data.Cp_nonElectrolyte_coeff.empty() ) { + stream << " Cp_nonElectrolyte_coeff: " << data.Cp_nonElectrolyte_coeff << "\n"; + } + if( !data.phase_transition_prop.empty() ) { + stream << " phase_transition_prop: " << data.phase_transition_prop << "\n"; + } + if( !data.phase_transition_prop_Berman.empty() ) { + stream << " phase_transition_prop_Berman: " << data.phase_transition_prop_Berman << "\n"; + } + if( !data.m_landau_phase_trans_props.empty() ) { + stream << " m_landau_phase_trans_props: " << data.m_landau_phase_trans_props << "\n"; + } + if( !data.HKF_parameters.empty() ) { + stream << " HKF_parameters: " << data.HKF_parameters << "\n"; + } + if( !data.volume_coeff.empty() ) { + stream << " volume_coeff: " << data.volume_coeff << "\n"; + } + if( !data.critical_parameters.empty() ) { + stream << " critical_parameters: " << data.critical_parameters << "\n"; + } + if( !data.volume_BirchM_coeff.empty() ) { + stream << " volume_BirchM_coeff: " << data.volume_BirchM_coeff << "\n"; + } + if( !data.empirical_coeff.empty() ) { + stream << " empirical_coeff: " << data.empirical_coeff << "\n"; + } + if( !data.solute_holland_powell98_coeff.empty() ) { + stream << " solute_holland_powell98_coeff: " << data.solute_holland_powell98_coeff << "\n"; + } + return stream; +} + +auto operator<<(std::ostream& stream, const Substance& subst) -> std::ostream& +{ + stream << "Substance(\n"; + stream << " name: " << subst.name() << "\n"; + stream << " symbol: " << subst.symbol() << "\n"; + stream << " formula: " << subst.formula() << "\n"; + stream << " reactionSymbol: " << subst.reactionSymbol() << "\n"; + stream << " molarMass: " << subst.molarMass() << "\n"; + stream << " T: ( " << subst.referenceT() << ", " << subst.lowerT() << ", " << subst.upperT() << " )\n"; + stream << " P: ( " << subst.referenceP() << ", " << subst.lowerP() << ", " << subst.upperP() << " )\n"; + stream << " thermoProperties: " << subst.thermoProperties() << "\n"; + stream << " thermoParameters: " << subst.thermoParameters(); + stream << " thermoReferenceProperties: " << subst.thermoReferenceProperties() << "\n"; + stream << " methodGenEOS: " << subst.methodGenEOS() << "\n"; + stream << " method_T: " << subst.method_T() << "\n"; + stream << " method_P: " << subst.method_P() << "\n"; + stream << " substanceClass: " << subst.substanceClass() << "\n"; + stream << " thermoCalculationType: " << subst.thermoCalculationType() << "\n"; + stream << " aggregateState: " << subst.aggregateState() << "\n"; + stream << " charge: " << subst.charge() << "\n)" << std::endl; + return stream; +} + } // namespace ThermoFun diff --git a/ThermoFun/Substance.h b/ThermoFun/Substance.h index 00c1c9c5..d85553f6 100644 --- a/ThermoFun/Substance.h +++ b/ThermoFun/Substance.h @@ -208,6 +208,8 @@ auto operator>(const Substance& lhs, const Substance& rhs) -> bool; /// Compare two Substance instances for equality auto operator==(const Substance& lhs, const Substance& rhs) -> bool; +auto operator<<(std::ostream& stream, const Substance& subst) -> std::ostream&; + } // namespace ThermoFun #endif // SUBSTANCE_H diff --git a/ci/pipelines/install.sh b/ci/pipelines/install.sh index 4381ef10..6094d57d 100644 --- a/ci/pipelines/install.sh +++ b/ci/pipelines/install.sh @@ -1,6 +1,6 @@ if [ ! -f $HOME/miniconda/bin/conda ]; then echo "Downloading and installing miniconda" - wget -O miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh + wget --no-check-certificate -O miniconda.sh https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh rm -rf $HOME/miniconda bash miniconda.sh -b -p $HOME/miniconda fi @@ -14,6 +14,7 @@ conda config --set always_yes yes --set changeps1 no conda config --add channels conda-forge conda install conda-devenv conda update -q conda +conda config --set ssl_verify false || exit 1 conda info -a conda devenv source activate thermofun diff --git a/examples/database_api.py b/examples/database_api.py new file mode 100644 index 00000000..9fe229b8 --- /dev/null +++ b/examples/database_api.py @@ -0,0 +1,46 @@ +import thermofun as thermofun + +database = thermofun.Database('test-database-thermofun.json') + +print("Elements \n", database.getElementsList()) +print("Substances \n", database.getSubstancesList()) +print("Reactions \n", database.getReactionsList()) + +# Element +elment_O = database.getElement("O") +print(elment_O) +elment_O.setValence(-2) +print(elment_O) +print(database.getElement("O")) + +elment_ref = database.element("H") +print(elment_ref) +elment_ref.setValence(1) +print(elment_ref) +print(database.getElement("H")) + +elment_new = database.element("Co"); # get from defaults +print(elment_new) +print(database.getElement("Co")) + +elment_empty = database.element("Ac"); #empty data +print(elment_empty) +print(database.getElement("Ac")) + +# Substance + +subst = database.substance("Quartz") +subst.setMolarMass(60.084300994873) +print(database.getSubstance("Quartz")) +subst_H2O = database.substance("H2O@") +subst_H2O.setMolarMass(18.015300750732) +print(database.getSubstance("H2O@")) + +subst_Co = database.substance("Co+2") +print(subst_Co) + +# Reaction +react = database.reaction("Gedrite-Mg") +react.setUpperP(1e5) +print(react) +#print(database) diff --git a/examples/test-database-thermofun.json b/examples/test-database-thermofun.json new file mode 100644 index 00000000..f499a0f5 --- /dev/null +++ b/examples/test-database-thermofun.json @@ -0,0 +1,1121 @@ +{ + "thermodataset": "compiled for testing the database parser", + "datasources": [], + "date": "09.12.2019 13:03:05", + "substances": [ + { + "name": "Water HGK", + "symbol": "H2O@", + "formula": "H2O@", + "formula_charge": 0, + "aggregate_state": { + "4": "AS_AQUEOUS" + }, + "class_": { + "3": "SC_AQSOLVENT" + }, + "Tst": 298.15, + "Pst": 100000, + "TPMethods": [ + { + "method": { + "32": "water_eos_iapws95_reaktoro" + } + }, + { + "method": { + "25": "water_diel_jnort91_reaktoro" + } + } + ], + "sm_heat_capacity_p": { + "values": [ + 75.360527038574 + ], + "errors": [ + 0 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_gibbs_energy": { + "values": [ + -237183 + ], + "errors": [ + 100 + ], + "units": [ + "J/mol" + ] + }, + "sm_enthalpy": { + "values": [ + -285881 + ], + "errors": [ + 200 + ], + "units": [ + "J/mol" + ] + }, + "sm_entropy_abs": { + "values": [ + 69.922996520996 + ], + "errors": [ + 0.10000000149012 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_volume": { + "values": [ + 1.8068397045136 + ], + "errors": [ + 0 + ], + "units": [ + "J/bar" + ] + }, + "references": [ + "[1992JOH/OEL]" + ] + }, + { + "name": "Quartz (q)", + "symbol": "Quartz", + "formula": "SiO2", + "formula_charge": 0, + "aggregate_state": { + "3": "AS_CRYSTAL" + }, + "class_": { + "0": "SC_COMPONENT" + }, + "Tst": 298.15, + "Pst": 100000, + "TPMethods": [ + { + "method": { + "0": "cp_ft_equation" + }, + "limitsTP": { + "range": true, + "lowerT": 273.15, + "upperT": 2273.15 + }, + "m_heat_capacity_ft_coeffs": { + "values": [ + 110.69999694824, + -0.0051890001632273, + 0, + -1128.3000488281, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0 + ], + "units": [ + "J/(mol*K)", + "J/(mol*K^2)", + "(J*K)/mol", + "J/(mol*K^0.5)", + "J/(mol*K^3)", + "J/(mol*K^4)", + "J/(mol*K^5)", + "(J*K^2)/mol", + "J/mol", + "J/(mol*K^1.5)", + "J/(mol*K)" + ], + "names": [ + "a0", + "a1", + "a2", + "a3", + "a4", + "a5", + "a6", + "a7", + "a8", + "a9", + "a10" + ] + } + }, + { + "method": { + "5": "landau_holland_powell98" + }, + "m_landau_phase_trans_props": { + "values": [ + 573.84997558594, + 4.9499998092651, + 0.11879999935627 + ] + } + }, + { + "method": { + "38": "mv_eos_murnaghan_hp98" + } + } + ], + "sm_heat_capacity_p": { + "values": [ + 44.89091873169 + ], + "errors": [ + 0 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_gibbs_energy": { + "values": [ + -856433 + ], + "units": [ + "J/mol" + ] + }, + "sm_enthalpy": { + "values": [ + -910830 + ], + "units": [ + "J/mol" + ] + }, + "sm_entropy_abs": { + "values": [ + 41.5 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_volume": { + "values": [ + 2.2688000202179 + ], + "errors": [ + 0 + ], + "units": [ + "J/bar" + ] + }, + "m_compressibility": { + "values": [ + 750 + ], + "units": [ + "1e-05/K" + ] + }, + "m_expansivity": { + "values": [ + 0.0000064999999267457 + ], + "units": [ + "kbar" + ] + }, + "datasources": [ + "[1998HOL/POW]" + ] + }, + { + "name": "Al(OH)2+", + "symbol": "Al(OH)2+", + "formula": "Al(OH)2+", + "formula_charge": 1, + "aggregate_state": { + "4": "AS_AQUEOUS" + }, + "class_": { + "2": "SC_AQSOLUTE" + }, + "Tst": 298.15, + "Pst": 100000, + "TPMethods": [ + { + "method": { + "3": "solute_hkf88_reaktoro" + }, + "eos_hkf_coeffs": { + "values": [ + 0.24940000474453, + -169.08999633789, + 6.4145998954773, + -27091, + 16.743900299072, + -43785.56, + 53240, + 0 + ], + "units": [ + "cal/(mol*bar)", + "cal/mol", + "(cal*K)/(mol*bar)", + "(cal*K)/mol", + "cal/(mol*K)", + "(J*K)/mol", + "cal/mol" + ], + "names": [ + "a1", + "a2", + "a3", + "a4", + "c1", + "c2", + "wref" + ] + } + } + ], + "sm_heat_capacity_p": { + "values": [ + 40.865230560303 + ], + "errors": [ + 0 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_gibbs_energy": { + "values": [ + -898292 + ], + "units": [ + "J/mol" + ] + }, + "sm_enthalpy": { + "values": [ + -995581 + ], + "units": [ + "J/mol" + ] + }, + "sm_entropy_abs": { + "values": [ + -27.530000686646 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_volume": { + "values": [ + 0.38507527112961 + ], + "errors": [ + 0 + ], + "units": [ + "J/bar" + ] + }, + "references": [ + "[2001TAG/SCH]", + "[2017MIR/WAG]" + ] + }, + { + "name": "Al(OH)3 (aq)", + "symbol": "Al(OH)3@", + "formula": "Al(OH)3@", + "formula_charge": 0, + "aggregate_state": { + "4": "AS_AQUEOUS" + }, + "class_": { + "2": "SC_AQSOLUTE" + }, + "Tst": 298.15, + "Pst": 100000, + "TPMethods": [ + { + "method": { + "3": "solute_hkf88_reaktoro" + }, + "eos_hkf_coeffs": { + "values": [ + 0.61976999044418, + 828.15997314453, + 2.4949998855591, + -31214, + 71.100303649902, + -10644, + 104610, + 0 + ], + "units": [ + "cal/(mol*bar)", + "cal/mol", + "(cal*K)/mol", + "cal/(mol*K)", + "(cal*K)/mol", + "cal/mol" + ], + "names": [ + "a1", + "a2", + "a3", + "a4", + "c1", + "c2", + "wref" + ] + } + } + ], + "sm_heat_capacity_p": { + "values": [ + 248.5594329834 + ], + "errors": [ + 0 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_gibbs_energy": { + "values": [ + -1105813 + ], + "units": [ + "J/mol" + ] + }, + "sm_enthalpy": { + "values": [ + -1262898 + ], + "units": [ + "J/mol" + ] + }, + "sm_entropy_abs": { + "values": [ + 5.1609997749329 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_volume": { + "values": [ + 3.0679812431335 + ], + "errors": [ + 0 + ], + "units": [ + "J/bar" + ] + }, + "references": [ + "[2016MIR/WAG]", + "[2017MIR/WAG]" + ] + }, + { + "name": "Al(OH)4-", + "symbol": "Al(OH)4-", + "formula": "Al(OH)4-", + "formula_charge": -1, + "aggregate_state": { + "4": "AS_AQUEOUS" + }, + "class_": { + "2": "SC_AQSOLUTE" + }, + "Tst": 298.15, + "Pst": 100000, + "TPMethods": [ + { + "method": { + "3": "solute_hkf88_reaktoro" + }, + "eos_hkf_coeffs": { + "values": [ + 0.8493999838829, + 1295.7600097656, + 0.65700000524521, + -33147, + 55.726501464844, + -114047, + 104030, + 0 + ], + "units": [ + "cal/(mol*bar)", + "cal/mol", + "(cal*K)/mol", + "cal/(mol*K)", + "(cal*K)/mol", + "cal/mol" + ], + "names": [ + "a1", + "a2", + "a3", + "a4", + "c1", + "c2", + "wref" + ] + } + } + ], + "sm_heat_capacity_p": { + "values": [ + 96.54020690918 + ], + "errors": [ + 0 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_gibbs_energy": { + "values": [ + -1305097 + ], + "units": [ + "J/mol" + ] + }, + "sm_enthalpy": { + "values": [ + -1502391 + ], + "units": [ + "J/mol" + ] + }, + "sm_entropy_abs": { + "values": [ + 103.55000305176 + ], + "units": [ + "J/(mol*K)" + ] + }, + "sm_volume": { + "values": [ + 4.6286010742188 + ], + "errors": [ + 0 + ], + "units": [ + "J/bar" + ] + }, + "references": [ + "[2017MIR/WAG]", + "[2001TAG/SCH]" + ] + } + ], + "reactions": [ + { + "symbol": "Meionite-Ca", + "equation": "Ca4Al6Si6O24(CO3) + 25H+ = HCO3- + 6H4SiO4@ + 4Ca+2 + 6Al+3", + "reactants": [ + { + "symbol": "Meionite-Ca", + "coefficient": -1 + }, + { + "symbol": "Ca+2", + "coefficient": 4 + }, + { + "symbol": "H+", + "coefficient": -25 + }, + { + "symbol": "Al+3", + "coefficient": 6 + }, + { + "symbol": "HCO3-", + "coefficient": 1 + }, + { + "symbol": "H4SiO4@", + "coefficient": 6 + } + ], + "limitsTP": { + "range": false, + "lowerP": 0.1, + "lowerT": 273.15, + "upperP": 1000000, + "upperT": 298.15 + }, + "TPMethods": [ + { + "method": { + "7": "logk_3_term_extrap" + }, + "logk_ft_coeffs": { + "values": [ + 0, + 0, + 49480.5741302139, + -135.727504800267, + 0, + 0, + 0 + ] + } + } + ], + "logKr": { + "values": [ + 80.875017 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_heat_capacity_p": { + "values": [ + -2.598484998 + ], + "status": [ + {} + ], + "errors": [ + 0 + ], + "units": [ + "kJ/(mol*K)" + ] + }, + "drsm_gibbs_energy": { + "values": [ + -461638 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_enthalpy": { + "values": [ + -947299 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_entropy": { + "values": [ + -1628.802946 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_volume": { + "values": [ + -34.822208 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "references": [] + }, + { + "symbol": "Gedrite-Mg", + "equation": "Mg5Al4Si6O22(OH)2 + 22H+ = 5Mg+2 + 6H4SiO4@ + 4Al+3", + "reactants": [ + { + "symbol": "Al+3", + "coefficient": 4 + }, + { + "symbol": "H+", + "coefficient": -22 + }, + { + "symbol": "Mg+2", + "coefficient": 5 + }, + { + "symbol": "H4SiO4@", + "coefficient": 6 + }, + { + "symbol": "Gedrite-Mg", + "coefficient": -1 + } + ], + "limitsTP": { + "range": false, + "lowerP": 0.1, + "lowerT": 273.15, + "upperP": 1000000, + "upperT": 298.15 + }, + "TPMethods": [ + { + "method": { + "7": "logk_3_term_extrap" + }, + "logk_ft_coeffs": { + "values": [ + 0, + 0, + 45576.5511431312, + -116.731447311398, + 0, + 0, + 0 + ] + } + } + ], + "logKr": { + "values": [ + 86.347122 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_heat_capacity_p": { + "values": [ + -2234.808008 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_gibbs_energy": { + "values": [ + -492873 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_enthalpy": { + "values": [ + -872557 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_entropy": { + "values": [ + -1273.361998 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_volume": { + "values": [ + -23.621949 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "references": [] + }, + { + "symbol": "Tschermakite-Mg", + "equation": "Ca2Mg3Al4Si6O22(OH)2 + 22H+ = 3Mg+2 + 6H4SiO4@ + 2Ca+2 + 4Al+3", + "reactants": [ + { + "symbol": "Tschermakite-Mg", + "coefficient": -1 + }, + { + "symbol": "Ca+2", + "coefficient": 2 + }, + { + "symbol": "H+", + "coefficient": -22 + }, + { + "symbol": "Mg+2", + "coefficient": 3 + }, + { + "symbol": "Al+3", + "coefficient": 4 + }, + { + "symbol": "H4SiO4@", + "coefficient": 6 + } + ], + "limitsTP": { + "range": false, + "lowerP": 0.1, + "lowerT": 273.15, + "upperP": 1000000, + "upperT": 298.15 + }, + "TPMethods": [ + { + "method": { + "7": "logk_3_term_extrap" + }, + "logk_ft_coeffs": { + "values": [ + 0, + 0, + 41843.5400537728, + -117.965713199459, + 0, + 0, + 0 + ] + } + } + ], + "logKr": { + "values": [ + 80.782516 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_heat_capacity_p": { + "values": [ + -2258.437864 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_gibbs_energy": { + "values": [ + -461110 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_enthalpy": { + "values": [ + -801089 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_entropy": { + "values": [ + -1140.189985 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_volume": { + "values": [ + -23.906949 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "references": [] + }, + { + "symbol": "Pargasite-Mg", + "equation": "NaCa2Mg4Al3Si6O22(OH)2 + 22H+ = Na+ + 4Mg+2 + 6H4SiO4@ + 2Ca+2 + 3Al+3", + "reactants": [ + { + "symbol": "Pargasite-Mg", + "coefficient": -1 + }, + { + "symbol": "H4SiO4@", + "coefficient": 6 + }, + { + "symbol": "H+", + "coefficient": -22 + }, + { + "symbol": "Ca+2", + "coefficient": 2 + }, + { + "symbol": "Na+", + "coefficient": 1 + }, + { + "symbol": "Al+3", + "coefficient": 3 + }, + { + "symbol": "Mg+2", + "coefficient": 4 + } + ], + "limitsTP": { + "range": false, + "lowerP": 0.1, + "lowerT": 273.15, + "upperP": 1000000, + "upperT": 298.15 + }, + "TPMethods": [ + { + "method": { + "7": "logk_3_term_extrap" + }, + "logk_ft_coeffs": { + "values": [ + 0, + 0, + 41068.2930818657, + -112.608666730033, + 0, + 0, + 0 + ] + } + } + ], + "logKr": { + "values": [ + 88.842023 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_heat_capacity_p": { + "values": [ + -2155.877923 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_gibbs_energy": { + "values": [ + -507114 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_enthalpy": { + "values": [ + -786247 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_entropy": { + "values": [ + -936.111361 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "drsm_volume": { + "values": [ + -22.085351 + ], + "status": [ + {} + ], + "errors": [ + 0 + ] + }, + "references": [] + } + ], + "elements": [ + { + "symbol": "Zz", + "class_": { + "4": "CHARGE" + }, + "entropy": { + "values": [ + -65.3399963378906 + ], + "name": "S0i" + }, + "atomic_mass": { + "values": [ + 0 + ], + "name": "M0i" + }, + "references": [ + "[1998SHO/EA]" + ] + }, + { + "symbol": "H", + "class_": { + "0": "ELEMENT" + }, + "entropy": { + "values": [ + 65.3399963378906 + ], + "name": "S0i" + }, + "atomic_mass": { + "values": [ + 1.00794994831085 + ], + "name": "M0i" + }, + "references": [ + "[1998SHO/EA]" + ] + }, + { + "symbol": "C", + "class_": { + "0": "ELEMENT" + }, + "entropy": { + "values": [ + 5.73999977111816 + ], + "name": "S0i" + }, + "atomic_mass": { + "values": [ + 12.0108003616333 + ], + "name": "M0i" + }, + "references": [ + "[1998SHO/EA]" + ] + }, + { + "symbol": "O", + "class_": { + "0": "ELEMENT" + }, + "entropy": { + "values": [ + 102.569000244141 + ], + "name": "S0i" + }, + "atomic_mass": { + "values": [ + 15.999400138855 + ], + "name": "M0i" + }, + "references": [ + "[1998SHO/EA]" + ] + } + ] +} \ No newline at end of file diff --git a/pytests/test_database.py b/pytests/test_database.py index e5445a76..cd686027 100644 --- a/pytests/test_database.py +++ b/pytests/test_database.py @@ -49,6 +49,55 @@ def test_append_element(self): assert self.database.parseSubstanceFormula('Co+2') assert self.database.numberOfElements() == 5 + def test_reference_element(self): + elment_O = self.database.getElement("O") + elment_O.setValence(-3) + assert self.database.getElement("O").valence() != -3 + assert elment_O.valence() == -3 + elment_H = self.database.element("H") + elment_H.setValence(1) + assert self.database.getElement("H").valence() == 1 + # new + elment_new = self.database.element("Co"); # get from defaults + assert self.database.numberOfElements() == 5 + assert self.database.element("Co").name() == 'Co' + assert self.database.element("Co").symbol() == 'Co' + assert self.database.element("Co").molarMass() == 58.9332008361816 + assert self.database.element("Co").entropy() == 30.0400009155273 + assert self.database.element("Co").heatCapacity() == 24.8099994659424 + assert self.database.element("Co").volume() == 6.61999988555908 + assert self.database.element("Co").valence() == 2 + assert self.database.element("Co").class_() == 0 + assert self.database.element("Co").isotopeMass() == 0 + assert self.database.element("Co").number() == 27 + + def test_reference_substance(self): + subst = self.database.substance("Quartz") + subst.setMolarMass(60.084300994873) + assert self.database.getSubstance("Quartz").molarMass() == 60.084300994873 + subst2 = self.database.substance("H2O@") + subst2.setMolarMass(18.015300750732) + assert self.database.getSubstance("H2O@").molarMass() == 18.015300750732 + # new empty + subst_new = self.database.substance("Co+2"); # zero values + assert self.database.numberOfSubstances() == 6 + assert self.database.getSubstancesList() == ['Al(OH)2+', 'Al(OH)3@', 'Al(OH)4-', 'Co+2', 'H2O@', 'Quartz'] + assert self.database.getSubstance("Co+2").name() == 'Co+2' + assert self.database.getSubstance("Co+2").symbol() == 'Co+2' + assert self.database.getSubstance("Co+2").molarMass() == 0 + + def test_reference_reaction(self): + react = self.database.reaction("Gedrite-Mg") + react.setUpperP(1e5) + assert self.database.getReaction("Gedrite-Mg").upperP() == 1e5 + # new empty + react_new = self.database.reaction("Co+2"); # zero values + assert self.database.numberOfReactions() == 5 + assert self.database.getReactionsList() == ['Co+2', 'Gedrite-Mg', 'Meionite-Ca', 'Pargasite-Mg', 'Tschermakite-Mg'] + assert self.database.getReaction("Co+2").name() == 'Co+2' + assert self.database.getReaction("Co+2").symbol() == 'Co+2' + assert self.database.getReaction("Co+2").upperP() == 0 + def test_formula_parser(self): self.database.appendData('pytests/Fe-O_system.json') assert self.database.parseSubstanceFormula('FeFe|3|2O4') diff --git a/python/pyThermoFun/pyDatabase.cpp b/python/pyThermoFun/pyDatabase.cpp index 6c031386..4ca2a085 100644 --- a/python/pyThermoFun/pyDatabase.cpp +++ b/python/pyThermoFun/pyDatabase.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with ThermoFun code. If not, see <http://www.gnu.org/licenses/>. +#include <sstream> #if _MSC_VER >= 1929 #include <corecrt.h> #endif @@ -78,6 +79,9 @@ void exportDatabase(py::module& m) .def("getElements", &Database::getElements, "Return all elements in the database") .def("getSubstances", &Database::getSubstances, "Return all substances in the database") .def("getReactions", &Database::getReactions, "Return all reactions in the database") + .def("getElementsList", &Database::getElementsList, "List of all elements in the database") + .def("getSubstancesList", &Database::getSubstancesList, "List of all substances in the database") + .def("getReactionsList", &Database::getReactionsList, "List of all reactions in the database") .def("mapElements", &Database::mapElements, "Returns the map of elements in the database") .def("mapSubstances", &Database::mapSubstances, "Returns the map of substances in the database") .def("mapReactions", &Database::mapReactions, "Returns the map of reactions in the database") @@ -87,10 +91,14 @@ void exportDatabase(py::module& m) .def("getElement", &Database::getElement, "Return a element in the database") .def("getSubstance", &Database::getSubstance, "Return a substance in the database") .def("getReaction", &Database::getReaction, "Return a reactions in the database") + .def("element", &Database::element, py::return_value_policy::reference, "Reference to the element in the database") + .def("substance", &Database::substance, py::return_value_policy::reference, "Reference to the substance in the database") + .def("reaction", &Database::reaction, py::return_value_policy::reference, "Reference to the reaction in the database") .def("containsElement", &Database::containsElement, "Check if the database contains a given element") .def("containsSubstance", &Database::containsSubstance, "Check if the database contains a given substance") .def("containsReaction", &Database::containsReaction, "Check if the database contains a given reaction") .def("parseSubstanceFormula", &Database::parseSubstanceFormula, "Parses a given substance formula present in the database") + .def("__str__", [](const Database& self) { std::stringstream ss; ss << self.getElements(); ss << self.getSubstances(); ss << self.getReactions(); return ss.str(); }) ; } diff --git a/python/pyThermoFun/pyElement.cpp b/python/pyThermoFun/pyElement.cpp index aaf0a004..cf4c53c8 100644 --- a/python/pyThermoFun/pyElement.cpp +++ b/python/pyThermoFun/pyElement.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with ThermoFun code. If not, see <http://www.gnu.org/licenses/>. +#include <sstream> #if _MSC_VER >= 1929 #include <corecrt.h> #endif @@ -57,6 +58,7 @@ void exportElement(py::module& m) .def("isotopeMass", &Element::isotopeMass, "Return the rounded isotopic mass of the element") .def("number", &Element::number, "Return the Mendeleev table number of the element") .def("jsonString", &Element::jsonString, "Return the record as a json string") + .def("__str__", [](const Element& self) { std::stringstream ss; ss << self; return ss.str(); }) ; } diff --git a/python/pyThermoFun/pyReaction.cpp b/python/pyThermoFun/pyReaction.cpp index 5e834b10..0665264c 100644 --- a/python/pyThermoFun/pyReaction.cpp +++ b/python/pyThermoFun/pyReaction.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with ThermoFun code. If not, see <http://www.gnu.org/licenses/>. +#include <sstream> #if _MSC_VER >= 1929 #include <corecrt.h> #endif @@ -71,6 +72,7 @@ void exportReaction(py::module& m) .def("method_T", &Reaction::method_T,"Return the temperature correction method code") .def("method_P", &Reaction::method_P,"Return the pressure correction method code") .def("jsonString", &Reaction::jsonString, "Return the record as a json string") + .def("__str__", [](const Reaction& self) { std::stringstream ss; ss << self; return ss.str(); }) ; } diff --git a/python/pyThermoFun/pySubstance.cpp b/python/pyThermoFun/pySubstance.cpp index 84c7c2eb..4ac3d251 100644 --- a/python/pyThermoFun/pySubstance.cpp +++ b/python/pyThermoFun/pySubstance.cpp @@ -16,6 +16,7 @@ // You should have received a copy of the GNU General Public License // along with ThermoFun code. If not, see <http://www.gnu.org/licenses/>. +#include <sstream> #if _MSC_VER >= 1929 #include <corecrt.h> #endif @@ -80,6 +81,7 @@ void exportSubstance(py::module& m) .def("aggregateState", &Substance::aggregateState, "Return the aggregate state of a substance") .def("charge", &Substance::charge, "Return the charge of a substance") .def("jsonString", &Substance::jsonString, "Return the record as a json string") + .def("__str__", [](const Substance& self) { std::stringstream ss; ss << self; return ss.str(); }) ; } diff --git a/python/thermofun/CMakeLists.txt b/python/thermofun/CMakeLists.txt index cb4460fe..4d7b8ccc 100644 --- a/python/thermofun/CMakeLists.txt +++ b/python/thermofun/CMakeLists.txt @@ -34,8 +34,26 @@ add_dependencies(thermofun PyThermoFun) # Set the path where the python package is installed to CMAKE_INSTALL_PREFIX if not given if(NOT DEFINED THERMOFUN_PYTHON_INSTALL_PREFIX) - set(THERMOFUN_PYTHON_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) -endif() + +# Install the thermofun python package using setuptools +install(CODE +" + if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/../../lib/PyThermoFun.pdb) + string(REPLACE .pyd .pdb THERMOFUN_PDB_FILENAME \"${THERMOFUN_PYTHON_MODULE_FILENAME}\") + + execute_process( + COMMAND \${CMAKE_COMMAND} -E copy ../../lib/PyThermoFun.pdb \${THERMOFUN_PDB_FILENAME} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + execute_process( + COMMAND ${PYTHON_EXECUTABLE} -m pip install ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) +" +) + +else() + # If the path is already in Windows format (with backslashes), it can't be added directly # to the string below, otherwise CMake will later complain about "Invalid escape sequence". file(TO_CMAKE_PATH "${THERMOFUN_PYTHON_INSTALL_PREFIX}" THERMOFUN_PYTHON_INSTALL_PREFIX) @@ -58,3 +76,5 @@ install(CODE WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) " ) + +endif() diff --git a/tests/interfaceTest/src/main.cpp b/tests/interfaceTest/src/main.cpp index 26299c72..b63363c4 100644 --- a/tests/interfaceTest/src/main.cpp +++ b/tests/interfaceTest/src/main.cpp @@ -1,4 +1,5 @@ - #include "ThermoFun.h" +#include <iostream> +#include "ThermoFun.h" #include "ChemicalFun/FormulaParser.h" #include "GlobalVariables.h" //#include "ThermoFun/Common/ThermoScalar.hpp" @@ -89,8 +90,39 @@ // Test mines add string /* Database db("mines16-thermofun.json"); - auto test = db.getSubstance("O2"); - + std::cout << "Elements \n" << db.getElementsList() << endl; + //std::cout << "Substances \n" << db.getSubstancesList() << endl; + //std::cout << "Reactions \n" << db.getReactionsList() << endl; + + auto elment = db.getElement("O"); + std::cout << elment << endl; + elment.setValence(ChemicalFun::DBElements::defaultValence("O")); + std::cout << elment << endl; + std::cout << db.getElement("O") << endl; + + auto& elment_ref = db.element("H"); + std::cout << elment_ref << endl; + elment_ref.setValence(ChemicalFun::DBElements::defaultValence("H")); + std::cout << elment_ref << endl; + std::cout << db.getElement("H") << endl; + std::cout << db.getElement("H").valence() << endl; + + auto& elment_new = db.element("Ir"); // get from defaults + std::cout << elment_new << endl; + + auto& elment_empty = db.element("Ac"); // get from defaults + std::cout << elment_empty << endl; + + auto sbst = db.getSubstance("O2"); + //std::cout << sbst << endl; + + auto react = db.getReaction("ZrCl+3"); + //std::cout << react << endl; + + //std::cout << db.getElements() << endl; + //std::cout << db.getSubstances() << endl; + //std::cout << db.getReactions() << endl; + return 0; ThermoEngine engine("aq17-thermofun.json"); //engine.appendData("append-thermofun.json");