Skip to content
Snippets Groups Projects
Commit e975a7bc authored by Ian Bell's avatar Ian Bell
Browse files

Add VLE method for pures

See #2
parent fc5262ae
No related branches found
No related tags found
No related merge requests found
......@@ -61,3 +61,26 @@ public:
return J;
}
};
template<typename Residual, typename Scalar>
auto do_pure_VLE(Residual &resid, Scalar T, Scalar rhoL, Scalar rhoV) {
auto rhovec = (Eigen::ArrayXd(2) << rhoL, rhoV).finished();
auto r0 = resid.call(rhovec);
auto J = resid.Jacobian(rhovec);
for (int iter = 0; iter < 100; ++iter){
if (iter > 0) {
r0 = resid.call(rhovec);
J = resid.Jacobian(rhovec);
}
auto v = J.matrix().colPivHouseholderQr().solve(-r0.matrix()).array().eval();
auto rhovecnew = (rhovec + v).eval();
// If the solution has stopped improving, stop. The change in rhovec is equal to v in infinite precision, but
// not when finite precision is involved, so use the minimum non-denormal float as the determination of whether
// the values are done changing
if (((rhovecnew - rhovec).cwiseAbs() < std::numeric_limits<Scalar>::min()).all()) {
break;
}
rhovec += v;
}
}
\ No newline at end of file
......@@ -242,4 +242,6 @@ TEST_CASE("Test pure VLE", "") {
auto rhovec1 = rhovec + v;
auto r1 = resid.call(rhovec1);
CHECK((r0.cwiseAbs() > r1.cwiseAbs()).eval().all());
do_pure_VLE(resid, T, 22834.056386882046, 1025.106554560764);
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment