initial import
This commit is contained in:
parent
275865b5a9
commit
63b3b5ebc8
2 changed files with 136 additions and 0 deletions
68
Cantera/src/zeroD/ReactorFactory.cpp
Normal file
68
Cantera/src/zeroD/ReactorFactory.cpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* @file ReactorFactory.cpp
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Author$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
// Copyright 2006 California Institute of Technology
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning(disable:4786)
|
||||
#endif
|
||||
|
||||
#include "ReactorFactory.h"
|
||||
|
||||
#include "Reservoir.h"
|
||||
#include "Reactor.h"
|
||||
#include "FlowReactor.h"
|
||||
#include "ConstPressureReactor.h"
|
||||
|
||||
namespace CanteraZeroD {
|
||||
|
||||
ReactorFactory* ReactorFactory::s_factory = 0;
|
||||
|
||||
static int ntypes = 4;
|
||||
static string _types[] = {"Reservoir", "Reactor", "ConstPressureReactor",
|
||||
"FlowReactor"};
|
||||
|
||||
// these constants are defined in ReactorBase.h
|
||||
static int _itypes[] = {ReservoirType, ReactorType, FlowReactorType,
|
||||
ConstPressureReactorType};
|
||||
|
||||
/**
|
||||
* This method returns a new instance of a subclass of ThermoPhase
|
||||
*/
|
||||
ReactorBase* ReactorFactory::newReactor(string reactorType) {
|
||||
|
||||
int ir=-1;
|
||||
|
||||
for (int n = 0; n < ntypes; n++) {
|
||||
if (reactorType == _types[n]) ir = _itypes[n];
|
||||
}
|
||||
|
||||
return newReactor(ir);
|
||||
}
|
||||
|
||||
|
||||
ReactorBase* ReactorFactory::newReactor(int ir) {
|
||||
switch (ir) {
|
||||
case ReservoirType:
|
||||
return new Reservoir();
|
||||
case ReactorType:
|
||||
return new Reactor();
|
||||
case FlowReactorType:
|
||||
return new FlowReactor();
|
||||
case ConstPressureReactorType:
|
||||
return new ConstPressureReactor();
|
||||
default:
|
||||
throw CanteraError("ReactorFactory::newReactor",
|
||||
"unknown reactor type!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
68
Cantera/src/zeroD/ReactorFactory.h
Normal file
68
Cantera/src/zeroD/ReactorFactory.h
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* @file ReactorFactory.h
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Author$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*/
|
||||
|
||||
// Copyright 2001 California Institute of Technology
|
||||
|
||||
|
||||
#ifndef REACTOR_FACTORY_H
|
||||
#define REACTOR_FACTORY_H
|
||||
|
||||
#include "ReactorBase.h"
|
||||
|
||||
namespace CanteraZeroD {
|
||||
|
||||
|
||||
class ReactorFactory {
|
||||
|
||||
public:
|
||||
|
||||
static ReactorFactory* factory() {
|
||||
if (!s_factory) s_factory = new ReactorFactory;
|
||||
return s_factory;
|
||||
}
|
||||
|
||||
static void deleteFactory() {
|
||||
if (s_factory) {
|
||||
delete s_factory;
|
||||
s_factory = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Destructor doesn't do anything.
|
||||
*/
|
||||
virtual ~ReactorFactory() {}
|
||||
|
||||
/**
|
||||
* Create a new reactor.
|
||||
* @param n the type to be created.
|
||||
*/
|
||||
virtual ReactorBase* newReactor(int n);
|
||||
virtual ReactorBase* newReactor(string reactorType);
|
||||
|
||||
private:
|
||||
|
||||
static ReactorFactory* s_factory;
|
||||
ReactorFactory(){}
|
||||
};
|
||||
|
||||
inline ReactorBase* newReactor(string model,
|
||||
ReactorFactory* f=0) {
|
||||
if (f == 0) {
|
||||
f = ReactorFactory::factory();
|
||||
}
|
||||
return f->newReactor(model);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue