Skip to content

Tupek/tr core mfem subspace - #1629

Open
tupek2 wants to merge 46 commits into
developfrom
tupek/tr-core-mfem-subspace
Open

Tupek/tr core mfem subspace#1629
tupek2 wants to merge 46 commits into
developfrom
tupek/tr-core-mfem-subspace

Conversation

@tupek2

@tupek2 tupek2 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

The intent here is mostly to get away from requiring PETSc to use the 'subspace' option for the trust-region solver, and to have additional header files for the trust-region implementation so the equations_solver.cpp does not keep getting larger. There were some additional performance optimizations, such as reducing the total dot products and the number of parallel reductions, saving off subspace results when doing linesearching (as the subspace does not change), tuned some defaults based on a suite of benchmarks that I will add in a follow on PR, and some other small adjustments.

  • Remove PETSc/SLEPc dependency from trust-region subspace solver.
  • Replace PETSc reduced solve with MFEM/LAPACK implementation.
  • Cache reduced subspace projections across trust-radius retries.
  • Extract Steihaug-Toint CG into private implementation helper.
  • Keep public entry through NonlinearSolver::TrustRegion.
  • Use one batched global dot-product path for trust-region math.
  • Add previous accepted steps to subspace basis, default 2.
  • Add tuned trust-region defaults from benchmark runs.
  • Add MFEM subspace and Steihaug-Toint CG tests.
  • Guard LAPACK subspace tests on MFEM_USE_LAPACK.
  • Add shallow-arch snap-through physics coverage.

mrtupek2 and others added 30 commits April 29, 2026 12:00
…ions that we can use with our new matrix-free nonlinear solver.
…g forward. Try to simpify some of the testing and changes.
@tupek2
tupek2 requested review from btalamini, chapman39 and ebchin and removed request for btalamini July 29, 2026 13:43
Comment thread src/smith/physics/weak_form.hpp Outdated

#pragma once

#include <cstddef>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this required?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, fixed.

Comment thread src/smith/numerics/solver_config.hpp

@btalamini btalamini left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions, but they're small.

Comment thread src/smith/numerics/solver_config.hpp Outdated
int num_previous_steps = 2;

/// Relative CG forcing term for TrustRegion model solves.
double cg_forcing_rel = 1.2981521889723316e-05;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you give this a more meaningful name and explanation? I can suggest cg_residual_reduction_for_early_exit, but I'm open to better ideas.

void checkProjectionInputs(const std::vector<const mfem::Vector*>& states,
const std::vector<const mfem::Vector*>& Astates, const mfem::Vector& b)
{
MFEM_VERIFY(states.size() == Astates.size(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be our own assertions, rather than MFEM ones?

Comment on lines +21 to +32
double dot(const mfem::Vector& a, const mfem::Vector& b) { return a * b; }

double norm(const mfem::Vector& x) { return x.Norml2(); }

double sumAbs(const mfem::Vector& x)
{
double total = 0.0;
for (int i = 0; i < x.Size(); ++i) {
total += std::abs(x[i]);
}
return total;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests probably cover this, but just to be thorough: are these ok in parallel?


size_t rootOnlyPrintLevel(const mfem::NewtonSolver& solver, size_t level)
{
#ifdef MFEM_USE_MPI

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll need @white238 to confirm, but I think we always build with MPI and the guards are unnecessary. In fact, this function could possibly be reduced to a clear one-liner.

Comment thread src/smith/numerics/steihaug_toint_cg.cpp

std::vector<mfem::Vector> kept_columns;
for (int i = 0; i < evals.Size(); ++i) {
if (evals[i] > 1e-9 * trace_mag) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably ok here, but hard-coded tolerances are a code smell. Want to make sure you're ok with this one.

@ebchin ebchin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good. Mostly questions about testing.

Comment thread src/smith/numerics/tests/test_steihaug_toint_cg.cpp
Comment thread src/smith/numerics/tests/test_trust_region_solver_mfem.cpp
Comment thread src/smith/numerics/tests/CMakeLists.txt

} // namespace

void TrustRegionSubspaceCache::prepare(const std::vector<const mfem::Vector*>& directions,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had trouble finding this implementation since it's declaration is in trust_region_subspace_cache.hpp. Can you clarify the choices behind the file names?

const mfem::Vector& b, int num_leftmost, MPI_Comm comm = MPI_COMM_WORLD);

/// @brief solves cached reduced trust-region problem for given trust-region radius
TrustRegionSubspaceResult solve(double delta) const;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any testing for re-use of the cached values?

Comment thread src/smith/numerics/tests/test_trust_region_solver_mfem.cpp
}

/// apply trust region specific preconditioner
void precond(const mfem::Vector& x_, mfem::Vector& v_) const

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this unused now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants