Skip to content

Commit

Permalink
[Reactor] Implement newWall3 to return shared_ptr
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Jun 21, 2023
1 parent 0ab5a0e commit 03c7264
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
12 changes: 10 additions & 2 deletions include/cantera/zeroD/WallFactory.h
Expand Up @@ -14,10 +14,10 @@ namespace Cantera

//! Factory class to create WallBase objects
//!
//! This class is mainly used via the newWall() function, for example:
//! This class is mainly used via the newWall3() function, for example:
//!
//! ```cpp
//! unique_ptr<WallBase> piston(newWall("Wall"));
//! shared_ptr<WallBase> piston = newWall3("Wall");
//! ```
//!
//! @ingroup ZeroD
Expand All @@ -31,6 +31,7 @@ class WallFactory : public Factory<WallBase>
//! Create a new wall by type name.
/*!
* @param wallType the type to be created.
* @deprecated To be removed after Cantera 3.0; replaceable by newWall3.
*/
virtual WallBase* newWall(const std::string& wallType);

Expand All @@ -41,9 +42,16 @@ class WallFactory : public Factory<WallBase>
};

//! Create a WallBase object of the specified type
//! @deprecated To be changed after Cantera 3.0; for new behavior, see newWall3.
//! @ingroup ZeroD
WallBase* newWall(const string& model);

//! Create a WallBase object of the specified type
//! @ingroup ZeroD
//! @since New in Cantera 3.0.
//! @todo Transition back to newWall after Cantera 3.0
shared_ptr<WallBase> newWall3(const string& model);

}

#endif
3 changes: 2 additions & 1 deletion interfaces/cython/cantera/reactor.pxd
Expand Up @@ -32,7 +32,7 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
# factories
cdef shared_ptr[CxxReactorBase] newReactor3(string) except +translate_exception
cdef CxxFlowDevice* newFlowDevice(string) except +translate_exception
cdef CxxWallBase* newWall(string) except +translate_exception
cdef shared_ptr[CxxWallBase] newWall3(string) except +translate_exception

# reactors
cdef cppclass CxxReactorBase "Cantera::ReactorBase":
Expand Down Expand Up @@ -253,6 +253,7 @@ cdef class ReactorSurface:
cdef Kinetics _kinetics

cdef class WallBase:
cdef shared_ptr[CxxWallBase] _wall
cdef CxxWallBase* wall
cdef object _velocity_func
cdef object _heat_flux_func
Expand Down
3 changes: 2 additions & 1 deletion interfaces/cython/cantera/reactor.pyx
Expand Up @@ -838,7 +838,8 @@ cdef class WallBase:
"""
wall_type = "none"
def __cinit__(self, *args, **kwargs):
self.wall = newWall(stringify(self.wall_type))
self._wall = newWall3(stringify(self.wall_type))
self.wall = self._wall.get()

def __init__(self, left, right, *, name=None, A=None, K=None, U=None,
Q=None, velocity=None):
Expand Down
5 changes: 2 additions & 3 deletions src/clib/ctreactor.cpp
Expand Up @@ -19,7 +19,7 @@ using namespace Cantera;
typedef SharedCabinet<ReactorBase> ReactorCabinet;
typedef SharedCabinet<ReactorNet> NetworkCabinet;
typedef Cabinet<FlowDevice> FlowDeviceCabinet;
typedef Cabinet<WallBase> WallCabinet;
typedef SharedCabinet<WallBase> WallCabinet;
typedef Cabinet<Func1> FuncCabinet;
typedef SharedCabinet<ThermoPhase> ThermoCabinet;
typedef SharedCabinet<Kinetics> KineticsCabinet;
Expand Down Expand Up @@ -459,8 +459,7 @@ extern "C" {
int wall_new(const char* type)
{
try {
WallBase* w = WallFactory::factory()->newWall(type);
return WallCabinet::add(w);
return WallCabinet::add(newWall3(type));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
Expand Down
10 changes: 10 additions & 0 deletions src/zeroD/WallFactory.cpp
Expand Up @@ -33,12 +33,22 @@ void WallFactory::deleteFactory() {

WallBase* WallFactory::newWall(const std::string& wallType)
{
warn_deprecated("WallFactory::newWall",
"To be removed after Cantera 3.0; for new behavior, see 'newWall3'.");
return create(wallType);
}

WallBase* newWall(const string& model)
{
warn_deprecated("newWall",
"To be changed after Cantera 3.0; for new behavior, see 'newWall3'.");
return WallFactory::factory()->newWall(model);
}

shared_ptr<WallBase> newWall3(const string& model)
{
shared_ptr<WallBase> wptr(WallFactory::factory()->create(model));
return wptr;
}

}

0 comments on commit 03c7264

Please sign in to comment.