Skip to content

Commit

Permalink
Merge pull request idaholab#27323 from lindsayad/eigen-fixes
Browse files Browse the repository at this point in the history
Eigen fixes
  • Loading branch information
lindsayad committed May 21, 2024
2 parents 1d2f966 + a465db2 commit ef92d30
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
36 changes: 14 additions & 22 deletions framework/src/systems/NonlinearEigenSystem.C
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,15 @@ NonlinearEigenSystem::postAddResidualObject(ResidualObject & object)

auto & vtags = object.getVectorTags({});
auto & mtags = object.getMatrixTags({});

const bool eigen = (vtags.find(_Bx_tag) != vtags.end()) || (mtags.find(_B_tag) != mtags.end());

if (eigen && !_eigen_sys.generalized())
object.mooseError("This object has been marked as contributing to B or Bx but the eigen "
"problem type is not a generalized one");

// If it is an eigen kernel, mark its variable as eigen
if (vtags.find(_Bx_tag) != vtags.end() || mtags.find(_B_tag) != mtags.end())
if (eigen)
{
// Note: the object may be on the displaced system
auto sys = object.parameters().get<SystemBase *>("_sys");
Expand All @@ -159,12 +166,13 @@ NonlinearEigenSystem::postAddResidualObject(ResidualObject & object)
sys->getScalarVariable(0, vname).eigen(true);
else
sys->getVariable(0, vname).eigen(true);
}

// If this is not an eigen kernel
// If there is no vector eigen tag and no matrix eigen tag,
// then we consider this as noneigen kernel
if (vtags.find(_Bx_tag) == vtags.end() && mtags.find(_B_tag) == mtags.end())
// Associate the eigen matrix tag and the vector tag
// if this is a eigen kernel
object.useMatrixTag(_B_tag, {});
object.useVectorTag(_Bx_tag, {});
}
else
{
// Noneigen Vector tag
object.useVectorTag(_Ax_tag, {});
Expand All @@ -173,13 +181,6 @@ NonlinearEigenSystem::postAddResidualObject(ResidualObject & object)
// Noneigen Kernels
object.useMatrixTag(_precond_tag, {});
}
else
{
// Associate the eigen matrix tag and the vector tag
// if this is a eigen kernel
object.useMatrixTag(_B_tag, {});
object.useVectorTag(_Bx_tag, {});
}
}

void
Expand All @@ -189,15 +190,6 @@ NonlinearEigenSystem::solve()
if (!presolve_succeeded)
return;

// In DEBUG mode, Libmesh will check the residual automatically. This may cause
// an error because B does not need to assembly by default.
// When PETSc is older than 3.13, we always need to do an extra assembly,
// so we do not do "close" here
#if DEBUG && !PETSC_RELEASE_LESS_THAN(3, 13, 0)
if (sys().has_matrix_B())
sys().get_matrix_B().close();
#endif

// We apply initial guess for only nonlinear solver
if (_eigen_problem.isNonlinearEigenvalueSolver())
_eigen_sys.set_initial_space(solution());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
[]

[Kernels]
inactive = 'rhs'
[./rhs]
type = Reaction
variable = u
Expand Down
8 changes: 8 additions & 0 deletions test/tests/problems/eigen_problem/eigensolvers/tests
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,12 @@
issues = '#15048'
requirement = 'The system shall be able to automatically scale a nonlinear eigen-solve based on entries in the non-eigen residual vector.'
[]

[error_eigen_non_generalized]
type = 'RunException'
input = 'dg_krylovschur.i'
expect_err = 'This object has been marked as contributing to B or Bx but the eigen problem type is not a generalized one'
requirement = "The system shall error if a user requests a standard eigenvalue solve when there are objects marked to contribute to the Bx vector or B matrix."
cli_args = "Kernels/inactive=''"
[]
[]

0 comments on commit ef92d30

Please sign in to comment.