mirror of
https://github.com/Cantera/cantera.git
synced 2026-08-05 18:57:00 -05:00
[Reactor] Check for Reactor contents before installing FlowDevice
Fixes #279.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user