Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GEMS3K/gems3k_version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define GEMS3K_VERSION "4.4.4"
#define GEMS3K_VERSION_HASH "0995d4c"
#define GEMS3K_VERSION_HASH "b57199a"
#define GEMS3K_GIT_BRANCH "master"
#define GEMS3K_ChemicalFun "0.1.13"
#define GEMS3K_ThermoFun "0.5.4"
3 changes: 3 additions & 0 deletions GEMS3K/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,12 @@ TNode::TNode()
{
std::call_once(once_flag, [](){
// Thread-safe one-time operation
if(!ipmlog_file) {
ipmlog_file = spdlog::rotating_logger_mt("ipmlog", GemsSettings::with_directory("ipmlog.txt"),
GemsSettings::log_file_size,
GemsSettings::log_file_count);

}
});
CSD = NULL;
CNode = NULL;
Expand Down
40 changes: 22 additions & 18 deletions GEMS3K/node_copy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ bool TNode::load_all_thermodynamic_from_thermo( double TK, double PPa )
pmm->FRT = F_CONSTANT/pmm->RT;
pmm->lnP = log( P );

#ifdef USE_THERMO_LOG
std::fstream f_log;
if(GemsSettings::log_thermodynamic) {
f_log.open(GemsSettings::with_directory("thermodynamic-log.csv"), std::ios::out/*|std::ios::app*/);
f_log << "\n Calc ThermoEngine;T;" << TK << ";P;" << PPa << "\n";
}
#endif
if( CSD->ccPH[0] == PH_AQUEL )
{
std::string h2o_key = dCH->DCNL[pmm->LO];
Expand Down Expand Up @@ -656,26 +663,23 @@ bool TNode::load_all_thermodynamic_from_thermo( double TK, double PPa )
pmm->epsWg[3] = water_gas_electro.epsilonP.val;
pmm->denWg[4] = water_gas_props.densityPP.val/1e3;
pmm->epsWg[4] = water_gas_electro.epsilonPP.val;
}
#ifdef USE_THERMO_LOG
std::fstream f_log;
if(GemsSettings::log_thermodynamic) {
f_log.open(GemsSettings::with_directory("thermodynamic-log.csv"), std::ios::out/*|std::ios::app*/ );
f_log << "\nCalc ThermoEngine;T;" << TK << ";P;" << PPa << "\n";
f_log << "denW";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->denW[jj]);
f_log << "\nepsW";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->epsW[jj]);
f_log << "\ndenWg";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->denWg[jj]);
f_log << "\nepsWg";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->epsWg[jj]);
}
if(GemsSettings::log_thermodynamic) {
f_log << "denW";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->denW[jj]);
f_log << "\nepsW";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->epsW[jj]);
f_log << "\ndenWg";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->denWg[jj]);
f_log << "\nepsWg";
for( jj=0; jj<5; jj++)
f_log << ";" << floating_point_to_string(pmm->epsWg[jj]);
}
#endif
}

