Move factory function definitions out of .h files

This commit is contained in:
Ray Speth 2023-01-24 11:10:41 -05:00 committed by Ingmar Schoegl
parent c0ae563def
commit 622b37efa4
18 changed files with 203 additions and 147 deletions

View File

@ -21,19 +21,9 @@ namespace Cantera
class KineticsFactory : public Factory<Kinetics>
{
public:
static KineticsFactory* factory() {
std::unique_lock<std::mutex> lock(kinetics_mutex);
if (!s_factory) {
s_factory = new KineticsFactory;
}
return s_factory;
}
static KineticsFactory* factory();
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(kinetics_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
/**
* Return a new, empty kinetics manager.
@ -49,19 +39,12 @@ private:
/**
* Create a new kinetics manager.
*/
inline Kinetics* newKineticsMgr(const std::string& model)
{
return KineticsFactory::factory()->newKinetics(model);
}
Kinetics* newKineticsMgr(const string& model);
/**
* Create a new Kinetics instance.
*/
inline shared_ptr<Kinetics> newKinetics(const std::string& model)
{
shared_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(model));
return kin;
}
shared_ptr<Kinetics> newKinetics(const string& model);
/*!
* Create a new kinetics manager, initialize it, and add reactions

View File

@ -38,19 +38,9 @@ public:
* created. Since there is no need to instantiate more than one factory,
* on all subsequent calls, a pointer to the existing factory is returned.
*/
static ReactionRateFactory* factory() {
std::unique_lock<std::mutex> lock(rate_mutex);
if (!s_factory) {
s_factory = new ReactionRateFactory;
}
return s_factory;
}
static ReactionRateFactory* factory();
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(rate_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
private:
//! Pointer to the single instance of the factory

View File

@ -17,20 +17,10 @@ class PreconditionerBase;
class PreconditionerFactory : public Factory<PreconditionerBase>
{
public:
static PreconditionerFactory* factory() {
std::unique_lock<std::mutex> lock(precon_mutex);
if (!s_factory) {
s_factory = new PreconditionerFactory;
}
return s_factory;
};
static PreconditionerFactory* factory();
//! Delete preconditioner factory
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(precon_mutex);
delete s_factory;
s_factory = 0;
};
virtual void deleteFactory();
private:
static PreconditionerFactory* s_factory;
@ -39,10 +29,7 @@ private:
};
//! Create a Preconditioner object of the specified type
inline std::shared_ptr<PreconditionerBase> newPreconditioner(const std::string& precon)
{
return std::shared_ptr<PreconditionerBase>(PreconditionerFactory::factory()->create(precon));
};
shared_ptr<PreconditionerBase> newPreconditioner(const string& precon);
}

View File

