Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zerod connector nodes #1848

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions include/cantera/clib/ctreactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ extern "C" {

CANTERA_CAPI int reactor_new(const char* type, int n, const char* name);
CANTERA_CAPI int reactor_del(int i);
CANTERA_CAPI int reactor_type(int i, int len, char* nbuf);
CANTERA_CAPI int reactor_name(int i, int len, char* nbuf);
CANTERA_CAPI int reactor_setName(int i, const char* name);
CANTERA_CAPI int reactor_setInitialVolume(int i, double v);
CANTERA_CAPI int reactor_setChemistry(int i, int cflag);
CANTERA_CAPI int reactor_setEnergy(int i, int eflag);
CANTERA_CAPI int reactor_setSolution(int i, int n);
CANTERA_CAPI double reactor_mass(int i);
CANTERA_CAPI double reactor_volume(int i);
CANTERA_CAPI double reactor_density(int i);
Expand All @@ -51,11 +51,12 @@ extern "C" {
CANTERA_CAPI double reactornet_atol(int i);
CANTERA_CAPI double reactornet_sensitivity(int i, const char* v, int p, int r);

CANTERA_CAPI int flowdev_new(const char* type, const char* name);
CANTERA_CAPI int flowdev_del(int i);
CANTERA_CAPI int flowdev_name(int i, int len, char* nbuf);
CANTERA_CAPI int flowdev_setName(int i, const char* name);
CANTERA_CAPI int flowdev_install(int i, int n, int m);
CANTERA_CAPI int connector_new(const char* type, int r0, int r1, const char* name);
CANTERA_CAPI int connector_del(int i);
CANTERA_CAPI int connector_type(int i, int len, char* nbuf);
CANTERA_CAPI int connector_name(int i, int len, char* nbuf);
CANTERA_CAPI int connector_setName(int i, const char* name);

CANTERA_CAPI int flowdev_setPrimary(int i, int n);
CANTERA_CAPI double flowdev_massFlowRate(int i);
CANTERA_CAPI int flowdev_setMassFlowCoeff(int i, double v);
Expand All @@ -64,11 +65,6 @@ extern "C" {
CANTERA_CAPI int flowdev_setPressureFunction(int i, int n);
CANTERA_CAPI int flowdev_setTimeFunction(int i, int n);

CANTERA_CAPI int wall_new(const char* type, const char* name);
CANTERA_CAPI int wall_del(int i);
CANTERA_CAPI int wall_name(int i, int len, char* nbuf);
CANTERA_CAPI int wall_setName(int i, const char* name);
CANTERA_CAPI int wall_install(int i, int n, int m);
CANTERA_CAPI double wall_expansionRate(int i);
CANTERA_CAPI double wall_heatRate(int i);
CANTERA_CAPI double wall_area(int i);
Expand All @@ -79,7 +75,6 @@ extern "C" {
CANTERA_CAPI int wall_setExpansionRateCoeff(int i, double k);
CANTERA_CAPI int wall_setVelocity(int i, int n);
CANTERA_CAPI int wall_setEmissivity(int i, double epsilon);
CANTERA_CAPI int wall_ready(int i);

CANTERA_CAPI int reactorsurface_new(const char* name);
CANTERA_CAPI int reactorsurface_del(int i);
Expand Down
80 changes: 80 additions & 0 deletions include/cantera/zeroD/ConnectorFactory.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
//! @file ConnectorFactory.h

// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.

#ifndef CONNECTOR_FACTORY_H
#define CONNECTOR_FACTORY_H

#include "cantera/base/FactoryBase.h"
#include "cantera/zeroD/ConnectorNode.h"

namespace Cantera
{

class FlowDevice;
class WallBase;

//! Factory class to create ConnectorNode objects.
//!
//! This class is mainly used via the newConnectorNode() function, for example:
//!
//! ```cpp
//! shared_ptr<ConnectorNode> valve = newConnectorNode("Valve", r0, r1, "my_valve");
//! ```
//!
//! where `r0` and `r1` are reactor objects.
class ConnectorFactory :
public Factory<ConnectorNode,
shared_ptr<ReactorBase>, shared_ptr<ReactorBase>, const string&>
{
public:
static ConnectorFactory* factory();

void deleteFactory() override;

private:
static ConnectorFactory* s_factory;
static std::mutex connector_mutex;
ConnectorFactory();
};

//! @defgroup connectorGroup Connectors
//! %ConnectorNode objects connect zero-dimensional reactors.
//! ConnectorNode objects should be instantiated via the newConnectorNode() function,
//! for example:
//!
//! ```cpp
//! shared_ptr<ConnectorNode> valve = newConnectorNode("Valve", r0, r1, "my_valve");
//! ```
//!
//! where `r0` and `r1` are reactor objects.
//!
//! @since New in %Cantera 3.2.
//!
//! @ingroup zerodGroup
//! @{

//! Create a %ConnectorNode object of the specified type
//! @param model String specifying reactor type.
//! @param r0 First reactor.
//! @param r1 Second reactor.
//! @param name Name of the connector.
//! @since New in %Cantera 3.2.
shared_ptr<ConnectorNode> newConnectorNode(const string& model,
shared_ptr<ReactorBase> r0,
shared_ptr<ReactorBase> r1,
const string& name="(none)");

//! Create a FlowDevice object of the specified type
//! @since Starting in %Cantera 3.1, this method returns a `shared_ptr<FlowDevice>`
shared_ptr<FlowDevice> newFlowDevice(const string& model, 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>`
shared_ptr<WallBase> newWall(const string& model, const string& name="(none)");

//! @}
}

#endif
72 changes: 72 additions & 0 deletions include/cantera/zeroD/ConnectorNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//! @file ConnectorNode.h

// This file is part of Cantera. See License.txt in the top-level directory or
// at https://cantera.org/license.txt for license and copyright information.

#ifndef CT_CONNECTOR_H
#define CT_CONNECTOR_H

#include "cantera/base/ct_defs.h"
#include "cantera/base/global.h"

namespace Cantera
{
class ReactorBase;

/**
* Base class for walls and flow devices connecting reactors.
* In a reactor network, walls and flow devices (valves, pressure regulators, etc.)
* form edges of a directed graph that connect reactors that form nodes.
Comment on lines +18 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to get into the nomenclature question -- are connectors nodes (vertices) as the name ConnectorNode implies, or edges, as described here?

*
* @since New in %Cantera 3.1.
*
Comment on lines +21 to +22
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @since New in %Cantera 3.1.
*
* @since New in %Cantera 3.2.
*

* @ingroup connectorGroup
*/
class ConnectorNode
{
public:
//! Transitional constructor.
//! @todo Implement deprecation warning.
ConnectorNode(const string& name="(none)") : m_name(name) {}

//! Instantiate a ConnectorNode object with associated ReactorBase objects.
//! @param r0 First reactor.
//! @param r1 Second reactor.
//! @param name Name of the connector.
ConnectorNode(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
const string& name="(none)") : m_nodes({r0, r1}), m_name(name) {}

virtual ~ConnectorNode() = default;
ConnectorNode(const ConnectorNode&) = delete;
ConnectorNode& operator=(const ConnectorNode&) = delete;

//! String indicating the connector implemented. Usually
//! corresponds to the name of the derived class.
virtual string type() const {
return "ConnectorNode";

Check warning on line 46 in include/cantera/zeroD/ConnectorNode.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/ConnectorNode.h#L45-L46

Added lines #L45 - L46 were not covered by tests
}

//! Retrieve connector name.
string name() const {
return m_name;
}

//! Set connector name.
void setName(const string& name) {
m_name = name;
}

//! Set the default name of a connector. Returns `false` if it was previously set.
void setDefaultName(map<string, int>& counts);

protected:
//! Pair of reactors forming end points of the connector.
pair<shared_ptr<ReactorBase>, shared_ptr<ReactorBase>> m_nodes;
Comment on lines +63 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the pair adds much here -- two separate member variables ends up being easier to use.


string m_name; //!< ConnectorNode name.
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
};

}

#endif
35 changes: 9 additions & 26 deletions include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "cantera/base/ct_defs.h"
#include "cantera/base/global.h"
#include "cantera/base/ctexceptions.h"
#include "ConnectorNode.h"

namespace Cantera
{
Expand All @@ -18,36 +19,19 @@
/**
* Base class for 'flow devices' (valves, pressure regulators, etc.)
* connecting reactors.
* @ingroup flowDeviceGroup
* @ingroup connectorGroup
*/
class FlowDevice
class FlowDevice : public ConnectorNode
{
public:
FlowDevice(const string& name="(none)") : m_name(name) {}
FlowDevice(shared_ptr<ReactorBase> r0, shared_ptr<ReactorBase> r1,
const string& name="(none)");
using ConnectorNode::ConnectorNode; // inherit constructors

virtual ~FlowDevice() = default;
FlowDevice(const FlowDevice&) = delete;
FlowDevice& operator=(const FlowDevice&) = delete;

//! String indicating the flow device implemented. Usually
//! corresponds to the name of the derived class.
virtual string type() const {
string type() const override {

Check warning on line 31 in include/cantera/zeroD/FlowDevice.h

View check run for this annotation

Codecov / codecov/patch

include/cantera/zeroD/FlowDevice.h#L31

Added line #L31 was not covered by tests
return "FlowDevice";
}

//! Retrieve flow device name.
string name() const {
return m_name;
}

//! Set flow device name.
void setName(const string& name) {
m_name = name;
}

//! Set the default name of a flow device. Returns `false` if it was previously set.
bool setDefaultName(map<string, int>& counts);

//! Mass flow rate (kg/s).
double massFlowRate() {
if (m_mdot == Undef) {
Expand All @@ -73,6 +57,8 @@
/*!
* @param in Upstream reactor.
* @param out Downstream reactor.
* @deprecated To be removed after Cantera 3.2. Reactors should be provided to
* constructor instead.
*/
bool install(ReactorBase& in, ReactorBase& out);

Expand Down Expand Up @@ -133,9 +119,6 @@
}

protected:
string m_name; //!< Flow device name.
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.

double m_mdot = Undef;

//! Function set by setPressureFunction; used by updateMassFlowRate
Expand Down
45 changes: 3 additions & 42 deletions include/cantera/zeroD/FlowDeviceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,9 @@
#ifndef FLOWDEVICE_FACTORY_H
#define FLOWDEVICE_FACTORY_H

#include "cantera/base/FactoryBase.h"
#include "cantera/zeroD/FlowDevice.h"
#pragma message("warning: FlowDeviceFactory.h is deprecated and will be removed " \
"after Cantera 3.2. Use ConnectorFactory.h instead.")

namespace Cantera
{

//! Factory class to create FlowDevice objects.
//!
//! This class is mainly used via the newFlowDevice() function, for example:
//!
//! ```cpp
//! shared_ptr<FlowDevice> mfc = newFlowDevice("MassFlowController");
//! ```
class FlowDeviceFactory : public Factory<FlowDevice, const string&>
{
public:
static FlowDeviceFactory* factory();

void deleteFactory() override;

private:
static FlowDeviceFactory* s_factory;
static std::mutex flowDevice_mutex;
FlowDeviceFactory();
};

//! @defgroup flowDeviceGroup Flow Devices
//! Flow device objects connect zero-dimensional reactors.
//! FlowDevice objects should be instantiated via the newFlowDevice function, for
//! example:
//!
//! ```cpp
//! shared_ptr<FlowDevice> mfc = newFlowDevice("MassFlowController", "my_mfc");
//! ```
//! @ingroup zerodGroup
//! @{

//! Create a FlowDevice object of the specified type
//! @since Starting in %Cantera 3.1, this method returns a `shared_ptr<FlowDevice>`
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name="(none)");

//! @}
}
#include "ConnectorFactory.h"

#endif
2 changes: 2 additions & 0 deletions include/cantera/zeroD/ReactorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class ReactorBase
//! Set the Solution specifying the ReactorBase content.
//! @param sol Solution object to be set.
//! @since New in %Cantera 3.1.
//! @deprecated To be removed after %Cantera 3.2. Superseded by instantiation of
//! ReactorBase with Solution object.
void setSolution(shared_ptr<Solution> sol);

//! @name Methods to set up a simulation
Expand Down
1 change: 0 additions & 1 deletion include/cantera/zeroD/ReactorSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class SurfPhase;

//! A surface where reactions can occur that is in contact with the bulk fluid of a
//! Reactor.
//! @ingroup wallGroup
class ReactorSurface
{
public:
Expand Down
Loading
Loading