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

Revert "Condensed eigen system refactor" #28624

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 10 additions & 0 deletions framework/include/systems/NonlinearEigenSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ class NonlinearEigenSystem : public NonlinearSystemBase

void residualAndJacobianTogether() override;

/**
* Initialize the condensed matrices. This is a no-op if there are no
* constraints in the DofMap
*/
void initializeCondensedMatrices();

virtual void postInit() override;
virtual void reinit() override;

Expand All @@ -197,6 +203,10 @@ class NonlinearEigenSystem : public NonlinearSystemBase
bool _precond_matrix_includes_eigen;
// Libmesh preconditioner
Preconditioner<Number> * _preconditioner;

/// The number of degrees of freedom constrained at the libMesh level, e.g. via hanging node or
/// periodic boundary constraints
dof_id_type _num_constrained_dofs;
};

#else
Expand Down
41 changes: 35 additions & 6 deletions framework/src/systems/NonlinearEigenSystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ NonlinearEigenSystem::NonlinearEigenSystem(EigenProblem & eigen_problem, const s
_work_rhs_vector_AX(addVector("work_rhs_vector_Ax", false, PARALLEL)),
_work_rhs_vector_BX(addVector("work_rhs_vector_Bx", false, PARALLEL)),
_precond_matrix_includes_eigen(false),
_preconditioner(nullptr)
_preconditioner(nullptr),
_num_constrained_dofs(0)
{
SlepcEigenSolver<Number> * solver =
cast_ptr<SlepcEigenSolver<Number> *>(_eigen_sys.eigen_solver.get());
Expand Down Expand Up @@ -190,18 +191,46 @@ NonlinearEigenSystem::postAddResidualObject(ResidualObject & object)
}
}

void
NonlinearEigenSystem::initializeCondensedMatrices()
{
if (!(_num_constrained_dofs = dofMap().n_constrained_dofs()))
return;

_eigen_sys.initialize_condensed_dofs();
const auto m = cast_int<numeric_index_type>(_eigen_sys.local_non_condensed_dofs_vector.size());
auto M = m;
_communicator.sum(M);
if (_eigen_sys.has_condensed_matrix_A())
{
_eigen_sys.get_condensed_matrix_A().init(M, M, m, m);
// A bit ludicrously MatCopy requires the matrix being copied to to be assembled
_eigen_sys.get_condensed_matrix_A().close();
}
if (_eigen_sys.has_condensed_matrix_B())
{
_eigen_sys.get_condensed_matrix_B().init(M, M, m, m);
_eigen_sys.get_condensed_matrix_B().close();
}
if (_eigen_sys.has_condensed_precond_matrix())
{
_eigen_sys.get_condensed_precond_matrix().init(M, M, m, m);
_eigen_sys.get_condensed_precond_matrix().close();
}
}

void
NonlinearEigenSystem::postInit()
{
NonlinearSystemBase::postInit();
_eigen_sys.initialize_condensed_matrices();
initializeCondensedMatrices();
}

void
NonlinearEigenSystem::reinit()
{
NonlinearSystemBase::reinit();
_eigen_sys.initialize_condensed_matrices();
initializeCondensedMatrices();
}

void
Expand All @@ -216,7 +245,7 @@ NonlinearEigenSystem::solve()
// We apply initial guess for only nonlinear solver
if (_eigen_problem.isNonlinearEigenvalueSolver())
{
if (_eigen_sys.have_condensed_dofs())
if (_num_constrained_dofs)
{
subvec = solution().get_subvector(_eigen_sys.local_non_condensed_dofs_vector);
_eigen_sys.set_initial_space(*subvec);
Expand Down Expand Up @@ -251,7 +280,7 @@ NonlinearEigenSystem::solve()
if (n_converged_eigenvalues)
getConvergedEigenpair(_eigen_problem.activeEigenvalueIndex());

if (_eigen_problem.isNonlinearEigenvalueSolver() && _eigen_sys.have_condensed_dofs())
if (_eigen_problem.isNonlinearEigenvalueSolver() && _num_constrained_dofs)
solution().restore_subvector(std::move(subvec), _eigen_sys.local_non_condensed_dofs_vector);
}

Expand All @@ -261,7 +290,7 @@ NonlinearEigenSystem::attachSLEPcCallbacks()
// Tell libmesh not to close matrices before solve
_eigen_sys.get_eigen_solver().set_close_matrix_before_solve(false);

if (_eigen_sys.have_condensed_dofs())
if (_num_constrained_dofs)
{
// Condensed Matrix A
if (_eigen_sys.has_condensed_matrix_A())
Expand Down