Skip to content

Commit

Permalink
fixed tests/examples (#66)
Browse files Browse the repository at this point in the history
* bugfix examples

* fixed tests/examples to updated function calls and includes
  • Loading branch information
gdmiron authored Jan 8, 2024
1 parent ec1cbf3 commit ecf510b
Show file tree
Hide file tree
Showing 24 changed files with 222 additions and 460 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ include(GNUInstallDirs)
if(TFUN_BUILD_ALL MATCHES ON)
set(TFUN_BUILD_SHARED_LIBS ON)
set(TFUN_BUILD_STATIC_LIBS ON)
# set(TFUN_BUILD_TESTS ON)
set(TFUN_BUILD_TESTS OFF)
set(TFUN_BUILD_PYTHON ON)
endif()

Expand Down Expand Up @@ -100,11 +100,11 @@ file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/Resources
DESTINATION ${CMAKE_BINARY_DIR})

# Build the tests
#if(BUILD_TESTS)
# add_subdirectory(tests)
if(BUILD_TESTS)
add_subdirectory(tests)
#else()
# add_subdirectory(tests EXCLUDE_FROM_ALL)
#endif()
endif()

# Build python wraper
if(TFUN_BUILD_PYTHON)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ More information on Jupyter Notebooks: [Jupyter Documentation](https://jupyter.r
int main()
{
// Create the batch object using a database file in JSON
ThermoFun::Batch batch("Resources/Databases/aq17-thermofun.json");
ThermoFun::ThermoBatch batch("Resources/Databases/aq17-thermofun.json");
// Optional: set units, default units are in SI
batch.setPropertiesUnits({"temperature", "pressure"},{"degC","bar"});
Expand Down Expand Up @@ -71,7 +71,7 @@ int main()
ThermoFun::Database db(dbc.getDatabase('aq17'));
// Initialize an batch object using the database
ThermoFun::Batch batch (db);
ThermoFun::ThermoBatch batch (db);
// Optional set calculation and output preferences
ThermoFun::OutputSettings op;
Expand Down
9 changes: 6 additions & 3 deletions ThermoFun/ThermoModelsSubstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@ class SoluteAkinfievDiamondEOS
/// Returns the thermodynamic properties of the substance.
/// @param T The temperature value (in units of K)
/// @param P The pressure value (in units of Pa)
/// @param tps thermodynamic properties of the substance previosuly corrected with the AD EOS
/// @param tps thermodynamic properties of the substance previously corrected with the AD EOS
/// @param wtp thermodynamic properties of liquid H2O
/// @param wigp themrodynamic properties of water in ideal gas state
/// @param wp water solvent proeoprties (e.g. density, alpha, beta, etc.)
/// @param wigp thermodynamic properties of water in ideal gas state
/// @param wp water solvent properties (e.g. density, alpha, beta, etc.)
/// @param wtpr thermodynamic properties of liquid H2O at ref T and P
/// @param wigpr thermodynamic properties of water in ideal gas state at ref T and P
/// @param wpr water solvent properties at ref T and P
auto thermoProperties (double T, double P, ThermoPropertiesSubstance tps, const ThermoPropertiesSubstance &wtp, const ThermoPropertiesSubstance &wigp, const PropertiesSolvent& wp, const ThermoPropertiesSubstance &wtpr, const ThermoPropertiesSubstance &wigpr, const PropertiesSolvent &wpr) -> ThermoPropertiesSubstance;

private:
Expand Down
6 changes: 5 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
# Add ReaktoroInterpreter tests to the build system
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

add_subdirectory(dbclientTest)
add_subdirectory(unit01)
add_subdirectory(unit02)
add_subdirectory(unit03)
add_subdirectory(unit04)
add_subdirectory(reactionsTest)
14 changes: 14 additions & 0 deletions tests/reactionsTest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Specify the minimum cmake version
cmake_minimum_required(VERSION 3.9)

# Specify the name of your project
project(reactions)

# Find the ThermoFun dependency.
find_package(ThermoFun REQUIRED)

# Create an executable named app with source code main.cpp
add_executable(reactions src/main.cpp)

# Link your application against ThermoFun C++ library.
target_link_libraries(reactions ThermoFun::ThermoFun)
11 changes: 6 additions & 5 deletions tests/reactionsTest/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "Interfaces/Interface.h"
#include <iostream>
#include "ThermoFun/ThermoFun.h"

using namespace std;
using namespace ThermoFun;
Expand All @@ -11,16 +12,16 @@ int main(int argc, char *argv[])

Database thermoDB(databaseFile);

Thermo thermo(thermoDB);
ThermoEngine thermo(thermoDB);

ThermoPropertiesReaction tpr;

double T = 25;
double P = 1;
double T = 298.15;
double P = 1e5;

tpr = thermo.thermoPropertiesReaction(T, P, "CaSiO3@");

cout << tpr.log_equilibrium_constant << endl << tpr.reaction_gibbs_energy << endl;
std::cout << tpr.log_equilibrium_constant << endl << tpr.reaction_gibbs_energy << endl;

return 0;
}
Expand Down
14 changes: 14 additions & 0 deletions tests/unit01/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Specify the minimum cmake version
cmake_minimum_required(VERSION 3.9)

# Specify the name of your project
project(test01)

# Find the ThermoFun dependency.
find_package(ThermoFun REQUIRED)

# Create an executable named app with source code main.cpp
add_executable(test01 src/main.cpp)

# Link your application against ThermoFun C++ library.
target_link_libraries(test01 ThermoFun::ThermoFun)
50 changes: 27 additions & 23 deletions tests/unit01/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include <iostream>
#include <fstream>
//#include "tcorrpt.h"
#include "Database.h"
#include "Substance.h"
#include "ThermoModelsSubstance.h"
#include "ThermoFun_global.h"
#include "Thermo.h"
#include "ThermoFun/Database.h"
#include "ThermoFun/Substance.h"
#include "ThermoFun/ThermoEngine.h"
#include "ThermoFun/ThermoModelsSubstance.h"
#include "ThermoFun/ThermoProperties.h"
#include "ThermoFun/ThermoParameters.h"
#include "ThermoFun/ThermoModelsSolvent.h"
#include "ThermoFun/GlobalVariables.h"

using namespace std;
using namespace ThermoFun;
Expand All @@ -26,8 +28,8 @@ int main(int argc, char *argv[])

double Tr = 298.15, ///< Reference temperature for standard state (usually 298.15 K)
Pr = 1e05; ///< Reference pressure (usually 1 bar or 10^5 Pa, sometimes 1.013 bar = 1 atm)
double currentP = 2000, ///<
currentT = 400; ///<
double currentP = 2000e5, ///<
currentT = 473.15; ///<

/// END thermo properties ///

Expand Down Expand Up @@ -88,7 +90,7 @@ int main(int argc, char *argv[])

dtb.addSubstance(corundum);

Thermo thermo (dtb);
ThermoEngine thermo (dtb);

// Test error out of the interval
// currentT = 2005;
Expand All @@ -101,7 +103,7 @@ int main(int argc, char *argv[])
// +++ END test CP +++

// +++ Test H2O_HGK +++
// #define TEST_H2O_HGK
//#define TEST_H2O_HGK
#ifdef TEST_H2O_HGK

Substance water;
Expand Down Expand Up @@ -129,22 +131,23 @@ int main(int argc, char *argv[])

dtb.addSubstance(water);

Thermo thermo (dtb);
result2 = thermo.thermoPropertiesSubstance(25, 1, "water");
ThermoEngine thermo (dtb);
currentP = 1e5;
result2 = thermo.thermoPropertiesSubstance(298.15, currentP, "water");

water.setThermoReferenceProperties(result2);

WaterHGK waterHGK(water);

result1 = waterHGK.propertiesSolvent(25, 1);
result1 = waterHGK.propertiesSolvent(298.15, currentP, 0);

result3 = thermo.propertiesSolvent(25, 1, "water");
result3 = thermo.propertiesSolvent(298.15, currentP, 0);

#endif
// +++ END test H2O_HGK +++

// +++ Test H2O_HGKreaktoro +++
// #define TEST_H2O_HGKreaktoro
//#define TEST_H2O_HGKreaktoro
#ifdef TEST_H2O_HGKreaktoro

Substance water;
Expand Down Expand Up @@ -172,16 +175,17 @@ int main(int argc, char *argv[])

dtb.addSubstance(water);

Thermo thermo (dtb);
result2 = thermo.thermoPropertiesSubstance(25, 1, "water");
ThermoEngine thermo (dtb);
currentP = 1e5;
result2 = thermo.thermoPropertiesSubstance(298.15, currentP, "water");

water.setThermoReferenceProperties(result2);

#endif
// +++ END test H2O_HGKreaktoro +++

// +++ Test H2O_HGKgems Vs H2O_HGKreaktoro +++
#define TEST_H2O_VS
//#define TEST_H2O_VS
#ifdef TEST_H2O_VS

Substance water;
Expand All @@ -199,8 +203,8 @@ int main(int argc, char *argv[])
WaterHGKreaktoro H2OHGKreaktoro ( water );

double T, P;
T = 100;
P = 5000;
T = 100+273.15;
P = 5000e5;
ThermoPropertiesSubstance resSubstG, resSubstR;

ElectroPropertiesSolvent resSolvG, resSolvR;
Expand Down Expand Up @@ -239,7 +243,7 @@ int main(int argc, char *argv[])
// +++ END Test H2O_HGKgems Vs H2O_HGKreaktoro +++

// +++ Test H2O_WP95reaktoro Vs H2O_HGKreaktoro +++
// #define TEST_H2O_HGK_VS_H2O_WP95
//#define TEST_H2O_HGK_VS_H2O_WP95
#ifdef TEST_H2O_HGK_VS_H2O_WP95

Substance water;
Expand All @@ -257,8 +261,8 @@ int main(int argc, char *argv[])
WaterHGKreaktoro H2OHGKreaktoro ( water );

double T, P;
T = 100;
P = 5000;
T = 100+273.15;
P = 5000e5;
ThermoPropertiesSubstance resWP95, resHGKreak;

// ElectroPropertiesSolvent resSolvG, resSolvR;
Expand Down
14 changes: 14 additions & 0 deletions tests/unit02/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Specify the minimum cmake version
cmake_minimum_required(VERSION 3.9)

# Specify the name of your project
project(test02)

# Find the ThermoFun dependency.
find_package(ThermoFun REQUIRED)

# Create an executable named app with source code main.cpp
add_executable(test02 src/main.cpp)

# Link your application against ThermoFun C++ library.
target_link_libraries(test02 ThermoFun::ThermoFun)
29 changes: 17 additions & 12 deletions tests/unit02/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include <iostream>
#include <fstream>
//#include "tcorrpt.h"
#include "Database.h"
#include "Substance.h"
#include "ThermoModelsSubstance.h"
#include "ThermoFun_global.h"
#include "Thermo.h"

#include "ThermoFun/Database.h"
#include "ThermoFun/Substance.h"
#include "ThermoFun/ThermoEngine.h"
#include "ThermoFun/ThermoModelsSubstance.h"
#include "ThermoFun/ThermoProperties.h"
#include "ThermoFun/ThermoParameters.h"
#include "ThermoFun/ThermoModelsSolvent.h"
#include "ThermoFun/ElectroModelsSolvent.h"
#include "ThermoFun/GlobalVariables.h"
#include "ThermoFun/Substances/Solute/SoluteHKFreaktoro.h"
#include "ThermoFun/Substances/Solute/SoluteHKFgems.h"

using namespace std;
using namespace ThermoFun;
Expand Down Expand Up @@ -38,7 +44,6 @@ int main(int argc, char *argv[])
al3.setName("Al+3");
al3.setFormula("Al+3");
al3.setCharge(3);
al3.setSolventSymbol("H2O@");

al3.setSubstanceClass(SubstanceClass::type::AQSOLUTE);
al3.setAggregateState(AggregateState::type::AQUEOUS);
Expand Down Expand Up @@ -67,6 +72,8 @@ int main(int argc, char *argv[])

PropertiesSolvent wp = H2OHGKgems.propertiesSolvent(T, P, 0);

FunctionG g = functionG(T, P, wp);

water.setMethodGenEoS(MethodGenEoS_Thrift::type::CTPM_WJNG);

WaterJNgems H2OJNgems ( water );
Expand All @@ -82,7 +89,7 @@ int main(int argc, char *argv[])
#endif

// +++ Test HKFgems +++
// #define TEST_HKFreaktoro
// #define TEST_HKFreaktoro
#ifdef TEST_HKFreaktoro

// water.setMethod_T(MethodCorrT_Thrift::type::CTM_WAT);
Expand All @@ -99,7 +106,6 @@ int main(int argc, char *argv[])
al3.setName("Al+3");
al3.setFormula("Al+3");
al3.setCharge(3);
al3.setSolventSymbol("H2O@");

al3.setSubstanceClass(SubstanceClass::type::AQSOLUTE);
al3.setAggregateState(AggregateState::type::AQUEOUS);
Expand Down Expand Up @@ -128,7 +134,7 @@ int main(int argc, char *argv[])

PropertiesSolvent wp = H2OHGKreaktoro.propertiesSolvent(T, P, 0);

water.setMethodGenEoS(MethodGenEoS_Thrift::type::CEM_WJNG);
water.setMethodGenEoS(MethodGenEoS_Thrift::type::CTPM_WJNR);

WaterJNreaktoro H2OJNreaktoro ( water );

Expand All @@ -155,7 +161,7 @@ int main(int argc, char *argv[])
al3.setName("Al+3");
al3.setFormula("Al+3");
al3.setCharge(3);
al3.setSymbol("H2O@");
al3.setSymbol("Al+3");

al3.setSubstanceClass(SubstanceClass::type::AQSOLUTE);
al3.setAggregateState(AggregateState::type::AQUEOUS);
Expand Down Expand Up @@ -228,7 +234,6 @@ int main(int argc, char *argv[])
aloh3.setName("Al(OH)3");
aloh3.setFormula("Al(OH)3@");
aloh3.setCharge(0);
aloh3.setSolventSymbol("H2O@");

aloh3.setSubstanceClass(SubstanceClass::type::AQSOLUTE);
aloh3.setAggregateState(AggregateState::type::AQUEOUS);
Expand Down
14 changes: 14 additions & 0 deletions tests/unit03/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Specify the minimum cmake version
cmake_minimum_required(VERSION 3.9)

# Specify the name of your project
project(test03)

# Find the ThermoFun dependency.
find_package(ThermoFun REQUIRED)

# Create an executable named app with source code main.cpp
add_executable(test03 src/main.cpp)

# Link your application against ThermoFun C++ library.
target_link_libraries(test03 ThermoFun::ThermoFun)
Loading

0 comments on commit ecf510b

Please sign in to comment.