Commit 542c8fc3 authored by webmanue's avatar webmanue
Browse files

explicitly specify default problem type in API

- SLEPc does not permit resetting problem type to default "0"
parent 961b1d62
Pipeline #139031 passed with stages
in 7 minutes and 40 seconds
......@@ -38,7 +38,6 @@ public:
explicit LinearEigenvalueProblemSolver();
enum class Type {
unspecified = 0,
hermitian = EPS_HEP,
nonhermitian = EPS_NHEP,
generalized_hermitian = EPS_GHEP,
......@@ -53,7 +52,7 @@ public:
* @throw InvalidProblemTypeException if the type does not represent a
* nongeneralized problem
*/
void setOperators(const matrix_type *A, const Type type = Type::unspecified);
void setOperators(const matrix_type *A, const Type type = Type::nonhermitian);
/**
* @brief Sets the matrices associated with a generalized eigenvalue
......@@ -62,7 +61,7 @@ public:
* generalized problem
*/
void setOperators(const matrix_type *A, const matrix_type *B,
const Type type = Type::unspecified);
const Type type = Type::generalized_nonhermitian);
/**
* @brief Solve linear eigenvalue problem.
......@@ -187,15 +186,13 @@ LinearEigenvalueProblemSolver<Policy>::numberOfEigenpairs() const {
template <class Policy>
void LinearEigenvalueProblemSolver<Policy>::setType(
const Type type, const GeneralizedProblem generalized) {
if (type != Type::unspecified) {
const auto generalizedType =
bool{type == Type::generalized_hermitian ||
type == Type::generalized_nonhermitian ||
type == Type::generalized_nonhermitian_spd ||
type == Type::generalized_indefinite};
if (generalizedType != (generalized == GeneralizedProblem::yes)) {
throw InvalidProblemTypeException();
}
const auto generalizedType =
bool{type == Type::generalized_hermitian ||
type == Type::generalized_nonhermitian ||
type == Type::generalized_nonhermitian_spd ||
type == Type::generalized_indefinite};
if (generalizedType != (generalized == GeneralizedProblem::yes)) {
throw InvalidProblemTypeException();
}
Policy::handleError(
EPSSetProblemType(this->data(), static_cast<EPSProblemType>(type)));
......
......@@ -352,7 +352,7 @@ TYPED_TEST(LinearEigenvalueProblemSolver_Test,
}
TYPED_TEST(LinearEigenvalueProblemSolver_Test,
solver_supports_switching_problem_type) {
solver_supports_switching_problem_type_to_hermitian_type) {
using solver_type = typename TestFixture::solver_type;
using matrix_type = typename TestFixture::matrix_type;
......@@ -376,6 +376,31 @@ TYPED_TEST(LinearEigenvalueProblemSolver_Test,
EXPECT_THAT(solver.getEigenvalue(1), cppptest::ScalarNear(1., 1e-15));
}
TYPED_TEST(LinearEigenvalueProblemSolver_Test,
solver_supports_switching_problem_type_to_unspecified_type) {
using solver_type = typename TestFixture::solver_type;
using matrix_type = typename TestFixture::matrix_type;
auto solver = solver_type{};
const auto A = matrix_type::fromList({
{1., 0.},
{0., 1.},
});
const auto B = matrix_type::fromList({
{2., 0.},
{0., 2.},
});
solver.setOperators(&A, &B, solver_type::Type::generalized_hermitian);
solver.setOperators(&A);
solver.solve();
EXPECT_THAT(solver.getEigenvalue(0), cppptest::ScalarNear(1., 1e-15));
EXPECT_THAT(solver.getEigenvalue(1), cppptest::ScalarNear(1., 1e-15));
}
} // namespace
} // namespace cppslepc
} // namespace ae108
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment