Skip to content

Commit

Permalink
Fixes for MRB model (#22)
Browse files Browse the repository at this point in the history
* fixed reaction volume unit in RB model

* fix to allow appending elements to the database

* added automatic tests for RB model, thermofun v0.3.5

* test for appending elements

* removed old functions
  • Loading branch information
gdmiron authored Nov 30, 2020
1 parent ec2cb95 commit 5a781ae
Show file tree
Hide file tree
Showing 13 changed files with 5,110 additions and 38 deletions.
40 changes: 23 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Require a certain version of cmake
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.9)

# Set the name of the project
project(ThermoFun VERSION 0.3.3 LANGUAGES CXX)
project(ThermoFun VERSION 0.3.5 LANGUAGES CXX)

# Set the cmake module path of the project
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
Expand All @@ -13,15 +13,6 @@ include(CCache)
# Define variables with the GNU standard installation directories
include(GNUInstallDirs)

# Ensure proper configuration if in a conda environment
include(CondaAware)

# Define which types of libraries to build
option(TFUN_BUILD_SHARED_LIBS "Build shared libraries." ON)
option(TFUN_BUILD_STATIC_LIBS "Build static libraries." ON)
#option(TFUN_BUILD_TESTS "Build tests." OFF)
option(TFUN_BUILD_PYTHON "Build the python wrappers and python package thermofun." ON)

# Modify the TFUN_BUILD_* variables accordingly to BUILD_ALL
if(TFUN_BUILD_ALL MATCHES ON)
set(TFUN_BUILD_SHARED_LIBS ON)
Expand All @@ -30,6 +21,27 @@ if(TFUN_BUILD_ALL MATCHES ON)
set(TFUN_BUILD_PYTHON ON)
endif()

if (TFUN_WASM MATCHES ON)
# Define which types of libraries to build
option(TFUN_BUILD_STATIC_LIBS "Build static libraries." ON)
set(TFUN_BUILD_PYTHON OFF)
# Set the list of compiler flags for Clang compiler
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options(-std=c++11 -Wall -Wno-ignored-attributes -Wno-pedantic -Wno-variadic-macros -Wno-deprecated -fcxx-exceptions -frtti)
endif()
else()
# Ensure proper configuration if in a conda environment
include(CondaAware)
option(TFUN_BUILD_SHARED_LIBS "Build shared libraries." ON)
option(TFUN_BUILD_STATIC_LIBS "Build static libraries." ON)
#option(TFUN_BUILD_TESTS "Build tests." OFF)
option(TFUN_BUILD_PYTHON "Build the python wrappers and python package thermofun." ON)
# Define if shared library should be build instead of static.
option(BUILD_SHARED_LIBS "Build shared libraries." ON)

# Set libraries to be compiled with position independent code mode (i.e., fPIC option in GNU compilers)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

# Set the default build type to Release
if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -40,12 +52,6 @@ if(NOT CMAKE_BUILD_TYPE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo)
endif()

# Define if shared library should be build instead of static.
option(BUILD_SHARED_LIBS "Build shared libraries." ON)

# Set libraries to be compiled with position independent code mode (i.e., fPIC option in GNU compilers)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand Down
23 changes: 17 additions & 6 deletions ThermoFun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@ file(GLOB_RECURSE HEADER_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.hpp *.h)
# Recursively collect all source files from the current directory
file(GLOB_RECURSE SOURCE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)

# The name of the shared and static libraries
set(THERMOFUN_SHARED_LIB ${PROJECT_NAME}${SUFFIX_SHARED_LIBS})
set(THERMOFUN_STATIC_LIB ${PROJECT_NAME}${SUFFIX_STATIC_LIBS})
if(TFUN_BUILD_SHARED_LIBS)
set(THERMOFUN_SHARED_LIB ${PROJECT_NAME}${SUFFIX_SHARED_LIBS})
# Enable automatic creation of a module definition (.def) file for a SHARED library on Windows.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
#add_library(XGEMS_SHARED SHARED $<TARGET_OBJECTS:XGEMS_OBJECT>)
#target_link_libraries(XGEMS_SHARED GEMS3K-static)
#set_target_properties(XGEMS_SHARED PROPERTIES OUTPUT_NAME xGEMS)
#install(TARGETS XGEMS_SHARED DESTINATION "lib" COMPONENT libraries)
endif()