@ -17,20 +17,10 @@ class PDSSFactory : public Factory<PDSS>
{
public:
//! Static function that creates a static instance of the factory.
static PDSSFactory* factory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
if (!s_factory) {
s_factory = new PDSSFactory;
}
return s_factory;
}
static PDSSFactory* factory();
//! delete the static instance of this factory
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
//! Create a new thermodynamic property manager.
/*!

View File

@ -34,20 +34,10 @@ class ThermoFactory : public Factory<ThermoPhase>
{
public:
//! Static function that creates a static instance of the factory.
static ThermoFactory* factory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
if (!s_factory) {
s_factory = new ThermoFactory;
}
return s_factory;
}
static ThermoFactory* factory();
//! delete the static instance of this factory
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
//! Create a new thermodynamic property manager.
/*!
@ -69,21 +59,14 @@ private:
};
//! @copydoc ThermoFactory::newThermoPhase
inline ThermoPhase* newThermoPhase(const std::string& model)
{
return ThermoFactory::factory()->create(model);
}
ThermoPhase* newThermoPhase(const string& model);
//! Create a new ThermoPhase instance.
/*!
* @param model String to look up the model against
* @returns a shared pointer to a new ThermoPhase instance matching the model string.
*/
inline shared_ptr<ThermoPhase> newThermo(const std::string& model)
{
ThermoPhase* tptr = ThermoFactory::factory()->create(model);
return shared_ptr<ThermoPhase> (tptr);
}
shared_ptr<ThermoPhase> newThermo(const string& model);
//! Create a new ThermoPhase object and initialize it
/*!

View File

@ -42,13 +42,7 @@ public:
* f = TransportFactory::factory();
* @endcode
*/
static TransportFactory* factory() {
std::unique_lock<std::mutex> transportLock(transport_mutex);
if (!s_factory) {
s_factory = new TransportFactory();
}
return s_factory;
}
static TransportFactory* factory();
//! Deletes the statically allocated factory instance.
virtual void deleteFactory();
@ -104,16 +98,7 @@ Transport* newTransportMgr(const std::string& model="", ThermoPhase* thermo=0,
* @returns a Transport object for the phase
* @ingroup tranprops
*/
inline shared_ptr<Transport> newTransport(ThermoPhase* thermo,
const std::string& model = "default") {
Transport* tr;
if (model == "default") {
tr = TransportFactory::factory()->newTransport(thermo, 0);
} else {
tr = TransportFactory::factory()->newTransport(model, thermo, 0);
}
return shared_ptr<Transport> (tr);
}
shared_ptr<Transport> newTransport(ThermoPhase* thermo, const string& model="default");
//! Create a new transport manager instance.
/*!

View File

@ -24,19 +24,9 @@ namespace Cantera
class FlowDeviceFactory : public Factory<FlowDevice>
{
public:
static FlowDeviceFactory* factory() {
std::unique_lock<std::mutex> lock(flowDevice_mutex);
if (!s_factory) {
s_factory = new FlowDeviceFactory;
}
return s_factory;
}
static FlowDeviceFactory* factory();
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(flowDevice_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
//! Create a new flow device by type name.
/*!
@ -52,10 +42,7 @@ private:
//! Create a FlowDevice object of the specified type
//! @ingroup ZeroD
inline FlowDevice* newFlowDevice(const std::string& model)
{
return FlowDeviceFactory::factory()->newFlowDevice(model);
}
FlowDevice* newFlowDevice(const string& model);
}

View File

@ -24,19 +24,9 @@ namespace Cantera
class ReactorFactory : public Factory<ReactorBase>
{
public:
static ReactorFactory* factory() {
std::unique_lock<std::mutex> lock(reactor_mutex);
if (!s_factory) {
s_factory = new ReactorFactory;
}
return s_factory;
}
static ReactorFactory* factory();
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(reactor_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
//! Create a new reactor by type name.
/*!
@ -52,10 +42,7 @@ private:
//! Create a Reactor object of the specified type
//! @ingroup ZeroD
inline ReactorBase* newReactor(const std::string& model)
{
return ReactorFactory::factory()->newReactor(model);
}
ReactorBase* newReactor(const string& model);
}

View File

@ -24,19 +24,9 @@ namespace Cantera
class WallFactory : public Factory<WallBase>
{
public:
static WallFactory* factory() {
std::unique_lock<std::mutex> lock(wall_mutex);
if (!s_factory) {
s_factory = new WallFactory;
}
return s_factory;
}
static WallFactory* factory();
virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(wall_mutex);
delete s_factory;
s_factory = 0;
}
virtual void deleteFactory();
//! Create a new wall by type name.
/*!
@ -52,10 +42,7 @@ private:
//! Create a WallBase object of the specified type
//! @ingroup ZeroD
inline WallBase* newWall(const std::string& model)
{
return WallFactory::factory()->newWall(model);
}
WallBase* newWall(const string& model);
}

View File

@ -35,11 +35,36 @@ KineticsFactory::KineticsFactory() {
addAlias("edge", "Edge");
}
KineticsFactory* KineticsFactory::factory() {
std::unique_lock<std::mutex> lock(kinetics_mutex);
if (!s_factory) {
s_factory = new KineticsFactory;
}
return s_factory;
}
void KineticsFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(kinetics_mutex);
delete s_factory;
s_factory = 0;
}
Kinetics* KineticsFactory::newKinetics(const string& model)
{
return create(toLowerCopy(model));
}
Kinetics* newKineticsMgr(const string& model)
{
return KineticsFactory::factory()->newKinetics(model);
}
shared_ptr<Kinetics> newKinetics(const string& model)
{
shared_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(model));
return kin;
}
unique_ptr<Kinetics> newKinetics(const vector<ThermoPhase*>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode)

View File

@ -100,6 +100,20 @@ ReactionRateFactory::ReactionRateFactory()
});
}
ReactionRateFactory* ReactionRateFactory::factory() {
std::unique_lock<std::mutex> lock(rate_mutex);
if (!s_factory) {
s_factory = new ReactionRateFactory();
}
return s_factory;
}
void ReactionRateFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(rate_mutex);
delete s_factory;
s_factory = 0;
}
shared_ptr<ReactionRate> newReactionRate(const std::string& type)
{
return shared_ptr<ReactionRate> (

View File

@ -11,6 +11,21 @@ using namespace std;
namespace Cantera
{
PreconditionerFactory* PreconditionerFactory::factory() {
std::unique_lock<std::mutex> lock(precon_mutex);
if (!s_factory) {
s_factory = new PreconditionerFactory;
}
return s_factory;
};
//! Delete preconditioner factory
void PreconditionerFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(precon_mutex);
delete s_factory;
s_factory = 0;
};
PreconditionerFactory* PreconditionerFactory::s_factory = 0;
std::mutex PreconditionerFactory::precon_mutex;
@ -19,4 +34,9 @@ PreconditionerFactory::PreconditionerFactory()
reg("Adaptive", []() { return new AdaptivePreconditioner(); });
}
shared_ptr<PreconditionerBase> newPreconditioner(const string& precon)
{
return shared_ptr<PreconditionerBase>(PreconditionerFactory::factory()->create(precon));
};
}

View File

@ -37,6 +37,20 @@ PDSSFactory::PDSSFactory()
reg("HKFT", []() { return new PDSS_HKFT(); });
}
PDSSFactory* PDSSFactory::factory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
if (!s_factory) {
s_factory = new PDSSFactory;
}
return s_factory;
}
void PDSSFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(thermo_mutex);
delete s_factory;
s_factory = 0;
}
PDSS* PDSSFactory::newPDSS(const std::string& model)
{
return create(model);

View File

@ -106,6 +106,33 @@ ThermoFactory::ThermoFactory()
reg("Peng-Robinson", []() { return new PengRobinson(); });
}
ThermoFactory* ThermoFactory::factory()
{
std::unique_lock<std::mutex> lock(thermo_mutex);
if (!s_factory) {
s_factory = new ThermoFactory;
}
return s_factory;
}
void ThermoFactory::deleteFactory()
{
std::unique_lock<std::mutex> lock(thermo_mutex);
delete s_factory;
s_factory = 0;
}
ThermoPhase* newThermoPhase(const string& model)
{
return ThermoFactory::factory()->create(model);
}
shared_ptr<ThermoPhase> newThermo(const string& model)
{
shared_ptr<ThermoPhase> tptr(ThermoFactory::factory()->create(model));
return tptr;
}
ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model)
{
return create(model);

View File

@ -52,6 +52,14 @@ TransportFactory::TransportFactory()
m_CK_mode["CK_Multi"] = m_CK_mode["multicomponent-CK"] = true;
}
TransportFactory* TransportFactory::factory() {
std::unique_lock<std::mutex> transportLock(transport_mutex);
if (!s_factory) {
s_factory = new TransportFactory();
}
return s_factory;
}
void TransportFactory::deleteFactory()
{
std::unique_lock<std::mutex> transportLock(transport_mutex);
@ -106,6 +114,17 @@ Transport* newTransportMgr(const std::string& model, ThermoPhase* thermo, int lo
return f->newTransport(model, thermo, log_level);
}
shared_ptr<Transport> newTransport(ThermoPhase* thermo, const string& model)
{
Transport* tr;
if (model == "default") {
tr = TransportFactory::factory()->newTransport(thermo, 0);
} else {
tr = TransportFactory::factory()->newTransport(model, thermo, 0);
}
return shared_ptr<Transport>(tr);
}
Transport* newDefaultTransportMgr(ThermoPhase* thermo, int loglevel)
{
return TransportFactory::factory()->newTransport(thermo, loglevel);

View File

@ -20,9 +20,29 @@ FlowDeviceFactory::FlowDeviceFactory()
reg("Valve", []() { return new Valve(); });
}
FlowDeviceFactory* FlowDeviceFactory::factory() {
std::unique_lock<std::mutex> lock(flowDevice_mutex);
if (!s_factory) {
s_factory = new FlowDeviceFactory;
}
return s_factory;
}
void FlowDeviceFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(flowDevice_mutex);
delete s_factory;
s_factory = 0;
}
FlowDevice* FlowDeviceFactory::newFlowDevice(const std::string& flowDeviceType)
{
return create(flowDeviceType);
}
FlowDevice* newFlowDevice(const string& model)
{
return FlowDeviceFactory::factory()->newFlowDevice(model);
}
}

View File

@ -55,9 +55,28 @@ ReactorFactory::ReactorFactory()
reg("MoleReactor", []() { return new MoleReactor(); });
}
ReactorFactory* ReactorFactory::factory() {
std::unique_lock<std::mutex> lock(reactor_mutex);
if (!s_factory) {
s_factory = new ReactorFactory;
}
return s_factory;
}
void ReactorFactory::deleteFactory() {
std::unique_lock<std::mutex> lock(reactor_mutex);
delete s_factory;
s_factory = 0;
}
ReactorBase* ReactorFactory::newReactor(const std::string& reactorType)
{
return create(reactorType);
}
ReactorBase* newReactor(const string& model)
{
return ReactorFactory::factory()->newReactor(model);
}
}

View File

@ -18,9 +18,28 @@ WallFactory::WallFactory()
reg("Wall", []() { return new Wall(); });
}
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;
}
WallBase* WallFactory::newWall(const std::string& wallType)
{
return create(wallType);
}
WallBase* newWall(const string& model)
{
return WallFactory::factory()->newWall(model);
}
}