-
Notifications
You must be signed in to change notification settings - Fork 34
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
Fix a bunch of small errors. #1301
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,12 +382,32 @@ class TrustRegion : public mfem::NewtonSolver { | |
H_directions.emplace_back(H_left.get()); | ||
} | ||
|
||
std::tie(directions, H_directions) = removeDependentDirections(directions, H_directions); | ||
try { | ||
std::tie(directions, H_directions) = removeDependentDirections(directions, H_directions); | ||
} catch (const std::exception& e) { | ||
if (print_options.warnings) { | ||
mfem::out << "remove dependent directions failed with " << e.what() << std::endl; | ||
} | ||
return; | ||
} | ||
|
||
mfem::Vector b(g); | ||
b *= -1; | ||
auto [sol, leftvecs, leftvals, energy_change] = | ||
solveSubspaceProblem(directions, H_directions, b, delta, num_leftmost); | ||
|
||
mfem::Vector sol; | ||
std::vector<std::shared_ptr<mfem::Vector>> leftvecs; | ||
std::vector<double> leftvals; | ||
double energy_change; | ||
|
||
try { | ||
std::tie(sol, leftvecs, leftvals, energy_change) = | ||
solveSubspaceProblem(directions, H_directions, b, delta, num_leftmost); | ||
} catch (const std::exception& e) { | ||
if (print_options.warnings) { | ||
mfem::out << "subspace solve failed with " << e.what() << std::endl; | ||
} | ||
return; | ||
} | ||
|
||
left_mosts.clear(); | ||
for (auto& lv : leftvecs) { | ||
|
@@ -398,8 +418,9 @@ class TrustRegion : public mfem::NewtonSolver { | |
double subspace_energy = computeEnergy(g, hess_vec_func, sol); | ||
|
||
if (print_options.iterations || print_options.warnings) { | ||
double leftval = leftvals.size() ? leftvals[0] : 1.0; | ||
mfem::out << "Energy using subspace solver from: " << base_energy << ", to: " << subspace_energy << " / " | ||
<< energy_change << ". Min eig: " << leftvals[0] << std::endl; | ||
<< energy_change << ". Min eig: " << leftval << std::endl; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like the minimum eigenvalue estimate will be reported as 1.0 when no min eigenvalues estimates have been requested. I'm fine with this for now, since it's really an inconsistent request from the user, but it is misleading. An option to consider is to check if |
||
} | ||
|
||
if (subspace_energy < base_energy) { | ||
|
@@ -727,7 +748,6 @@ class TrustRegion : public mfem::NewtonSolver { | |
if (use_with_option1 || use_with_option2 || use_with_option3) { | ||
if (!have_computed_Hvs) { | ||
have_computed_Hvs = true; | ||
|
||
hess_vec_func(trResults.z, trResults.H_z); | ||
hess_vec_func(trResults.d_old, trResults.H_d_old); | ||
hess_vec_func(trResults.cauchy_point, trResults.H_cauchy_point); | ||
|
@@ -755,9 +775,8 @@ class TrustRegion : public mfem::NewtonSolver { | |
double realObjective = std::numeric_limits<double>::max(); | ||
double normPred = std::numeric_limits<double>::max(); | ||
try { | ||
normPred = computeResidual(x_pred, r_pred); | ||
double obj1 = 0.5 * (Dot(r, trResults.d) + Dot(r_pred, trResults.d)) - roundOffTol; | ||
|
||
normPred = computeResidual(x_pred, r_pred); | ||
double obj1 = 0.5 * (Dot(r, trResults.d) + Dot(r_pred, trResults.d)) - roundOffTol; | ||
realObjective = obj1; | ||
} catch (const std::exception&) { | ||
realObjective = std::numeric_limits<double>::max(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done the testing, so I trust you on this. If you actually wanted me to double check, let me know. Otherwise mark as resolved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The assembly are definitely needed. The Copy, maybe not. But I'm sick of trying to guess what PETSc is going to do, best be safe. It costs nothing in practice.