Do species indexing in GeneralSpeciesThermo instead of STIT

This means that GeneralSpeciesThermo no longer modifies the
SpeciesThermoInterpType objects, permitting them to be shared between
ThermoPhase objects.
This commit is contained in:
Ray Speth 2015-02-27 18:57:59 -05:00
parent 5195e4f9b8
commit 8f36e524fe
2 changed files with 21 additions and 14 deletions

View file

@ -133,11 +133,14 @@ private:
const SpeciesThermoInterpType* provideSTIT(size_t k) const;
protected:
typedef std::map<int, std::vector<shared_ptr<SpeciesThermoInterpType> > > STIT_map;
typedef std::pair<size_t, shared_ptr<SpeciesThermoInterpType> > index_STIT;
typedef std::map<int, std::vector<index_STIT> > STIT_map;
typedef std::map<int, std::vector<double> > tpoly_map;
/**
* This is the main unknown in the object. It contains pointers to
* This is the main data structure, which contains the
* SpeciesThermoInterpType objects, sorted by the parameterization type.
* `m_sp[i]` is the vector of [species index, STIT] pairs which use
* parameterization `i`.
*/
STIT_map m_sp;

View file

@ -32,8 +32,10 @@ GeneralSpeciesThermo::GeneralSpeciesThermo(const GeneralSpeciesThermo& b) :
iter != b.m_sp.end();
iter++) {
for (size_t k = 0; k < iter->second.size(); k++) {
shared_ptr<SpeciesThermoInterpType> spec(iter->second[k]->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(spec);
size_t i = iter->second[k].first;
shared_ptr<SpeciesThermoInterpType> spec(
iter->second[k].second->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(std::make_pair(i, spec));
}
}
}
@ -52,8 +54,10 @@ GeneralSpeciesThermo::operator=(const GeneralSpeciesThermo& b)
iter != b.m_sp.end();
iter++) {
for (size_t k = 0; k < iter->second.size(); k++) {
shared_ptr<SpeciesThermoInterpType> spec(iter->second[k]->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(spec);
size_t i = iter->second[k].first;
shared_ptr<SpeciesThermoInterpType> spec(
iter->second[k].second->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(std::make_pair(i, spec));
}
}
@ -106,10 +110,9 @@ void GeneralSpeciesThermo::install_STIT(size_t index,
}
AssertThrow(m_speciesLoc.find(index) == m_speciesLoc.end(),
"Index position isn't null, duplication of assignment: " + int2str(index));
stit_ptr->setIndex(index);
int type = stit_ptr->reportType();
m_speciesLoc[index] = std::make_pair(type, m_sp[type].size());
m_sp[type].push_back(stit_ptr);
m_sp[type].push_back(std::make_pair(index, stit_ptr));
if (m_sp[type].size() == 1) {
m_tpoly[type].resize(stit_ptr->temperaturePolySize());
}
@ -132,7 +135,7 @@ void GeneralSpeciesThermo::update_one(size_t k, doublereal t, doublereal* cp_R,
{
const SpeciesThermoInterpType* sp_ptr = provideSTIT(k);
if (sp_ptr) {
sp_ptr->updatePropertiesTemp(t, cp_R, h_RT, s_R);
sp_ptr->updatePropertiesTemp(t, cp_R+k, h_RT+k, s_R+k);
}
}
@ -142,11 +145,12 @@ void GeneralSpeciesThermo::update(doublereal t, doublereal* cp_R,
STIT_map::const_iterator iter = m_sp.begin();
tpoly_map::iterator jter = m_tpoly.begin();
for (; iter != m_sp.end(); iter++, jter++) {
const std::vector<shared_ptr<SpeciesThermoInterpType> >& species = iter->second;
const std::vector<index_STIT>& species = iter->second;
double* tpoly = &jter->second[0];
species[0]->updateTemperaturePoly(t, tpoly);
species[0].second->updateTemperaturePoly(t, tpoly);
for (size_t k = 0; k < species.size(); k++) {
species[k]->updateProperties(tpoly, cp_R, h_RT, s_R);
size_t i = species[k].first;
species[k].second->updateProperties(tpoly, cp_R+i, h_RT+i, s_R+i);
}
}
}
@ -215,7 +219,7 @@ SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k)
{
try {
const std::pair<int, size_t>& loc = getValue(m_speciesLoc, k);
return getValue(m_sp, loc.first)[loc.second].get();
return getValue(m_sp, loc.first)[loc.second].second.get();
} catch (std::out_of_range&) {
return 0;
}
@ -225,7 +229,7 @@ const SpeciesThermoInterpType* GeneralSpeciesThermo::provideSTIT(size_t k) const
{
try {
const std::pair<int, size_t>& loc = getValue(m_speciesLoc, k);
return getValue(m_sp, loc.first)[loc.second].get();
return getValue(m_sp, loc.first)[loc.second].second.get();
} catch (std::out_of_range&) {
return 0;
}