Skip to content

Commit 836d0b5

Browse files
authored
Merge pull request #49 from sdmytrievs/master
Bugfix for using from GEMSGUI
2 parents e3c29b1 + 07dd204 commit 836d0b5

File tree

8 files changed

+142
-32
lines changed

8 files changed

+142
-32
lines changed

GEMS3K/gems3k_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#define GEMS3K_VERSION "4.4.4"
4-
#define GEMS3K_VERSION_HASH "0995d4c"
4+
#define GEMS3K_VERSION_HASH "b57199a"
55
#define GEMS3K_GIT_BRANCH "master"
66
#define GEMS3K_ChemicalFun "0.1.13"
77
#define GEMS3K_ThermoFun "0.5.4"

GEMS3K/node.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,12 @@ TNode::TNode()
5656
{
5757
std::call_once(once_flag, [](){
5858
// Thread-safe one-time operation
59+
if(!ipmlog_file) {
5960
ipmlog_file = spdlog::rotating_logger_mt("ipmlog", GemsSettings::with_directory("ipmlog.txt"),
6061
GemsSettings::log_file_size,
6162
GemsSettings::log_file_count);
63+
64+
}
6265
});
6366
CSD = NULL;
6467
CNode = NULL;

GEMS3K/node_copy.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,13 @@ bool TNode::load_all_thermodynamic_from_thermo( double TK, double PPa )
619619
pmm->FRT = F_CONSTANT/pmm->RT;
620620
pmm->lnP = log( P );
621621

622+
#ifdef USE_THERMO_LOG
623+
std::fstream f_log;
624+
if(GemsSettings::log_thermodynamic) {
625+
f_log.open(GemsSettings::with_directory("thermodynamic-log.csv"), std::ios::out/*|std::ios::app*/);
626+
f_log << "\n Calc ThermoEngine;T;" << TK << ";P;" << PPa << "\n";
627+
}
628+
#endif
622629
if( CSD->ccPH[0] == PH_AQUEL )
623630
{
624631
std::string h2o_key = dCH->DCNL[pmm->LO];
@@ -656,26 +663,23 @@ bool TNode::load_all_thermodynamic_from_thermo( double TK, double PPa )
656663
pmm->epsWg[3] = water_gas_electro.epsilonP.val;
657664
pmm->denWg[4] = water_gas_props.densityPP.val/1e3;
658665
pmm->epsWg[4] = water_gas_electro.epsilonPP.val;
659-
}
660666
#ifdef USE_THERMO_LOG
661-
std::fstream f_log;
662-
if(GemsSettings::log_thermodynamic) {
663-
f_log.open(GemsSettings::with_directory("thermodynamic-log.csv"), std::ios::out/*|std::ios::app*/ );
664-
f_log << "\nCalc ThermoEngine;T;" << TK << ";P;" << PPa << "\n";
665-
f_log << "denW";
666-
for( jj=0; jj<5; jj++)
667-
f_log << ";" << floating_point_to_string(pmm->denW[jj]);
668-
f_log << "\nepsW";
669-
for( jj=0; jj<5; jj++)
670-
f_log << ";" << floating_point_to_string(pmm->epsW[jj]);
671-
f_log << "\ndenWg";
672-
for( jj=0; jj<5; jj++)
673-
f_log << ";" << floating_point_to_string(pmm->denWg[jj]);
674-
f_log << "\nepsWg";
675-
for( jj=0; jj<5; jj++)
676-
f_log << ";" << floating_point_to_string(pmm->epsWg[jj]);
677-
}
667+
if(GemsSettings::log_thermodynamic) {
668+
f_log << "denW";
669+
for( jj=0; jj<5; jj++)
670+
f_log << ";" << floating_point_to_string(pmm->denW[jj]);
671+
f_log << "\nepsW";
672+
for( jj=0; jj<5; jj++)
673+
f_log << ";" << floating_point_to_string(pmm->epsW[jj]);
674+
f_log << "\ndenWg";
675+
for( jj=0; jj<5; jj++)
676+
f_log << ";" << floating_point_to_string(pmm->denWg[jj]);
677+
f_log << "\nepsWg";
678+
for( jj=0; jj<5; jj++)
679+
f_log << ";" << floating_point_to_string(pmm->epsWg[jj]);
680+
}
678681
#endif
682+
}
679683

