From ded4513c8bda1b07f053db72e68e44c6cbb40da5 Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sun, 23 Jun 2024 08:51:22 +0200 Subject: [PATCH] [clib] Retain stflow_ routines but throw error --- include/cantera/clib/ctonedim.h | 10 +++++ src/clib/ctonedim.cpp | 73 ++++++++++++++++++++++++++++++++- test/clib/test_ctonedim.cpp | 22 ++++++++++ test/clib/utils.h | 0 4 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 test/clib/utils.h diff --git a/include/cantera/clib/ctonedim.h b/include/cantera/clib/ctonedim.h index e1267daf7..b5f3023a5 100644 --- a/include/cantera/clib/ctonedim.h +++ b/include/cantera/clib/ctonedim.h @@ -68,6 +68,16 @@ extern "C" { size_t m, const double* temp); CANTERA_CAPI int flow1D_solveEnergyEqn(int i, int flag); + //! @todo: Remove all functions with `stflow` prefix after Cantera 3.1 + CANTERA_CAPI int stflow_new(int iph, int ikin, int itr, int itype); + CANTERA_CAPI int stflow_setTransport(int i, int itr); + CANTERA_CAPI int stflow_enableSoret(int i, int iSoret); + CANTERA_CAPI int stflow_setPressure(int i, double p); + CANTERA_CAPI double stflow_pressure(int i); + CANTERA_CAPI int stflow_setFixedTempProfile(int i, size_t n, const double* pos, + size_t m, const double* temp); + CANTERA_CAPI int stflow_solveEnergyEqn(int i, int flag); + CANTERA_CAPI int sim1D_new(size_t nd, const int* domains); CANTERA_CAPI int sim1D_del(int i); CANTERA_CAPI int sim1D_setValue(int i, int dom, int comp, int localPoint, double value); diff --git a/src/clib/ctonedim.cpp b/src/clib/ctonedim.cpp index 355bd1508..4896bb978 100644 --- a/src/clib/ctonedim.cpp +++ b/src/clib/ctonedim.cpp @@ -398,7 +398,7 @@ extern "C" { } } - //------------------ stagnation flow domains -------------------- + //------------------ flow domains -------------------- int flow1D_new(int iph, int ikin, int itr, int itype) { @@ -490,6 +490,77 @@ extern "C" { } } + int stflow_new(int iph, int ikin, int itr, int itype) + { + try { + throw NotImplementedError("stflow_new", + "Function replaced by 'flow1D_new'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int stflow_setTransport(int i, int itr) + { + try { + throw NotImplementedError("stflow_setTransport", + "Function replaced by 'flow1D_setTransport'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int stflow_enableSoret(int i, int iSoret) + { + try { + throw NotImplementedError("stflow_enableSoret", + "Function replaced by 'flow1D_enableSoret'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int stflow_setPressure(int i, double p) + { + try { + throw NotImplementedError("stflow_setPressure", + "Function replaced by 'flow1D_setPressure'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + double stflow_pressure(int i) + { + try { + throw NotImplementedError("stflow_pressure", + "Function replaced by 'flow1D_pressure'."); + } catch (...) { + return handleAllExceptions(DERR, DERR); + } + } + + int stflow_setFixedTempProfile(int i, size_t n, const double* pos, + size_t m, const double* temp) + { + try { + throw NotImplementedError("stflow_setFixedTempProfile", + "Function replaced by 'flow1D_setFixedTempProfile'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + + int stflow_solveEnergyEqn(int i, int flag) + { + try { + throw NotImplementedError("stflow_solveEnergyEqn", + "Function replaced by 'flow1D_solveEnergyEqn'."); + } catch (...) { + return handleAllExceptions(-1, ERR); + } + } + //------------------- Sim1D -------------------------------------- int sim1D_new(size_t nd, const int* domains) diff --git a/test/clib/test_ctonedim.cpp b/test/clib/test_ctonedim.cpp index feff0abda..cf4752b20 100644 --- a/test/clib/test_ctonedim.cpp +++ b/test/clib/test_ctonedim.cpp @@ -254,3 +254,25 @@ TEST(ctonedim, freeflame_from_parts) Tprev = T; } } + +TEST(ctonedim, stflow_tests) +{ + //! @todo: To be removed after Cantera 3.1 + ct_resetStorage(); + auto gas = newThermo("h2o2.yaml", "ohmech"); + + int sol = soln_newSolution("h2o2.yaml", "ohmech", "default"); + int ph = soln_thermo(sol); + int kin = soln_kinetics(sol); + int tr = soln_transport(sol); + + // spot check some errors + int itype = 2; // free flow + int ret = stflow_new(ph, kin, tr, itype); + ASSERT_EQ(ret, -1); // -1 is an error code + + int flow = flow1D_new(ph, kin, tr, itype); + ASSERT_EQ(stflow_setTransport(flow, tr), -1); + ASSERT_EQ(stflow_pressure(flow), DERR); // DERR is an error code + ASSERT_EQ(stflow_setPressure(flow, OneAtm), -1); +} diff --git a/test/clib/utils.h b/test/clib/utils.h new file mode 100644 index 000000000..e69de29bb