[Reactor] Check for Reactor contents before installing FlowDevice
Fixes #279.
This commit is contained in:
parent
c0fa589b8c
commit
f6f868fe28
3 changed files with 17 additions and 3 deletions
|
|
@ -518,7 +518,7 @@ cdef extern from "cantera/zeroD/flowControllers.h":
|
|||
cdef cppclass CxxFlowDevice "Cantera::FlowDevice":
|
||||
CxxFlowDevice()
|
||||
double massFlowRate(double) except +
|
||||
cbool install(CxxReactorBase&, CxxReactorBase&)
|
||||
cbool install(CxxReactorBase&, CxxReactorBase&) except +
|
||||
void setFunction(CxxFunc1*)
|
||||
void setParameters(int, double*)
|
||||
|
||||
|
|
|
|||
|
|
@ -434,6 +434,19 @@ class TestReactor(utilities.CanteraTest):
|
|||
self.assertNear(speciesMass(kAr), mAr)
|
||||
self.assertNear(speciesMass(kO2), mO2)
|
||||
|
||||
def test_valve_errors(self):
|
||||
self.make_reactors()
|
||||
res = ct.Reservoir()
|
||||
|
||||
with self.assertRaises(RuntimeError):
|
||||
# Must assign contents of both reactors before creating Valve
|
||||
v = ct.Valve(self.r1, res)
|
||||
|
||||
v = ct.Valve(self.r1, self.r2)
|
||||
with self.assertRaises(RuntimeError):
|
||||
# inlet and outlet cannot be reassigned
|
||||
v._install(self.r2, self.r1)
|
||||
|
||||
def test_pressure_controller(self):
|
||||
self.make_reactors(n_reactors=1)
|
||||
g = ct.Solution('h2o2.xml')
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Cantera
|
|||
bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
|
||||
{
|
||||
if (m_in || m_out) {
|
||||
return false;
|
||||
throw CanteraError("FlowDevice::install", "Already installed");
|
||||
}
|
||||
m_in = ∈
|
||||
m_out = &out;
|
||||
|
|
@ -20,7 +20,8 @@ bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
|
|||
ThermoPhase* mixin = &m_in->contents();
|
||||
ThermoPhase* mixout = &m_out->contents();
|
||||
if (mixin == 0 || mixout == 0) {
|
||||
return false;
|
||||
throw CanteraError("FlowDevice::install", "Can't install flow device "
|
||||
"until reactor contents have been assigned.");
|
||||
}
|
||||
|
||||
m_nspin = mixin->nSpecies();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue