[zeroD] Move newWall to ConnectorFactory

fix doxygen for flowdeviceGroup
This commit is contained in:
Ingmar Schoegl 2024-08-22 09:44:20 -05:00
parent 3eba650550
commit 7659c1e9b4
7 changed files with 26 additions and 99 deletions

View File

@ -13,6 +13,7 @@ namespace Cantera
{
class FlowDevice;
class WallBase;
//! Factory class to create ConnectorNode objects.
//!
@ -69,6 +70,10 @@ shared_ptr<ConnectorNode> newConnectorNode(const string& model,
//! @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)");
//! @}
}

View File

@ -19,7 +19,7 @@ class ReactorBase;
/**
* Base class for 'flow devices' (valves, pressure regulators, etc.)
* connecting reactors.
* @ingroup flowDeviceGroup
* @ingroup connectorGroup
*/
class FlowDevice : public ConnectorNode
{

View File

@ -1,54 +0,0 @@
//! @file WallFactory.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 WALL_FACTORY_H
#define WALL_FACTORY_H
#include "cantera/base/FactoryBase.h"
#include "cantera/zeroD/Wall.h"
namespace Cantera
{
//! Factory class to create WallBase objects
//!
//! This class is mainly used via the newWall() function, for example:
//!
//! ```cpp
//! shared_ptr<WallBase> piston = newWall("Wall");
//! ```
class WallFactory : public Factory<WallBase, const string&>
{
public:
static WallFactory* factory();
void deleteFactory() override;
private:
static WallFactory* s_factory;
static std::mutex wall_mutex;
WallFactory();
};
//! @defgroup wallGroup Walls
//! Zero-dimensional objects adjacent to reactors.
//! Wall objects should be instantiated via the newWall function, for
//! example:
//!
//! ```cpp
//! 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, const string& name="(none)");
//! @}
}
#endif

View File

@ -15,7 +15,7 @@ namespace Cantera
/**
* A class for mass flow controllers. The mass flow rate is constant or
* specified as a function of time.
* @ingroup flowDeviceGroup
* @ingroup connectorGroup
*/
class MassFlowController : public FlowDevice
{
@ -60,7 +60,7 @@ public:
* A class for flow controllers where the flow rate is equal to the flow rate
* of a primary mass flow controller plus a correction proportional to the
* pressure difference between the inlet and outlet.
* @ingroup flowDeviceGroup
* @ingroup connectorGroup
*/
class PressureController : public FlowDevice
{
@ -118,7 +118,7 @@ protected:
* The default behavior is a linearly proportional to the pressure difference.
* Note that real valves do not have this behavior, so this class does not
* model real, physical valves.
* @ingroup flowDeviceGroup
* @ingroup connectorGroup
*/
class Valve : public FlowDevice
{

View File

@ -34,7 +34,6 @@
// factories
#include "cantera/zeroD/ReactorFactory.h"
#include "cantera/zeroD/ConnectorFactory.h"
#include "cantera/zeroD/WallFactory.h"
// func1
#include "cantera/numerics/Func1.h"

View File

@ -54,8 +54,24 @@ shared_ptr<ConnectorNode> newConnectorNode(
shared_ptr<FlowDevice> newFlowDevice(const string& model, const string& name)
{
return std::dynamic_pointer_cast<FlowDevice>(
auto dev = std::dynamic_pointer_cast<FlowDevice>(
newConnectorNode(model, nullptr, nullptr, name));
if (!dev) {
throw CanteraError("newFlowDevice",
"Detected incompatible ConnectorNode type '{}'", model);
}
return dev;
}
shared_ptr<WallBase> newWall(const string& model, const string& name)
{
auto wall = std::dynamic_pointer_cast<WallBase>(
newConnectorNode(model, nullptr, nullptr, name));
if (!wall) {
throw CanteraError("newWall",
"Detected incompatible ConnectorNode type '{}'", model);
}
return wall;
}
}

View File

@ -1,39 +0,0 @@
//! @file WallFactory.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/WallFactory.h"
#include "cantera/zeroD/Wall.h"
namespace Cantera
{
WallFactory* WallFactory::s_factory = 0;
std::mutex WallFactory::wall_mutex;
WallFactory::WallFactory()
{
reg("Wall", [](const string& name) { return new Wall(name); });
}
WallFactory* WallFactory::factory() {
std::unique_lock<std::mutex> lock(wall_mutex);
if (!s_factory) {
s_factory = new WallFactory;
}
return s_factory;
}
void WallFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(wall_mutex);
delete s_factory;
s_factory = 0;
}
shared_ptr<WallBase> newWall(const string& model, const string& name)
{
return shared_ptr<WallBase>(WallFactory::factory()->create(model, name));
}
}