# Enable automatic creation of a module definition (.def) file for a SHARED library on Windows.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
# Check if a static library must be built
if(TFUN_BUILD_STATIC_LIBS)
set(THERMOFUN_STATIC_LIB ${PROJECT_NAME}${SUFFIX_STATIC_LIBS})
#add_library(XGEMS_STATIC STATIC $<TARGET_OBJECTS:XGEMS_OBJECT>)
#target_link_libraries(XGEMS_STATIC GEMS3K-static)
#set_target_properties(XGEMS_STATIC PROPERTIES OUTPUT_NAME xGEMS)
#install(TARGETS XGEMS_STATIC DESTINATION "lib" COMPONENT libraries)
endif()

# Create a library using the collected source files
add_library(ThermoFun ${HEADER_FILES} ${SOURCE_FILES})

# Add aliases for ThermoFun shared and static libraries
add_library(ThermoFun::ThermoFun ALIAS ThermoFun)

Expand Down
2 changes: 1 addition & 1 deletion ThermoFun/Common/ThermoScalar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ThermoScalarBase
/// Construct a custom ThermoScalarBase instance with given value only.
/// @param val The value of the thermodynamic property
explicit ThermoScalarBase(double val)
: ThermoScalarBase(val, 0.0, 0.0, 0.0, {Status::initialized, ""}) {}
: ThermoScalarBase(val, 0.0, 0.0, 0.0, {Status::notdefined, ""}) {}

/// Construct a custom ThermoScalarBase instance with given value and derivatives.
/// @param val The value of the thermodynamic property
Expand Down
18 changes: 12 additions & 6 deletions ThermoFun/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ struct Database::Impl

auto addElement(const Element& element) -> void
{
checkIfSymbolExists(elements_map, "element", element.symbol());
elements_map.insert({element.symbol(), element});
}

auto setElement(const Element& element) -> void
{
checkIfSymbolExists(elements_map, "element", element.symbol());
elements_map[element.symbol()] = element;
}

auto addSubstance(const Substance& substance) -> void
{
checkIfSymbolExists(substances_map, "substance", substance.symbol());
substances_map.insert({substance.symbol(), substance});
}

auto setSubstance(const Substance& substance) -> void
{
checkIfSymbolExists(substances_map, "substance", substance.symbol());
substances_map[substance.symbol()] = substance;
}

Expand All @@ -100,12 +100,12 @@ struct Database::Impl

auto addReaction(const Reaction& reaction) -> void
{
checkIfSymbolExists(reactions_map, "reaction", reaction.symbol());
reactions_map.insert({reaction.symbol(), reaction});
}

auto setReaction(const Reaction& reaction) -> void
{
checkIfSymbolExists(reactions_map, "reaction", reaction.symbol());
reactions_map[reaction.symbol()] = reaction;
}

Expand Down Expand Up @@ -210,16 +210,16 @@ struct Database::Impl

