Eliminate some special cases by using std::vector.data()

Unlike &vec[0], vec.data() is a valid operation even when vec is empty,
removing the need to allocate space in vectors just so we can get an
address that won't be used.
This commit is contained in:
Ray Speth 2015-09-10 23:47:07 -04:00
parent 2589a27b6c
commit 78e2d13da7
5 changed files with 86 additions and 108 deletions

View file

@ -33,7 +33,7 @@ Kinetics* AqueousKinetics::duplMyselfAsKinetics(const std::vector<thermo_t*> & t
void AqueousKinetics::_update_rates_T()
{
doublereal T = thermo().temperature();
m_rates.update(T, log(T), &m_rfn[0]);
m_rates.update(T, log(T), m_rfn.data());
m_temp = T;
updateKc();
@ -42,13 +42,13 @@ void AqueousKinetics::_update_rates_T()
void AqueousKinetics::_update_rates_C()
{
thermo().getActivityConcentrations(&m_conc[0]);
thermo().getActivityConcentrations(m_conc.data());
m_ROP_ok = false;
}
void AqueousKinetics::updateKc()
{
thermo().getStandardChemPotentials(&m_grt[0]);
thermo().getStandardChemPotentials(m_grt.data());
fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
for (size_t k = 0; k < thermo().nSpecies(); k++) {
doublereal logStandConc_k = thermo().logStandardConc(k);
@ -56,7 +56,7 @@ void AqueousKinetics::updateKc()
}
// compute Delta G^0 for all reversible reactions
getRevReactionDelta(&m_grt[0], &m_rkcn[0]);
getRevReactionDelta(m_grt.data(), m_rkcn.data());
doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < m_revindex.size(); i++) {
@ -73,7 +73,7 @@ void AqueousKinetics::getEquilibriumConstants(doublereal* kc)
{
_update_rates_T();
thermo().getStandardChemPotentials(&m_grt[0]);
thermo().getStandardChemPotentials(m_grt.data());
fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
for (size_t k = 0; k < thermo().nSpecies(); k++) {
doublereal logStandConc_k = thermo().logStandardConc(k);
@ -81,7 +81,7 @@ void AqueousKinetics::getEquilibriumConstants(doublereal* kc)
}
// compute Delta G^0 for all reactions
getReactionDelta(&m_grt[0], &m_rkcn[0]);
getReactionDelta(m_grt.data(), m_rkcn.data());
doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < nReactions(); i++) {
@ -116,10 +116,10 @@ void AqueousKinetics::updateROP()
multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin());
// multiply ropf by concentration products
m_reactantStoich.multiply(&m_conc[0], &m_ropf[0]);
m_reactantStoich.multiply(m_conc.data(), m_ropf.data());
// for reversible reactions, multiply ropr by concentration products
m_revProductStoich.multiply(&m_conc[0], &m_ropr[0]);
m_revProductStoich.multiply(m_conc.data(), m_ropr.data());
for (size_t j = 0; j != nReactions(); ++j) {
m_ropnet[j] = m_ropf[j] - m_ropr[j];

View file

@ -28,25 +28,25 @@ bool BulkKinetics::isReversible(size_t i) {
void BulkKinetics::getDeltaGibbs(doublereal* deltaG)
{
// Get the chemical potentials of the species in the ideal gas solution.
thermo().getChemPotentials(&m_grt[0]);
thermo().getChemPotentials(m_grt.data());
// Use the stoichiometric manager to find deltaG for each reaction.
getReactionDelta(&m_grt[0], deltaG);
getReactionDelta(m_grt.data(), deltaG);
}
void BulkKinetics::getDeltaEnthalpy(doublereal* deltaH)
{
// Get the partial molar enthalpy of all species in the ideal gas.
thermo().getPartialMolarEnthalpies(&m_grt[0]);
thermo().getPartialMolarEnthalpies(m_grt.data());
// Use the stoichiometric manager to find deltaH for each reaction.
getReactionDelta(&m_grt[0], deltaH);
getReactionDelta(m_grt.data(), deltaH);
}
void BulkKinetics::getDeltaEntropy(doublereal* deltaS)
{
// Get the partial molar entropy of all species in the solid solution.
thermo().getPartialMolarEntropies(&m_grt[0]);
thermo().getPartialMolarEntropies(m_grt.data());
// Use the stoichiometric manager to find deltaS for each reaction.
getReactionDelta(&m_grt[0], deltaS);
getReactionDelta(m_grt.data(), deltaS);
}
void BulkKinetics::getDeltaSSGibbs(doublereal* deltaG)
@ -55,20 +55,20 @@ void BulkKinetics::getDeltaSSGibbs(doublereal* deltaG)
// array of chemical potentials at unit activity. We define these here as
// the chemical potentials of the pure species at the temperature and
// pressure of the solution.
thermo().getStandardChemPotentials(&m_grt[0]);
thermo().getStandardChemPotentials(m_grt.data());
// Use the stoichiometric manager to find deltaG for each reaction.
getReactionDelta(&m_grt[0], deltaG);
getReactionDelta(m_grt.data(), deltaG);
}
void BulkKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
{
// Get the standard state enthalpies of the species.
thermo().getEnthalpy_RT(&m_grt[0]);
thermo().getEnthalpy_RT(m_grt.data());
for (size_t k = 0; k < m_kk; k++) {
m_grt[k] *= thermo().RT();
}
// Use the stoichiometric manager to find deltaH for each reaction.
getReactionDelta(&m_grt[0], deltaH);
getReactionDelta(m_grt.data(), deltaH);
}
void BulkKinetics::getDeltaSSEntropy(doublereal* deltaS)
@ -76,12 +76,12 @@ void BulkKinetics::getDeltaSSEntropy(doublereal* deltaS)
// Get the standard state entropy of the species. We define these here as
// the entropies of the pure species at the temperature and pressure of the
// solution.
thermo().getEntropy_R(&m_grt[0]);
thermo().getEntropy_R(m_grt.data());
for (size_t k = 0; k < m_kk; k++) {
m_grt[k] *= GasConstant;
}
// Use the stoichiometric manager to find deltaS for each reaction.
getReactionDelta(&m_grt[0], deltaS);
getReactionDelta(m_grt.data(), deltaS);
}
void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)
@ -94,7 +94,7 @@ void BulkKinetics::getRevRateConstants(doublereal* krev, bool doIrreversible)
getFwdRateConstants(krev);
if (doIrreversible) {
getEquilibriumConstants(&m_ropnet[0]);
getEquilibriumConstants(m_ropnet.data());
for (size_t i = 0; i < nReactions(); i++) {
krev[i] /= m_ropnet[i];
}
@ -150,16 +150,6 @@ void BulkKinetics::init()
void BulkKinetics::finalize()
{
m_finalized = true;
// Guarantee that these arrays can be converted to double* even in the
// special case where there are no reactions defined.
if (!nReactions()) {
m_perturb.resize(1, 1.0);
m_ropf.resize(1, 0.0);
m_ropr.resize(1, 0.0);
m_ropnet.resize(1, 0.0);
m_rkcn.resize(1, 0.0);
}
}
bool BulkKinetics::ready() const

View file

@ -38,15 +38,15 @@ void GasKinetics::update_rates_T()
if (T != m_temp) {
if (!m_rfn.empty()) {
m_rates.update(T, logT, &m_rfn[0]);
m_rates.update(T, logT, m_rfn.data());
}
if (!m_rfn_low.empty()) {
m_falloff_low_rates.update(T, logT, &m_rfn_low[0]);
m_falloff_high_rates.update(T, logT, &m_rfn_high[0]);
m_falloff_low_rates.update(T, logT, m_rfn_low.data());
m_falloff_high_rates.update(T, logT, m_rfn_high.data());
}
if (!falloff_work.empty()) {
m_falloffn.updateTemp(T, &falloff_work[0]);
m_falloffn.updateTemp(T, falloff_work.data());
}
updateKc();
m_ROP_ok = false;
@ -54,12 +54,12 @@ void GasKinetics::update_rates_T()
if (T != m_temp || P != m_pres) {
if (m_plog_rates.nReactions()) {
m_plog_rates.update(T, logT, &m_rfn[0]);
m_plog_rates.update(T, logT, m_rfn.data());
m_ROP_ok = false;
}
if (m_cheb_rates.nReactions()) {
m_cheb_rates.update(T, logT, &m_rfn[0]);
m_cheb_rates.update(T, logT, m_rfn.data());
m_ROP_ok = false;
}
}
@ -69,17 +69,17 @@ void GasKinetics::update_rates_T()
void GasKinetics::update_rates_C()
{
thermo().getActivityConcentrations(&m_conc[0]);
thermo().getActivityConcentrations(m_conc.data());
doublereal ctot = thermo().molarDensity();
// 3-body reactions
if (!concm_3b_values.empty()) {
m_3b_concm.update(m_conc, ctot, &concm_3b_values[0]);
m_3b_concm.update(m_conc, ctot, concm_3b_values.data());
}
// Falloff reactions
if (!concm_falloff_values.empty()) {
m_falloff_concm.update(m_conc, ctot, &concm_falloff_values[0]);
m_falloff_concm.update(m_conc, ctot, concm_falloff_values.data());
}
// P-log reactions
@ -99,11 +99,11 @@ void GasKinetics::update_rates_C()
void GasKinetics::updateKc()
{
thermo().getStandardChemPotentials(&m_grt[0]);
thermo().getStandardChemPotentials(m_grt.data());
fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
// compute Delta G^0 for all reversible reactions
getRevReactionDelta(&m_grt[0], &m_rkcn[0]);
getRevReactionDelta(m_grt.data(), m_rkcn.data());
doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < m_revindex.size(); i++) {
@ -120,11 +120,11 @@ void GasKinetics::updateKc()
void GasKinetics::getEquilibriumConstants(doublereal* kc)
{
update_rates_T();
thermo().getStandardChemPotentials(&m_grt[0]);
thermo().getStandardChemPotentials(m_grt.data());
fill(m_rkcn.begin(), m_rkcn.end(), 0.0);
// compute Delta G^0 for all reactions
getReactionDelta(&m_grt[0], &m_rkcn[0]);
getReactionDelta(m_grt.data(), m_rkcn.data());
doublereal rrt = 1.0/(GasConstant * thermo().temperature());
for (size_t i = 0; i < nReactions(); i++) {
@ -147,8 +147,7 @@ void GasKinetics::processFalloffReactions()
"pr[" + int2str(i) + "] is not finite.");
}
double* work = (falloff_work.empty()) ? 0 : &falloff_work[0];
m_falloffn.pr_to_falloff(&pr[0], work);
m_falloffn.pr_to_falloff(pr.data(), falloff_work.data());
for (size_t i = 0; i < m_nfall; i++) {
if (reactionType(m_fallindx[i]) == FALLOFF_RXN) {
@ -175,7 +174,7 @@ void GasKinetics::updateROP()
// multiply ropf by enhanced 3b conc for all 3b rxns
if (!concm_3b_values.empty()) {
m_3b_concm.multiply(&m_ropf[0], &concm_3b_values[0]);
m_3b_concm.multiply(m_ropf.data(), concm_3b_values.data());
}
if (m_nfall) {
@ -193,10 +192,10 @@ void GasKinetics::updateROP()
multiply_each(m_ropr.begin(), m_ropr.end(), m_rkcn.begin());
// multiply ropf by concentration products
m_reactantStoich.multiply(&m_conc[0], &m_ropf[0]);
m_reactantStoich.multiply(m_conc.data(), m_ropf.data());
// for reversible reactions, multiply ropr by concentration products
m_revProductStoich.multiply(&m_conc[0], &m_ropr[0]);
m_revProductStoich.multiply(m_conc.data(), m_ropr.data());
for (size_t j = 0; j != nReactions(); ++j) {
m_ropnet[j] = m_ropf[j] - m_ropr[j];
@ -223,7 +222,7 @@ void GasKinetics::getFwdRateConstants(doublereal* kfwd)
// multiply ropf by enhanced 3b conc for all 3b rxns
if (!concm_3b_values.empty()) {
m_3b_concm.multiply(&m_ropf[0], &concm_3b_values[0]);
m_3b_concm.multiply(m_ropf.data(), concm_3b_values.data());
}
if (m_nfall) {

View file

@ -132,8 +132,8 @@ void InterfaceKinetics::_update_rates_T()
// First task is update the electrical potentials from the Phases
_update_rates_phi();
if (m_has_coverage_dependence) {
m_surf->getCoverages(DATA_PTR(m_actConc));
m_rates.update_C(DATA_PTR(m_actConc));
m_surf->getCoverages(m_actConc.data());
m_rates.update_C(m_actConc.data());
m_redo_rates = true;
}
@ -144,16 +144,16 @@ void InterfaceKinetics::_update_rates_T()
m_logtemp = log(T);
// Calculate the forward rate constant by calling m_rates and store it in m_rfn[]
m_rates.update(T, m_logtemp, DATA_PTR(m_rfn));
applyStickingCorrection(&m_rfn[0]);
m_rates.update(T, m_logtemp, m_rfn.data());
applyStickingCorrection(m_rfn.data());
// If we need to do conversions between exchange current density formulation and regular formulation
// (either way) do it here.
if (m_has_exchange_current_density_formulation) {
convertExchangeCurrentDensityFormulation(DATA_PTR(m_rfn));
convertExchangeCurrentDensityFormulation(m_rfn.data());
}
if (m_has_electrochem_rxns) {
applyVoltageKfwdCorrection(DATA_PTR(m_rfn));
applyVoltageKfwdCorrection(m_rfn.data());
}
m_temp = T;
updateKc();
@ -186,10 +186,10 @@ void InterfaceKinetics::_update_rates_C()
* are integer indices for that vector denoting the start of the
* species for each phase.
*/
tp->getActivityConcentrations(DATA_PTR(m_actConc) + m_start[n]);
tp->getActivityConcentrations(m_actConc.data() + m_start[n]);
// Get regular concentrations too
tp->getConcentrations(DATA_PTR(m_conc) + m_start[n]);
tp->getConcentrations(m_conc.data() + m_start[n]);
}
m_ROP_ok = false;
}
@ -213,7 +213,7 @@ void InterfaceKinetics::updateKc()
doublereal rrt = 1.0 / (GasConstant * thermo(0).temperature());
// compute Delta mu^0 for all reversible reactions
getRevReactionDelta(DATA_PTR(m_mu0_Kc), DATA_PTR(m_rkcn));
getRevReactionDelta(m_mu0_Kc.data(), m_rkcn.data());
for (size_t i = 0; i < m_nrev; i++) {
size_t irxn = m_revindex[i];
@ -242,7 +242,7 @@ void InterfaceKinetics::updateMu0()
size_t nsp, ik = 0;
size_t np = nPhases();
for (size_t n = 0; n < np; n++) {
thermo(n).getStandardChemPotentials(DATA_PTR(m_mu0) + m_start[n]);
thermo(n).getStandardChemPotentials(m_mu0.data() + m_start[n]);
nsp = thermo(n).nSpecies();
for (size_t k = 0; k < nsp; k++) {
m_mu0_Kc[ik] = m_mu0[ik] + Faraday * m_phi[n] * thermo(n).charge(k);
@ -264,7 +264,7 @@ void InterfaceKinetics::checkPartialEquil()
size_t nsp, ik=0;
doublereal delta;
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getChemPotentials(DATA_PTR(dmu) + m_start[n]);
thermo(n).getChemPotentials(dmu.data() + m_start[n]);
nsp = thermo(n).nSpecies();
for (size_t k = 0; k < nsp; k++) {
delta = Faraday * m_phi[n] * thermo(n).charge(k);
@ -274,7 +274,7 @@ void InterfaceKinetics::checkPartialEquil()
}
// compute Delta mu^ for all reversible reactions
getRevReactionDelta(DATA_PTR(dmu), DATA_PTR(rmu));
getRevReactionDelta(dmu.data(), rmu.data());
updateROP();
for (size_t i = 0; i < m_nrev; i++) {
size_t irxn = m_revindex[i];
@ -292,7 +292,7 @@ void InterfaceKinetics::getEquilibriumConstants(doublereal* kc)
updateMu0();
doublereal rrt = 1.0 / (GasConstant * thermo(0).temperature());
std::fill(kc, kc + nReactions(), 0.0);
getReactionDelta(DATA_PTR(m_mu0_Kc), kc);
getReactionDelta(m_mu0_Kc.data(), kc);
for (size_t i = 0; i < nReactions(); i++) {
kc[i] = exp(-kc[i]*rrt);
}
@ -317,7 +317,7 @@ void InterfaceKinetics::updateExchangeCurrentQuantities()
size_t ik = 0;
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getStandardChemPotentials(DATA_PTR(m_mu0) + m_start[n]);
thermo(n).getStandardChemPotentials(m_mu0.data() + m_start[n]);
size_t nsp = thermo(n).nSpecies();
for (size_t k = 0; k < nsp; k++) {
m_StandardConc[ik] = thermo(n).standardConcentration(k);
@ -325,13 +325,13 @@ void InterfaceKinetics::updateExchangeCurrentQuantities()
}
}
getReactionDelta(DATA_PTR(m_mu0), DATA_PTR(m_deltaG0));
getReactionDelta(m_mu0.data(), m_deltaG0.data());
// Calculate the product of the standard concentrations of the reactants
for (size_t i = 0; i < nReactions(); i++) {
m_ProdStanConcReac[i] = 1.0;
}
m_reactantStoich.multiply(DATA_PTR(m_StandardConc), DATA_PTR(m_ProdStanConcReac));
m_reactantStoich.multiply(m_StandardConc.data(), m_ProdStanConcReac.data());
}
void InterfaceKinetics::applyVoltageKfwdCorrection(doublereal* const kf)
@ -349,7 +349,7 @@ void InterfaceKinetics::applyVoltageKfwdCorrection(doublereal* const kf)
// Compute the change in electrical potential energy for each
// reaction. This will only be non-zero if a potential
// difference is present.
getReactionDelta(DATA_PTR(m_pot), DATA_PTR(deltaElectricEnergy_));
getReactionDelta(m_pot.data(), deltaElectricEnergy_.data());
// Modify the reaction rates. Only modify those with a
// non-zero activation energy. Below we decrease the
@ -432,7 +432,7 @@ void InterfaceKinetics::getRevRateConstants(doublereal* krev, bool doIrreversibl
{
getFwdRateConstants(krev);
if (doIrreversible) {
getEquilibriumConstants(&m_ropnet[0]);
getEquilibriumConstants(m_ropnet.data());
for (size_t i = 0; i < nReactions(); i++) {
krev[i] /= m_ropnet[i];
}
@ -468,10 +468,10 @@ void InterfaceKinetics::updateROP()
// multiply ropf by the activity concentration reaction orders to obtain
// the forward rates of progress.
m_reactantStoich.multiply(DATA_PTR(m_actConc), DATA_PTR(m_ropf));
m_reactantStoich.multiply(m_actConc.data(), m_ropf.data());
// For reversible reactions, multiply ropr by the activity concentration products
m_revProductStoich.multiply(DATA_PTR(m_actConc), DATA_PTR(m_ropr));
m_revProductStoich.multiply(m_actConc.data(), m_ropr.data());
// Fix up these calculations for cases where the above formalism doesn't hold
double OCV = 0.0;
@ -552,12 +552,12 @@ void InterfaceKinetics::getDeltaGibbs(doublereal* deltaG)
* kinetics mechanism
*/
for (size_t n = 0; n < nPhases(); n++) {
m_thermo[n]->getChemPotentials(DATA_PTR(m_mu) + m_start[n]);
m_thermo[n]->getChemPotentials(m_mu.data() + m_start[n]);
}
// Use the stoichiometric manager to find deltaG for each reaction.
getReactionDelta(DATA_PTR(m_mu), DATA_PTR(m_deltaG));
if (deltaG != 0 && (DATA_PTR(m_deltaG) != deltaG)) {
getReactionDelta(m_mu.data(), m_deltaG.data());
if (deltaG != 0 && (m_deltaG.data() != deltaG)) {
for (size_t j = 0; j < nReactions(); ++j) {
deltaG[j] = m_deltaG[j];
}
@ -571,13 +571,13 @@ void InterfaceKinetics::getDeltaElectrochemPotentials(doublereal* deltaM)
*/
size_t np = nPhases();
for (size_t n = 0; n < np; n++) {
thermo(n).getElectrochemPotentials(DATA_PTR(m_grt) + m_start[n]);
thermo(n).getElectrochemPotentials(m_grt.data() + m_start[n]);
}
/*
* Use the stoichiometric manager to find deltaG for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_grt), deltaM);
getReactionDelta(m_grt.data(), deltaM);
}
void InterfaceKinetics::getDeltaEnthalpy(doublereal* deltaH)
@ -586,13 +586,13 @@ void InterfaceKinetics::getDeltaEnthalpy(doublereal* deltaH)
* Get the partial molar enthalpy of all species
*/
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getPartialMolarEnthalpies(DATA_PTR(m_grt) + m_start[n]);
thermo(n).getPartialMolarEnthalpies(m_grt.data() + m_start[n]);
}
/*
* Use the stoichiometric manager to find deltaG for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_grt), deltaH);
getReactionDelta(m_grt.data(), deltaH);
}
void InterfaceKinetics::getDeltaEntropy(doublereal* deltaS)
@ -602,13 +602,13 @@ void InterfaceKinetics::getDeltaEntropy(doublereal* deltaS)
* the phases
*/
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getPartialMolarEntropies(DATA_PTR(m_grt) + m_start[n]);
thermo(n).getPartialMolarEntropies(m_grt.data() + m_start[n]);
}
/*
* Use the stoichiometric manager to find deltaS for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_grt), deltaS);
getReactionDelta(m_grt.data(), deltaS);
}
void InterfaceKinetics::getDeltaSSGibbs(doublereal* deltaGSS)
@ -620,13 +620,13 @@ void InterfaceKinetics::getDeltaSSGibbs(doublereal* deltaGSS)
* species at the temperature and pressure of the solution.
*/
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getStandardChemPotentials(DATA_PTR(m_mu0) + m_start[n]);
thermo(n).getStandardChemPotentials(m_mu0.data() + m_start[n]);
}
/*
* Use the stoichiometric manager to find deltaG for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_mu0), deltaGSS);
getReactionDelta(m_mu0.data(), deltaGSS);
}
void InterfaceKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
@ -638,7 +638,7 @@ void InterfaceKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
* species at the temperature and pressure of the solution.
*/
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getEnthalpy_RT(DATA_PTR(m_grt) + m_start[n]);
thermo(n).getEnthalpy_RT(m_grt.data() + m_start[n]);
}
for (size_t k = 0; k < m_kk; k++) {
m_grt[k] *= thermo(0).RT();
@ -647,7 +647,7 @@ void InterfaceKinetics::getDeltaSSEnthalpy(doublereal* deltaH)
* Use the stoichiometric manager to find deltaG for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_grt), deltaH);
getReactionDelta(m_grt.data(), deltaH);
}
void InterfaceKinetics::getDeltaSSEntropy(doublereal* deltaS)
@ -658,7 +658,7 @@ void InterfaceKinetics::getDeltaSSEntropy(doublereal* deltaS)
* species at the temperature and pressure of the solution.
*/
for (size_t n = 0; n < nPhases(); n++) {
thermo(n).getEntropy_R(DATA_PTR(m_grt) + m_start[n]);
thermo(n).getEntropy_R(m_grt.data() + m_start[n]);
}
for (size_t k = 0; k < m_kk; k++) {
m_grt[k] *= GasConstant;
@ -667,7 +667,7 @@ void InterfaceKinetics::getDeltaSSEntropy(doublereal* deltaS)
* Use the stoichiometric manager to find deltaS for each
* reaction.
*/
getReactionDelta(DATA_PTR(m_grt), deltaS);
getReactionDelta(m_grt.data(), deltaS);
}
bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base)
@ -883,8 +883,7 @@ void InterfaceKinetics::init()
void InterfaceKinetics::finalize()
{
Kinetics::finalize();
size_t safe_reaction_size = std::max<size_t>(nReactions(), 1);
deltaElectricEnergy_.resize(safe_reaction_size);
deltaElectricEnergy_.resize(nReactions());
size_t ks = reactionPhaseIndex();
if (ks == npos) throw CanteraError("InterfaceKinetics::finalize",
"no surface phase is present.");
@ -897,23 +896,13 @@ void InterfaceKinetics::finalize()
+int2str(m_surf->nDim()));
}
m_StandardConc.resize(m_kk, 0.0);
m_deltaG0.resize(safe_reaction_size, 0.0);
m_deltaG.resize(safe_reaction_size, 0.0);
m_ProdStanConcReac.resize(safe_reaction_size, 0.0);
m_deltaG0.resize(nReactions(), 0.0);
m_deltaG.resize(nReactions(), 0.0);
m_ProdStanConcReac.resize(nReactions(), 0.0);
if (m_thermo.size() != m_phaseExists.size()) {
throw CanteraError("InterfaceKinetics::finalize", "internal error");
}
// Guarantee that these arrays can be converted to double* even in the
// special case where there are no reactions defined.
if (!nReactions()) {
m_perturb.resize(1, 1.0);
m_ropf.resize(1, 0.0);
m_ropr.resize(1, 0.0);
m_ropnet.resize(1, 0.0);
m_rkcn.resize(1, 0.0);
}
m_finalized = true;
}

View file

@ -455,11 +455,11 @@ void Kinetics::getCreationRates(double* cdot)
fill(cdot, cdot + m_kk, 0.0);
// the forward direction creates product species
m_revProductStoich.incrementSpecies(&m_ropf[0], cdot);
m_irrevProductStoich.incrementSpecies(&m_ropf[0], cdot);
m_revProductStoich.incrementSpecies(m_ropf.data(), cdot);
m_irrevProductStoich.incrementSpecies(m_ropf.data(), cdot);
// the reverse direction creates reactant species
m_reactantStoich.incrementSpecies(&m_ropr[0], cdot);
m_reactantStoich.incrementSpecies(m_ropr.data(), cdot);
}
void Kinetics::getDestructionRates(doublereal* ddot)
@ -468,9 +468,9 @@ void Kinetics::getDestructionRates(doublereal* ddot)
fill(ddot, ddot + m_kk, 0.0);
// the reverse direction destroys products in reversible reactions
m_revProductStoich.incrementSpecies(&m_ropr[0], ddot);
m_revProductStoich.incrementSpecies(m_ropr.data(), ddot);
// the forward direction destroys reactants
m_reactantStoich.incrementSpecies(&m_ropf[0], ddot);
m_reactantStoich.incrementSpecies(m_ropf.data(), ddot);
}
void Kinetics::getNetProductionRates(doublereal* net)
@ -479,10 +479,10 @@ void Kinetics::getNetProductionRates(doublereal* net)
fill(net, net + m_kk, 0.0);
// products are created for positive net rate of progress
m_revProductStoich.incrementSpecies(&m_ropnet[0], net);
m_irrevProductStoich.incrementSpecies(&m_ropnet[0], net);
m_revProductStoich.incrementSpecies(m_ropnet.data(), net);
m_irrevProductStoich.incrementSpecies(m_ropnet.data(), net);
// reactants are destroyed for positive net rate of progress
m_reactantStoich.decrementSpecies(&m_ropnet[0], net);
m_reactantStoich.decrementSpecies(m_ropnet.data(), net);
}
void Kinetics::addPhase(thermo_t& thermo)