Skip to content

Commit

Permalink
throw tests
Browse files Browse the repository at this point in the history
  • Loading branch information
henrij22 committed Nov 28, 2024
1 parent 7093fdc commit 8dc4470
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 7 deletions.
6 changes: 3 additions & 3 deletions ikarus/solver/eigenvaluesolver/generaleigensolver.hh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct GeneralSymEigenSolver<EigenValueSolverType::Spectra, MT>
bOP_(std::forward<MATB>(B)),
solverSmallest_(aOP_, bOP_, nevsPartition_.first, std::min(nevsPartition_.second * 2, nev_)),
solverGreatest_(aOP_, bOP_, nevsPartition_.second, nevsPartition_.second * 2) {
if (A.cols() != B.cols())
if ((A.cols() != B.cols()) or (A.rows() != B.rows()) or (A.cols() != B.cols()))
DUNE_THROW(Dune::IOError, "GeneralSymEigenSolver: The passed matrices should have the same size");

Check warning on line 81 in ikarus/solver/eigenvaluesolver/generaleigensolver.hh

View check run for this annotation

Codecov / codecov/patch

ikarus/solver/eigenvaluesolver/generaleigensolver.hh#L81

Added line #L81 was not covered by tests
eigenvalues_.resize(nev_);
eigenvectors_.resize(A.rows(), nev_);
Expand Down Expand Up @@ -185,7 +185,7 @@ struct GeneralSymEigenSolver<EigenValueSolverType::Eigen, MT>
: matA_(std::forward<MATA>(A)),
matB_(std::forward<MATB>(B)),
solver_(A.size()) {
if (A.cols() != B.cols())
if ((A.cols() != B.cols()) or (A.rows() != B.rows()) or (A.cols() != B.cols()))
DUNE_THROW(Dune::IOError, "GeneralSymEigenSolver: The passed matrices should have the same size");
}

Expand Down Expand Up @@ -281,7 +281,7 @@ struct PartialGeneralSymEigenSolver
aOP_(std::forward<MATA>(A)),
bOP_(std::forward<MATB>(B)),
solver_(aOP_, bOP_, nev, 2 * nev <= A.cols() ? 2 * nev : A.cols()) {
if (A.cols() != B.cols())
if ((A.cols() != B.cols()) or (A.rows() != B.rows()) or (A.cols() != B.cols()))
DUNE_THROW(Dune::IOError, "GeneralSymEigenSolver: The passed matrices should have the same size");
}

Expand Down
4 changes: 3 additions & 1 deletion tests/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ set(programSourceFiles
testresultfunction.cpp
testtruss.cpp
testvtkwriter.cpp
testdynamics.cpp
testmodalanalysis.cpp
testeigenvaluesolver.cpp
)

Expand All @@ -53,6 +53,8 @@ set(TEST_DEPENDING_ON_LOCALFEFUNCTIONS
testnonlinearelasticitysvk
testadaptivestepsizing
testresultfunction.cpp
testmodalanalysis.cpp
testvtkwriter.cpp
)
# Compile only tests
dune_add_test(
Expand Down
41 changes: 41 additions & 0 deletions tests/src/testeigenvaluesolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,47 @@ auto testRealWorldProblem() {
static_assert(Ikarus::Concepts::EigenValueSolver<decltype(solver2)>);
static_assert(Ikarus::Concepts::EigenValueSolver<decltype(solver3)>);

auto testMatrix1 = Eigen::MatrixX<double>::Random(10, 10).eval();
auto testMatrix2 = Eigen::MatrixX<double>::Random(9, 9).eval();
auto testMatrix3 = Eigen::MatrixX<double>::Random(9, 10).eval();

auto sparseTestMatrix1 = Eigen::SparseMatrix<double>(testMatrix1.sparseView());
auto sparseTestMatrix2 = Eigen::SparseMatrix<double>(testMatrix2.sparseView());
auto sparseTestMatrix3 = Eigen::SparseMatrix<double>(testMatrix3.sparseView());

t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Spectra, Eigen::SparseMatrix<double>>(sparseTestMatrix1,
sparseTestMatrix2);
}) << testLocation();
t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Spectra, Eigen::SparseMatrix<double>>(sparseTestMatrix2,
sparseTestMatrix1);
}) << testLocation();
t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Spectra, Eigen::SparseMatrix<double>>(sparseTestMatrix3,
sparseTestMatrix1);
}) << testLocation();

t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Eigen, Eigen::MatrixX<double>>(testMatrix1, testMatrix2);
}) << testLocation();
t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Spectra, Eigen::MatrixX<double>>(testMatrix2, testMatrix1);
}) << testLocation();
t.checkThrow([&]() {
Ikarus::GeneralSymEigenSolver<EigenValueSolverType::Spectra, Eigen::MatrixX<double>>(testMatrix3, testMatrix1);
}) << testLocation();

t.checkThrow([&]() { Ikarus::PartialGeneralSymEigenSolver<Eigen::MatrixX<double>>(testMatrix1, testMatrix2, 7); })
<< testLocation();
t.checkThrow([&]() { Ikarus::PartialGeneralSymEigenSolver<Eigen::MatrixX<double>>(testMatrix2, testMatrix1, 7); })
<< testLocation();
t.checkThrow([&]() { Ikarus::PartialGeneralSymEigenSolver<Eigen::MatrixX<double>>(testMatrix3, testMatrix1, 7); })
<< testLocation();

t.checkThrow([&]() { Ikarus::PartialGeneralSymEigenSolver<Eigen::MatrixX<double>>(testMatrix1, testMatrix1, 15); })
<< testLocation();

return t;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

using Dune::TestSuite;

static auto dynamicsTest() {
TestSuite t("DynamicsTest");
static auto modalAnalysisTest() {
TestSuite t("ModalAnalysis test");
using Grid = Dune::YaspGrid<2>;

const double Lx = 4.0;
Expand Down Expand Up @@ -92,6 +92,6 @@ int main(int argc, char** argv) {
Ikarus::init(argc, argv);
TestSuite t;

t.subTest(dynamicsTest());
t.subTest(modalAnalysisTest());
return t.exit();
}
14 changes: 14 additions & 0 deletions tests/src/testnonlinearelasticity.hh
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ auto GreenLagrangeStrainTest(const Material& mat) {
<< KLE << "\n Diff:\n"
<< K - KLE;

Eigen::MatrixXd M, MLE;
M.setZero(nDOF, nDOF);
MLE.setZero(nDOF, nDOF);

calculateMatrix(fe, req, Ikarus::MatrixAffordance::linearMass, M);
calculateMatrix(feLE, reqLE, Ikarus::MatrixAffordance::linearMass, MLE);

t.check(isApproxSame(M, MLE, tol),
"Mismatch between linear and non-linear mass matrix with gridDim = " + std::to_string(gridDim))
<< "\n"
<< M << "\nand \n"
<< MLE << "\n Diff:\n"
<< M - MLE;

return t;
}

Expand Down

0 comments on commit 8dc4470

Please sign in to comment.