Skip to content
Draft
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
19 changes: 17 additions & 2 deletions include/cantera/zeroD/FlowDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const int Valve_Type = 3;
class FlowDevice
{
public:
FlowDevice();
FlowDevice(const std::string& name = "(none)");

virtual ~FlowDevice() {}
FlowDevice(const FlowDevice&) = delete;
Expand All @@ -54,6 +54,19 @@ class FlowDevice
return m_type;
}

//! Return the name of this flow device
std::string name() const {
return m_name;
}

//! Set the name of this flow device
void setName(const std::string& name) {
m_name = name;
}

//! Generate self-documenting YAML string.
virtual std::string toYAML() const;

//! Mass flow rate (kg/s).
//! @deprecated The 'time' argument will be removed after Cantera 2.5.
//! Evaluating the mass flow rate at times other than the current time
Expand Down Expand Up @@ -101,7 +114,7 @@ class FlowDevice
}

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

Expand Down Expand Up @@ -166,6 +179,8 @@ class FlowDevice

int m_type; //!< @deprecated To be removed after Cantera 2.5.

std::string m_name; //! flow device name

private:
size_t m_nspin, m_nspout;
ReactorBase* m_in;
Expand Down
3 changes: 0 additions & 3 deletions include/cantera/zeroD/Reactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ class Reactor : public ReactorBase
//! Get initial conditions for SurfPhase objects attached to this reactor
virtual void getSurfaceInitialConditions(double* y);

//! Pointer to the homogeneous Kinetics object that handles the reactions
Kinetics* m_kin;

doublereal m_vdot; //!< net rate of volume change from moving walls [m^3/s]
doublereal m_Q; //!< net heat transfer through walls [W]
doublereal m_mass; //!< total mass
Expand Down
20 changes: 16 additions & 4 deletions include/cantera/zeroD/ReactorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class ReactorBase
//! Specify the mixture contained in the reactor. Note that a pointer to
//! this substance is stored, and as the integration proceeds, the state of
//! the substance is modified.
virtual void setThermoMgr(thermo_t& thermo);
virtual void setThermoMgr(ThermoPhase& thermo);

//! Specify chemical kinetics governing the reactor.
virtual void setKineticsMgr(Kinetics& kin) {
Expand All @@ -101,6 +101,9 @@ class ReactorBase
throw NotImplementedError("ReactorBase::setChemistry");
}

//! Generate self-documenting YAML string.
virtual std::string toYAML() const;

//! Set the energy equation on or off.
virtual void setEnergy(int eflag = 1) {
throw NotImplementedError("ReactorBase::setEnergy");
Expand Down Expand Up @@ -136,6 +139,11 @@ class ReactorBase
return m_wall.size();
}

//! Return the number of ReactorSurface objects connected to this reactor.
size_t nSurfaces() {
return m_surfaces.size();
}

