Skip to content

Commit

Permalink
Ensure mass flow rate is set for FlowReactor
Browse files Browse the repository at this point in the history
Fixes a confusing error (depending on the LAPACK implementation) if
the reactor is initialized before setting the mass flow rate.
  • Loading branch information
speth committed Jul 2, 2023
1 parent ae3c63e commit c1b3d5c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/cantera/zeroD/FlowReactor.h
Expand Up @@ -140,7 +140,7 @@ class FlowReactor : public IdealGasReactor
//! 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.
Expand Down
5 changes: 5 additions & 0 deletions src/zeroD/FlowReactor.cpp
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions test/python/test_reactor.py
Expand Up @@ -1499,6 +1499,7 @@ def test_component_names(self):
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()
Expand Down Expand Up @@ -1530,6 +1531,14 @@ def make_reactors(self, gas, surf):
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)
Expand Down

0 comments on commit c1b3d5c

Please sign in to comment.