doublereal Elements::entropyElement298(size_t m) const { AssertThrowMsg(m_entropy298[m] != ENTROPY298_UNKNOWN, "Elements::entropy298", "Entropy at 298 K of element is unknown"); AssertTrace(m < m_mm); return (m_entropy298[m]); }
void VCS_SOLVE::vcs_switch_elem_pos(size_t ipos, size_t jpos) { if (ipos == jpos) { return; } AssertThrowMsg(ipos < m_nelem && jpos < m_nelem, "vcs_switch_elem_pos", "inappropriate args: {} {}", ipos, jpos); // Change the element Global Index list in each vcs_VolPhase object // to reflect the switch in the element positions. for (size_t iph = 0; iph < m_numPhases; iph++) { vcs_VolPhase* volPhase = m_VolPhaseList[iph].get(); for (size_t e = 0; e < volPhase->nElemConstraints(); e++) { if (volPhase->elemGlobalIndex(e) == ipos) { volPhase->setElemGlobalIndex(e, jpos); } if (volPhase->elemGlobalIndex(e) == jpos) { volPhase->setElemGlobalIndex(e, ipos); } } } std::swap(m_elemAbundancesGoal[ipos], m_elemAbundancesGoal[jpos]); std::swap(m_elemAbundances[ipos], m_elemAbundances[jpos]); std::swap(m_elementMapIndex[ipos], m_elementMapIndex[jpos]); std::swap(m_elType[ipos], m_elType[jpos]); std::swap(m_elementActive[ipos], m_elementActive[jpos]); for (size_t j = 0; j < m_nsp; ++j) { std::swap(m_formulaMatrix(j,ipos), m_formulaMatrix(j,jpos)); } std::swap(m_elementName[ipos], m_elementName[jpos]); }
doublereal Sim1D::workValue(size_t dom, size_t comp, size_t localPoint) const { size_t iloc = domain(dom).loc() + domain(dom).index(comp, localPoint); AssertThrowMsg(iloc < m_x.size(), "Sim1D::workValue", "Index out of bounds:" + int2str(iloc) + " > " + int2str(m_x.size())); return m_xnew[iloc]; }
void Sim1D::setValue(size_t dom, size_t comp, size_t localPoint, doublereal value) { size_t iloc = domain(dom).loc() + domain(dom).index(comp, localPoint); AssertThrowMsg(iloc < m_x.size(), "Sim1D::setValue", "Index out of bounds:" + int2str(iloc) + " > " + int2str(m_x.size())); m_x[iloc] = value; }
/* * void _updateStandardStateThermo() (protected, virtual, const) * * If m_useTmpStandardStateStorage is true, * This function must be called for every call to functions in this * class that need standard state properties. * Child classes may require that it be called even if m_useTmpStandardStateStorage * is not true. * It checks to see whether the temperature has changed and * thus the ss thermodynamics functions for all of the species * must be recalculated. * * This */ void VPStandardStateTP::_updateStandardStateThermo() const { double Tnow = temperature(); m_Plast_ss = m_Pcurrent; m_Tlast_ss = Tnow; AssertThrowMsg(m_VPSS_ptr != 0, "VPStandardStateTP::_updateStandardStateThermo()", "Probably indicates that ThermoPhase object wasn't initialized correctly"); m_VPSS_ptr->setState_TP(Tnow, m_Pcurrent); }
/* * setSolvent(): * Utilities for Solvent ID and Molality * Here we also calculate and store the molecular weight * of the solvent and the m_Mnaught parameter. * @param k index of the solvent. */ void MolalityVPSSTP::setSolvent(size_t k) { if (k >= m_kk) { throw CanteraError("MolalityVPSSTP::setSolute ", "bad value"); } m_indexSolvent = k; AssertThrowMsg(m_indexSolvent==0, "MolalityVPSSTP::setSolvent", "Molality-based methods limit solvent id to being 0"); m_weightSolvent = molecularWeight(k); m_Mnaught = m_weightSolvent / 1000.; }
/*! * Given temperature T in K, this method updates the values of * the non-dimensional heat capacity at constant pressure, * enthalpy, and entropy, at the reference pressure, Pref * of one of the species. The species index is used * to reference into the cp_R, h_RT, and s_R arrays. * * @param temp Temperature (Kelvin) * @param cp_R Vector of Dimensionless heat capacities. * (length m_kk). * @param h_RT Vector of Dimensionless enthalpies. * (length m_kk). * @param s_R Vector of Dimensionless entropies. * (length m_kk). */ void STITbyPDSS::updatePropertiesTemp(const doublereal temp, doublereal* cp_R, doublereal* h_RT, doublereal* s_R) const { //m_vpssmgr_ptr->setState_T(temp); m_PDSS_ptr->setTemperature(temp); AssertThrowMsg(m_speciesIndex >= 0, "STITbyPDSS::updatePropertiesTemp", "object was probably not installed correctly"); h_RT[m_speciesIndex] = m_PDSS_ptr->enthalpy_RT_ref(); cp_R[m_speciesIndex] = m_PDSS_ptr->cp_R_ref(); s_R[m_speciesIndex] = m_PDSS_ptr->entropy_R_ref(); }
size_t VCS_PROB::addOnePhaseSpecies(vcs_VolPhase* volPhase, size_t k, size_t kT) { if (kT > nspecies) { // Need to expand the number of species here throw CanteraError("VCS_PROB::addOnePhaseSpecies", "Shouldn't be here"); } const Array2D& fm = volPhase->getFormulaMatrix(); for (size_t eVP = 0; eVP < volPhase->nElemConstraints(); eVP++) { size_t e = volPhase->elemGlobalIndex(eVP); AssertThrowMsg(e != npos, "VCS_PROB::addOnePhaseSpecies", "element not found"); FormulaMatrix(kT,e) = fm(k,eVP); } // Tell the phase object about the current position of the species within // the global species vector volPhase->setSpGlobalIndexVCS(k, kT); return kT; }
void vcs_VolPhase::setTotalMoles(const double totalMols) { v_totalMoles = totalMols; if (m_totalMolesInert > 0.0) { m_existence = VCS_PHASE_EXIST_ALWAYS; AssertThrowMsg(totalMols >= m_totalMolesInert, "vcs_VolPhase::setTotalMoles", "totalMoles less than inert moles: " + fp2str(totalMols) + " " + fp2str(m_totalMolesInert)); } else { if (m_singleSpecies && (m_phiVarIndex == 0)) { m_existence = VCS_PHASE_EXIST_ALWAYS; } else { if (totalMols > 0.0) { m_existence = VCS_PHASE_EXIST_YES; } else { m_existence = VCS_PHASE_EXIST_NO; } } } }
void MultiSpeciesThermo::install_STIT(size_t index, shared_ptr<SpeciesThermoInterpType> stit_ptr) { if (!stit_ptr) { throw CanteraError("MultiSpeciesThermo::install_STIT", "null pointer"); } AssertThrowMsg(m_speciesLoc.find(index) == m_speciesLoc.end(), "MultiSpeciesThermo::install_STIT", "Index position isn't null, duplication of assignment: {}", index); int type = stit_ptr->reportType(); m_speciesLoc[index] = {type, m_sp[type].size()}; m_sp[type].emplace_back(index, stit_ptr); if (m_sp[type].size() == 1) { m_tpoly[type].resize(stit_ptr->temperaturePolySize()); } // Calculate max and min T m_tlow_max = std::max(stit_ptr->minTemp(), m_tlow_max); m_thigh_min = std::min(stit_ptr->maxTemp(), m_thigh_min); markInstalled(index); }
void vcs_VolPhase::setMolesFromVCS(const int stateCalc, const double* molesSpeciesVCS) { v_totalMoles = m_totalMolesInert; if (molesSpeciesVCS == 0) { AssertThrowMsg(m_owningSolverObject, "vcs_VolPhase::setMolesFromVCS", "shouldn't be here"); if (stateCalc == VCS_STATECALC_OLD) { molesSpeciesVCS = VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old); } else if (stateCalc == VCS_STATECALC_NEW) { molesSpeciesVCS = VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new); } else if (DEBUG_MODE_ENABLED) { throw CanteraError("vcs_VolPhase::setMolesFromVCS", "shouldn't be here"); } } else if (DEBUG_MODE_ENABLED && m_owningSolverObject) { if (stateCalc == VCS_STATECALC_OLD) { if (molesSpeciesVCS != VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_old)) { throw CanteraError("vcs_VolPhase::setMolesFromVCS", "shouldn't be here"); } } else if (stateCalc == VCS_STATECALC_NEW) { if (molesSpeciesVCS != VCS_DATA_PTR(m_owningSolverObject->m_molNumSpecies_new)) { throw CanteraError("vcs_VolPhase::setMolesFromVCS", "shouldn't be here"); } } } for (size_t k = 0; k < m_numSpecies; k++) { if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { size_t kglob = IndSpecies[k]; v_totalMoles += std::max(0.0, molesSpeciesVCS[kglob]); } } if (v_totalMoles > 0.0) { for (size_t k = 0; k < m_numSpecies; k++) { if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) { size_t kglob = IndSpecies[k]; double tmp = std::max(0.0, molesSpeciesVCS[kglob]); Xmol_[k] = tmp / v_totalMoles; } } m_existence = VCS_PHASE_EXIST_YES; } else { // This is where we will start to store a better approximation // for the mole fractions, when the phase doesn't exist. // This is currently unimplemented. m_existence = VCS_PHASE_EXIST_NO; } /* * Update the electric potential if it is a solution variable * in the equation system */ if (m_phiVarIndex != npos) { size_t kglob = IndSpecies[m_phiVarIndex]; if (m_numSpecies == 1) { Xmol_[m_phiVarIndex] = 1.0; } else { Xmol_[m_phiVarIndex] = 0.0; } double phi = molesSpeciesVCS[kglob]; setElectricPotential(phi); if (m_numSpecies == 1) { m_existence = VCS_PHASE_EXIST_YES; } } _updateMoleFractionDependencies(); if (m_totalMolesInert > 0.0) { m_existence = VCS_PHASE_EXIST_ALWAYS; } /* * If stateCalc is old and the total moles is positive, * then we have a valid state. If the phase went away, it would * be a valid starting point for F_k's. So, save the state. */ if (stateCalc == VCS_STATECALC_OLD) { if (v_totalMoles > 0.0) { creationMoleNumbers_ = Xmol_; } } /* * Set flags indicating we are up to date with the VCS state vector. */ m_UpToDate = true; m_vcsStateStatus = stateCalc; }
void vcs_VolPhase::resize(const size_t phaseNum, const size_t nspecies, const size_t numElem, const char* const phaseName, const double molesInert) { AssertThrowMsg(nspecies > 0, "vcs_VolPhase::resize", "nspecies Error"); setTotalMolesInert(molesInert); m_phi = 0.0; m_phiVarIndex = npos; if (phaseNum == VP_ID_) { if (strcmp(PhaseName.c_str(), phaseName)) { throw CanteraError("vcs_VolPhase::resize", "Strings are different: " + PhaseName + " " + phaseName + " :unknown situation"); } } else { VP_ID_ = phaseNum; if (!phaseName) { std::stringstream sstmp; sstmp << "Phase_" << VP_ID_; PhaseName = sstmp.str(); } else { PhaseName = phaseName; } } if (nspecies > 1) { m_singleSpecies = false; } else { m_singleSpecies = true; } if (m_numSpecies == nspecies && numElem == m_numElemConstraints) { return; } m_numSpecies = nspecies; if (nspecies > 1) { m_singleSpecies = false; } IndSpecies.resize(nspecies, npos); if (ListSpeciesPtr.size() >= m_numSpecies) { for (size_t i = 0; i < m_numSpecies; i++) { if (ListSpeciesPtr[i]) { delete ListSpeciesPtr[i]; ListSpeciesPtr[i] = 0; } } } ListSpeciesPtr.resize(nspecies, 0); for (size_t i = 0; i < nspecies; i++) { ListSpeciesPtr[i] = new vcs_SpeciesProperties(phaseNum, i, this); } Xmol_.resize(nspecies, 0.0); creationMoleNumbers_.resize(nspecies, 0.0); creationGlobalRxnNumbers_.resize(nspecies, npos); for (size_t i = 0; i < nspecies; i++) { Xmol_[i] = 1.0/nspecies; creationMoleNumbers_[i] = 1.0/nspecies; if (IndSpecies[i] >= m_numElemConstraints) { creationGlobalRxnNumbers_[i] = IndSpecies[i] - m_numElemConstraints; } else { creationGlobalRxnNumbers_[i] = npos; } } SS0ChemicalPotential.resize(nspecies, -1.0); StarChemicalPotential.resize(nspecies, -1.0); StarMolarVol.resize(nspecies, -1.0); PartialMolarVol.resize(nspecies, -1.0); ActCoeff.resize(nspecies, 1.0); np_dLnActCoeffdMolNumber.resize(nspecies, nspecies, 0.0); m_speciesUnknownType.resize(nspecies, VCS_SPECIES_TYPE_MOLNUM); m_UpToDate = false; m_vcsStateStatus = VCS_STATECALC_OLD; m_UpToDate_AC = false; m_UpToDate_VolStar = false; m_UpToDate_VolPM = false; m_UpToDate_GStar = false; m_UpToDate_G0 = false; elemResize(numElem); }