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

Reproducible names for zeroD objects #1765

Merged
merged 9 commits into from
Aug 24, 2024
Merged
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
14 changes: 11 additions & 3 deletions include/cantera/clib/ctreactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ 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_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);
Expand Down Expand Up @@ -49,8 +51,10 @@ 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);
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 flowdev_setPrimary(int i, int n);
CANTERA_CAPI double flowdev_massFlowRate(int i);
Expand All @@ -60,8 +64,10 @@ 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);
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);
Expand All @@ -75,8 +81,10 @@ extern "C" {
CANTERA_CAPI int wall_setEmissivity(int i, double epsilon);
CANTERA_CAPI int wall_ready(int i);

CANTERA_CAPI int reactorsurface_new(int type);
CANTERA_CAPI int reactorsurface_new(const char* name);
CANTERA_CAPI int reactorsurface_del(int i);
CANTERA_CAPI int reactorsurface_name(int i, int len, char* nbuf);
CANTERA_CAPI int reactorsurface_setName(int i, const char* name);
CANTERA_CAPI int reactorsurface_install(int i, int n);
CANTERA_CAPI int reactorsurface_setkinetics(int i, int n);
CANTERA_CAPI double reactorsurface_area(int i);
Expand Down
23 changes: 22 additions & 1 deletion include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ReactorBase;
class FlowDevice
{
public:
FlowDevice() = default;
FlowDevice(const string& name="(none)") : m_name(name) {}

virtual ~FlowDevice() = default;
FlowDevice(const FlowDevice&) = delete;
Expand All @@ -35,6 +35,19 @@ class FlowDevice
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 Down Expand Up @@ -77,6 +90,11 @@ class FlowDevice
return *m_out;
}

//! Return a mutable reference to the downstream reactor.
ReactorBase& out() {
return *m_out;
}

//! Return current value of the pressure function.
/*!
* The mass flow rate [kg/s] is calculated given the pressure drop [Pa] and a
Expand Down Expand Up @@ -115,6 +133,9 @@ class FlowDevice
}

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
10 changes: 5 additions & 5 deletions include/cantera/zeroD/FlowDeviceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Cantera
//! ```cpp
//! shared_ptr<FlowDevice> mfc = newFlowDevice("MassFlowController");
//! ```
class FlowDeviceFactory : public Factory<FlowDevice>
class FlowDeviceFactory : public Factory<FlowDevice, const string&>
{
public:
static FlowDeviceFactory* factory();
Expand All @@ -34,22 +34,22 @@ class FlowDeviceFactory : public Factory<FlowDevice>

//! @defgroup flowDeviceGroup Flow Devices
//! Flow device objects connect zero-dimensional reactors.
//! FlowDevice objects should be instantiated via the newFlowDevice() function, for
//! FlowDevice objects should be instantiated via the newFlowDevice function, for
//! example:
//!
//! ```cpp
//! shared_ptr<FlowDevice> mfc = newFlowDevice("MassFlowController");
//! 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);
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name="(none)");

//! Create a FlowDevice object of the specified type
//! @since New in %Cantera 3.0.
//! @deprecated Transitional method. Use newFlowDevice() instead.
//! @deprecated Replaced by newFlowDevice. To be removed after %Cantera 3.1.
shared_ptr<FlowDevice> newFlowDevice3(const string& model);

//! @}
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/zeroD/Reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class AnyMap;
class Reactor : public ReactorBase
{
public:
Reactor(shared_ptr<Solution> sol, const string& name = "(none)");
Reactor(shared_ptr<Solution> sol, const string& name="(none)");
using ReactorBase::ReactorBase; // inherit constructors

string type() const override {
Expand Down
10 changes: 7 additions & 3 deletions include/cantera/zeroD/ReactorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ struct SensitivityParameter
class ReactorBase
{
public:
explicit ReactorBase(const string& name = "(none)");
explicit ReactorBase(const string& name="(none)");
//! Instantiate a ReactorBase object with Solution contents.
//! @param sol Solution object to be set.
//! @param name Name of the reactor.
//! @since New in %Cantera 3.1.
ReactorBase(shared_ptr<Solution> sol, const string& name = "(none)");
ReactorBase(shared_ptr<Solution> sol, const string& name="(none)");
virtual ~ReactorBase();
ReactorBase(const ReactorBase&) = delete;
ReactorBase& operator=(const ReactorBase&) = delete;
Expand All @@ -76,6 +76,9 @@ class ReactorBase
m_name = name;
}

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

//! Set the Solution specifying the ReactorBase content.
//! @param sol Solution object to be set.
//! @since New in %Cantera 3.1.
Expand Down Expand Up @@ -307,7 +310,8 @@ class ReactorBase
//! Vector of length nWalls(), indicating whether this reactor is on the left (0)
//! or right (1) of each wall.
vector<int> m_lr;
string m_name;
string m_name; //!< Reactor name.
bool m_defaultNameSet = false; //!< `true` if default name has been previously set.

//! The ReactorNet that this reactor is part of
ReactorNet* m_net = nullptr;
Expand Down
8 changes: 7 additions & 1 deletion include/cantera/zeroD/ReactorDelegator.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ template <class R>
class ReactorDelegator : public Delegator, public R, public ReactorAccessor
{
public:
ReactorDelegator() {
ReactorDelegator(shared_ptr<Solution> contents, const string& name="(none)")
: R(contents, name)
{
install("initialize", m_initialize, [this](double t0) { R::initialize(t0); });
install("syncState", m_syncState, [this]() { R::syncState(); });
install("getState", m_getState,
Expand Down Expand Up @@ -96,6 +98,10 @@ class ReactorDelegator : public Delegator, public R, public ReactorAccessor

// Overrides of Reactor methods

string type() const override {
return fmt::format("Extensible{}", R::type());
}

void initialize(double t0) override {
m_initialize(t0);
}
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/zeroD/ReactorFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Cantera
//! ```cpp
//! shared_ptr<ReactorBase> r1 = newReactor("IdealGasReactor");
//! ```
class ReactorFactory : public Factory<ReactorBase>
class ReactorFactory : public Factory<ReactorBase, shared_ptr<Solution>, const string&>
{
public:
static ReactorFactory* factory();
Expand Down
4 changes: 4 additions & 0 deletions include/cantera/zeroD/ReactorNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ class ReactorNet : public FuncEval

void updatePreconditioner(double gamma) override;

//! Create reproducible names for reactors and walls/connectors.
void updateNames(Reactor& r);

//! Estimate a future state based on current derivatives.
//! The function is intended for internal use by ReactorNet::advance
//! and deliberately not exposed in external interfaces.
Expand All @@ -316,6 +319,7 @@ class ReactorNet : public FuncEval
virtual int lastOrder() const;

vector<Reactor*> m_reactors;
map<string, int> m_counts; //!< Map used for default name generation
unique_ptr<Integrator> m_integ;

//! The independent variable in the system. May be either time or space depending
Expand Down
23 changes: 22 additions & 1 deletion include/cantera/zeroD/ReactorSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,29 @@ class SurfPhase;
class ReactorSurface
{
public:
ReactorSurface() = default;
ReactorSurface(const string& name="(none)") : m_name(name) {}
virtual ~ReactorSurface() = default;
ReactorSurface(const ReactorSurface&) = delete;
ReactorSurface& operator=(const ReactorSurface&) = delete;

//! String indicating the wall model implemented.
virtual string type() const {
return "ReactorSurface";
}

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

//! Set reactor surface 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);

//! Returns the surface area [m^2]
double area() const;

Expand Down Expand Up @@ -87,6 +105,9 @@ class ReactorSurface
void resetSensitivityParameters();

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

double m_area = 1.0;

SurfPhase* m_thermo = nullptr;
Expand Down
22 changes: 19 additions & 3 deletions include/cantera/zeroD/Wall.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Func1;
class WallBase
{
public:
WallBase() = default;
WallBase(const string& name="(none)") : m_name(name) {}

virtual ~WallBase() {}
WallBase(const WallBase&) = delete;
Expand All @@ -33,6 +33,19 @@ class WallBase
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.
/*!
Expand Down Expand Up @@ -79,7 +92,7 @@ class WallBase
}

//! Return a reference to the Reactor or Reservoir to the right of the wall.
const ReactorBase& right() {
ReactorBase& right() {
return *m_right;
}

Expand All @@ -92,6 +105,9 @@ class WallBase
}

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;

Expand All @@ -110,7 +126,7 @@ class WallBase
class Wall : public WallBase
{
public:
Wall() = default;
using WallBase::WallBase; // inherit constructors

//! String indicating the wall model implemented. Usually
//! corresponds to the name of the derived class.
Expand Down
10 changes: 5 additions & 5 deletions include/cantera/zeroD/WallFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Cantera
//! ```cpp
//! shared_ptr<WallBase> piston = newWall("Wall");
//! ```
class WallFactory : public Factory<WallBase>
class WallFactory : public Factory<WallBase, const string&>
{
public:
static WallFactory* factory();
Expand All @@ -34,22 +34,22 @@ class WallFactory : public Factory<WallBase>

//! @defgroup wallGroup Walls
//! Zero-dimensional objects adjacent to reactors.
//! Wall objects should be instantiated via the newWall() function, for
//! Wall objects should be instantiated via the newWall function, for
//! example:
//!
//! ```cpp
//! shared_ptr<WallBase> piston = newWall("Wall");
//! shared_ptr<WallBase> piston = newWall("Wall", "my_piston");
//! ```
//! @ingroup zerodGroup
//! @{

//! 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);
shared_ptr<WallBase> newWall(const string& model, const string& name="(none)");

//! Create a WallBase object of the specified type
//! @since New in %Cantera 3.0.
//! @deprecated Transitional method. Use newWall() instead.
//! @deprecated Replaced by newWall. To be removed after %Cantera 3.1.
shared_ptr<WallBase> newWall3(const string& model);

//! @}
Expand Down
6 changes: 3 additions & 3 deletions include/cantera/zeroD/flowControllers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Cantera
class MassFlowController : public FlowDevice
{
public:
MassFlowController() = default;
using FlowDevice::FlowDevice; // inherit constructors

string type() const override {
return "MassFlowController";
Expand Down Expand Up @@ -65,7 +65,7 @@ class MassFlowController : public FlowDevice
class PressureController : public FlowDevice
{
public:
PressureController() = default;
using FlowDevice::FlowDevice; // inherit constructors

string type() const override {
return "PressureController";
Expand Down Expand Up @@ -123,7 +123,7 @@ class PressureController : public FlowDevice
class Valve : public FlowDevice
{
public:
Valve() = default;
using FlowDevice::FlowDevice; // inherit constructors

string type() const override {
return "Valve";
Expand Down
Loading
Loading