Skip to content

Commit

Permalink
Origin bucket (#27)
Browse files Browse the repository at this point in the history
    add records as json strings
    functions to list available methods, properties
    when the reaction equation is given the reactants are added to the record.
  • Loading branch information
gdmiron committed Jun 27, 2021
1 parent f4da39b commit eb226b0
Show file tree
Hide file tree
Showing 25 changed files with 60,711 additions and 29 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.9)

# Set the name of the project
project(ThermoFun VERSION 0.3.7 LANGUAGES CXX)
project(ThermoFun VERSION 0.3.8 LANGUAGES CXX)

# Set the cmake module path of the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
Expand Down Expand Up @@ -77,6 +77,10 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
include_directories("/usr/local/include")
link_directories("/usr/local/lib")
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
include_directories("c:/usr/local/include")
link_directories("c:/usr/local/lib")
endif()

# Find all Reaktoro dependencies
include(ThermoFunFindDeps)
Expand Down
3 changes: 3 additions & 0 deletions ThermoFun/Common/ParseJsonToData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,10 @@ auto parseReaction(const std::string &data) -> Reaction

if (j.contains("equation"))
if (!j["equation"].is_null())
{
r.setEquation(j["equation"]);
r.fromEquation(r.equation());
}

if (j.contains("limitsTP"))
if (!j["limitsTP"].is_null())
Expand Down
35 changes: 33 additions & 2 deletions ThermoFun/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ struct Database::Impl
{
auto it = map_.find(symbol);
if (it != map_.end())
cout << "The "<< record_type <<" with the symbol " << symbol
cout << "The "<< record_type <<" with symbol " << symbol
<< " is already in the database. Overwritting ..." << endl
<< "To add it to the database assign it a different symbol." << endl;
<< "To add it to the database as a separate record assign it a different symbol." << endl;
}

auto addRecord(json j, std::string _label) -> void
Expand Down Expand Up @@ -367,6 +367,17 @@ auto Database::setElement(const Element& element) -> void
pimpl->setElement(element);
}

auto Database::addElement(const std::string& jsonElement) -> void
{
pimpl->addElement(Element(jsonElement));
}

auto Database::setElement(const std::string& jsonElement) -> void
{
pimpl->setElement(Element(jsonElement));
}


auto Database::addMapElements(const ElementsMap& elements) -> void
{
pimpl->addMapElements(elements);
Expand All @@ -382,6 +393,16 @@ auto Database::setSubstance(const Substance& substance) -> void
pimpl->setSubstance(substance);
}

auto Database::addSubstance(const std::string &jsonSubstance) -> void
{
pimpl->addSubstance(Substance(jsonSubstance));
}

auto Database::setSubstance(const std::string &jsonSubstance) -> void
{
pimpl->setSubstance(Substance(jsonSubstance));
}

auto Database::addMapSubstances(const SubstancesMap& substances) -> void
{
pimpl->addMapSubstances(substances);
Expand All @@ -397,6 +418,16 @@ auto Database::setReaction(const Reaction& reaction) -> void
pimpl->setReaction(reaction);
}

auto Database::addReaction(const std::string &jsonReaction) -> void
{
pimpl->addReaction(Reaction(jsonReaction));
}

auto Database::setReaction(const std::string &jsonReaction) -> void
{
pimpl->setReaction(Reaction(jsonReaction));
}

