|
| 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