-
Notifications
You must be signed in to change notification settings - Fork 35
Roy/saddle point preconditioning #1598
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
Open
tlroy
wants to merge
10
commits into
develop
Choose a base branch
from
roy/saddle_point_preconditioning
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4706ac9
Support a None preconditioner.
mrtupek2 f752dad
Mixed poisson saddle point problem with correct vdim on subsolver AMG
tlroy 8132a7d
Actually switch to LinearSolver::None
tlroy d0447ec
Fix Wshadow in PreconditionerOnlySolver
tlroy b87f2f6
Expose block preconditioner sub-solvers
tlroy dced5ca
Merge branch 'tupek/system_solver' into roy/saddle_point_precon_clean
tlroy 12338ce
fix style
tlroy 311ba94
Merge branch 'develop' into roy/saddle_point_preconditioning
tlroy caa2849
doxygen docs headers
tlroy feae278
Merge branch 'develop' into roy/saddle_point_preconditioning
tlroy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/smith/differentiable_numerics/tests/test_amg_vdim_block_preconditioner.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| // Copyright (c) Lawrence Livermore National Security, LLC and | ||
| // other Smith Project Developers. See the top-level LICENSE file for | ||
| // details. | ||
| // | ||
| // SPDX-License-Identifier: (BSD-3-Clause) | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <mpi.h> | ||
|
|
||
| #include "mfem.hpp" | ||
| #include <HYPRE_parcsr_ls.h> | ||
|
|
||
| #include "smith/infrastructure/application_manager.hpp" | ||
| #include "smith/differentiable_numerics/nonlinear_block_solver.hpp" | ||
| #include "smith/numerics/equation_solver.hpp" | ||
| #include "smith/numerics/solver_config.hpp" | ||
| #include "smith/numerics/block_preconditioner.hpp" | ||
| #include "smith/numerics/solver_with_preconditioner.hpp" | ||
| #include "smith/physics/state/finite_element_state.hpp" | ||
|
|
||
| namespace smith { | ||
| namespace { | ||
|
|
||
| HYPRE_Int GetBoomerAMGNumFunctions(const mfem::HypreBoomerAMG& amg) | ||
| { | ||
| HYPRE_Solver h = amg; // mfem::HypreBoomerAMG has operator HYPRE_Solver() | ||
| HYPRE_Int dim = -1; | ||
| HYPRE_BoomerAMGGetNumFunctions(h, &dim); | ||
| return dim; | ||
| } | ||
|
|
||
| TEST(AMGVdimSetup, BlockDiagonalPreconditionerSetsPerBlockVdim) | ||
| { | ||
| MPI_Comm comm = MPI_COMM_WORLD; | ||
|
|
||
| mfem::Mesh mesh = mfem::Mesh::MakeCartesian2D(1, 1, mfem::Element::QUADRILATERAL, 1, 1.0, 1.0); | ||
| mfem::ParMesh pmesh(comm, mesh); | ||
| mesh.Clear(); | ||
|
|
||
| const int order = 1; | ||
| mfem::H1_FECollection fec(order, pmesh.Dimension()); | ||
|
|
||
| // Block 0: vdim=2 | ||
| mfem::ParFiniteElementSpace fes_v2(&pmesh, &fec, 2, smith::ordering); | ||
| // Block 1: vdim=1 | ||
| mfem::ParFiniteElementSpace fes_v1(&pmesh, &fec, 1, smith::ordering); | ||
|
|
||
| auto u0 = std::make_shared<FiniteElementState>(fes_v2, "u0"); | ||
| auto u1 = std::make_shared<FiniteElementState>(fes_v1, "u1"); | ||
| std::vector<NonlinearBlockSolverBase::FieldPtr> us{u0, u1}; | ||
|
|
||
| NonlinearSolverOptions nonlin_opts; | ||
| nonlin_opts.nonlin_solver = NonlinearSolver::Newton; | ||
| nonlin_opts.max_iterations = 1; | ||
| nonlin_opts.print_level = 0; | ||
| nonlin_opts.absolute_tol = 1e-12; | ||
| nonlin_opts.relative_tol = 1e-10; | ||
|
|
||
| LinearSolverOptions lin_opts; | ||
| lin_opts.linear_solver = LinearSolver::GMRES; | ||
| lin_opts.preconditioner = Preconditioner::BlockDiagonal; | ||
| lin_opts.max_iterations = 1; | ||
| lin_opts.print_level = 0; | ||
| lin_opts.preconditioner_print_level = 0; | ||
|
|
||
| LinearSolverOptions sub; | ||
| sub.linear_solver = LinearSolver::GMRES; | ||
| sub.preconditioner = Preconditioner::HypreAMG; | ||
| sub.max_iterations = 1; | ||
| sub.relative_tol = 0.99; | ||
| sub.absolute_tol = 0.0; | ||
| sub.print_level = 0; | ||
| sub.preconditioner_print_level = 0; | ||
|
|
||
| lin_opts.sub_block_linear_solver_options.push_back(sub); | ||
| lin_opts.sub_block_linear_solver_options.push_back(sub); | ||
|
|
||
| auto eq = std::make_unique<EquationSolver>(nonlin_opts, lin_opts, comm); | ||
| mfem::Solver* top_prec = &eq->preconditioner(); | ||
|
|
||
| NonlinearBlockSolver nbs(std::move(eq), comm, nonlin_opts.absolute_tol, nonlin_opts.relative_tol, nonlin_opts, | ||
| lin_opts); | ||
| nbs.completeSetup(us); | ||
|
|
||
| auto* block_diag = dynamic_cast<smith::BlockDiagonalPreconditioner*>(top_prec); | ||
| ASSERT_NE(block_diag, nullptr); | ||
| ASSERT_GE(block_diag->numSubSolvers(), 2); | ||
|
|
||
| // Block 0 | ||
| { | ||
| auto* wrapped = dynamic_cast<smith::SolverWithPreconditioner*>(block_diag->subSolver(0)); | ||
| ASSERT_NE(wrapped, nullptr); | ||
|
|
||
| auto* amg = dynamic_cast<mfem::HypreBoomerAMG*>(wrapped->preconditioner()); | ||
| ASSERT_NE(amg, nullptr); | ||
| EXPECT_EQ(GetBoomerAMGNumFunctions(*amg), 2); | ||
| } | ||
|
|
||
| // Block 1 | ||
| { | ||
| auto* wrapped = dynamic_cast<smith::SolverWithPreconditioner*>(block_diag->subSolver(1)); | ||
| ASSERT_NE(wrapped, nullptr); | ||
|
|
||
| auto* amg = dynamic_cast<mfem::HypreBoomerAMG*>(wrapped->preconditioner()); | ||
| ASSERT_NE(amg, nullptr); | ||
| EXPECT_EQ(GetBoomerAMGNumFunctions(*amg), 1); | ||
| } | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace smith | ||
|
|
||
| int main(int argc, char** argv) | ||
| { | ||
| ::testing::InitGoogleTest(&argc, argv); | ||
| smith::ApplicationManager applicationManager(argc, argv); | ||
| return RUN_ALL_TESTS(); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is this a deep copy or shallow copy?
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.
@tupek2 Shallow copy