680684
for( k=0; k<pmm->FI; k++ )
681685
{

GEMS3K/s_solmod.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ TSolMod::TSolMod( SolutionData *sd ):
6767
aIPx = sd->arIPx; // Direct access to index list and parameter coeff arrays!
6868
aIPc = sd->arIPc;
6969
aIP = new double[NPar];
70+
for(int ii=0; ii<NPar; ii++ )
71+
aIP[ii] = 0.0;
72+
7073
aGEX = sd->arGEX; // Reciprocal energies, Darken terms, pure fugacities of DC (corr. to TP)
7174
aPparc = sd->arPparc; // Partial pressures NComp
7275
aMoiSN = sd->arMoiSN; // End member moiety- site multiplicity number tables NComp x NSub x NMoi

GEMS3K/s_solmod2.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,11 +1219,14 @@ long int TCGFcalc::CGActivCoefPT( double *X,double *param, double *act,
12191219
{
12201220
double *xtmp,*Fx;
12211221
double P = Pbar1/10.;
1222-
std::shared_ptr<double> xtmp_mem = std::make_shared<double>(NN); // new double [NN];
1223-
std::shared_ptr<double> Fx_mem = std::make_shared<double>(NN); // new double [NN];
1222+
// std::shared_ptr<double> xtmp_mem = std::make_shared<double>(NN); // new double [NN];
1223+
// std::shared_ptr<double> Fx_mem = std::make_shared<double>(NN); // new double [NN];
12241224

1225-
xtmp = xtmp_mem.get();
1226-
Fx = Fx_mem.get();
1225+
// xtmp = xtmp_mem.get();
1226+
// Fx = Fx_mem.get();
1227+
1228+
xtmp = new double [NN];
1229+
Fx = new double [NN];
12271230

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

12421245
ro = ROTOTALMIX(P,T,paar);
12431246

1244-
if( ro < 0.0 ) // Too low pressure, no corrections will be done
1245-
return ( -1 );
1247+
if( ro < 0.0 ) { // Too low pressure, no corrections will be done
1248+
delete[]xtmp;
1249+
delete[]Fx;
1250+
return ( -1 );
1251+
}
12461252

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

12841290
// GMix+=F0 + ax;
12851291
// MLPutRealList(stdlink,act,paar.NCmp());
1286-
//delete[]xtmp;
1287-
//delete[]Fx;
1292+
delete[]xtmp;
1293+
delete[]Fx;
12881294
roro = ro; // added, 21.06.2008 (TW)
12891295

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

16071613
delete [] xtmp;
16081614
if( ro < 0. )
1609-
Error( ""," Error - density cannot be found at this T,P" );
1615+
Error( "","CG fluid: Error - density cannot be found at this T,P" );
16101616
return ro;
16111617
}
16121618

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

21612167
if ( i==FIRSTSEED || i==0 )
21622168
{
2163-
solmod_logger->error("Input pressure is too high!\n");
2169+
solmod_logger->error("CG fluid: Input pressure is too high!\n");
21642170
// exit(1);
21652171
return (-1.0);
21662172
}

tools/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ find_package(Threads REQUIRED)
77

88
set(Tools
99
kva2json
10-
thread_test )
10+
thread_test
11+
thermofun_test)
1112

1213
foreach (toolName ${Tools})
1314

tools/kva2json.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ VERSION = 3.4.6
99
CONFIG -= qt
1010
CONFIG += warn_on
1111
CONFIG += thread console
12-
CONFIG += c++17
12+
CONFIG += c++20
1313
#CONFIG += sanitaze sanitaze_thread
1414

1515
#DEFINES += NO_NODEARRAYLEVEL
@@ -61,5 +61,5 @@ include($$GEMS3K_CPP/gems3k.pri)
6161

6262
HEADERS += args_tool.h
6363
SOURCES += kva2json.cpp
64-
64+
#SOURCES += thermofun_test.cpp
6565
#SOURCES += thread_test.cpp

tools/thermofun_test.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#ifdef OVERFLOW_EXCEPT
2+
#ifdef __linux__
3+
#include <cfenv>
4+
#elif _MSC_VER
5+
#include <float.h>
6+
#else
7+
#include <cfenv>
8+
#endif
9+
#endif
10+
11+
#include <iostream>
12+
#include "ThermoFun/ThermoFun.h"
13+
#include "v_detail.h"
14+
15+
bool load_thermodynamic(ThermoFun::ThermoEngine* thermo_engine, double TK, double PPa);
16+
17+
int main( int argc, char* argv[] )
18+
{
19+
20+
#if defined(OVERFLOW_EXCEPT)
21+
#ifdef __linux__
22+
feenableexcept (FE_DIVBYZERO|FE_OVERFLOW|FE_UNDERFLOW);
23+
#elif _MSC_VER
24+
_clearfp();
25+
_controlfp(_controlfp(0, 0) & ~(_EM_INVALID | _EM_ZERODIVIDE | _EM_OVERFLOW),
26+
_MCW_EM);
27+
#else
28+
29+
#endif
30+
#endif
31+
try {
32+
33+
std::string thermo_file = "UOx_jsonfun/UOx-fun.json";
34+
35+
std::unique_ptr<ThermoFun::ThermoEngine> thermo_engine;
36+
thermo_engine.reset(new ThermoFun::ThermoEngine(thermo_file));
37+
38+
std::cout << "\n 1 ";
39+
load_thermodynamic(thermo_engine.get(), 298.15, 100000);
40+
41+
std::cout << "\n 2 ";
42+
load_thermodynamic(thermo_engine.get(), 298.15, 100000);
43+
44+
std::cout << "\n 3 ";
45+
load_thermodynamic(thermo_engine.get(), 298.15, 100000);
46+
std::cout << std::endl;
47+
return 0;
48+
}
49+
catch(std::exception& e)
50+
{
51+
std::cout << "std::exception: " << e.what() << std::endl;
52+
}
53+
catch(...)
54+
{
55+
std::cout << "unknown exception" << std::endl;
56+
}
57+
return -1;
58+
}
59+
60+
bool load_thermodynamic(ThermoFun::ThermoEngine* thermo_engine, double TK, double PPa)
61+
{
62+
if(!thermo_engine) {
63+
return false;
64+
}
65+
try {
66+
std::cout << "\nCalc ThermoEngine T: " << TK <<" P: " << PPa;
67+
68+
double G0, Vol, S0, H0, Cp0;
69+
double funT = TK, funP=PPa; // T in K, P in Pa
70+
71+
std::vector<std::string> subst_list = {"O(g)", "O2(g)", "O3(g)"};
72+
//std::vector<std::string> subst_list = thermo_engine->database().getSubstancesList();
73+
74+
for(const auto& symbol: subst_list) {
75+
auto propAl = thermo_engine->thermoPropertiesSubstance(funT, funP, symbol);
76+
77+
G0 = propAl.gibbs_energy.val;
78+
Vol= propAl.volume.val*10;
79+
S0 = propAl.entropy.val;
80+
H0 = propAl.enthalpy.val;
81+
Cp0 = propAl.heat_capacity_cp.val;
82+
83+
std::cout << "\n" << symbol << ";" << floating_point_to_string(G0)
84+
<< ";" << floating_point_to_string(Vol) << ";" << floating_point_to_string(S0)
85+
<< ";" << floating_point_to_string(H0) << ";" << floating_point_to_string(Cp0);
86+
}
87+
}
88+
catch(const std::runtime_error& exception) {
89+
std::cout << "\nThermoEngine error: " << exception.what();
90+
}
91+
return true;
92+
}
93+

0 commit comments

Comments
 (0)