diff --git a/include/cantera/zeroD/FlowReactor.h b/include/cantera/zeroD/FlowReactor.h index 6b163cbd6..d13ae10cd 100644 --- a/include/cantera/zeroD/FlowReactor.h +++ b/include/cantera/zeroD/FlowReactor.h @@ -140,7 +140,7 @@ protected: //! Density [kg/m^3]. First component of the state vector. double m_rho = NAN; //! Axial velocity [m/s]. Second component of the state vector. - double m_u = NAN; + double m_u = -1.0; //! Pressure [Pa]. Third component of the state vector. double m_P = NAN; //! Temperature [K]. Fourth component of the state vector. diff --git a/src/zeroD/FlowReactor.cpp b/src/zeroD/FlowReactor.cpp index 2d034fed2..6c0ffb6db 100644 --- a/src/zeroD/FlowReactor.cpp +++ b/src/zeroD/FlowReactor.cpp @@ -29,6 +29,11 @@ void FlowReactor::getStateDae(double* y, double* ydot) // set the first component to the initial density y[0] = m_rho; + if (m_u < 0) { + throw CanteraError("FlowReactor::getStateDae", + "Set mass flow rate before initializing reactor"); + } + // set the second component to the initial speed y[1] = m_u; diff --git a/test/python/test_reactor.py b/test/python/test_reactor.py index a50428c1a..4bb8d37f7 100644 --- a/test/python/test_reactor.py +++ b/test/python/test_reactor.py @@ -1499,6 +1499,7 @@ class TestFlowReactor(utilities.CanteraTest): surf = ct.Interface('methane_pox_on_pt.yaml', 'Pt_surf') gas = surf.adjacent['gas'] r = ct.FlowReactor(gas) + r.mass_flow_rate = 0.1 rsurf = ct.ReactorSurface(surf, r) sim = ct.ReactorNet([r]) sim.initialize() @@ -1530,6 +1531,14 @@ class TestFlowReactor2(utilities.CanteraTest): sim = ct.ReactorNet([r]) return r, rsurf, sim + def test_no_mass_flow_rate(self): + surf, gas = self.import_phases() + r = ct.FlowReactor(gas) + rsurf = ct.ReactorSurface(surf, r) + sim = ct.ReactorNet([r]) + with pytest.raises(ct.CanteraError, match="mass flow rate"): + sim.initialize() + def test_mixed_reactor_types(self): surf, gas = self.import_phases() r1 = ct.FlowReactor(gas)