diff --git a/include/cantera/zeroD/ReactorNet.h b/include/cantera/zeroD/ReactorNet.h index 92ce111d2..40186d87f 100644 --- a/include/cantera/zeroD/ReactorNet.h +++ b/include/cantera/zeroD/ReactorNet.h @@ -114,6 +114,13 @@ public: //@} //! Add the reactor *r* to this reactor network. + void addReactor(Reactor& r); + + //! Add the reactor *r* to this reactor network. + /** + * @deprecated To be removed after Cantera 2.2. Use addReactor(Reactor&) + * instead. + */ void addReactor(Reactor* r, bool iown = false); //! Return a reference to the *n*-th reactor in this network. The reactor diff --git a/interfaces/cython/cantera/_cantera.pxd b/interfaces/cython/cantera/_cantera.pxd index f5d92111d..00a68cbf9 100644 --- a/interfaces/cython/cantera/_cantera.pxd +++ b/interfaces/cython/cantera/_cantera.pxd @@ -324,7 +324,7 @@ cdef extern from "cantera/zeroD/flowControllers.h": cdef extern from "cantera/zeroD/ReactorNet.h": cdef cppclass CxxReactorNet "Cantera::ReactorNet": CxxReactorNet() - void addReactor(CxxReactor*) + void addReactor(CxxReactor&) void advance(double) except + double step(double) except + double time() diff --git a/interfaces/cython/cantera/reactor.pyx b/interfaces/cython/cantera/reactor.pyx index e5a21b0aa..cf4324a47 100644 --- a/interfaces/cython/cantera/reactor.pyx +++ b/interfaces/cython/cantera/reactor.pyx @@ -732,7 +732,7 @@ cdef class ReactorNet: def add_reactor(self, Reactor r): """Add a reactor to the network.""" self._reactors.append(r) - self.net.addReactor(r.reactor) + self.net.addReactor(deref(r.reactor)) def advance(self, double t): """ diff --git a/samples/cxx/combustor/combustor.cpp b/samples/cxx/combustor/combustor.cpp index ec30abb57..c238d68b8 100644 --- a/samples/cxx/combustor/combustor.cpp +++ b/samples/cxx/combustor/combustor.cpp @@ -98,7 +98,7 @@ void runexample() // the simulation only contains one reactor ReactorNet sim; - sim.addReactor(&combustor); + sim.addReactor(combustor); // take single steps to 6 s, writing the results to a CSV file // for later plotting. diff --git a/samples/cxx/kinetics1/kinetics1.cpp b/samples/cxx/kinetics1/kinetics1.cpp index 97f609ee5..4f1b1dd94 100644 --- a/samples/cxx/kinetics1/kinetics1.cpp +++ b/samples/cxx/kinetics1/kinetics1.cpp @@ -74,7 +74,7 @@ int kinetics1(int np, void* p) // create a container object to run the simulation // and add the reactor to it ReactorNet sim; - sim.addReactor(&r, false); + sim.addReactor(&r); // main loop clock_t t0 = clock(); // save start time diff --git a/src/clib/ctreactor.cpp b/src/clib/ctreactor.cpp index 05ecb318a..360c64be1 100644 --- a/src/clib/ctreactor.cpp +++ b/src/clib/ctreactor.cpp @@ -304,7 +304,7 @@ extern "C" { { try { NetworkCabinet::item(i).addReactor( - &dynamic_cast(ReactorCabinet::item(n))); + dynamic_cast(ReactorCabinet::item(n))); return 0; } catch (...) { return handleAllExceptions(-1, ERR); diff --git a/src/zeroD/ReactorNet.cpp b/src/zeroD/ReactorNet.cpp index 1b4493764..49c31da1f 100644 --- a/src/zeroD/ReactorNet.cpp +++ b/src/zeroD/ReactorNet.cpp @@ -163,6 +163,12 @@ double ReactorNet::step(doublereal time) void ReactorNet::addReactor(Reactor* r, bool iown) { + warn_deprecated("ReactorNet::addReactor(Reactor*)", + "To be removed after Cantera 2.2. Use 'addReactor(Reactor&) instead'."); + if (iown) { + warn_deprecated("ReactorNet::addReactor", + "Ownership of Reactors by ReactorNet is deprecated."); + } r->setNetwork(this); if (r->type() >= ReactorType) { m_reactors.push_back(r); @@ -174,6 +180,13 @@ void ReactorNet::addReactor(Reactor* r, bool iown) } } +void ReactorNet::addReactor(Reactor& r) +{ + r.setNetwork(this); + m_reactors.push_back(&r); + m_iown.push_back(false); +} + void ReactorNet::eval(doublereal t, doublereal* y, doublereal* ydot, doublereal* p) { diff --git a/test_problems/cxx_ex/kinetics_example1.cpp b/test_problems/cxx_ex/kinetics_example1.cpp index 9f14ee5e2..ee3d8d187 100644 --- a/test_problems/cxx_ex/kinetics_example1.cpp +++ b/test_problems/cxx_ex/kinetics_example1.cpp @@ -76,7 +76,7 @@ int kinetics_example1(int job) // and add the reactor to it ReactorNet* sim_ptr = new ReactorNet(); sim_ptr->setVerbose(false); - sim_ptr->addReactor(&r); + sim_ptr->addReactor(r); double tm; double dt = 1.e-5; // interval at which output is written diff --git a/test_problems/cxx_ex/kinetics_example3.cpp b/test_problems/cxx_ex/kinetics_example3.cpp index 288ac3df0..b5510d91e 100644 --- a/test_problems/cxx_ex/kinetics_example3.cpp +++ b/test_problems/cxx_ex/kinetics_example3.cpp @@ -73,7 +73,7 @@ int kinetics_example3(int job) // and add the reactor to it ReactorNet& sim = *(new ReactorNet()); sim.setVerbose(false); - sim.addReactor(&r); + sim.addReactor(r); double tm; double dt = 1.e-5; // interval at which output is written diff --git a/test_problems/cxx_ex/rxnpath_example1.cpp b/test_problems/cxx_ex/rxnpath_example1.cpp index f44c17352..e7398c957 100644 --- a/test_problems/cxx_ex/rxnpath_example1.cpp +++ b/test_problems/cxx_ex/rxnpath_example1.cpp @@ -120,7 +120,7 @@ int rxnpath_example1(int job) // create a container object to run the simulation // and add the reactor to it ReactorNet& sim = *(new ReactorNet()); - sim.addReactor(&r); + sim.addReactor(r); // create a reaction path diagram builder ReactionPathBuilder b;