Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pure fluid reactor #487

Merged
merged 2 commits into from
Dec 3, 2017
Merged
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
3 changes: 3 additions & 0 deletions include/cantera/thermo/PureFluidPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class PureFluidPhase : public ThermoPhase
m_tpx_name = name;
}

virtual double minTemp(size_t k=npos) const;
virtual double maxTemp(size_t k=npos) const;

virtual doublereal enthalpy_mole() const;
virtual doublereal intEnergy_mole() const;
virtual doublereal entropy_mole() const;
Expand Down
5 changes: 5 additions & 0 deletions interfaces/cython/cantera/test/test_purefluid.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ def test_critical_properties(self):
self.assertNear(self.water.critical_temperature, 647.286)
self.assertNear(self.water.critical_density, 317.0)

def test_temperature_limits(self):
co2 = ct.CarbonDioxide()
self.assertNear(co2.min_temp, 216.54)
self.assertNear(co2.max_temp, 1500.0)

def test_set_state(self):
self.water.PX = 101325, 0.5
self.assertNear(self.water.P, 101325)
Expand Down
26 changes: 26 additions & 0 deletions interfaces/cython/cantera/test/test_reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,32 @@ def test_Reactor(self):
self.assertEqual(states.X[-1], 1)
self.assertNear(states.X[30], 0.54806, 1e-4)

def test_Reactor_2(self):
phase = ct.PureFluid('liquidvapor.xml', 'carbondioxide')
air = ct.Solution('air.xml')

phase.TP = 218, 5e6
r1 = ct.Reactor(phase)
r1.volume = 0.1

air.TP = 500, 5e6
r2 = ct.Reactor(air)
r2.volume = 10.0

w1 = ct.Wall(r1, r2, U=10000, A=1)
w1.expansion_rate_coeff = 1e-3
net = ct.ReactorNet([r1,r2])

states = ct.SolutionArray(phase, extra='t')
for t in np.arange(0.0, 60.0, 1):
net.advance(t)
states.append(TD=r1.thermo.TD, t=net.time)

self.assertEqual(states.X[0], 0)
self.assertEqual(states.X[-1], 1)
self.assertNear(states.X[20], 0.644865, 1e-4)


def test_ConstPressureReactor(self):
phase = ct.Nitrogen()
air = ct.Solution('air.xml')
Expand Down
10 changes: 10 additions & 0 deletions src/thermo/PureFluidPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ void PureFluidPhase::setParametersFromXML(const XML_Node& eosdata)
}
}

double PureFluidPhase::minTemp(size_t k) const
{
return m_sub->Tmin();
}

double PureFluidPhase::maxTemp(size_t k) const
{
return m_sub->Tmax();
}

doublereal PureFluidPhase::enthalpy_mole() const
{
setTPXState();
Expand Down
17 changes: 12 additions & 5 deletions src/zeroD/Reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,20 @@ void Reactor::updateState(doublereal* y)
TT = bmt::bracket_and_solve_root(
u_err, T, 1.2, true, bmt::eps_tolerance<double>(48), maxiter);
} catch (std::exception& err) {
// Set m_thermo back to a reasonable state if root finding fails
m_thermo->setState_TR(T, m_mass / m_vol);
throw CanteraError("Reactor::updateState", err.what());
// Try full-range bisection if bracketing fails (e.g. near
// temperature limits for the phase's equation of state)
try {
TT = bmt::bisect(u_err, m_thermo->minTemp(), m_thermo->maxTemp(),
bmt::eps_tolerance<double>(48), maxiter);
} catch (std::exception& err2) {
// Set m_thermo back to a reasonable state if root finding fails
m_thermo->setState_TR(T, m_mass / m_vol);
throw CanteraError("Reactor::updateState",
"{}\nat U = {}, rho = {}", err2.what(), U, m_mass / m_vol);
}
}
if (fabs(TT.first - TT.second) > 1e-7*TT.first) {
throw CanteraError("Reactor::updateState",
"bracket_and_solve_root failed");
throw CanteraError("Reactor::updateState", "root finding failed");
}
m_thermo->setState_TR(TT.second, m_mass / m_vol);
} else {
Expand Down