From 2334ad8d55b81c11b02ca919a9e73d6a44f9ff0c Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Fri, 23 Aug 2024 08:11:35 -0500 Subject: [PATCH] Change return type of newReactor with contents The newReactor function with contents was only introduced in 3.1 and thus can be modified without deprecations. --- include/cantera/zeroD/ReactorFactory.h | 21 ++++++++++++++------- interfaces/cython/cantera/reactor.pxd | 4 ++-- interfaces/cython/cantera/reactor.pyx | 6 +++--- src/clib/ctreactor.cpp | 2 +- src/zeroD/ReactorFactory.cpp | 12 ++++++++++-- test/zeroD/test_zeroD.cpp | 20 ++++++++++---------- 6 files changed, 40 insertions(+), 25 deletions(-) diff --git a/include/cantera/zeroD/ReactorFactory.h b/include/cantera/zeroD/ReactorFactory.h index c9705da8cfa..fa0158b5902 100644 --- a/include/cantera/zeroD/ReactorFactory.h +++ b/include/cantera/zeroD/ReactorFactory.h @@ -43,23 +43,30 @@ class ReactorFactory : public Factory, const s //! @ingroup zerodGroup //! @{ -//! Create a ReactorNode object of the specified type +//! Create a %ReactorNode object of the specified type. //! @param model String representing type of reactor node. //! @param contents Solution object holding thermo/kinetics. //! @param name Name of reactor. //! @since New in %Cantera 3.1. -shared_ptr newReactorNode( - const string& model, shared_ptr contents=nullptr, +shared_ptr newReactor( + const string& model, shared_ptr contents, const string& name="(none)"); -//! Create a Reactor object of the specified type +//! Create an empty ReactorNode object of the specified type. +//! @since Transitional method; new in %Cantera 3.1. +//! @deprecated Empty reactors will no longer be supported after %Cantera 3.1. +//! Use newReactor() with contents instead. +shared_ptr newReactor4(const string& model); + +//! Create an empty ReactorBase object of the specified type. //! @since Starting in %Cantera 3.1, this method returns a `shared_ptr` -//! @deprecated Transitional method. Use newReactor() with contents instead. +//! @deprecated Empty reactors will no longer be supported after %Cantera 3.1. +//! Use newReactor() with contents instead. shared_ptr newReactor(const string& model); -//! Create a Reactor object of the specified type +//! Create a Reactor object of the specified type. //! @since New in %Cantera 3.0. -//! @deprecated Transitional method. Use newReactor() instead. +//! @deprecated Transitional method. Use non-empty newReactor() instead. shared_ptr newReactor3(const string& model); //! @} diff --git a/interfaces/cython/cantera/reactor.pxd b/interfaces/cython/cantera/reactor.pxd index 8241f26ce44..8f649683901 100644 --- a/interfaces/cython/cantera/reactor.pxd +++ b/interfaces/cython/cantera/reactor.pxd @@ -30,8 +30,8 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera": cdef cppclass CxxFlowDevice "Cantera::FlowDevice" # factories - cdef shared_ptr[CxxReactorNode] newReactorNode(string) except +translate_exception - cdef shared_ptr[CxxReactorNode] newReactorNode(string, shared_ptr[CxxSolution], string) except +translate_exception + cdef shared_ptr[CxxReactorNode] newReactor4(string) except +translate_exception + cdef shared_ptr[CxxReactorNode] newReactor(string, shared_ptr[CxxSolution], string) except +translate_exception cdef shared_ptr[CxxConnector] newConnector(string, shared_ptr[CxxReactorNode], shared_ptr[CxxReactorNode], string) except +translate_exception # reactors diff --git a/interfaces/cython/cantera/reactor.pyx b/interfaces/cython/cantera/reactor.pyx index aba9987242f..27704e00e7e 100644 --- a/interfaces/cython/cantera/reactor.pyx +++ b/interfaces/cython/cantera/reactor.pyx @@ -20,11 +20,11 @@ cdef class ReactorNode: def __cinit__(self, _SolutionBase contents=None, *args, name="(none)", **kwargs): if isinstance(contents, _SolutionBase): - self._node = newReactorNode(stringify(self.reactor_type), - contents._base, stringify(name)) + self._node = newReactor(stringify(self.reactor_type), + contents._base, stringify(name)) else: # deprecated: will raise warnings in C++ layer - self._node = newReactorNode(stringify(self.reactor_type)) + self._node = newReactor4(stringify(self.reactor_type)) self._node.get().setName(stringify(name)) self.node = self._node.get() diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 6f8768e82e3..5623a15264c 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -41,7 +41,7 @@ extern "C" { { try { return ReactorCabinet::add( - newReactorNode(type, SolutionCabinet::at(n), name)); + newReactor(type, SolutionCabinet::at(n), name)); } catch (...) { return handleAllExceptions(-1, ERR); } diff --git a/src/zeroD/ReactorFactory.cpp b/src/zeroD/ReactorFactory.cpp index a58aacd239a..8780025d2d3 100644 --- a/src/zeroD/ReactorFactory.cpp +++ b/src/zeroD/ReactorFactory.cpp @@ -98,19 +98,27 @@ void ReactorFactory::deleteFactory() { s_factory = 0; } -shared_ptr newReactorNode( +shared_ptr newReactor( const string& model, shared_ptr contents, const string& name) { return shared_ptr( ReactorFactory::factory()->create(model, contents, name)); } +shared_ptr newReactor4(const string& model) +{ + warn_deprecated("newReactor4", + "Replaced by newReactor with contents; to be removed after Cantera 3.1."); + return shared_ptr( + ReactorFactory::factory()->create(model, nullptr, "")); +} + shared_ptr newReactor(const string& model) { warn_deprecated("newReactor", "Replaced by newReactor with contents; to be removed after Cantera 3.1."); auto reactor = std::dynamic_pointer_cast( - newReactorNode(model, nullptr, "")); + newReactor(model, nullptr, "")); if (!reactor) { throw CanteraError("newReactor", "Detected incompatible ReactorBase type '{}'", model); diff --git a/test/zeroD/test_zeroD.cpp b/test/zeroD/test_zeroD.cpp index 178bef38b83..6921b130c9e 100644 --- a/test/zeroD/test_zeroD.cpp +++ b/test/zeroD/test_zeroD.cpp @@ -19,7 +19,7 @@ TEST(zerodim, simple) auto sol = newSolution("gri30.yaml", "gri30", "none"); sol->thermo()->setState_TPX(T, P, X); - auto cppNode = newReactorNode("IdealGasReactor", sol, "simple"); + auto cppNode = newReactor("IdealGasReactor", sol, "simple"); ASSERT_EQ(cppNode->name(), "simple"); auto reactor = std::dynamic_pointer_cast(cppNode); reactor->initialize(); @@ -62,11 +62,11 @@ TEST(zerodim, surface) auto gas = newSolution("ptcombust.yaml", "gas"); auto surf = newInterface("ptcombust.yaml", "Pt_surf", {gas}); - auto node0 = newReactorNode("IdealGasReactor", gas, "bulk"); + auto node0 = newReactor("IdealGasReactor", gas, "bulk"); auto reactor = std::dynamic_pointer_cast(node0); ASSERT_EQ(reactor->name(), "bulk"); - auto node1 = newReactorNode("ReactorSurface", surf, "surface"); + auto node1 = newReactor("ReactorSurface", surf, "surface"); auto cppSurface = std::dynamic_pointer_cast(node1); ASSERT_EQ(cppSurface->name(), "surface"); } @@ -75,8 +75,8 @@ TEST(zerodim, flowdevice) { auto gas = newSolution("gri30.yaml", "gri30", "none"); - auto node0 = newReactorNode("IdealGasReactor", gas, "upstream"); - auto node1 = newReactorNode("IdealGasReactor", gas, "downstream"); + auto node0 = newReactor("IdealGasReactor", gas, "upstream"); + auto node1 = newReactor("IdealGasReactor", gas, "downstream"); auto edge = newConnector("Valve", node0, node1, "valve"); ASSERT_EQ(edge->name(), "valve"); @@ -95,8 +95,8 @@ TEST(zerodim, wall) { auto gas = newSolution("gri30.yaml", "gri30", "none"); - auto node0 = newReactorNode("IdealGasReactor", gas, "left"); - auto node1 = newReactorNode("IdealGasReactor", gas, "right"); + auto node0 = newReactor("IdealGasReactor", gas, "left"); + auto node1 = newReactor("IdealGasReactor", gas, "right"); auto edge = newConnector("Wall", node0, node1, "wall"); ASSERT_EQ(edge->name(), "wall"); @@ -112,12 +112,12 @@ TEST(zerodim, wall) TEST(zerodim, empty) { // Deprecated/transitional modes. Remove after Cantera 3.1. - EXPECT_THROW(newReactorNode("IdealGasReactor", nullptr, "igr"), CanteraError); + EXPECT_THROW(newReactor("IdealGasReactor", nullptr, "igr"), CanteraError); EXPECT_THROW(newConnector("Valve", nullptr, nullptr, "valve"), CanteraError); suppress_deprecation_warnings(); - auto node0 = newReactorNode("IdealGasReactor", nullptr, "r0"); - auto node1 = newReactorNode("IdealGasReactor", nullptr, "r1"); + auto node0 = newReactor("IdealGasReactor", nullptr, "r0"); + auto node1 = newReactor("IdealGasReactor", nullptr, "r1"); make_deprecation_warnings_fatal(); auto gas = newSolution("gri30.yaml", "gri30", "none");