auto addRecord(json j, std::string _label) -> void
{
auto properties = j;
auto props= j;

if (j.contains("properties"))
if (!j["properties"].is_null())
properties = j["properties"];
props = j["properties"];
if (j.contains("_label"))
if (!j["_label"].is_null())
_label = j["_label"].get<std::string>();

auto props = properties.dump();
props = props.dump();

if (_label == "substance")
{
Expand Down Expand Up @@ -343,12 +343,18 @@ auto Database::operator=(Database other) -> Database&

auto Database::appendData(std::string filename) -> void
{
auto elements_number = pimpl->mapElements().size();
pimpl->fromFile(filename);
if (elements_number != pimpl->mapElements().size())
ChemicalFormula::setDBElements(pimpl->mapElements());
}

auto Database::appendData(vector<string> jsonRecords, std::string _label = "unknown label") -> void
{
auto elements_number = pimpl->mapElements().size();
pimpl->fromJSONs(jsonRecords, _label);
if (elements_number != pimpl->mapElements().size())
ChemicalFormula::setDBElements(pimpl->mapElements());
}

auto Database::addElement(const Element& element) -> void
Expand Down
10 changes: 9 additions & 1 deletion ThermoFun/GlobalVariables.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const std::map<const SubstanceTPMethodType, const std::vector<std::string>> meth
/// Indexes for species-dependent EoS subroutines used in thrift DOM and ThermoFun class
typedef struct {
enum type {
CTPM_CON = 99, // constant properties from ref T-P
CTPM_CPT = 100,
CTPM_HKF = 101,
CTPM_REA = 102,
Expand Down Expand Up @@ -573,10 +574,17 @@ typedef struct {
typedef struct {
enum type {
DCOMP = 0, ///< Dependent component, properties calculated using a PT model for the substance
REACDC = 1 ///< Reaction dependent component, proeprties claculated from the reaction properties
REACDC = 1 ///< Reaction dependent component, properties calculated from the reaction properties
};
} SubstanceThermoCalculationType;

typedef struct {
enum type {
REACTION = 0, ///< Reaction, properties calculated using a PT model for the reaction
REACTANTS = 1 ///< Properties calculated from reactants
};
} RectionThermoCalculationType;


/// Key for reading substance / reaction data from input files
static const char * label = "_label";
Expand Down
4 changes: 4 additions & 0 deletions ThermoFun/Reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct Reaction::Impl
/// Method of pressure correction of thermodynamic properties
MethodCorrP_Thrift::type method_P;

/// Type of calculation used for determining the reaction properties
/// using a defined PT correction model or from reactants
RectionThermoCalculationType::type thermo_calculation_type = RectionThermoCalculationType::type::REACTANTS;

/// Reference temperature (in K)
double reference_T = 298.15;

Expand Down
2 changes: 1 addition & 1 deletion ThermoFun/Reactions/RyzhenkoBryzgalyn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ auto thermoPropertiesRyzhenkoBryzgalin(Reaktoro_::Temperature TK, Reaktoro_::Pre
tpr.reaction_entropy = dSr;
tpr.reaction_enthalpy = dHr;
tpr.reaction_heat_capacity_cp = dCPr;
tpr.reaction_volume = dVr;
tpr.reaction_volume = dVr*1e5; // to J/bar
tpr.reaction_helmholtz_energy = dAr;
tpr.reaction_internal_energy = dUr;

Expand Down
24 changes: 22 additions & 2 deletions ThermoFun/ThermoEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ struct ThermoEngine::Impl

if (pref.isHydrogen)
{
tps.volume = 0.0;
tps.entropy = 0.0;
tps.enthalpy = 0.0;
tps.gibbs_energy = 0.0;
tps.internal_energy = 0.0;
tps.heat_capacity_cp = 0.0;
tps.heat_capacity_cv = 0.0;
tps.helmholtz_energy = 0.0;
return tps;
}

Expand All @@ -223,6 +231,11 @@ struct ThermoEngine::Impl
// metohd EOS
switch (pref.method_genEOS)
{
case MethodGenEoS_Thrift::type::CTPM_CON:
{
tps = substance.thermoReferenceProperties();
break;
}
case MethodGenEoS_Thrift::type::CTPM_CPT:
{
tps = EmpiricalCpIntegration(pref.workSubstance).thermoProperties(T, P);
Expand Down Expand Up @@ -574,9 +587,16 @@ struct ThermoEngine::Impl
{
switch (pref.method_genEOS)
{
case MethodGenEoS_Thrift::type::CTPM_CON:
{
tpr = reaction.thermoReferenceProperties();
break;
}
case MethodGenEoS_Thrift::type::CTPM_REA:
{
pref.method_T = MethodCorrT_Thrift::type::CTM_LGK;

break;
}
}

switch (pref.method_T)
Expand Down Expand Up @@ -660,7 +680,7 @@ struct ThermoEngine::Impl
else
tpr = thermoPropertiesReactionFromReactants(T, P, reaction);

return tpr;
return tpr;
}

auto thermoPropertiesReactionFromReactants(double T, double &P, std::string symbol) const -> ThermoPropertiesReaction
Expand Down
6 changes: 3 additions & 3 deletions ci/appveyor/install.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
conda config --set always_yes yes --set changeps1 no
conda config --add channels conda-forge
conda install conda-devenv
conda config --system --set always_yes yes --set changeps1 no
conda config --system --append channels conda-forge
conda install -n base conda-devenv
conda update -q conda
conda info -a
conda devenv
Expand Down
Loading

0 comments on commit 5a781ae

Please sign in to comment.