auto Database::addMapReactions(const ReactionsMap& reactions) -> void
{
pimpl->addMapReactions(reactions);
Expand Down
45 changes: 36 additions & 9 deletions ThermoFun/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,63 @@ class Database
*/
auto appendData(std::vector<std::string> jsonRecords, std::string _label) -> void;

/// Add an Element instance in the database.
/// Add an Element instance in the database. If the element with the symbol exists the record will not be added.
auto addElement(const Element& element) -> void;

/// Sets an Element in the database.
/// Sets an Element in the database. If the element with the symbol exists the record will be overwritten.
auto setElement(const Element& element) -> void;

/// Add a map of Elements in the database. If the element exists the record will be overwritten
/// Add an Element instance in the database from a JSON string. If the element with the symbol exists the record will not be added.
auto addElement(const std::string& jsonElement) -> void;

/// Sets an Element in the database from a JSON string. If the element with the symbol exists the record will be overwritten.
auto setElement(const std::string& jsonElement) -> void;

/// Add a map of Elements in the database. If the element with the symbol exists the record will not be added.
auto addMapElements(const ElementsMap& elements) -> void;

/// Add an Substance instance in the database. If the substance exists the record will be overwritten
/// Add a map of Elements in the database. If the element with the symbol exists the record will be overwritten.
auto setMapElements(const ElementsMap& elements) -> void;

/// Add a Substance instance in the database. If the substance with the symbol exists the record will not be added.
auto addSubstance(const Substance& substance) -> void;

/// Sets a substance in the database.
/// Add a Substance instance in the database from a JSON string. If the substance with the symbol exists the record will not be added.
auto addSubstance(const std::string& jsonSubstance) -> void;

/// Sets a substance in the database. If the substance with the symbol exists the record will be overwritten.
auto setSubstance(const Substance& substance) -> void;

/// Add a map of Substances in the database.
/// Sets a substance in the database from a JSON string. If the substance with the symbol exists the record will be overwritten.
auto setSubstance(const std::string& jsonSubstance) -> void;

/// Add a map of Substances in the database. If the substance with the symbol exists the record will not be added.
auto addMapSubstances(const SubstancesMap& substances) -> void;

/// Add an Reaction instance in the database. If the reaction exists the record will be overwritten
/// Set a map of Substances in the database. If the substance with the symbol exists the record will be overwritten.
auto setMapSubstances(const SubstancesMap& substances) -> void;

/// Add a Reaction instance in the database. If the reaction with the symbol exists the record will not be added.
auto addReaction(const Reaction& reaction) -> void;

/// Sets a reaction in the database.
/// Set a reaction in the database. If the reaction with the symbol exists the record will be overwritten.
auto setReaction(const Reaction& reaction) -> void;

/// Add a Reaction instance in the database from a JSON string. If the reaction with the symbol exists the record will not be added.
auto addReaction(const std::string& jsonReaction) -> void;

/// Set a reaction in the database from a JSON string. If the reaction with the symbol exists the record will be overwritten.
auto setReaction(const std::string& jsonReaction) -> void;

/// Calculates the reaction record parameters, based on the defined method and available data
// auto calcParametersReactions( ) -> void;

/// Add a map pf Reactions in the database.
/// Add a map of Reactions in the database. If the reaction with the symbol exists the record will not be added.
auto addMapReactions(const ReactionsMap& reactions) -> void;

/// Sets a map of Reactions in the database. If the reaction with the symbol exists the record will be overwritten.
auto setMapReactions(const ReactionsMap& reactions) -> void;

/// Return all elements in the database
auto getElements() const -> std::vector<Element>;

Expand Down
9 changes: 9 additions & 0 deletions ThermoFun/Element.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Element.h"
#include "Common/ParseJsonToData.h"

namespace ThermoFun {

Expand Down Expand Up @@ -42,6 +43,14 @@ Element::Element()
: pimpl(new Impl())
{}

Element::Element(std::string jsonElement)
: pimpl(new Impl())
{
Element other = parseElement(jsonElement);
pimpl = std::move(other.pimpl);
setJsonString(jsonElement);
}

Element::Element(const Element& other)
: pimpl(new Impl(*other.pimpl))
{}
Expand Down
3 changes: 3 additions & 0 deletions ThermoFun/Element.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Element
/// Construct a default Element instance
Element();

/// Constrcut an Element instance from a JSON string
Element(std::string jsonElement);

/// Construct a copy of an Element instance
Element(const Element& other);

Expand Down
61 changes: 61 additions & 0 deletions ThermoFun/GlobalFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "GlobalVariables.h"
#include "Batch/ThermoBatch.h"

namespace ThermoFun {

auto availableSubstanceTPMethods() -> const std::string
{
std::string r;
for (auto a : enum_method_substance)
{
r += "{\"method\": {\"" + to_string(a.first) + "\": \"" + a.second + "\"}";
auto type = (SubstanceTPMethodType) a.first;
if (substance_method_parameters.at(type).size() == 1 && substance_method_parameters.at(type)[0] !="")
{
r += ", \"" + substance_method_parameters.at(type)[0] +"\" : { \"values\": []}}\n";
} else
r += "}\n";
}
return r;
}

auto scanProperties(const std::string& what) -> const std::string
{
std::string r = "property (unit)\n---------------\n";
for (auto a: defaultPropertyNames)
{
if (a.second == what)
{
r += a.first + " (";
r += defaultPropertyUnits.at(a.first)+ ")\n";
}
}
return r;
}

auto availablePropertiesSubstance() -> const std::string
{
return scanProperties("substance");
}

auto availablePropertiesReaction() -> const std::string
{
return scanProperties("reaction");
}

auto availableReactionTPMethods() -> const std::string
{
std::string r;
for (auto a : enum_method_reaction)
{
r += "{\"method\": {\"" + to_string(a.first) + "\": \"" + a.second + "\"}";
auto type = (ReactionTPMethodType) a.first;
if (reaction_method_parameters.at(type).size() == 1 && reaction_method_parameters.at(type)[0] !="")
{
r += ", \"" + reaction_method_parameters.at(type)[0] +"\" : { \"values\": []}}\n";
} else
r += "}\n";
}
return r;
}
} // namespace ThermoFun
94 changes: 93 additions & 1 deletion ThermoFun/GlobalVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,91 @@ enum ReactionTPMethodType {
logk_dolejs_manning10 = 14
};

const std::map<const SubstanceTPMethodType, const std::vector<std::string>> method_parameters = {
const std::map<const unsigned int, const std::string> enum_method_substance = {
{0,"cp_ft_equation"},
{1,"cp_ft_equation_saxena86"},
{2,"solute_hkf88_gems"},
{3,"solute_hkf88_reaktoro"},
{4,"solute_aknifiev_diamond03"},
{5,"landau_holland_powell98"},
{6,"landau_berman88"},
//{7,"general_equation_of_state"},
{8,"fug_critical_param"},
{9,"fluid_prsv"},
{10,"fluid_churakov_gottschalk"},
{11,"fluid_soave_redlich_kwong"},
{12,"fluid_sterner_pitzer"},
{13,"fluid_peng_robinson78"},
{14,"fluid_comp_redlich_kwong_hp91"},
//{15,"fluid_generic"},
//{16,"fluid_H2O"},
//{17,"fluid_CO2"},
//{18,"fluid_CH4"},
//{19,"fluid_N2"},
//{20,"fluid_H2"},
//{21,"fluid_O2"},
//{22,"fluid_Ar"},
//{23,"fluid_polar"},
//{24,"fluid_nonpolar"},
{25,"water_diel_jnort91_reaktoro"},
{26,"water_diel_jnort91_gems"},
{27,"water_diel_sverj14"},
{28,"water_diel_fern97"},
{29,"water_eos_hgk84_lvs83_gems"},
{30,"water_eos_iapws95_gems"},
{31,"water_eos_hgk84_reaktoro"},
{32,"water_eos_iapws95_reaktoro"},
{33,"water_pvt_zhang_duan05"},
{34,"mv_constant"},
{35,"mv_equation_dorogokupets88"},
{36,"mv_equation_berman88"},
{37,"mv_eos_birch_murnaghan_gott97"},
{38,"mv_eos_murnaghan_hp98"},
{39,"mv_eos_tait_hp11"},
{40,"mv_pvnrt"},
{41,"solute_holland_powell98"},
{42,"solute_anderson91"},
{43,"standard_entropy_cp_integration"}
};

const std::map<const unsigned int, const std::string> enum_method_reaction = {
{0,"logk_fpt_function"},
//{1,"adsor_ion_exchange"},
//{2,"iso_compounds_grichuk88"},
{3,"logk_nordstrom_munoz88"},
{4,"logk_1_term_extrap0"},
{5,"logk_1_term_extrap1"},
{6,"logk_2_term_extrap"},
{7,"logk_3_term_extrap"},
{8,"logk_lagrange_interp"},
{9,"logk_marshall_frank78"},
{10,"solute_eos_ryzhenko_gems"},
{11,"dr_heat_capacity_ft"},
{12,"dr_volume_fpt"},
{13,"dr_volume_constant"},
{14,"logk_dolejs_manning10"}
};

const std::map<const ReactionTPMethodType, const std::vector<std::string>> reaction_method_parameters = {
{ReactionTPMethodType::logk_fpt_function, {"logk_ft_coeffs"}},
{ReactionTPMethodType::adsor_ion_exchange, {""}},
{ReactionTPMethodType::iso_compounds_grichuk88, {""}},
{ReactionTPMethodType::logk_nordstrom_munoz88, {"logk_ft_coeffs"}},
{ReactionTPMethodType::logk_1_term_extrap0, {"logk_ft_coeffs"}},
{ReactionTPMethodType::logk_1_term_extrap1, {"logk_ft_coeffs"}},
{ReactionTPMethodType::logk_2_term_extrap, {"logk_ft_coeffs"}},
{ReactionTPMethodType::logk_3_term_extrap, {"logk_ft_coeffs"}},
{ReactionTPMethodType::logk_lagrange_interp, {""}},
{ReactionTPMethodType::logk_marshall_frank78, {"dr_marshall_franck_coeffs"}},
{ReactionTPMethodType::solute_eos_ryzhenko_gems, {"dr_ryzhenko_coeffs"}},
{ReactionTPMethodType::dr_heat_capacity_ft, {"dr_heat_capacity_ft_coeffs"}},
{ReactionTPMethodType::dr_volume_fpt, {"dr_volume_fpt_coeffs"}},
{ReactionTPMethodType::dr_volume_constant, {""}},
{ReactionTPMethodType::logk_dolejs_manning10, {"dr_dolejs_manning10_coeffs"}},
};


const std::map<const SubstanceTPMethodType, const std::vector<std::string>> substance_method_parameters = {
{SubstanceTPMethodType::cp_ft_equation, {"m_heat_capacity_ft_coeffs"} },
{SubstanceTPMethodType::solute_hkf88_gems, {"eos_hkf_coeffs"} },
{SubstanceTPMethodType::solute_hkf88_reaktoro, {"eos_hkf_coeffs"} },
Expand All @@ -134,6 +218,7 @@ const std::map<const SubstanceTPMethodType, const std::vector<std::string>> meth
{SubstanceTPMethodType::water_eos_iapws95_reaktoro, {""} },
{SubstanceTPMethodType::water_pvt_zhang_duan05, {""} },
{SubstanceTPMethodType::mv_constant, {""} },
{SubstanceTPMethodType::mv_pvnrt, {""} },
{SubstanceTPMethodType::mv_equation_dorogokupets88, {"m_volume_fpt_coeffs"} },
{SubstanceTPMethodType::mv_equation_berman88, {"m_volume_fpt_coeffs"} },
{SubstanceTPMethodType::mv_eos_birch_murnaghan_gott97, {"eos_birch_murnaghan_coeffs"} },
Expand All @@ -152,6 +237,13 @@ const std::map<const SubstanceTPMethodType, const std::vector<std::string>> meth
{SubstanceTPMethodType::standard_entropy_cp_integration, {""} }
};


auto availableSubstanceTPMethods() -> const std::string;
auto availableReactionTPMethods() -> const std::string;
auto availablePropertiesReaction() -> const std::string;
auto availablePropertiesSubstance() -> const std::string;


/// Indexes for species-dependent EoS subroutines used in thrift DOM and ThermoFun class
typedef struct {
enum type {
Expand Down
Loading

0 comments on commit eb226b0

Please sign in to comment.