-
-
Notifications
You must be signed in to change notification settings - Fork 360
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
ischoegl
wants to merge
18
commits into
Cantera:main
Choose a base branch
from
ischoegl:zerod-connector-nodes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Zerod connector nodes #1848
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f9578bb
[zeroD] Implement Connector base class
ischoegl 9a9f378
[zeroD] Implement ConnectorFactory
ischoegl 3eba650
[zeroD] Move newFlowDevice to ConnectorFactory
ischoegl 7659c1e
[zeroD] Move newWall to ConnectorFactory
ischoegl f545527
[clib] Switch to ConnectorCabinet
ischoegl ad81e20
[zeroD] Add deprecations
ischoegl 7a6cc9a
[zeroD] Install Reactors when instantiating connectors
ischoegl b057dab
[Python] Derive Wall/FlowDevice from ConnectorNode
ischoegl d0e9622
[zeroD] Add alternative Connector instantiations
ischoegl 27f4ff2
[unittests] Improve test-zeroD coverage
ischoegl bd5b2e2
[clib] Add new Connector functions
ischoegl 0ce3a7c
[MATLAB] Use CLib connector functions
ischoegl 7809c73
[clib] Remove obsolete functions
ischoegl 7bd0303
[sourcegen] Add Connector crosswalk
ischoegl 1d749a2
[zeroD] Remove ReactorSurface from wallGroup
ischoegl 6d36d94
[zeroD] Deprecate Wall/FlowDevice factories
ischoegl 1d86759
[Python] Clarifiy reactor content nomenclature
ischoegl c791052
[samples] Add plt.show() to Python samples
ischoegl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//! @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>` | ||
//! @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)"); | ||
|
||
//! @} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a (slight?) preference for
pair
as it is a directed graph, where aConnectorNode
connects to exactly two reactors. As it is an implementation detail, we can always adjust at a later point.