[zeroD] Add alternative Connector instantiations

Add newWall and newFlowDevice with reactors as parameters, and
deprecate old versions.
This commit is contained in:
Ingmar Schoegl 2025-02-16 10:15:21 -06:00
parent b057dab41c
commit d0e96223a2
4 changed files with 43 additions and 7 deletions

View File

@ -55,7 +55,7 @@ private:
//! @ingroup zerodGroup
//! @{
//! Create a %ConnectorNode object of the specified type
//! Create a ConnectorNode object of the specified type
//! @param model String specifying reactor type.
//! @param r0 First reactor.
//! @param r1 Second reactor.
@ -68,12 +68,30 @@ shared_ptr<ConnectorNode> newConnectorNode(const string& model,
//! Create a FlowDevice object of the specified type
//! @since Starting in %Cantera 3.1, this method returns a `shared_ptr<FlowDevice>`
//! @deprecated To be removed after %Cantera 3.2. Use version that provides reactors
//! as parameter instead.
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name="(none)");
//! Create a FlowDevice object of the specified type.
//! @copydetails newConnectorNode
shared_ptr<FlowDevice> newFlowDevice(const string& model,
shared_ptr<ReactorBase> r0,
shared_ptr<ReactorBase> r1,
const string& name="(none)");
//! Create a WallBase object of the specified type
//! @since Starting in %Cantera 3.1, this method returns a `shared_ptr<WallBase>`
//! @deprecated To be removed after %Cantera 3.2. Use version that provides reactors
//! as parameter instead.
shared_ptr<WallBase> newWall(const string& model, const string& name="(none)");
//! Create a WallBase object of the specified type.
//! @copydetails newConnectorNode
shared_ptr<WallBase> newWall(const string& model,
shared_ptr<ReactorBase> r0,
shared_ptr<ReactorBase> r1,
const string& name="(none)");
//! @}
}

View File

@ -57,7 +57,7 @@ public:
/*!
* @param in Upstream reactor.
* @param out Downstream reactor.
* @deprecated To be removed after Cantera 3.2. Reactors should be provided to
* @deprecated To be removed after %Cantera 3.2. Reactors should be provided to
* constructor instead.
*/
bool install(ReactorBase& in, ReactorBase& out);

View File

@ -60,7 +60,7 @@ public:
virtual void setArea(double a);
//! Install the wall between two reactors or reservoirs
//! @deprecated To be removed after Cantera 3.2. Reactors should be provided to
//! @deprecated To be removed after %Cantera 3.2. Reactors should be provided to
//! constructor instead.
bool install(ReactorBase& leftReactor, ReactorBase& rightReactor);

View File

@ -52,10 +52,12 @@ shared_ptr<ConnectorNode> newConnectorNode(
ConnectorFactory::factory()->create(model, r0, r1, name));
}
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
shared_ptr<FlowDevice> newFlowDevice(
const string& model,
shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
{
auto dev = std::dynamic_pointer_cast<FlowDevice>(
newConnectorNode(model, nullptr, nullptr, name));
newConnectorNode(model, r0, r1, name));
if (!dev) {
throw CanteraError("newFlowDevice",
"Detected incompatible ConnectorNode type '{}'", model);
@ -63,10 +65,19 @@ shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
return dev;
}
shared_ptr<WallBase> newWall(const string& model, const string& name)
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
{
warn_deprecated("newFlowDevice",
"After Cantera 3.1, Reactors must be provided as parameters.");
return newFlowDevice(model, nullptr, nullptr, name);
}
shared_ptr<WallBase> newWall(
const string& model,
shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1, const string& name)
{
auto wall = std::dynamic_pointer_cast<WallBase>(
newConnectorNode(model, nullptr, nullptr, name));
newConnectorNode(model, r0, r1, name));
if (!wall) {
throw CanteraError("newWall",
"Detected incompatible ConnectorNode type '{}'", model);
@ -74,4 +85,11 @@ shared_ptr<WallBase> newWall(const string& model, const string& name)
return wall;
}
shared_ptr<WallBase> newWall(const string& model, const string& name)
{
warn_deprecated("newWall",
"After Cantera 3.1, Reactors must be provided as parameters.");
return newWall(model, nullptr, nullptr, name);
}
}