//! Insert a Wall between this reactor and another reactor.
/*!
* `lr` = 0 if this reactor is to the left of the wall and `lr` = 1 if
Expand Down Expand Up @@ -177,15 +185,15 @@ class ReactorBase
virtual void syncState();

//! return a reference to the contents.
thermo_t& contents() {
ThermoPhase& contents() {
if (!m_thermo) {
throw CanteraError("ReactorBase::contents",
"Reactor contents not defined.");
}
return *m_thermo;
}

const thermo_t& contents() const {
const ThermoPhase& contents() const {
if (!m_thermo) {
throw CanteraError("ReactorBase::contents",
"Reactor contents not defined.");
Expand Down Expand Up @@ -261,7 +269,11 @@ class ReactorBase
//! Number of homogeneous species in the mixture
size_t m_nsp;

thermo_t* m_thermo;
ThermoPhase* m_thermo;

//! Pointer to the homogeneous Kinetics object that handles the reactions
Kinetics* m_kin;

doublereal m_vol;
doublereal m_enthalpy;
doublereal m_intEnergy;
Expand Down
3 changes: 3 additions & 0 deletions include/cantera/zeroD/ReactorNet.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class ReactorNet : public FuncEval

//@}

//! Generate self-documenting YAML string.
std::string toYAML() const;

//! Add the reactor *r* to this reactor network.
void addReactor(Reactor& r);

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 @@ -17,11 +17,30 @@ class SurfPhase;
class ReactorSurface
{
public:
ReactorSurface();
ReactorSurface(const std::string& name = "(none)");
virtual ~ReactorSurface() {}
ReactorSurface(const ReactorSurface&) = delete;
ReactorSurface& operator=(const ReactorSurface&) = delete;

//! String indicating the wall model implemented. Usually
//! corresponds to the name of the derived class.
virtual std::string type() const {
return "ReactorSurface";
}

//! Return the name of this surface
std::string name() const {
return m_name;
}

//! Set the name of this surface
void setName(const std::string& name) {
m_name = name;
}

//! Generate self-documenting YAML string.
virtual std::string toYAML() const;

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

Expand Down Expand Up @@ -90,6 +109,8 @@ class ReactorSurface
ReactorBase* m_reactor;
vector_fp m_cov;
std::vector<SensitivityParameter> m_params;

std::string m_name; //! reactor surface name
};

}
Expand Down
19 changes: 17 additions & 2 deletions include/cantera/zeroD/Wall.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const int WallType = 1;
class WallBase
{
public:
WallBase();
WallBase(const std::string& name = "(none)");

virtual ~WallBase() {}
WallBase(const WallBase&) = delete;
Expand All @@ -40,6 +40,19 @@ class WallBase
return "WallBase";
}

//! Return the name of this wall
std::string name() const {
return m_name;
}

//! Set the name of this wall
void setName(const std::string& name) {
m_name = name;
}

//! Generate self-documenting YAML string.
virtual std::string toYAML() const;

//! Rate of volume change (m^3/s) for the adjacent reactors.
/*!
* This method is called by Reactor::evalWalls(). Base class method
Expand Down Expand Up @@ -95,7 +108,7 @@ class WallBase
}

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

Expand All @@ -106,6 +119,8 @@ class WallBase
std::vector<ReactorSurface> m_surf;

double m_area;

std::string m_name; //! wall name
};

//! Represents a wall between between two ReactorBase objects.
Expand Down
14 changes: 12 additions & 2 deletions interfaces/cython/cantera/_cantera.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
cdef cppclass CxxReactorBase "Cantera::ReactorBase":
CxxReactorBase()
string typeStr()
string toYAML()
void setThermoMgr(CxxThermoPhase&) except +translate_exception
void restoreState() except +translate_exception
void syncState() except +translate_exception
Expand Down Expand Up @@ -582,6 +583,9 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
cdef cppclass CxxWallBase "Cantera::WallBase":
CxxWallBase()
string type()
string name()
void setName(string)
string toYAML()
cbool install(CxxReactorBase&, CxxReactorBase&)
double area()
void setArea(double)
Expand Down Expand Up @@ -610,6 +614,10 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":

cdef cppclass CxxReactorSurface "Cantera::ReactorSurface":
CxxReactorSurface()
string type()
string name()
void setName(string)
string toYAML()
double area()
void setArea(double)
void setKinetics(CxxKinetics*)
Expand All @@ -624,6 +632,9 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
cdef cppclass CxxFlowDevice "Cantera::FlowDevice":
CxxFlowDevice()
string typeStr()
string name()
void setName(string)
string toYAML()
double massFlowRate() except +translate_exception
double massFlowRate(double) except +translate_exception
cbool install(CxxReactorBase&, CxxReactorBase&) except +translate_exception
Expand Down Expand Up @@ -652,6 +663,7 @@ cdef extern from "cantera/zerodim.h" namespace "Cantera":
cdef cppclass CxxReactorNet "Cantera::ReactorNet":
CxxReactorNet()
void addReactor(CxxReactor&)
string toYAML() except +translate_exception
double advance(double, cbool) except +translate_exception
double step() except +translate_exception
void initialize() except +translate_exception
Expand Down Expand Up @@ -1088,7 +1100,6 @@ cdef class WallBase:
cdef object _heat_flux_func
cdef ReactorBase _left_reactor
cdef ReactorBase _right_reactor
cdef str name

cdef class Wall(WallBase):
pass
Expand All @@ -1097,7 +1108,6 @@ cdef class FlowDevice:
cdef CxxFlowDevice* dev
cdef Func1 _rate_func
cdef Func1 _time_func
cdef str name
cdef ReactorBase _upstream
cdef ReactorBase _downstream

Expand Down
18 changes: 9 additions & 9 deletions interfaces/cython/cantera/examples/reactors/ic_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,26 @@ def piston_speed(t):

# define initial state and set up reactor
gas.TPX = T_inlet, p_inlet, comp_inlet
cyl = ct.IdealGasReactor(gas)
cyl = ct.IdealGasReactor(gas, name='Cylinder')
cyl.volume = V_oT

# define inlet state
gas.TPX = T_inlet, p_inlet, comp_inlet
inlet = ct.Reservoir(gas)
inlet = ct.Reservoir(gas, name='Inlet')

# inlet valve
inlet_valve = ct.Valve(inlet, cyl)
inlet_valve = ct.Valve(inlet, cyl, name='InletValve')
inlet_delta = np.mod(inlet_close - inlet_open, 4 * np.pi)
inlet_valve.valve_coeff = inlet_valve_coeff
inlet_valve.set_time_function(
lambda t: np.mod(crank_angle(t) - inlet_open, 4 * np.pi) < inlet_delta)

# define injector state (gaseous!)
gas.TPX = T_injector, p_injector, comp_injector
injector = ct.Reservoir(gas)
injector = ct.Reservoir(gas, name='Fuel')

# injector is modeled as a mass flow controller
injector_mfc = ct.MassFlowController(injector, cyl)
injector_mfc = ct.MassFlowController(injector, cyl, name='Injector')
injector_delta = np.mod(injector_close - injector_open, 4 * np.pi)
injector_t_open = (injector_close - injector_open) / 2. / np.pi / f
injector_mfc.mass_flow_coeff = injector_mass / injector_t_open
Expand All @@ -125,21 +125,21 @@ def piston_speed(t):

# define outlet pressure (temperature and composition don't matter)
gas.TPX = T_ambient, p_outlet, comp_ambient
outlet = ct.Reservoir(gas)
outlet = ct.Reservoir(gas, name='Outlet')

# outlet valve
outlet_valve = ct.Valve(cyl, outlet)
outlet_valve = ct.Valve(cyl, outlet, name='OutletValve')
outlet_delta = np.mod(outlet_close - outlet_open, 4 * np.pi)
outlet_valve.valve_coeff = outlet_valve_coeff
outlet_valve.set_time_function(
lambda t: np.mod(crank_angle(t) - outlet_open, 4 * np.pi) < outlet_delta)

# define ambient pressure (temperature and composition don't matter)
gas.TPX = T_ambient, p_ambient, comp_ambient
ambient_air = ct.Reservoir(gas)
ambient_air = ct.Reservoir(ct.Solution('air.cti'), name='Ambient')

# piston is modeled as a moving wall
piston = ct.Wall(ambient_air, cyl)
piston = ct.Wall(ambient_air, cyl, name='Piston')
piston.area = A_piston
piston.set_velocity(piston_speed)

Expand Down
Loading