Skip to content

Commit

Permalink
Move factory function definitions out of .h files
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Feb 3, 2023
1 parent c0ae563 commit 622b37e
Show file tree
Hide file tree
Showing 18 changed files with 206 additions and 150 deletions.
25 changes: 4 additions & 21 deletions include/cantera/kinetics/KineticsFactory.h
Expand Up @@ -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.
Expand All @@ -49,19 +39,12 @@ class KineticsFactory : public Factory<Kinetics>
/**
* 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
Expand Down
14 changes: 2 additions & 12 deletions include/cantera/kinetics/ReactionRateFactory.h
Expand Up @@ -38,19 +38,9 @@ class ReactionRateFactory
* 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
Expand Down
19 changes: 3 additions & 16 deletions include/cantera/numerics/PreconditionerFactory.h
Expand Up @@ -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;
Expand All @@ -39,10 +29,7 @@ class PreconditionerFactory : public Factory<PreconditionerBase>
};

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

}

Expand Down
14 changes: 2 additions & 12 deletions include/cantera/thermo/PDSSFactory.h
Expand Up @@ -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.
/*!
Expand Down
25 changes: 4 additions & 21 deletions include/cantera/thermo/ThermoFactory.h
Expand Up @@ -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.
/*!
Expand All @@ -69,21 +59,14 @@ class ThermoFactory : public Factory<ThermoPhase>
};

//! @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
/*!
Expand Down
19 changes: 2 additions & 17 deletions include/cantera/transport/TransportFactory.h
Expand Up @@ -42,13 +42,7 @@ class TransportFactory : public Factory<Transport>
* 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();
Expand Down Expand Up @@ -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.
/*!
Expand Down
21 changes: 4 additions & 17 deletions include/cantera/zeroD/FlowDeviceFactory.h
Expand Up @@ -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;
}

virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(flowDevice_mutex);
delete s_factory;
s_factory = 0;
}
static FlowDeviceFactory* factory();

virtual void deleteFactory();

//! Create a new flow device by type name.
/*!
Expand All @@ -52,10 +42,7 @@ class FlowDeviceFactory : public Factory<FlowDevice>

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

}

Expand Down
21 changes: 4 additions & 17 deletions include/cantera/zeroD/ReactorFactory.h
Expand Up @@ -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;
}

virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(reactor_mutex);
delete s_factory;
s_factory = 0;
}
static ReactorFactory* factory();

virtual void deleteFactory();

//! Create a new reactor by type name.
/*!
Expand All @@ -52,10 +42,7 @@ class ReactorFactory : public Factory<ReactorBase>

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

}

Expand Down
21 changes: 4 additions & 17 deletions include/cantera/zeroD/WallFactory.h
Expand Up @@ -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;
}

virtual void deleteFactory() {
std::unique_lock<std::mutex> lock(wall_mutex);
delete s_factory;
s_factory = 0;
}
static WallFactory* factory();

virtual void deleteFactory();

//! Create a new wall by type name.
/*!
Expand All @@ -52,10 +42,7 @@ class WallFactory : public Factory<WallBase>

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

}

Expand Down
25 changes: 25 additions & 0 deletions src/kinetics/KineticsFactory.cpp
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/kinetics/ReactionRateFactory.cpp
Expand Up @@ -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> (
Expand Down
20 changes: 20 additions & 0 deletions src/numerics/PreconditionerFactory.cpp
Expand Up @@ -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;

Expand All @@ -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));
};

}

0 comments on commit 622b37e

Please sign in to comment.