Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch singular explosions in saturation_PHSU_pure #2250

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/Backends/Helmholtz/VLERoutines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,41 @@ void SaturationSolvers::saturation_PHSU_pure(HelmholtzEOSMixtureBackend& HEOS, C
info.c_str(), specified_value, error));
}
} while (error > 1e-9);
// recalculate error
negativer[0] = -(deltaV * (1 + deltaV * SatV->dalphar_dDelta()) - deltaL * (1 + deltaL * SatL->dalphar_dDelta()));
negativer[1] = -(deltaV * SatV->dalphar_dDelta() + SatV->alphar() + log(deltaV) - deltaL * SatL->dalphar_dDelta() - SatL->alphar() - log(deltaL));
switch (options.specified_variable) {
case saturation_PHSU_pure_options::IMPOSED_PL:
// -r_3 (equate calculated pressure and specified liquid pressure)
negativer[2] = -(SatL->p() / specified_value - 1);
break;
case saturation_PHSU_pure_options::IMPOSED_PV:
// -r_3 (equate calculated pressure and specified vapor pressure)
negativer[2] = -(SatV->p() / specified_value - 1);
break;
case saturation_PHSU_pure_options::IMPOSED_HL:
// -r_3 (equate calculated liquid enthalpy and specified liquid enthalpy)
negativer[2] = -(SatL->hmolar() - specified_value);
break;
case saturation_PHSU_pure_options::IMPOSED_HV:
// -r_3 (equate calculated vapor enthalpy and specified vapor enthalpy)
negativer[2] = -(SatV->hmolar() - specified_value);
break;
case saturation_PHSU_pure_options::IMPOSED_SL:
// -r_3 (equate calculated liquid entropy and specified liquid entropy)
negativer[2] = -(SatL->smolar() - specified_value);
break;
case saturation_PHSU_pure_options::IMPOSED_SV:
// -r_3 (equate calculated vapor entropy and specified vapor entropy)
negativer[2] = -(SatV->smolar() - specified_value);
break;
default:
throw ValueError(format("options.specified_variable to saturation_PHSU_pure [%d] is invalid", options.specified_variable));
}
error = sqrt(pow(negativer[0], 2) + pow(negativer[1], 2) + pow(negativer[2], 2));
if (error > 1e-8){
throw SolutionError(format("saturation_PHSU_pure solver was good, but went bad. Current error is %Lg", error));
}
}
void SaturationSolvers::saturation_D_pure(HelmholtzEOSMixtureBackend& HEOS, CoolPropDbl rhomolar, saturation_D_pure_options& options)
{
Expand Down