Merge nested if statements

This commit is contained in:
Ray Speth 2015-07-31 20:48:45 -04:00
parent 546eede80c
commit 801334c84e
45 changed files with 694 additions and 1019 deletions

View file

@ -173,12 +173,10 @@ int XML_Reader::findQuotedString(const std::string& s, std::string& rstring) con
ilocStart = iloc2;
qtype = q2;
}
if (iloc1 != string::npos) {
if (iloc1 < ilocStart) {
if (iloc1 != string::npos && iloc1 < ilocStart) {
ilocStart = iloc1;
qtype = q1;
}
}
if (qtype == ' ') {
return 0;
}
@ -349,13 +347,11 @@ XML_Node& XML_Node::operator=(const XML_Node& right)
{
if (&right != this) {
for (size_t i = 0; i < m_children.size(); i++) {
if (m_children[i]) {
if (m_children[i]->parent() == this) {
if (m_children[i] && m_children[i]->parent() == this) {
delete m_children[i];
m_children[i] = 0;
}
}
}
m_children.resize(0);
right.copy(this);
}
@ -368,25 +364,21 @@ XML_Node::~XML_Node()
writelog("XML_Node::~XML_Node: deleted a locked XML_Node: "+name());
}
for (size_t i = 0; i < m_children.size(); i++) {
if (m_children[i]) {
if (m_children[i]->parent() == this) {
if (m_children[i] && m_children[i]->parent() == this) {
delete m_children[i];
m_children[i] = 0;
}
}
}
}
void XML_Node::clear()
{
for (size_t i = 0; i < m_children.size(); i++) {
if (m_children[i]) {
if (m_children[i]->parent() == this) {
if (m_children[i] && m_children[i]->parent() == this) {
delete m_children[i];
m_children[i] = 0;
}
}
}
m_value.clear();
m_childindex.clear();
m_attribs.clear();
@ -593,11 +585,9 @@ bool XML_Node::isComment() const
void XML_Node::_require(const std::string& a, const std::string& v) const
{
if (hasAttrib(a)) {
if (attrib(a) == v) {
if (hasAttrib(a) && attrib(a) == v) {
return;
}
}
string msg="XML_Node "+name()+" is required to have an attribute named " + a +
" with the value \"" + v +"\", but instead the value is \"" + attrib(a);
throw CanteraError("XML_Node::require", msg);
@ -609,11 +599,9 @@ XML_Node* XML_Node::findNameID(const std::string& nameTarget,
XML_Node* scResult = 0;
XML_Node* sc;
std::string idattrib = id();
if (name() == nameTarget) {
if (idTarget == "" || idTarget == idattrib) {
if (name() == nameTarget && (idTarget == "" || idTarget == idattrib)) {
return const_cast<XML_Node*>(this);
}
}
for (size_t n = 0; n < m_children.size(); n++) {
sc = m_children[n];
if (sc->name() == nameTarget) {
@ -645,24 +633,18 @@ XML_Node* XML_Node::findNameIDIndex(const std::string& nameTarget,
std::string ii = attrib("index");
std::string index_s = int2str(index_i);
int iMax = -1000000;
if (name() == nameTarget) {
if (idTarget == "" || idTarget == idattrib) {
if (index_s == ii) {
if (name() == nameTarget && (idTarget == "" || idTarget == idattrib) && index_s == ii) {
return const_cast<XML_Node*>(this);
}
}
}
for (size_t n = 0; n < m_children.size(); n++) {
sc = m_children[n];
if (sc->name() == nameTarget) {
ii = sc->attrib("index");
int indexR = atoi(ii.c_str());
idattrib = sc->id();
if (idTarget == idattrib || idTarget == "") {
if (index_s == ii) {
if ((idTarget == idattrib || idTarget == "") && index_s == ii) {
return sc;
}
}
if (indexR > iMax) {
scResult = sc;
iMax = indexR;
@ -674,11 +656,9 @@ XML_Node* XML_Node::findNameIDIndex(const std::string& nameTarget,
XML_Node* XML_Node::findID(const std::string& id_, const int depth) const
{
if (hasAttrib("id")) {
if (attrib("id") == id_) {
if (hasAttrib("id") && attrib("id") == id_) {
return const_cast<XML_Node*>(this);
}
}
if (depth > 0) {
XML_Node* r = 0;
for (size_t i = 0; i < nChildren(); i++) {
@ -694,11 +674,9 @@ XML_Node* XML_Node::findID(const std::string& id_, const int depth) const
XML_Node* XML_Node::findByAttr(const std::string& attr,
const std::string& val, int depth) const
{
if (hasAttrib(attr)) {
if (attrib(attr) == val) {
if (hasAttrib(attr) && attrib(attr) == val) {
return const_cast<XML_Node*>(this);
}
}
if (depth > 0) {
XML_Node* r = 0;
size_t n = nChildren();
@ -829,26 +807,18 @@ void XML_Node::copyUnion(XML_Node* const node_dest) const
for (size_t idc = 0; idc < ndc; idc++) {
XML_Node* dcc = vsc[idc];
if (dcc->name() == sc->name()) {
if (sc->hasAttrib("id")) {
if (sc->attrib("id") != dcc->attrib("id")) {
if (sc->hasAttrib("id") && sc->attrib("id") != dcc->attrib("id")) {
break;
}
}
if (sc->hasAttrib("name")) {
if (sc->attrib("name") != dcc->attrib("name")) {
if (sc->hasAttrib("name") && sc->attrib("name") != dcc->attrib("name")) {
break;
}
}
if (sc->hasAttrib("model")) {
if (sc->attrib("model") != dcc->attrib("model")) {
if (sc->hasAttrib("model") && sc->attrib("model") != dcc->attrib("model")) {
break;
}
}
if (sc->hasAttrib("title")) {
if (sc->attrib("title") != dcc->attrib("title")) {
if (sc->hasAttrib("title") && sc->attrib("title") != dcc->attrib("title")) {
break;
}
}
dc = vsc[idc];
}
}

View file

@ -755,12 +755,10 @@ int ChemEquil::equilibrate(thermo_t& s, const char* XYstr,
}
}
// Delta Damping
if (m == mm) {
if (fabs(res_trial[mm]) > 0.2) {
if (m == mm && fabs(res_trial[mm]) > 0.2) {
fctr = std::min(fctr, 0.2/fabs(res_trial[mm]));
}
}
}
if (fctr != 1.0 && DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) {
writelogf("WARNING Soln Damping because of bounds: %g\n", fctr);
}
@ -1057,12 +1055,10 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
}
}
for (m = 0; m < m_mm; m++) {
if (m != m_eloc) {
if (elMoles[m] <= options.absElemTol) {
if (m != m_eloc && elMoles[m] <= options.absElemTol) {
x[m] = -200.;
}
}
}
/*
* -------------------------------------------------------------------
@ -1124,19 +1120,16 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
}
}
}
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) {
if (!normalStep) {
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0 && !normalStep) {
writelogf(" NOTE: iter(%d) Doing an abnormal step due to row %d\n", iter, iM);
}
}
if (!normalStep) {
beta = 1.0;
resid[m_mm] = 0.0;
for (im = 0; im < m_mm; im++) {
m = m_orderVectorElements[im];
resid[m] = 0.0;
if (im < m_nComponents) {
if (elMoles[m] > 0.001 * elMolesTotal) {
if (im < m_nComponents && elMoles[m] > 0.001 * elMolesTotal) {
if (eMolesCalc[m] > 1000. * elMoles[m]) {
resid[m] = -0.5;
resid[m_mm] -= 0.5;
@ -1147,7 +1140,6 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
}
}
}
}
if (n_t < (elMolesTotal / nAtomsMax)) {
if (resid[m_mm] < 0.0) {
resid[m_mm] = 0.1;
@ -1193,8 +1185,7 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
size_t kMSp2 = npos;
int nSpeciesWithElem = 0;
for (k = 0; k < m_kk; k++) {
if (n_i_calc[k] > nCutoff) {
if (fabs(nAtoms(k,m)) > 0.001) {
if (n_i_calc[k] > nCutoff && fabs(nAtoms(k,m)) > 0.001) {
nSpeciesWithElem++;
if (kMSp != npos) {
kMSp2 = k;
@ -1210,7 +1201,6 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
}
}
}
}
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) {
string nnn = s.elementName(m);
writelogf(" %5s %3d : %5d %5d\n",nnn.c_str(), lumpSum[m], kMSp, kMSp2);
@ -1443,12 +1433,10 @@ int ChemEquil::estimateEP_Brinkley(thermo_t& s, vector_fp& x,
beta = std::min(beta, -1.0 / resid[m]);
}
}
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) {
if (beta != 1.0) {
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0 && beta != 1.0) {
writelogf("(it %d) Beta = %g\n", iter, beta);
}
}
}
/*
* Update the solution vector
*/
@ -1498,20 +1486,16 @@ void ChemEquil::adjustEloc(thermo_t& s, vector_fp& elMolesGoal)
double maxNegVal = -1.0;
if (DEBUG_MODE_ENABLED && ChemEquil_print_lvl > 0) {
for (k = 0; k < m_kk; k++) {
if (nAtoms(k,m_eloc) > 0.0) {
if (m_molefractions[k] > maxPosVal && m_molefractions[k] > 0.0) {
if (nAtoms(k,m_eloc) > 0.0 && m_molefractions[k] > maxPosVal && m_molefractions[k] > 0.0) {
maxPosVal = m_molefractions[k];
maxPosEloc = k;
}
}
if (nAtoms(k,m_eloc) < 0.0) {
if (m_molefractions[k] > maxNegVal && m_molefractions[k] > 0.0) {
if (nAtoms(k,m_eloc) < 0.0 && m_molefractions[k] > maxNegVal && m_molefractions[k] > 0.0) {
maxNegVal = m_molefractions[k];
maxNegEloc = k;
}
}
}
}
double sumPos = 0.0;
double sumNeg = 0.0;

View file

@ -41,8 +41,7 @@ MultiPhaseEquil::MultiPhaseEquil(MultiPhase* mix, bool start, int loglevel) : m_
// it from the calculation. Electrons are a special case,
// since a species can have a negative number of 'atoms'
// of electrons (positive ions).
if (m_mix->elementMoles(m) <= 0.0) {
if (m != m_eloc) {
if (m_mix->elementMoles(m) <= 0.0 && m != m_eloc) {
m_incl_element[m] = 0;
for (k = 0; k < m_nsp_mix; k++) {
if (m_mix->nAtoms(k,m) != 0.0) {
@ -51,7 +50,6 @@ MultiPhaseEquil::MultiPhaseEquil(MultiPhase* mix, bool start, int loglevel) : m_
}
}
}
}
// Now build the list of elements to be included, starting with
// electrons, if they are present.
@ -348,13 +346,11 @@ void MultiPhaseEquil::getComponents(const std::vector<size_t>& order)
doublereal maxmoles = -999.0;
size_t kmax = 0;
for (k = m+1; k < nColumns; k++) {
if (m_A(m,k) != 0.0) {
if (fabs(m_moles[m_order[k]]) > maxmoles) {
if (m_A(m,k) != 0.0 && fabs(m_moles[m_order[k]]) > maxmoles) {
kmax = k;
maxmoles = fabs(m_moles[m_order[k]]);
}
}
}
// Now exchange the column with zero pivot with the
// column for this major species

View file

@ -44,13 +44,11 @@ double VCS_SOLVE::vcs_GibbsPhase(size_t iphase, const double* const w,
double g = 0.0;
double phaseMols = 0.0;
for (size_t kspec = 0; kspec < m_numSpeciesRdc; ++kspec) {
if (m_phaseID[kspec] == iphase) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_phaseID[kspec] == iphase && m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
g += w[kspec] * fe[kspec];
phaseMols += w[kspec];
}
}
}
if (TPhInertMoles[iphase] > 0.0) {
phaseMols += TPhInertMoles[iphase];

View file

@ -321,15 +321,13 @@ int vcs_MultiPhaseEquil::equilibrate_SP(doublereal Starget,
Tlow = Tnow;
Slow = Snow;
} else {
if (Slow > Starget) {
if (Snow < Slow) {
if (Slow > Starget && Snow < Slow) {
Thigh = Tlow;
Shigh = Slow;
Tlow = Tnow;
Slow = Snow;
}
}
}
} else {
// the current enthalpy is greater than the target; therefore the
// current temperature is too high. Set the high bounds.
@ -573,12 +571,10 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
}
plogf("------------------------------------------"
"-------------------\n");
if (printLvl > 2) {
if (m_vsolve.m_timing_print_lvl > 0) {
if (printLvl > 2 && m_vsolve.m_timing_print_lvl > 0) {
plogf("Total time = %12.6e seconds\n", te);
}
}
}
return iSuccess;
}
@ -1362,12 +1358,10 @@ int vcs_MultiPhaseEquil::determine_PhaseStability(int iph, double& funcStab, int
}
plogf("------------------------------------------"
"-------------------\n");
if (printLvl > 2) {
if (m_vsolve.m_timing_print_lvl > 0) {
if (printLvl > 2 && m_vsolve.m_timing_print_lvl > 0) {
plogf("Total time = %12.6e seconds\n", te);
}
}
}
return iStable;
}

View file

@ -493,11 +493,9 @@ void vcs_VolPhase::setMolesFromVCS(const int stateCalc,
* 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) {
if (stateCalc == VCS_STATECALC_OLD && v_totalMoles > 0.0) {
creationMoleNumbers_ = Xmol_;
}
}
/*
* Set flags indicating we are up to date with the VCS state vector.
@ -528,14 +526,11 @@ void vcs_VolPhase::setMolesFromVCSCheck(const int vcsStateStatus,
void vcs_VolPhase::updateFromVCS_MoleNumbers(const int vcsStateStatus)
{
if (!m_UpToDate || (vcsStateStatus != m_vcsStateStatus)) {
if (vcsStateStatus == VCS_STATECALC_OLD || vcsStateStatus == VCS_STATECALC_NEW) {
if (m_owningSolverObject) {
if ((!m_UpToDate || vcsStateStatus != m_vcsStateStatus) && m_owningSolverObject &&
(vcsStateStatus == VCS_STATECALC_OLD || vcsStateStatus == VCS_STATECALC_NEW)) {
setMolesFromVCS(vcsStateStatus);
}
}
}
}
void vcs_VolPhase::sendToVCS_ActCoeff(const int vcsStateStatus,
double* const AC)
@ -591,11 +586,9 @@ double vcs_VolPhase::electricPotential() const
void vcs_VolPhase::setState_TP(const double temp, const double pres)
{
if (Temp_ == temp) {
if (Pres_ == pres) {
if (Temp_ == temp && Pres_ == pres) {
return;
}
}
TP_ptr->setElectricPotential(m_phi);
TP_ptr->setState_TP(temp, pres);
Temp_ = temp;
@ -906,12 +899,10 @@ void vcs_VolPhase::setPhiVarIndex(size_t phiVarIndex)
{
m_phiVarIndex = phiVarIndex;
m_speciesUnknownType[m_phiVarIndex] = VCS_SPECIES_TYPE_INTERFACIALVOLTAGE;
if (m_singleSpecies) {
if (m_phiVarIndex == 0) {
if (m_singleSpecies && m_phiVarIndex == 0) {
m_existence = VCS_PHASE_EXIST_ALWAYS;
}
}
}
vcs_SpeciesProperties* vcs_VolPhase::speciesProperty(const size_t kindex)
{
@ -935,21 +926,15 @@ void vcs_VolPhase::setExistence(const int existence)
}
}
} else if (DEBUG_MODE_ENABLED && m_totalMolesInert == 0.0) {
if (v_totalMoles == 0.0) {
if (!m_singleSpecies || m_phiVarIndex != 0) {
if (v_totalMoles == 0.0 && (!m_singleSpecies || m_phiVarIndex != 0)) {
throw CanteraError("vcs_VolPhase::setExistence",
"setting true existence for phase with no moles");
}
}
}
if (DEBUG_MODE_ENABLED && m_singleSpecies) {
if (m_phiVarIndex == 0) {
if (existence == VCS_PHASE_EXIST_NO || existence == VCS_PHASE_EXIST_ZEROEDPHASE) {
if (DEBUG_MODE_ENABLED && m_singleSpecies && m_phiVarIndex == 0 && (existence == VCS_PHASE_EXIST_NO || existence == VCS_PHASE_EXIST_ZEROEDPHASE)) {
throw CanteraError("vcs_VolPhase::setExistence",
"Trying to set existence of an electron phase to false");
}
}
}
m_existence = existence;
}
@ -1040,11 +1025,9 @@ static bool hasChargedSpecies(const ThermoPhase* const tPhase)
static bool chargeNeutralityElement(const ThermoPhase* const tPhase)
{
int hasCharge = hasChargedSpecies(tPhase);
if (tPhase->chargeNeutralityNecessary()) {
if (hasCharge) {
if (tPhase->chargeNeutralityNecessary() && hasCharge) {
return true;
}
}
return false;
}
@ -1155,12 +1138,10 @@ size_t vcs_VolPhase::transferElementsFM(const ThermoPhase* const tPhase)
* The logic isn't set in stone, and is just for a particular type
* of problem that I'm solving first.
*/
if (ns == 1) {
if (tPhase->charge(0) != 0.0) {
if (ns == 1 && tPhase->charge(0) != 0.0) {
m_speciesUnknownType[0] = VCS_SPECIES_TYPE_INTERFACIALVOLTAGE;
setPhiVarIndex(0);
}
}
return ne;
}

View file

@ -32,8 +32,7 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
* Require 12 digits of accuracy on non-zero constraints.
*/
for (size_t i = 0; i < top; ++i) {
if (m_elementActive[i]) {
if (fabs(m_elemAbundances[i] - m_elemAbundancesGoal[i]) > (fabs(m_elemAbundancesGoal[i]) * 1.0e-12)) {
if (m_elementActive[i] && fabs(m_elemAbundances[i] - m_elemAbundancesGoal[i]) > fabs(m_elemAbundancesGoal[i]) * 1.0e-12) {
/*
* This logic is for charge neutrality condition
*/
@ -82,7 +81,6 @@ bool VCS_SOLVE::vcs_elabcheck(int ibound)
}
}
}
}
return true;
}
@ -91,14 +89,12 @@ void VCS_SOLVE::vcs_elabPhase(size_t iphase, double* const elemAbundPhase)
for (size_t j = 0; j < m_numElemConstraints; ++j) {
elemAbundPhase[j] = 0.0;
for (size_t i = 0; i < m_numSpeciesTot; ++i) {
if (m_speciesUnknownType[i] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_phaseID[i] == iphase) {
if (m_speciesUnknownType[i] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE && m_phaseID[i] == iphase) {
elemAbundPhase[j] += m_formulaMatrix(i,j) * m_molNumSpecies_old[i];
}
}
}
}
}
int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
{
@ -385,16 +381,13 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
if (m_elType[i] == VCS_ELEM_TYPE_CHARGENEUTRALITY ||
(m_elType[i] == VCS_ELEM_TYPE_ABSPOS && m_elemAbundancesGoal[i] == 0.0)) {
for (size_t kspec = 0; kspec < m_numSpeciesRdc; kspec++) {
if (m_elemAbundances[i] > 0.0) {
if (m_formulaMatrix(kspec,i) < 0.0) {
if (m_elemAbundances[i] > 0.0 && m_formulaMatrix(kspec,i) < 0.0) {
m_molNumSpecies_old[kspec] -= m_elemAbundances[i] / m_formulaMatrix(kspec,i) ;
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 0.0);
vcs_elab();
break;
}
}
if (m_elemAbundances[i] < 0.0) {
if (m_formulaMatrix(kspec,i) > 0.0) {
if (m_elemAbundances[i] < 0.0 && m_formulaMatrix(kspec,i) > 0.0) {
m_molNumSpecies_old[kspec] -= m_elemAbundances[i] / m_formulaMatrix(kspec,i);
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 0.0);
vcs_elab();
@ -403,7 +396,6 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
}
}
}
}
if (vcs_elabcheck(1)) {
retn = 1;
goto L_CLEANUP;
@ -420,32 +412,25 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
bool useZeroed = true;
for (size_t kspec = 0; kspec < m_numSpeciesRdc; kspec++) {
if (dev < 0.0) {
if (m_formulaMatrix(kspec,i) < 0.0) {
if (m_molNumSpecies_old[kspec] > 0.0) {
if (m_formulaMatrix(kspec,i) < 0.0 && m_molNumSpecies_old[kspec] > 0.0) {
useZeroed = false;
}
}
} else {
if (m_formulaMatrix(kspec,i) > 0.0) {
if (m_molNumSpecies_old[kspec] > 0.0) {
if (m_formulaMatrix(kspec,i) > 0.0 && m_molNumSpecies_old[kspec] > 0.0) {
useZeroed = false;
}
}
}
}
for (size_t kspec = 0; kspec < m_numSpeciesRdc; kspec++) {
if (m_molNumSpecies_old[kspec] > 0.0 || useZeroed) {
if (dev < 0.0) {
if (m_formulaMatrix(kspec,i) < 0.0) {
if (dev < 0.0 && m_formulaMatrix(kspec,i) < 0.0) {
double delta = dev / m_formulaMatrix(kspec,i) ;
m_molNumSpecies_old[kspec] += delta;
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 0.0);
vcs_elab();
break;
}
}
if (dev > 0.0) {
if (m_formulaMatrix(kspec,i) > 0.0) {
if (dev > 0.0 && m_formulaMatrix(kspec,i) > 0.0) {
double delta = dev / m_formulaMatrix(kspec,i) ;
m_molNumSpecies_old[kspec] += delta;
m_molNumSpecies_old[kspec] = std::max(m_molNumSpecies_old[kspec], 0.0);
@ -456,7 +441,6 @@ int VCS_SOLVE::vcs_elcorr(double aa[], double x[])
}
}
}
}
if (vcs_elabcheck(1)) {
retn = 1;
goto L_CLEANUP;

View file

@ -68,13 +68,11 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
*/
k = m_numElemConstraints;
for (size_t ielem = jr; ielem < m_numElemConstraints; ielem++) {
if (m_elementActive[ielem]) {
if (aw[ielem] != test) {
if (m_elementActive[ielem] && aw[ielem] != test) {
k = ielem;
break;
}
}
}
if (k == m_numElemConstraints) {
throw CanteraError("vcs_elem_rearrange",
"Shouldn't be here. Algorithm misfired.");

View file

@ -212,12 +212,11 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
/* *********************************************************** */
double par = 0.5;
for (size_t kspec = 0; kspec < m_numComponents; ++kspec) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (par < -m_deltaMolNumSpecies[kspec] / m_molNumSpecies_new[kspec]) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE &&
par < -m_deltaMolNumSpecies[kspec] / m_molNumSpecies_new[kspec]) {
par = -m_deltaMolNumSpecies[kspec] / m_molNumSpecies_new[kspec];
}
}
}
par = 1. / par;
if (par <= 1.0 && par > 0.0) {
par *= 0.8;
@ -239,12 +238,11 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
}
for (size_t kspec = m_numComponents; kspec < nspecies; ++kspec) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_deltaMolNumSpecies[kspec] != 0.0) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE &&
m_deltaMolNumSpecies[kspec] != 0.0) {
m_molNumSpecies_old[kspec] = m_deltaMolNumSpecies[kspec] * par;
}
}
}
/*
* We have a new w[] estimate, go get the
* TMoles and m_tPhaseMoles_old[] values
@ -265,11 +263,9 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
if (s == 0.0) {
break;
}
if (s < 0.0) {
if (ikl == 0) {
if (s < 0.0 && ikl == 0) {
break;
}
}
/* ***************************************** */
/* *** TRY HALF STEP SIZE ****************** */
/* ***************************************** */

View file

@ -70,12 +70,10 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
foundJrxn = true;
// We can do the reaction if all other reactant components have positive mole fractions
for (size_t kcomp = 0; kcomp < m_numComponents; kcomp++) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) < 0.0) {
if (m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) < 0.0 && m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
foundJrxn = false;
}
}
}
if (foundJrxn) {
return true;
}
@ -89,12 +87,10 @@ bool VCS_SOLVE::vcs_popPhasePossible(const size_t iphasePop) const
}
// We can do the backwards reaction if all of the product components species are positive
for (size_t kcomp = 0; kcomp < m_numComponents; kcomp++) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) > 0.0) {
if (m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
if (m_stoichCoeffRxnMatrix(kcomp,jrxn) > 0.0 && m_molNumSpecies_old[kcomp] <= VCS_DELETE_ELEMENTABS_CUTOFF*0.5) {
foundJrxn = false;
}
}
}
if (foundJrxn) {
return true;
}
@ -125,8 +121,7 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
* The logic below calculates zeroedComponentLinkedPhasePops
*/
for (size_t j = 0; j < m_numComponents; j++) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
if (m_molNumSpecies_old[j] <= 0.0) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS && m_molNumSpecies_old[j] <= 0.0) {
std::vector<size_t> &jList = zeroedComponentLinkedPhasePops[j];
size_t iph = m_phaseID[j];
jList.push_back(iph);
@ -135,17 +130,13 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
iph = m_phaseID[kspec];
vcs_VolPhase* Vphase = m_VolPhaseList[iph];
int existence = Vphase->exists();
if (existence < 0) {
if (m_stoichCoeffRxnMatrix(j,irxn) > 0.0) {
if (std::find(jList.begin(), jList.end(), iph) != jList.end()) {
if (existence < 0 && m_stoichCoeffRxnMatrix(j,irxn) > 0.0 &&
std::find(jList.begin(), jList.end(), iph) != jList.end()) {
jList.push_back(iph);
}
}
}
}
}
}
}
/*
* This is a vector over each zeroed phase
* For zeroed phases, it lists the components, which are currently zeroed,
@ -168,9 +159,7 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
size_t kspec = Vphase->spGlobalIndexVCS(k);
size_t irxn = kspec - m_numComponents;
for (size_t j = 0; j < m_numComponents; j++) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
if (m_molNumSpecies_old[j] <= 0.0) {
if (m_stoichCoeffRxnMatrix(j,irxn) < 0.0) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS && m_molNumSpecies_old[j] <= 0.0 && m_stoichCoeffRxnMatrix(j,irxn) < 0.0) {
bool foundPos = false;
for (size_t kk = 0; kk < nsp; kk++) {
size_t kkspec = Vphase->spGlobalIndexVCS(kk);
@ -181,8 +170,7 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
}
}
}
if (!foundPos) {
if (std::find(iphList.begin(), iphList.end(), j) != iphList.end()) {
if (!foundPos && std::find(iphList.begin(), iphList.end(), j) != iphList.end()) {
iphList.push_back(j);
}
}
@ -190,9 +178,6 @@ int VCS_SOLVE::vcs_phasePopDeterminePossibleList()
}
}
}
}
}
}
/*
* Now fill in the phasePopProblemLists_ list.
@ -350,20 +335,16 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
if (Vphase->m_singleSpecies) {
double s = 0.0;
for (size_t j = 0; j < m_numComponents; ++j) {
if (!m_SSPhase[j]) {
if (m_molNumSpecies_old[j] > 0.0) {
if (!m_SSPhase[j] && m_molNumSpecies_old[j] > 0.0) {
s += pow(m_stoichCoeffRxnMatrix(j,irxn), 2) / m_molNumSpecies_old[j];
}
}
}
for (size_t j = 0; j < m_numPhases; j++) {
Vphase = m_VolPhaseList[j];
if (! Vphase->m_singleSpecies) {
if (m_tPhaseMoles_old[j] > 0.0) {
if (! Vphase->m_singleSpecies && m_tPhaseMoles_old[j] > 0.0) {
s -= pow(m_deltaMolNumPhase(j,irxn), 2) / m_tPhaseMoles_old[j];
}
}
}
if (s != 0.0) {
double s_old = s;
s = vcs_Hessian_diag_adj(irxn, s_old);
@ -379,8 +360,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
*/
for (size_t j = 0; j < m_numComponents; ++j) {
double stoicC = m_stoichCoeffRxnMatrix(j,irxn);
if (stoicC != 0.0) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
if (stoicC != 0.0 && m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
double negChangeComp = - stoicC * m_deltaMolNumSpecies[kspec];
if (negChangeComp > m_molNumSpecies_old[j]) {
if (m_molNumSpecies_old[j] > 0.0) {
@ -391,7 +371,6 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
}
}
}
}
// Implement a damping term that limits m_deltaMolNumSpecies to the size of the mole number
if (-m_deltaMolNumSpecies[kspec] > m_molNumSpecies_old[kspec]) {
m_deltaMolNumSpecies[kspec] = -m_molNumSpecies_old[kspec];
@ -421,14 +400,12 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
irxn = kspec - m_numComponents;
for (size_t j = 0; j < m_numComponents; ++j) {
double stoicC = m_stoichCoeffRxnMatrix(j,irxn);
if (stoicC != 0.0) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
if (stoicC != 0.0 && m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
molNumSpecies_tmp[j] += stoicC * delmol;
}
}
}
}
}
doublereal ratioComp = 0.0;
for (size_t j = 0; j < m_numComponents; ++j) {
@ -456,11 +433,9 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
// Here we create a damp > 1 to account for this possibility.
// We adjust upwards to make sure that a component in an existing multispecies
// phase is modified by a factor of 1/1000.
if (ratioComp > 1.0E-30) {
if (ratioComp < 0.001) {
if (ratioComp > 1.0E-30 && ratioComp < 0.001) {
damp = 0.001 / ratioComp;
}
}
if (damp <= 1.0E-6) {
return 3;
}
@ -721,17 +696,13 @@ double VCS_SOLVE::vcs_phaseStabilityTest(const size_t iph)
damp = std::max(0.3*fabs(fracDelta_old[k]) / fabs(delFrac[k]),
1.0E-8/fabs(delFrac[k]));
}
if (delFrac[k] < 0.0) {
if (2.0 * damp * (-delFrac[k]) > fracDelta_old[k]) {
if (delFrac[k] < 0.0 && 2.0 * damp * (-delFrac[k]) > fracDelta_old[k]) {
damp = fracDelta_old[k] / (2.0 * -delFrac[k]);
}
}
if (delFrac[k] > 0.0) {
if (2.0 * damp * delFrac[k] > fracDelta_old[k]) {
if (delFrac[k] > 0.0 && 2.0 * damp * delFrac[k] > fracDelta_old[k]) {
damp = fracDelta_old[k] / (2.0 * delFrac[k]);
}
}
}
damp = std::max(damp, 0.000001);
for (size_t k = 0; k < nsp; k++) {
fracDelta_new[k] = fracDelta_old[k] + damp * delFrac[k];

View file

@ -32,12 +32,10 @@ void VCS_SOLVE::vcs_SSPhase()
if (TPhInertMoles[iph] > 0.0) {
Vphase->setExistence(2);
}
if (numPhSpecies[iph] <= 1) {
if (TPhInertMoles[iph] == 0.0) {
if (numPhSpecies[iph] <= 1 && TPhInertMoles[iph] == 0.0) {
Vphase->m_singleSpecies = true;
}
}
}
/*
* Fill in some useful arrays here that have to do with the

View file

@ -219,11 +219,10 @@ int VCS_SOLVE::vcs_report(int iconv)
plogf("%-12.12s |",VPhase->PhaseName.c_str());
plogf("%10.3e |", m_tPhaseMoles_old[iphase]*molScale);
totalMoles += m_tPhaseMoles_old[iphase];
if (m_tPhaseMoles_old[iphase] != VPhase->totalMoles()) {
if (! vcs_doubleEqual(m_tPhaseMoles_old[iphase], VPhase->totalMoles())) {
if (m_tPhaseMoles_old[iphase] != VPhase->totalMoles() &&
!vcs_doubleEqual(m_tPhaseMoles_old[iphase], VPhase->totalMoles())) {
throw CanteraError("VCS_SOLVE::vcs_report", "we have a problem");
}
}
vcs_elabPhase(iphase, &gaPhase[0]);
for (size_t j = 0; j < m_numElemConstraints; j++) {
plogf(" %10.3g", gaPhase[j]);

View file

@ -166,20 +166,16 @@ size_t VCS_SOLVE::vcs_RxnStepSizes(int& forceComponentCalc, size_t& kSpecial)
s = 1.0 / m_molNumSpecies_old[kspec];
}
for (size_t j = 0; j < m_numComponents; ++j) {
if (!m_SSPhase[j]) {
if (m_molNumSpecies_old[j] > 0.0) {
if (!m_SSPhase[j] && m_molNumSpecies_old[j] > 0.0) {
s += pow(m_stoichCoeffRxnMatrix(j,irxn), 2) / m_molNumSpecies_old[j];
}
}
}
for (size_t j = 0; j < m_numPhases; j++) {
vcs_VolPhase* Vphase = m_VolPhaseList[j];
if (!Vphase->m_singleSpecies) {
if (m_tPhaseMoles_old[j] > 0.0) {
if (!Vphase->m_singleSpecies && m_tPhaseMoles_old[j] > 0.0) {
s -= pow(m_deltaMolNumPhase(j,irxn), 2) / m_tPhaseMoles_old[j];
}
}
}
if (s != 0.0) {
/*
* Take into account of the
@ -455,12 +451,10 @@ int VCS_SOLVE::vcs_rxn_adj_cg()
}
}
for (size_t j = 0; j < m_numPhases; j++) {
if (!m_VolPhaseList[j]->m_singleSpecies) {
if (m_tPhaseMoles_old[j] > 0.0) {
if (!m_VolPhaseList[j]->m_singleSpecies && m_tPhaseMoles_old[j] > 0.0) {
s -= pow(m_deltaMolNumPhase(j,irxn), 2) / m_tPhaseMoles_old[j];
}
}
}
if (s != 0.0) {
m_deltaMolNumSpecies[kspec] = -m_deltaGRxn_new[irxn] / s;
} else {

View file

@ -128,14 +128,12 @@ int VCS_SOLVE::vcs_setMolesLinProg()
delta_xi = fabs(m_molNumSpecies_old[jcomp]/nu);
// if a component has nearly zero moles, redo
// with a new set of components
if (!redo) {
if (delta_xi < 1.0e-10 && (m_molNumSpecies_old[ik] >= 1.0E-10)) {
if (!redo && delta_xi < 1.0e-10 && (m_molNumSpecies_old[ik] >= 1.0E-10)) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" --- Component too small: %s\n", m_speciesName[jcomp].c_str());
}
redo = true;
}
}
dxi_min = std::min(dxi_min, delta_xi);
}
}
@ -153,13 +151,11 @@ int VCS_SOLVE::vcs_setMolesLinProg()
}
m_molNumSpecies_old[jcomp] += sc_irxn[jcomp] * dsLocal;
m_molNumSpecies_old[jcomp] = max(0.0, m_molNumSpecies_old[jcomp]);
if (full) {
if (m_molNumSpecies_old[jcomp] < 1.0E-60) {
if (full && m_molNumSpecies_old[jcomp] < 1.0E-60) {
redo = true;
}
}
}
}
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
printProgress(m_speciesName, m_molNumSpecies_old, m_SSfeSpecies);

View file

@ -484,12 +484,10 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
if (pub->gai.size() != 0) {
for (size_t i = 0; i < nelements; i++) {
m_elemAbundancesGoal[i] = pub->gai[i];
if (pub->m_elType[i] == VCS_ELEM_TYPE_LATTICERATIO) {
if (m_elemAbundancesGoal[i] < 1.0E-10) {
if (pub->m_elType[i] == VCS_ELEM_TYPE_LATTICERATIO && m_elemAbundancesGoal[i] < 1.0E-10) {
m_elemAbundancesGoal[i] = 0.0;
}
}
}
} else {
if (m_doEstimateEquil == 0) {
double sum = 0;
@ -501,12 +499,10 @@ int VCS_SOLVE::vcs_prob_specifyFully(const VCS_PROB* pub)
m_elemAbundancesGoal[j] += m_formulaMatrix(kspec,j) * m_molNumSpecies_old[kspec];
}
}
if (pub->m_elType[j] == VCS_ELEM_TYPE_LATTICERATIO) {
if (m_elemAbundancesGoal[j] < 1.0E-10 * sum) {
if (pub->m_elType[j] == VCS_ELEM_TYPE_LATTICERATIO && m_elemAbundancesGoal[j] < 1.0E-10 * sum) {
m_elemAbundancesGoal[j] = 0.0;
}
}
}
} else {
plogf("%sElement Abundances, m_elemAbundancesGoal[], not specified\n", ser);
return VCS_PUB_BAD;

View file

@ -908,14 +908,12 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
if (DEBUG_MODE_ENABLED) {
doPhaseDeleteKspec = kspec;
if (m_debug_print_lvl >= 2) {
if (m_speciesStatus[kspec] >= 0) {
if (m_debug_print_lvl >= 2 && m_speciesStatus[kspec] >= 0) {
plogf(" --- SS species changed to zeroedss: ");
plogf("%-12s", m_speciesName[kspec].c_str());
plogendl();
}
}
}
m_speciesStatus[kspec] = VCS_SPECIES_ZEROEDSS;
++m_numRxnMinorZeroed;
allMinorZeroedSpecies = (m_numRxnMinorZeroed == m_numRxnRdc);
@ -1387,16 +1385,13 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
size_t kspec = m_indexRxnToSpecies[irxn];
int speciesType = vcs_species_type(kspec);
if (speciesType < VCS_SPECIES_MINOR) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
if (m_speciesStatus[kspec] >= VCS_SPECIES_MINOR) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2 && m_speciesStatus[kspec] >= VCS_SPECIES_MINOR) {
plogf(" --- major/minor species is now zeroed out: %s\n",
m_speciesName[kspec].c_str());
}
}
++m_numRxnMinorZeroed;
} else if (speciesType == VCS_SPECIES_MINOR) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
if (m_speciesStatus[kspec] != VCS_SPECIES_MINOR) {
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2 && m_speciesStatus[kspec] != VCS_SPECIES_MINOR) {
if (m_speciesStatus[kspec] == VCS_SPECIES_MAJOR) {
plogf(" --- Noncomponent turned from major to minor: ");
} else if (kspec < m_numComponents) {
@ -1407,7 +1402,6 @@ void VCS_SOLVE::solve_tp_inner(size_t& iti, size_t& it1,
}
plogf("%s\n", m_speciesName[kspec].c_str());
}
}
++m_numRxnMinorZeroed;
} else if (speciesType == VCS_SPECIES_MAJOR) {
if (m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) {
@ -1776,13 +1770,11 @@ int VCS_SOLVE::delta_species(const size_t kspec, double* const delta_ptr)
* If the component has a zero concentration and is a reactant
* in the formation reaction, then dx == 0.0, and we just return.
*/
if (m_molNumSpecies_old[j] <= 0.0) {
if (sc_irxn[j] < 0.0) {
if (m_molNumSpecies_old[j] <= 0.0 && sc_irxn[j] < 0.0) {
*delta_ptr = 0.0;
return 0;
}
}
}
/*
* ok, we found a positive dx. implement it.
*/
@ -1878,24 +1870,19 @@ int VCS_SOLVE::vcs_delete_species(const size_t kspec)
* Check to see whether we have just annihilated a multispecies phase.
* If it is extinct, call the delete_multiphase() function.
*/
if (! m_SSPhase[klast]) {
if (Vphase->exists() != VCS_PHASE_EXIST_ALWAYS) {
if (! m_SSPhase[klast] && Vphase->exists() != VCS_PHASE_EXIST_ALWAYS) {
bool stillExists = false;
for (size_t k = 0; k < m_numSpeciesRdc; k++) {
if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_phaseID[k] == iph) {
if (m_molNumSpecies_old[k] > 0.0) {
if (m_speciesUnknownType[k] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE &&
m_phaseID[k] == iph && m_molNumSpecies_old[k] > 0.0) {
stillExists = true;
break;
}
}
}
}
if (!stillExists) {
vcs_delete_multiphase(iph);
}
}
}
/*
* When the total number of noncomponent species is zero, we
* have to signal the calling code
@ -1940,13 +1927,11 @@ void VCS_SOLVE::vcs_reinsert_deleted(size_t kspec)
if (Vphase->exists() == VCS_PHASE_EXIST_NO) {
Vphase->setExistence(VCS_PHASE_EXIST_YES);
for (size_t k = 0; k < m_numSpeciesTot; k++) {
if (m_phaseID[k] == iph) {
if (m_speciesStatus[k] != VCS_SPECIES_DELETED) {
if (m_phaseID[k] == iph && m_speciesStatus[k] != VCS_SPECIES_DELETED) {
m_speciesStatus[k] = VCS_SPECIES_MINOR;
}
}
}
}
} else {
Vphase->setExistence(VCS_PHASE_EXIST_YES);
}
@ -2310,8 +2295,7 @@ size_t VCS_SOLVE::vcs_add_all_deleted()
for (size_t irxn = m_numRxnRdc; irxn < m_numRxnTot; ++irxn) {
size_t kspec = m_indexRxnToSpecies[irxn];
size_t iph = m_phaseID[kspec];
if (m_tPhaseMoles_old[iph] > 0.0) {
if (fabs(m_deltaGRxn_old[irxn]) > m_tolmin) {
if (m_tPhaseMoles_old[iph] > 0.0 && fabs(m_deltaGRxn_old[irxn]) > m_tolmin) {
if (((m_molNumSpecies_old[kspec] * exp(-m_deltaGRxn_old[irxn])) >
VCS_DELETE_MINORSPECIES_CUTOFF) ||
(m_molNumSpecies_old[kspec] > VCS_DELETE_MINORSPECIES_CUTOFF)) {
@ -2325,7 +2309,6 @@ size_t VCS_SOLVE::vcs_add_all_deleted()
}
}
}
}
return retn;
}
@ -2587,13 +2570,11 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
int minNonZeroes = 100000;
int nonZeroesKspec = 0;
for (size_t kspec = ncTrial; kspec < m_numSpeciesTot; kspec++) {
if (aw[kspec] >= 0.0) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (aw[kspec] >= 0.0 && m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
maxConcPossKspec = 1.0E10;
nonZeroesKspec = 0;
for (size_t j = 0; j < m_numElemConstraints; ++j) {
if (m_elementActive[j]) {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
if (m_elementActive[j] && m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
double nu = m_formulaMatrix(kspec,j);
if (nu != 0.0) {
nonZeroesKspec++;
@ -2601,7 +2582,6 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
}
}
}
}
if ((maxConcPossKspec >= maxConcPoss) || (maxConcPossKspec > 1.0E-5)) {
if (nonZeroesKspec <= minNonZeroes) {
if (kfound == npos || nonZeroesKspec < minNonZeroes) {
@ -2618,7 +2598,6 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
}
}
}
}
if (kfound == npos) {
double gmin = 0.0;
kfound = k;
@ -2812,19 +2791,15 @@ L_END_LOOP:
juse = npos;
jlose = npos;
for (size_t j = 0; j < m_numElemConstraints; j++) {
if (!m_elementActive[j]) {
if (!strcmp(m_elementName[j].c_str(), "E")) {
if (!m_elementActive[j] && !strcmp(m_elementName[j].c_str(), "E")) {
juse = j;
}
}
}
for (size_t j = 0; j < m_numElemConstraints; j++) {
if (m_elementActive[j]) {
if (!strncmp((m_elementName[j]).c_str(), "cn_", 3)) {
if (m_elementActive[j] && !strncmp((m_elementName[j]).c_str(), "cn_", 3)) {
jlose = j;
}
}
}
for (k = 0; k < m_numSpeciesTot; k++) {
if (m_speciesUnknownType[k] == VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
for (size_t j = 0; j < ncTrial; ++j) {
@ -3029,11 +3004,9 @@ size_t VCS_SOLVE::vcs_basisOptMax(const double* const molNum, const size_t j,
bool doSwap = false;
if (m_SSPhase[j]) {
doSwap = (molNum[i] * m_spSize[i]) > big;
if (!m_SSPhase[i]) {
if (doSwap) {
if (!m_SSPhase[i] && doSwap) {
doSwap = molNum[i] > (molNum[largest] * 1.001);
}
}
} else {
if (m_SSPhase[i]) {
doSwap = (molNum[i] * m_spSize[i]) > big;
@ -3066,11 +3039,9 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const
// ---------- Treat zeroed out species first ----------------
if (m_molNumSpecies_old[kspec] <= 0.0) {
if (m_tPhaseMoles_old[iph] <= 0.0) {
if (!m_SSPhase[kspec]) {
if (m_tPhaseMoles_old[iph] <= 0.0 && !m_SSPhase[kspec]) {
return VCS_SPECIES_ZEROEDMS;
}
}
/*
* see if the species has an element
@ -3145,8 +3116,7 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const
}
}
if (irxn >= 0) {
if (m_deltaGRxn_old[irxn] >= 0.0) {
if (irxn >= 0 && m_deltaGRxn_old[irxn] >= 0.0) {
/*
* We are here when the species is or should remain zeroed out
*/
@ -3162,7 +3132,6 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const
}
}
}
}
/*
* If the current phase already exists,
*/
@ -3226,15 +3195,11 @@ int VCS_SOLVE::vcs_species_type(const size_t kspec) const
} else {
double szAdj = m_scSize[irxn] * std::sqrt((double)m_numRxnTot);
for (size_t k = 0; k < m_numComponents; ++k) {
if (!m_SSPhase[k]) {
if (m_stoichCoeffRxnMatrix(k,irxn) != 0.0) {
if (m_molNumSpecies_old[kspec] * szAdj >= m_molNumSpecies_old[k] * 0.01) {
if (!m_SSPhase[k] && m_stoichCoeffRxnMatrix(k,irxn) != 0.0 && m_molNumSpecies_old[kspec] * szAdj >= m_molNumSpecies_old[k] * 0.01) {
return VCS_SPECIES_MAJOR;
}
}
}
}
}
return VCS_SPECIES_MINOR;
}
@ -3689,12 +3654,10 @@ void VCS_SOLVE::check_tmoles() const
double m_tPhaseMoles_old_a = TPhInertMoles[i];
for (size_t k = 0; k < m_numSpeciesTot; k++) {
if (m_speciesUnknownType[k] == VCS_SPECIES_TYPE_MOLNUM) {
if (m_phaseID[k] == i) {
if (m_speciesUnknownType[k] == VCS_SPECIES_TYPE_MOLNUM && m_phaseID[k] == i) {
m_tPhaseMoles_old_a += m_molNumSpecies_old[k];
}
}
}
sum += m_tPhaseMoles_old_a;
double denom = m_tPhaseMoles_old[i]+ m_tPhaseMoles_old_a + 1.0E-19;
@ -3784,12 +3747,10 @@ bool VCS_SOLVE::vcs_evaluate_speciesType()
}
}
}
if (kspec >= m_numComponents) {
if (m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) {
if (kspec >= m_numComponents && m_speciesStatus[kspec] != VCS_SPECIES_MAJOR) {
++m_numRxnMinorZeroed;
}
}
}
if (DEBUG_MODE_ENABLED && m_debug_print_lvl >= 2) {
plogf(" ---");
plogendl();
@ -4163,8 +4124,7 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted,
bool zeroedPhase = true;
for (size_t irxn = 0; irxn < irxnl; ++irxn) {
size_t kspec = m_indexRxnToSpecies[irxn];
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_phaseID[kspec] == iphase) {
if (m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE && m_phaseID[kspec] == iphase) {
if (m_molNumSpecies_old[kspec] > 0.0) {
zeroedPhase = false;
}
@ -4174,7 +4134,6 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted,
}
}
}
}
/*
* special section for zeroed phases
@ -4214,8 +4173,7 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted,
* All of the dg[]'s will be equal. If dg[] is negative, then
* the phase will come back into existence.
*/
if (alterZeroedPhases) {
if (zeroedPhase) {
if (alterZeroedPhases && zeroedPhase) {
double phaseDG = 1.0;
for (size_t irxn = 0; irxn < irxnl; ++irxn) {
size_t kspec = m_indexRxnToSpecies[irxn];
@ -4236,7 +4194,6 @@ void VCS_SOLVE::vcs_deltag_Phase(const size_t iphase, const bool doDeleted,
}
}
}
}
void VCS_SOLVE::vcs_switch_pos(const bool ifunc, const size_t k1, const size_t k2)
{
@ -4373,13 +4330,11 @@ double VCS_SOLVE::vcs_birthGuess(const int kspec)
dx = std::min(dx, - 0.3333* m_molNumSpecies_old[j] / sc_irxn[j]);
}
}
if (m_molNumSpecies_old[j] <= 0.0) {
if (sc_irxn[j] < 0.0) {
if (m_molNumSpecies_old[j] <= 0.0 && sc_irxn[j] < 0.0) {
dx = 0.0;
}
}
}
}
return dx;
}

View file

@ -510,49 +510,38 @@ void InterfaceKinetics::updateROP()
for (size_t j = 0; j != nReactions(); ++j) {
if ((m_ropr[j] > m_ropf[j]) && (m_ropr[j] > 0.0)) {
for (size_t p = 0; p < nPhases(); p++) {
if (m_rxnPhaseIsProduct[j][p]) {
if (! m_phaseExists[p]) {
if (m_rxnPhaseIsProduct[j][p] && !m_phaseExists[p]) {
m_ropnet[j] = 0.0;
m_ropr[j] = m_ropf[j];
if (m_ropf[j] > 0.0) {
for (size_t rp = 0; rp < nPhases(); rp++) {
if (m_rxnPhaseIsReactant[j][rp]) {
if (! m_phaseExists[rp]) {
if (m_rxnPhaseIsReactant[j][rp] && !m_phaseExists[rp]) {
m_ropnet[j] = 0.0;
m_ropr[j] = m_ropf[j] = 0.0;
}
}
}
}
}
}
if (m_rxnPhaseIsReactant[j][p]) {
if (! m_phaseIsStable[p]) {
if (m_rxnPhaseIsReactant[j][p] && !m_phaseIsStable[p]) {
m_ropnet[j] = 0.0;
m_ropr[j] = m_ropf[j];
}
}
}
} else if ((m_ropf[j] > m_ropr[j]) && (m_ropf[j] > 0.0)) {
for (size_t p = 0; p < nPhases(); p++) {
if (m_rxnPhaseIsReactant[j][p]) {
if (! m_phaseExists[p]) {
if (m_rxnPhaseIsReactant[j][p] && !m_phaseExists[p]) {
m_ropnet[j] = 0.0;
m_ropf[j] = m_ropr[j];
if (m_ropf[j] > 0.0) {
for (size_t rp = 0; rp < nPhases(); rp++) {
if (m_rxnPhaseIsProduct[j][rp]) {
if (! m_phaseExists[rp]) {
if (m_rxnPhaseIsProduct[j][rp] && !m_phaseExists[rp]) {
m_ropnet[j] = 0.0;
m_ropf[j] = m_ropr[j] = 0.0;
}
}
}
}
}
}
if (m_rxnPhaseIsProduct[j][p]) {
if (! m_phaseIsStable[p]) {
if (m_rxnPhaseIsProduct[j][p] && !m_phaseIsStable[p]) {
m_ropnet[j] = 0.0;
m_ropf[j] = m_ropr[j];
}
@ -560,7 +549,6 @@ void InterfaceKinetics::updateROP()
}
}
}
}
m_ROP_ok = true;
}

View file

@ -259,11 +259,9 @@ void ReactionPathDiagram::exportToDot(ostream& s)
for (i2 = i1+1; i2 < nNodes(); i2++) {
k2 = m_speciesNumber[i2];
flx = netFlow(k1, k2);
if (m_local != npos) {
if (k1 != m_local && k2 != m_local) {
if (m_local != npos && k1 != m_local && k2 != m_local) {
flx = 0.0;
}
}
if (flx != 0.0) {
// set beginning and end of the path based on the
// sign of the net flow
@ -817,8 +815,7 @@ int ReactionPathBuilder::build(Kinetics& s, const string& element,
(m_atoms(kkr,m) < m_elatoms(m, i))) {
map<size_t, map<size_t, Group> >& g = m_transfer[i];
if (g.empty()) {
if (!warn[i]) {
if (!quiet) {
if (!warn[i] && !quiet) {
output << endl;
output << "*************** REACTION IGNORED ***************" << endl;
output << "Warning: no rule to determine partitioning of " << element
@ -827,7 +824,6 @@ int ReactionPathBuilder::build(Kinetics& s, const string& element,
output << endl;
warn[i] = 1;
}
}
f = 0.0;
} else {
if (!g[kkr][kkp]) {

View file

@ -152,14 +152,12 @@ bool importKinetics(const XML_Node& phase, std::vector<ThermoPhase*> th,
string owning_phase = phase["id"];
bool check_for_duplicates = false;
if (phase.parent()) {
if (phase.parent()->hasChild("validate")) {
if (phase.parent() && phase.parent()->hasChild("validate")) {
const XML_Node& d = phase.parent()->child("validate");
if (d["reactions"] == "yes") {
check_for_duplicates = true;
}
}
}
// if other phases are involved in the reaction mechanism,
// they must be listed in a 'phaseArray' child

View file

@ -357,14 +357,12 @@ int solveSP::solveSurfProb(int ifunc, doublereal time_scale, doublereal TKelvin,
* End Newton's method. If not converged, print error message and
* recalculate sdot's at equal site fractions.
*/
if (not_converged) {
if (m_ioflag) {
if (not_converged && m_ioflag) {
printf("#$#$#$# Error in solveSP $#$#$#$ \n");
printf("Newton iter on surface species did not converge, "
"update_norm = %e \n", update_norm);
printf("Continuing anyway\n");
}
}
/*
* Decide on what to return in the solution vector

View file

@ -269,15 +269,13 @@ doublereal IDA_Solver::getCurrentStepFromIDA()
void IDA_Solver::setJacobianType(int formJac)
{
m_formJac = formJac;
if (m_ida_mem) {
if (m_formJac == 1) {
if (m_ida_mem && m_formJac == 1) {
int flag = IDADlsSetDenseJacFn(m_ida_mem, ida_jacobian);
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDADlsSetDenseJacFn failed.");
}
}
}
}
void IDA_Solver::setMaxErrTestFailures(int maxErrTestFails)
{

View file

@ -116,14 +116,12 @@ void ResidJacEval::calcSolnScales(const doublereal t,
const doublereal* const ysolnOld,
doublereal* const ysolnScales)
{
if (ysolnScales) {
if (ysolnScales[0] == 0.0) {
if (ysolnScales && ysolnScales[0] == 0.0) {
for (int i = 0; i < neq_; i++) {
ysolnScales[i] = 1.0;
}
}
}
}
doublereal ResidJacEval::filterNewStep(doublereal t, const doublereal* const ybase, doublereal* const step)
{

View file

@ -522,11 +522,9 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
* the user has said that it is ok to take
*/
doublereal xDelMax = 1.5 * fabs(x2 - x1);
if (specifiedDeltaXnorm_) {
if (0.5 * DeltaXnorm_ > xDelMax) {
if (specifiedDeltaXnorm_ && 0.5 * DeltaXnorm_ > xDelMax) {
xDelMax = 0.5 *DeltaXnorm_ ;
}
}
if (fabs(xDelMax) < fabs(xnew - x2)) {
xnew = x2 + sign(xnew-x2) * xDelMax;
if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_) {
@ -590,19 +588,16 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
}
}
}
if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_) {
if (xorig != xnew) {
if (DEBUG_MODE_ENABLED && printLvl >= 3 && writeLogAllowed_ && xorig != xnew) {
fprintf(fp, " | xstraddle = %-11.5E", xnew);
}
}
}
/*
* Enforce a minimum stepsize if we haven't found a straddle.
*/
deltaXnew = xnew - x2;
if (fabs(deltaXnew) < 1.2 * delXMeaningful(xnew)) {
if (!foundStraddle) {
if (fabs(deltaXnew) < 1.2 * delXMeaningful(xnew) && !foundStraddle) {
sgn = 1.0;
if (x2 > xnew) {
sgn = -1.0;
@ -612,7 +607,6 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
" to " + fp2str(deltaXnew);
xnew = x2 + deltaXnew;
}
}
/*
* Guard against going above xmax or below xmin
@ -861,8 +855,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
/*
* Check for excess convergence in the x coordinate
*/
if (!converged) {
if (foundStraddle) {
if (!converged && foundStraddle) {
doublereal denom = fabs(x1 - x2);
if (denom < 1.0E-200) {
retn = ROOTFIND_FAILEDCONVERGENCE;
@ -875,13 +868,11 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
retn = ROOTFIND_SUCCESS;
}
}
}
} else {
/*
* We are here when F is not converged, but we may want to end anyway
*/
if (!converged) {
if (foundStraddle) {
if (!converged && foundStraddle) {
doublereal denom = fabs(x1 - x2);
if (denom < 1.0E-200) {
retn = ROOTFIND_FAILEDCONVERGENCE;
@ -900,7 +891,6 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
}
}
}
}
done:
if (converged) {
@ -961,12 +951,10 @@ done:
std::swap(f1, f2);
std::swap(x1, x2);
*xbest = x2;
if (fabs(fnew) < fabs(f1)) {
if (f1 * fnew > 0.0) {
if (fabs(fnew) < fabs(f1) && f1 * fnew > 0.0) {
std::swap(f1, fnew);
std::swap(x1, xnew);
}
}
rfT.its = its;
rfT.xval = *xbest;

View file

@ -53,15 +53,13 @@ doublereal bound_step(const doublereal* x, const doublereal* step,
for (j = 0; j < np; j++) {
val = x[index(m,j)];
if (loglevel > 0) {
if (val > above + 1.0e-12 || val < below - 1.0e-12) {
if (loglevel > 0 && (val > above + 1.0e-12 || val < below - 1.0e-12)) {
sprintf(buf, "domain %s: %20s(%s) = %10.3e (%10.3e, %10.3e)\n",
int2str(r.domainIndex()).c_str(),
r.componentName(m).c_str(), int2str(j).c_str(),
val, below, above);
writelog(string("\nERROR: solution out of bounds.\n")+buf);
}
}
newval = val + step[index(m,j)];

View file

@ -932,8 +932,7 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
/*
* Now look at the activity coefficient database
*/
if (acNodePtr) {
if (acNodePtr->hasChild("stoichIsMods")) {
if (acNodePtr && acNodePtr->hasChild("stoichIsMods")) {
XML_Node& sIsNode = acNodePtr->child("stoichIsMods");
map<std::string, std::string> msIs;
getMap(sIsNode, msIs);
@ -946,7 +945,6 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
/*
* Fill in the vector specifying the electrolyte species
@ -978,8 +976,7 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
for (size_t k = 0; k < m_kk; k++) {
std::string kname = speciesName(k);
const XML_Node* spPtr = xspecies[k];
if (spPtr) {
if (spPtr->hasChild("electrolyteSpeciesType")) {
if (spPtr && spPtr->hasChild("electrolyteSpeciesType")) {
std::string est = getChildValue(*spPtr, "electrolyteSpeciesType");
if ((m_electrolyteSpeciesType[k] = interp_est(est)) == -1) {
throw CanteraError("DebyeHuckel:initThermoXML",
@ -987,12 +984,10 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
/*
* Then look at the phase thermo specification
*/
if (acNodePtr) {
if (acNodePtr->hasChild("electrolyteSpeciesType")) {
if (acNodePtr && acNodePtr->hasChild("electrolyteSpeciesType")) {
XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType");
map<std::string, std::string> msEST;
getMap(ESTNode, msEST);
@ -1007,7 +1002,6 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
/*
* Lastly set the state

View file

@ -2004,8 +2004,7 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
if (charge(k) < 0.0) {
n = k + j * m_kk + i * m_kk * m_kk;
sum3 += molality[j]*molality[k]*psi_ijk[n];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (psi_ijk[n] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && psi_ijk[n] != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Psi term on %-16s m_j m_k psi_ijk = %10.5f\n", snj.c_str(),
molality[j]*molality[k]*psi_ijk[n]);
@ -2014,32 +2013,27 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
}
}
}
}
if (charge(j) > 0.0) {
// sum over all cations
if (j != i) {
sum2 += molality[j]*(2.0*Phi[counterIJ]);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j] * Phi[counterIJ])!= 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j] * Phi[counterIJ])!= 0.0) {
std::string snj = speciesName(j) + ":";
printf(" Phi term with %-12s 2 m_j Phi_cc = %10.5f\n", snj.c_str(),
molality[j]*(2.0*Phi[counterIJ]));
}
}
}
for (size_t k = 1; k < m_kk; k++) {
if (charge(k) < 0.0) {
// two inner sums over anions
n = k + j * m_kk + i * m_kk * m_kk;
sum2 += molality[j]*molality[k]*psi_ijk[n];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (psi_ijk[n] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && psi_ijk[n] != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Psi term on %-16s m_j m_k psi_ijk = %10.5f\n", snj.c_str(),
molality[j]*molality[k]*psi_ijk[n]);
}
}
/*
* Find the counterIJ for the j,k interaction
*/
@ -2047,8 +2041,7 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
size_t counterIJ2 = m_CounterIJ[n];
sum4 += (fabs(charge(i))*
molality[j]*molality[k]*CMX[counterIJ2]);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j]*molality[k]*CMX[counterIJ2]) != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j]*molality[k]*CMX[counterIJ2]) != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Tern CMX term on %-16s abs(z_i) m_j m_k CMX = %10.5f\n", snj.c_str(),
fabs(charge(i))* molality[j]*molality[k]*CMX[counterIJ2]);
@ -2056,20 +2049,17 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
}
}
}
}
/*
* Handle neutral j species
*/
if (charge(j) == 0) {
sum5 += molality[j]*2.0*m_Lambda_nj(j,i);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j]*2.0*m_Lambda_nj(j,i)) != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j]*2.0*m_Lambda_nj(j,i)) != 0.0) {
std::string snj = speciesName(j) + ":";
printf(" Lambda term with %-12s 2 m_j lam_ji = %10.5f\n", snj.c_str(),
molality[j]*2.0*m_Lambda_nj(j,i));
}
}
/*
* Zeta interaction term
*/
@ -2150,8 +2140,7 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
if (charge(k) > 0) {
n = k + j * m_kk + i * m_kk * m_kk;
sum3 += molality[j]*molality[k]*psi_ijk[n];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (psi_ijk[n] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && psi_ijk[n] != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Psi term on %-16s m_j m_k psi_ijk = %10.5f\n", snj.c_str(),
molality[j]*molality[k]*psi_ijk[n]);
@ -2160,7 +2149,6 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
}
}
}
}
/*
* For Anions, do the other anion interactions.
@ -2169,26 +2157,22 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
// sum over all anions
if (j != i) {
sum2 += molality[j]*(2.0*Phi[counterIJ]);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j] * Phi[counterIJ])!= 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j] * Phi[counterIJ])!= 0.0) {
std::string snj = speciesName(j) + ":";
printf(" Phi term with %-12s 2 m_j Phi_aa = %10.5f\n", snj.c_str(),
molality[j]*(2.0*Phi[counterIJ]));
}
}
}
for (size_t k = 1; k < m_kk; k++) {
if (charge(k) > 0.0) {
// two inner sums over cations
n = k + j * m_kk + i * m_kk * m_kk;
sum2 += molality[j]*molality[k]*psi_ijk[n];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (psi_ijk[n] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && psi_ijk[n] != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Psi term on %-16s m_j m_k psi_ijk = %10.5f\n", snj.c_str(),
molality[j]*molality[k]*psi_ijk[n]);
}
}
/*
* Find the counterIJ for the symmetric binary interaction
*/
@ -2196,8 +2180,7 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
size_t counterIJ2 = m_CounterIJ[n];
sum4 += fabs(charge(i))*
molality[j]*molality[k]*CMX[counterIJ2];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j]*molality[k]*CMX[counterIJ2]) != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j]*molality[k]*CMX[counterIJ2]) != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Tern CMX term on %-16s abs(z_i) m_j m_k CMX = %10.5f\n", snj.c_str(),
fabs(charge(i))* molality[j]*molality[k]*CMX[counterIJ2]);
@ -2205,20 +2188,17 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
}
}
}
}
/*
* for Anions, do the neutral species interaction
*/
if (charge(j) == 0.0) {
sum5 += molality[j]*2.0*m_Lambda_nj(j,i);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if ((molality[j]*2.0*m_Lambda_nj(j,i)) != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && (molality[j]*2.0*m_Lambda_nj(j,i)) != 0.0) {
std::string snj = speciesName(j) + ":";
printf(" Lambda term with %-12s 2 m_j lam_ji = %10.5f\n", snj.c_str(),
molality[j]*2.0*m_Lambda_nj(j,i));
}
}
/*
* Zeta interaction term
*/
@ -2263,13 +2243,11 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
double sum3 = 0.0;
for (size_t j = 1; j < m_kk; j++) {
sum1 += molality[j]*2.0*m_Lambda_nj(i,j);
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (m_Lambda_nj(i,j) != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && m_Lambda_nj(i,j) != 0.0) {
std::string snj = speciesName(j) + ":";
printf(" Lambda_n term on %-16s 2 m_j lambda_n_j = %10.5f\n", snj.c_str(),
molality[j]*2.0*m_Lambda_nj(i,j));
}
}
/*
* Zeta term -> we piggyback on the psi term
*/
@ -2278,8 +2256,7 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
if (charge(k) < 0.0) {
size_t n = k + j * m_kk + i * m_kk * m_kk;
sum3 += molality[j]*molality[k]*psi_ijk[n];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (psi_ijk[n] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && psi_ijk[n] != 0.0) {
std::string snj = speciesName(j) + "," + speciesName(k) + ":";
printf(" Zeta term on %-16s m_j m_k psi_ijk = %10.5f\n", snj.c_str(),
molality[j]*molality[k]*psi_ijk[n]);
@ -2288,14 +2265,11 @@ void HMWSoln::s_updatePitzer_lnMolalityActCoeff() const
}
}
}
}
double sum2 = 3.0 * molality[i]* molality[i] * m_Mu_nnn[i];
if (DEBUG_MODE_ENABLED && m_debugCalc) {
if (m_Mu_nnn[i] != 0.0) {
if (DEBUG_MODE_ENABLED && m_debugCalc && m_Mu_nnn[i] != 0.0) {
printf(" Mu_nnn term 3 m_n m_n Mu_n_n = %10.5f\n",
3.0 * molality[i]* molality[i] * m_Mu_nnn[i]);
}
}
m_lnActCoeffMolal_Unscaled[i] = sum1 + sum2 + sum3;
gamma_Unscaled[i] = exp(m_lnActCoeffMolal_Unscaled[i]);
if (DEBUG_MODE_ENABLED && m_debugCalc) {

View file

@ -465,13 +465,11 @@ void HMWSoln::readXMLPsiCommonCation(XML_Node& BinSalt)
stemp = xmlChild.value();
double old = m_Theta_ij[counter];
m_Theta_ij[counter] = fpValueCheck(stemp);
if (old != 0.0) {
if (old != m_Theta_ij[counter]) {
if (old != 0.0 && old != m_Theta_ij[counter]) {
throw CanteraError("HMWSoln::readXMLPsiCommonCation",
"conflicting values");
}
}
}
if (nodeName == "psi") {
getFloatArray(xmlChild, vParams, false, "", stemp);
size_t nParamsFound = vParams.size();
@ -601,13 +599,11 @@ void HMWSoln::readXMLPsiCommonAnion(XML_Node& BinSalt)
stemp = xmlChild.value();
double old = m_Theta_ij[counter];
m_Theta_ij[counter] = fpValueCheck(stemp);
if (old != 0.0) {
if (old != m_Theta_ij[counter]) {
if (old != 0.0 && old != m_Theta_ij[counter]) {
throw CanteraError("HMWSoln::readXMLPsiCommonAnion",
"conflicting values");
}
}
}
if (nodeName == "psi") {
getFloatArray(xmlChild, vParams, false, "", stemp);
size_t nParamsFound = vParams.size();
@ -1414,8 +1410,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
/*
* Now look at the activity coefficient database
*/
if (acNodePtr) {
if (acNodePtr->hasChild("stoichIsMods")) {
if (acNodePtr && acNodePtr->hasChild("stoichIsMods")) {
XML_Node& sIsNode = acNodePtr->child("stoichIsMods");
map<string, string> msIs;
getMap(sIsNode, msIs);
@ -1429,7 +1424,6 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
/*
* Loop through the children getting multiple instances of
@ -1496,8 +1490,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
std::vector<const XML_Node*> xspecies = speciesData();
for (size_t k = 0; k < m_kk; k++) {
const XML_Node* spPtr = xspecies[k];
if (spPtr) {
if (spPtr->hasChild("electrolyteSpeciesType")) {
if (spPtr && spPtr->hasChild("electrolyteSpeciesType")) {
string est = getChildValue(*spPtr, "electrolyteSpeciesType");
if ((m_electrolyteSpeciesType[k] = interp_est(est)) == -1) {
throw CanteraError("HMWSoln::initThermoXML",
@ -1505,12 +1498,10 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
/*
* Then look at the phase thermo specification
*/
if (acNodePtr) {
if (acNodePtr->hasChild("electrolyteSpeciesType")) {
if (acNodePtr && acNodePtr->hasChild("electrolyteSpeciesType")) {
XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType");
map<string, string> msEST;
getMap(ESTNode, msEST);
@ -1527,7 +1518,6 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
IMS_typeCutoff_ = 2;
if (IMS_typeCutoff_ == 2) {
@ -1585,8 +1575,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
if (notDone) {
if (kMaxC != npos) {
if (notDone && kMaxC != npos) {
if (mf[kMaxC] > (1.1 * sum / charge(kMaxC))) {
mf[kMaxC] -= sum / charge(kMaxC);
mf[0] += sum / charge(kMaxC);
@ -1597,7 +1586,6 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
}
}
}
}
setMoleFractions(DATA_PTR(mf));
} else {
notDone = false;

View file

@ -460,12 +460,10 @@ void IdealMolalSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
*/
initThermo();
if (id_.size() > 0) {
if (phaseNode.id() != id_) {
if (id_.size() > 0 && phaseNode.id() != id_) {
throw CanteraError("IdealMolalSoln::initThermo",
"phasenode and Id are incompatible");
}
}
/*
* Find the Thermo XML node

View file

@ -478,12 +478,10 @@ const vector_fp& IdealSolidSolnPhase::entropy_R_ref() const
void IdealSolidSolnPhase::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
if (id_.size() > 0) {
if (phaseNode.id() != id_) {
if (id_.size() > 0 && phaseNode.id() != id_) {
throw CanteraError("IdealSolidSolnPhase::initThermoXML",
"phasenode and Id are incompatible");
}
}
/*
* Check on the thermo field. Must have:

View file

@ -184,12 +184,10 @@ void IonsFromNeutralVPSSTP::constructPhaseFile(std::string inputFile, std::strin
void IonsFromNeutralVPSSTP::constructPhaseXML(XML_Node& phaseNode, std::string id_)
{
if (id_.size() > 0) {
if (phaseNode.id() != id_) {
if (id_.size() > 0 && phaseNode.id() != id_) {
throw CanteraError("IonsFromNeutralVPSSTP::constructPhaseXML",
"phasenode and Id are incompatible");
}
}
/*
* Find the thermo XML node
@ -769,8 +767,7 @@ static double factorOverlap(const std::vector<std::string>& elnamesVN ,
{
double fMax = 1.0E100;
for (size_t mi = 0; mi < nElementsI; mi++) {
if (elnamesVI[mi] != "E") {
if (elemVectorI[mi] > 1.0E-13) {
if (elnamesVI[mi] != "E" && elemVectorI[mi] > 1.0E-13) {
double eiNum = elemVectorI[mi];
for (size_t mn = 0; mn < nElementsN; mn++) {
if (elnamesVI[mi] == elnamesVN[mn]) {
@ -782,17 +779,14 @@ static double factorOverlap(const std::vector<std::string>& elnamesVN ,
}
}
}
}
return fMax;
}
void IonsFromNeutralVPSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id_)
{
if (id_.size() > 0) {
if (phaseNode.id() != id_) {
if (id_.size() > 0 && phaseNode.id() != id_) {
throw CanteraError("IonsFromNeutralVPSSTP::initThermoXML",
"phasenode and Id are incompatible");
}
}
/*
* Find the Thermo XML node

View file

@ -327,12 +327,10 @@ void LatticePhase::initThermoXML(XML_Node& phaseNode, const std::string& id_)
throw CanteraError(" LatticePhase::initThermoXML", "database problems");
}
XML_Node* ss = s->findByName("standardState");
if (ss) {
if (ss->findByName("molarVolume")) {
if (ss && ss->findByName("molarVolume")) {
m_speciesMolarVolume[k] = getFloat(*ss, "molarVolume", "toSI");
}
}
}
/*
* Call the base initThermo, which handles setting the initial

View file

@ -58,12 +58,10 @@ MetalSHEelectrons::MetalSHEelectrons(const std::string& infile, std::string id_)
MetalSHEelectrons::MetalSHEelectrons(XML_Node& xmlphase, const std::string& id_) :
xdef_(0)
{
if (id_ != "") {
if (id_ != xmlphase["id"]) {
if (id_ != "" && id_ != xmlphase["id"]) {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"id's don't match");
}
}
if (xmlphase.child("thermo")["model"] != "MetalSHEelectrons") {
throw CanteraError("MetalSHEelectrons::MetalSHEelectrons",
"thermo model attribute must be MetalSHEelectrons");

View file

@ -49,12 +49,10 @@ MineralEQ3::MineralEQ3(const std::string& infile, std::string id_)
MineralEQ3::MineralEQ3(XML_Node& xmlphase, const std::string& id_)
{
if (id_ != "") {
if (id_ != xmlphase["id"]) {
if (id_ != "" && id_ != xmlphase["id"]) {
throw CanteraError("MineralEQ3::MineralEQ3",
"id's don't match");
}
}
std::string model = xmlphase.child("thermo")["model"];
if (model != "StoichSubstance" && model != "MineralEQ3") {
throw CanteraError("MineralEQ3::MineralEQ3",

View file

@ -580,29 +580,23 @@ doublereal MixtureFugacityTP::densityCalc(doublereal TKelvin, doublereal presPa,
* of 0.1 times the current volume
*/
double delMV = - (presBase - presPa) / dpdV;
if (!gasSide || delMV < 0.0) {
if (fabs(delMV) > 0.2 * molarVolBase) {
if ((!gasSide || delMV < 0.0) && fabs(delMV) > 0.2 * molarVolBase) {
delMV = delMV / fabs(delMV) * 0.2 * molarVolBase;
}
}
/*
* Only go 1/10 the way towards the spinodal at any one time.
*/
if (TKelvin < tcrit) {
if (gasSide) {
if (delMV < 0.0) {
if (-delMV > 0.5 * (molarVolBase - molarVolSpinodal)) {
if (delMV < 0.0 && -delMV > 0.5 * (molarVolBase - molarVolSpinodal)) {
delMV = - 0.5 * (molarVolBase - molarVolSpinodal);
}
}
} else {
if (delMV > 0.0) {
if (delMV > 0.5 * (molarVolSpinodal - molarVolBase)) {
if (delMV > 0.0 && delMV > 0.5 * (molarVolSpinodal - molarVolBase)) {
delMV = 0.5 * (molarVolSpinodal - molarVolBase);
}
}
}
}
/*
* updated the molar volume value
*/
@ -828,8 +822,7 @@ doublereal MixtureFugacityTP::calculatePsat(doublereal TKelvin, doublereal& mola
}
}
if (foundGas && foundLiquid) {
if (presGas != presLiquid) {
if (foundGas && foundLiquid && presGas != presLiquid) {
pres = 0.5 * (presLiquid + presGas);
bool goodLiq;
bool goodGas;
@ -861,7 +854,6 @@ doublereal MixtureFugacityTP::calculatePsat(doublereal TKelvin, doublereal& mola
}
}
}
}
if (!foundGas || !foundLiquid) {
printf("error couldn't find a starting pressure\n");
return 0.0;

View file

@ -203,19 +203,15 @@ void MolalityVPSSTP::setMolalitiesByName(const compositionMap& mMap)
for (size_t k = 0; k < m_kk; k++) {
double ch = charge(k);
if (mf[k] > 0.0) {
if (ch > 0.0) {
if (ch * mf[k] > cPos) {
if (ch > 0.0 && ch * mf[k] > cPos) {
largePos = k;
cPos = ch * mf[k];
}
}
if (ch < 0.0) {
if (fabs(ch) * mf[k] > cNeg) {
if (ch < 0.0 && fabs(ch) * mf[k] > cNeg) {
largeNeg = k;
cNeg = fabs(ch) * mf[k];
}
}
}
sum += mf[k] * ch;
}
if (sum != 0.0) {

View file

@ -180,12 +180,10 @@ void Mu0Poly::processCoeffs(const doublereal* coeffs)
iT298 = i;
ifound = true;
}
if (i < nPoints - 1) {
if (coeffs[iindex+2] <= T1) {
if (i < nPoints - 1 && coeffs[iindex+2] <= T1) {
throw CanteraError("Mu0Poly",
"Temperatures are not monotonic increasing");
}
}
iindex += 2;
}
if (!ifound) {

View file

@ -316,13 +316,11 @@ void PDSS_Water::setPressure(doublereal p)
// We are only putting the phase check here because of speed considerations.
m_iState = m_sub.phaseState(true);
if (! m_allowGasPhase) {
if (m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
if (!m_allowGasPhase && m_iState != WATER_SUPERCRIT && m_iState != WATER_LIQUID && m_iState != WATER_UNSTABLELIQUID) {
throw CanteraError("PDSS_Water::setPressure",
"Water State isn't liquid or crit");
}
}
}
doublereal PDSS_Water::thermalExpansionCoeff() const
{

View file

@ -1318,8 +1318,7 @@ int RedlichKwongMFTP::NicholsSolve(double TKelvin, double pres, doublereal a, do
tmp = an * Vroot[i] * Vroot[i] * Vroot[i] + bn * Vroot[i] * Vroot[i] + cn * Vroot[i] + dn;
if (fabs(tmp) > 1.0E-4) {
for (int j = 0; j < 3; j++) {
if (j != i) {
if (fabs(Vroot[i] - Vroot[j]) < 1.0E-4 * (fabs(Vroot[i]) + fabs(Vroot[j]))) {
if (j != i && fabs(Vroot[i] - Vroot[j]) < 1.0E-4 * (fabs(Vroot[i]) + fabs(Vroot[j]))) {
writelog("RedlichKwongMFTP::NicholsSolve(T = " + fp2str(TKelvin) + ", p = " +
fp2str(pres) + "): WARNING roots have merged: " +
fp2str(Vroot[i]) + ", " + fp2str(Vroot[j]));
@ -1328,7 +1327,6 @@ int RedlichKwongMFTP::NicholsSolve(double TKelvin, double pres, doublereal a, do
}
}
}
}
} else if (desc == 0.0) {
if (yN == 0.0 && h == 0.0) {
Vroot[0] = xN;
@ -1400,12 +1398,10 @@ int RedlichKwongMFTP::NicholsSolve(double TKelvin, double pres, doublereal a, do
}
}
} else {
if (nSolnValues == 2) {
if (delta > 0.0) {
if (nSolnValues == 2 && delta > 0.0) {
nSolnValues = -2;
}
}
}
return nSolnValues;
}

View file

@ -377,14 +377,12 @@ void importPhase(XML_Node& phase, ThermoPhase* th)
* present.
***************************************************************/
vector<XML_Node*> sparrays = phase.getChildren("speciesArray");
if (ssConvention != cSS_CONVENTION_SLAVE) {
if (sparrays.empty()) {
if (ssConvention != cSS_CONVENTION_SLAVE && sparrays.empty()) {
throw CanteraError("importPhase",
"phase, " + th->id() + ", has zero \"speciesArray\" XML nodes.\n"
+ " There must be at least one speciesArray nodes "
"with one or more species");
}
}
vector<XML_Node*> dbases;
vector_int sprule(sparrays.size(),0);
@ -450,12 +448,10 @@ void importPhase(XML_Node& phase, ThermoPhase* th)
}
size_t nsp = spDataNodeList.size();
if (ssConvention == cSS_CONVENTION_SLAVE) {
if (nsp > 0) {
if (ssConvention == cSS_CONVENTION_SLAVE && nsp > 0) {
throw CanteraError("importPhase()", "For Slave standard states, number of species must be zero: "
+ int2str(nsp));
}
}
for (size_t k = 0; k < nsp; k++) {
XML_Node* s = spDataNodeList[k];
AssertTrace(s != 0);

View file

@ -625,11 +625,9 @@ void ThermoPhase::setSpeciesThermo(SpeciesThermo* spthermo)
"Use of SpeciesThermo classes other than "
"GeneralSpeciesThermo is deprecated.");
}
if (m_spthermo) {
if (m_spthermo != spthermo) {
if (m_spthermo && m_spthermo != spthermo) {
delete m_spthermo;
}
}
m_spthermo = spthermo;
}

View file

@ -209,8 +209,7 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr,
// First look for any explicit instructions within the XML Database
// for the standard state manager and the variable pressure
// standard state manager
if (phaseNode_ptr) {
if (phaseNode_ptr->hasChild("thermo")) {
if (phaseNode_ptr && phaseNode_ptr->hasChild("thermo")) {
const XML_Node& thermoNode = phaseNode_ptr->child("thermo");
if (thermoNode.hasChild("standardStateManager")) {
const XML_Node& ssNode = thermoNode.child("standardStateManager");
@ -221,7 +220,6 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr,
vpssManager = vpssNode["model"];
}
}
}
// first get the reference state handler.
SpeciesThermo* spth = new GeneralSpeciesThermo();
@ -270,11 +268,10 @@ VPSSMgr* VPSSMgrFactory::newVPSSMgr(VPStandardStateTP* vp_ptr,
}
}
}
if (inasaCV || ishomateCV || isimpleCV) {
if (!inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
if ((inasaCV || ishomateCV || isimpleCV) &&
!inasaIG && !ishomateIG && !isimpleIG && !itpx && !ihptx && !iother) {
return new VPSSMgr_ConstVol(vp_ptr, spth);
}
}
return new VPSSMgr_General(vp_ptr, spth);
}

View file

@ -88,13 +88,11 @@ PDSS* VPSSMgr_IdealGas::createInstallPDSS(size_t k, const XML_Node& speciesNode,
const XML_Node* const phaseNode_ptr)
{
const XML_Node* ss = speciesNode.findByName("standardState");
if (ss) {
if (ss->attrib("model") != "ideal_gas") {
if (ss && ss->attrib("model") != "ideal_gas") {
throw CanteraError("VPSSMgr_IdealGas::createInstallPDSS",
"standardState model for species isn't "
"ideal_gas: " + speciesNode["name"]);
}
}
if (m_Vss.size() < k+1) {
m_Vss.resize(k+1, 0.0);
}

View file

@ -353,8 +353,7 @@ doublereal WaterProps::viscosityWater() const
// Apply the near-critical point corrections if necessary
doublereal mu2bar = 1.0;
if ((tbar >= 0.9970) && tbar <= 1.0082) {
if ((rhobar >= 0.755) && (rhobar <= 1.290)) {
if (tbar >= 0.9970 && tbar <= 1.0082 && rhobar >= 0.755 && rhobar <= 1.290) {
doublereal drhodp = 1.0 / m_waterIAPWS->dpdrho();
drhodp *= presStar / rhoStar;
doublereal xsi = rhobar * drhodp;
@ -362,7 +361,6 @@ doublereal WaterProps::viscosityWater() const
mu2bar = 0.922 * std::pow(xsi, 0.0263);
}
}
}
doublereal mubar = mu0bar * mu1bar * mu2bar;
return mubar * muStar;

View file

@ -57,12 +57,10 @@ LTPspecies::LTPspecies(const XML_Node* const propNode, const std::string name,
m_thermo(thermo),
m_mixWeight(1.0)
{
if (propNode) {
if (propNode->hasChild("mixtureWeighting")) {
if (propNode && propNode->hasChild("mixtureWeighting")) {
m_mixWeight = getFloat(*propNode, "mixtureWeighting");
}
}
}
LTPspecies::LTPspecies(const LTPspecies& right)
{

View file

@ -78,13 +78,11 @@ int main(int argc, char** argv)
+ ISQRTbot*(1.0 - (double)i/(its - 1.0));
Is = ISQRT * ISQRT;
if (!doneSp) {
if (Is > 6.146) {
if (!doneSp && Is > 6.146) {
Is = 6.146;
doneSp = true;
i--;
}
}
moll[i1] = Is;
moll[i2] = Is;
HMW->setMolalities(moll);