[Reactor] Move reactor contents check into ReactorBase::contents

The check introduced in f6f868fe28 takes place too late, as the pointer to
ReactorBase.m_thermo has already been dereferenced at this point. Most compilers
let this pass, but it is techincally incorrect.
This commit is contained in:
Ray Speth 2015-06-18 17:51:46 -04:00
parent f6f868fe28
commit be24e9daf1
2 changed files with 16 additions and 12 deletions

View file

@ -133,10 +133,18 @@ public:
//! return a reference to the contents.
thermo_t& contents() {
if (!m_thermo) {
throw CanteraError("ReactorBase::contents",
"Reactor contents not defined.");
}
return *m_thermo;
}
const thermo_t& contents() const {
if (!m_thermo) {
throw CanteraError("ReactorBase::contents",
"Reactor contents not defined.");
}
return *m_thermo;
}

View file

@ -17,25 +17,21 @@ bool FlowDevice::install(ReactorBase& in, ReactorBase& out)
m_out->addInlet(*this);
// construct adapters between inlet and outlet species
ThermoPhase* mixin = &m_in->contents();
ThermoPhase* mixout = &m_out->contents();
if (mixin == 0 || mixout == 0) {
throw CanteraError("FlowDevice::install", "Can't install flow device "
"until reactor contents have been assigned.");
}
const ThermoPhase& mixin = m_in->contents();
const ThermoPhase& mixout = m_out->contents();
m_nspin = mixin->nSpecies();
m_nspout = mixout->nSpecies();
m_nspin = mixin.nSpecies();
m_nspout = mixout.nSpecies();
std::string nm;
size_t ki, ko;
for (ki = 0; ki < m_nspin; ki++) {
nm = mixin->speciesName(ki);
ko = mixout->speciesIndex(nm);
nm = mixin.speciesName(ki);
ko = mixout.speciesIndex(nm);
m_in2out.push_back(ko);
}
for (ko = 0; ko < m_nspout; ko++) {
nm = mixout->speciesName(ko);
ki = mixin->speciesIndex(nm);
nm = mixout.speciesName(ko);
ki = mixin.speciesIndex(nm);
m_out2in.push_back(ki);
}
return true;