for( k=0; k<pmm->FI; k++ )
{
Expand Down
3 changes: 3 additions & 0 deletions GEMS3K/s_solmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ TSolMod::TSolMod( SolutionData *sd ):
aIPx = sd->arIPx; // Direct access to index list and parameter coeff arrays!
aIPc = sd->arIPc;
aIP = new double[NPar];
for(int ii=0; ii<NPar; ii++ )
aIP[ii] = 0.0;

aGEX = sd->arGEX; // Reciprocal energies, Darken terms, pure fugacities of DC (corr. to TP)
aPparc = sd->arPparc; // Partial pressures NComp
aMoiSN = sd->arMoiSN; // End member moiety- site multiplicity number tables NComp x NSub x NMoi
Expand Down
26 changes: 16 additions & 10 deletions GEMS3K/s_solmod2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1219,11 +1219,14 @@ long int TCGFcalc::CGActivCoefPT( double *X,double *param, double *act,
{
double *xtmp,*Fx;
double P = Pbar1/10.;
std::shared_ptr<double> xtmp_mem = std::make_shared<double>(NN); // new double [NN];
std::shared_ptr<double> Fx_mem = std::make_shared<double>(NN); // new double [NN];
// std::shared_ptr<double> xtmp_mem = std::make_shared<double>(NN); // new double [NN];
// std::shared_ptr<double> Fx_mem = std::make_shared<double>(NN); // new double [NN];

xtmp = xtmp_mem.get();
Fx = Fx_mem.get();
// xtmp = xtmp_mem.get();
// Fx = Fx_mem.get();

xtmp = new double [NN];
Fx = new double [NN];

if(!paar)
paar = new EOSPARAM(X, param, NN);
Expand All @@ -1241,8 +1244,11 @@ long int TCGFcalc::CGActivCoefPT( double *X,double *param, double *act,

ro = ROTOTALMIX(P,T,paar);

if( ro < 0.0 ) // Too low pressure, no corrections will be done
return ( -1 );
if( ro < 0.0 ) { // Too low pressure, no corrections will be done
delete[]xtmp;
delete[]Fx;
return ( -1 );
}

Z = P/(R*T*ro);
F0 = FTOTALMIX(T,ro,paar);
Expand Down Expand Up @@ -1283,8 +1289,8 @@ long int TCGFcalc::CGActivCoefPT( double *X,double *param, double *act,

// GMix+=F0 + ax;
// MLPutRealList(stdlink,act,paar.NCmp());
//delete[]xtmp;
//delete[]Fx;
delete[]xtmp;
delete[]Fx;
roro = ro; // added, 21.06.2008 (TW)

return 0; // changed, 21.06.2008 (TW)
Expand Down Expand Up @@ -1606,7 +1612,7 @@ double TCGFcalc::DENSITY( double *X, double *param, unsigned long NN, double Pba

delete [] xtmp;
if( ro < 0. )
Error( ""," Error - density cannot be found at this T,P" );
Error( "","CG fluid: Error - density cannot be found at this T,P" );
return ro;
}

Expand Down Expand Up @@ -2160,7 +2166,7 @@ double TCGFcalc::ROTOTALMIX( double P,double TT,EOSPARAM* param )

if ( i==FIRSTSEED || i==0 )
{
solmod_logger->error("Input pressure is too high!\n");
solmod_logger->error("CG fluid: Input pressure is too high!\n");
// exit(1);
return (-1.0);
}
Expand Down
3 changes: 2 additions & 1 deletion tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ find_package(Threads REQUIRED)

set(Tools
kva2json
thread_test )
thread_test
thermofun_test)

foreach (toolName ${Tools})

Expand Down
4 changes: 2 additions & 2 deletions tools/kva2json.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ VERSION = 3.4.6
CONFIG -= qt
CONFIG += warn_on
CONFIG += thread console
CONFIG += c++17
CONFIG += c++20
#CONFIG += sanitaze sanitaze_thread

#DEFINES += NO_NODEARRAYLEVEL
Expand Down Expand Up @@ -61,5 +61,5 @@ include($$GEMS3K_CPP/gems3k.pri)

HEADERS += args_tool.h
SOURCES += kva2json.cpp

#SOURCES += thermofun_test.cpp
#SOURCES += thread_test.cpp
93 changes: 93 additions & 0 deletions tools/thermofun_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#ifdef OVERFLOW_EXCEPT
#ifdef __linux__
#include <cfenv>
#elif _MSC_VER
#include <float.h>
#else
#include <cfenv>
#endif
#endif

#include <iostream>
#include "ThermoFun/ThermoFun.h"
#include "v_detail.h"

bool load_thermodynamic(ThermoFun::ThermoEngine* thermo_engine, double TK, double PPa);

int main( int argc, char* argv[] )
{

#if defined(OVERFLOW_EXCEPT)
#ifdef __linux__
feenableexcept (FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW);
#elif _MSC_VER
_clearfp();
_controlfp(_controlfp(0, 0) & ~(_EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW),
_MCW_EM);
#else

#endif
#endif
try {

std::string thermo_file = "UOx_jsonfun/UOx-fun.json";

std::unique_ptr<ThermoFun::ThermoEngine> thermo_engine;
thermo_engine.reset(new ThermoFun::ThermoEngine(thermo_file));

std::cout << "\n 1 ";
load_thermodynamic(thermo_engine.get(), 298.15, 100000);

std::cout << "\n 2 ";
load_thermodynamic(thermo_engine.get(), 298.15, 100000);

std::cout << "\n 3 ";
load_thermodynamic(thermo_engine.get(), 298.15, 100000);
std::cout << std::endl;
return 0;
}
catch(std::exception& e)
{
std::cout << "std::exception: " << e.what() << std::endl;
}
catch(...)
{
std::cout << "unknown exception" << std::endl;
}
return -1;
}

bool load_thermodynamic(ThermoFun::ThermoEngine* thermo_engine, double TK, double PPa)
{
if(!thermo_engine) {
return false;
}
try {
std::cout << "\nCalc ThermoEngine T: " << TK <<" P: " << PPa;

double G0, Vol, S0, H0, Cp0;
double funT = TK, funP=PPa; // T in K, P in Pa

std::vector<std::string> subst_list = {"O(g)", "O2(g)", "O3(g)"};
//std::vector<std::string> subst_list = thermo_engine->database().getSubstancesList();

for(const auto& symbol: subst_list) {
auto propAl = thermo_engine->thermoPropertiesSubstance(funT, funP, symbol);

G0 = propAl.gibbs_energy.val;
Vol= propAl.volume.val*10;
S0 = propAl.entropy.val;
H0 = propAl.enthalpy.val;
Cp0 = propAl.heat_capacity_cp.val;

std::cout << "\n" << symbol << ";" << floating_point_to_string(G0)
<< ";" << floating_point_to_string(Vol) << ";" << floating_point_to_string(S0)
<< ";" << floating_point_to_string(H0) << ";" << floating_point_to_string(Cp0);
}
}
catch(const std::runtime_error& exception) {
std::cout << "\nThermoEngine error: " << exception.what();
}
return true;
}