mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[zeroD] Implement Connector base class
This commit is contained in:
parent
e6f3e9d448
commit
f9578bbedd
74
include/cantera/zeroD/ConnectorNode.h
Normal file
74
include/cantera/zeroD/ConnectorNode.h
Normal file
@ -0,0 +1,74 @@
|
||||
//! @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 (e.g., valves, pressure regulators)
|
||||
* represent nodes in a directed bipartite graph - a graph whose vertices can be
|
||||
* divided into two disjoint sets such that no two vertices within the same set are
|
||||
* adjacent - with reactors forming the second set of nodes.
|
||||
*
|
||||
* @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";
|
||||
}
|
||||
|
||||
//! 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;
|
||||
|
||||
string m_name; //!< ConnectorNode name.
|
||||
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -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
|
||||
{
|
||||
@ -20,34 +21,15 @@ class ReactorBase;
|
||||
* connecting reactors.
|
||||
* @ingroup flowDeviceGroup
|
||||
*/
|
||||
class FlowDevice
|
||||
class FlowDevice : public ConnectorNode
|
||||
{
|
||||
public:
|
||||
FlowDevice(const string& name="(none)") : m_name(name) {}
|
||||
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 {
|
||||
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) {
|
||||
@ -133,9 +115,6 @@ public:
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include "cantera/base/ctexceptions.h"
|
||||
#include "cantera/zeroD/ReactorBase.h"
|
||||
#include "ConnectorNode.h"
|
||||
|
||||
namespace Cantera
|
||||
{
|
||||
@ -16,36 +17,17 @@ class Func1;
|
||||
|
||||
/**
|
||||
* Base class for 'walls' (walls, pistons, etc.) connecting reactors.
|
||||
* @ingroup wallGroup
|
||||
* @ingroup connectorGroup
|
||||
*/
|
||||
class WallBase
|
||||
class WallBase : public ConnectorNode
|
||||
{
|
||||
public:
|
||||
WallBase(const string& name="(none)") : m_name(name) {}
|
||||
using ConnectorNode::ConnectorNode; // inherit constructors
|
||||
|
||||
virtual ~WallBase() {}
|
||||
WallBase(const WallBase&) = delete;
|
||||
WallBase& operator=(const WallBase&) = delete;
|
||||
|
||||
//! String indicating the wall model implemented. Usually
|
||||
//! corresponds to the name of the derived class.
|
||||
virtual string type() const {
|
||||
string type() const override {
|
||||
return "WallBase";
|
||||
}
|
||||
|
||||
//! Retrieve wall name.
|
||||
string name() const {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
//! Set wall name.
|
||||
void setName(const string& name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
//! Set the default name of a wall. Returns `false` if it was previously set.
|
||||
bool setDefaultName(map<string, int>& counts);
|
||||
|
||||
//! Rate of volume change (m^3/s) for the adjacent reactors at current reactor
|
||||
//! network time.
|
||||
/*!
|
||||
@ -105,9 +87,6 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
string m_name; //!< Wall name.
|
||||
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.
|
||||
|
||||
ReactorBase* m_left = nullptr;
|
||||
ReactorBase* m_right = nullptr;
|
||||
|
||||
@ -121,7 +100,7 @@ protected:
|
||||
/*!
|
||||
* Walls can move (changing the volume of the adjacent reactors) and allow heat
|
||||
* transfer between reactors.
|
||||
* @ingroup wallGroup
|
||||
* @ingroup connectorGroup
|
||||
*/
|
||||
class Wall : public WallBase
|
||||
{
|
||||
|
25
src/zeroD/ConnectorNode.cpp
Normal file
25
src/zeroD/ConnectorNode.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
//! @file ConnectorNode.cpp
|
||||
|
||||
// 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.
|
||||
|
||||
#include "cantera/zeroD/ConnectorNode.h"
|
||||
#include "cantera/zeroD/ReactorBase.h"
|
||||
|
||||
namespace Cantera
|
||||
{
|
||||
|
||||
void ConnectorNode::setDefaultName(map<string, int>& counts)
|
||||
{
|
||||
if (m_defaultNameSet) {
|
||||
return;
|
||||
}
|
||||
m_defaultNameSet = true;
|
||||
string typ(type());
|
||||
if (m_name == "(none)" || m_name == "") {
|
||||
m_name = fmt::format("{}_{}", type(), counts[type()]);
|
||||
}
|
||||
counts[type()]++;
|
||||
}
|
||||
|
||||
}
|
@ -11,20 +11,6 @@
|
||||
namespace Cantera
|
||||
{
|
||||
|
||||
bool FlowDevice::setDefaultName(map<string, int>& counts)
|
||||
{
|
||||
if (m_defaultNameSet) {
|
||||
return false;
|
||||
}
|
||||
m_defaultNameSet = true;
|
||||
string typ(type());
|
||||
if (m_name == "(none)" || m_name == "") {
|
||||
m_name = fmt::format("{}_{}", type(), counts[type()]);
|
||||
}
|
||||
counts[type()]++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
|
||||
{
|
||||
if (m_in || m_out) {
|
||||
|
@ -10,19 +10,6 @@
|
||||
namespace Cantera
|
||||
{
|
||||
|
||||
bool WallBase::setDefaultName(map<string, int>& counts)
|
||||
{
|
||||
if (m_defaultNameSet) {
|
||||
return false;
|
||||
}
|
||||
m_defaultNameSet = true;
|
||||
if (m_name == "(none)" || m_name == "") {
|
||||
m_name = fmt::format("{}_{}", type(), counts[type()]);
|
||||
}
|
||||
counts[type()]++;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WallBase::install(ReactorBase& rleft, ReactorBase& rright)
|
||||
{
|
||||
// check if wall is already installed
|
||||
|
Loading…
Reference in New Issue
Block a user