Skip to content
Snippets Groups Projects
Commit 16f49932 authored by webmanue's avatar webmanue
Browse files

fix Solver_Test in MPI-parallel

- e.g. forces were added multiple times
parent 2e016d89
No related branches found
No related tags found
No related merge requests found
......@@ -66,7 +66,6 @@ constexpr double constantTimeStep = .1;
template <class Policy> struct DynamicSolver_Test : Test {
using assembler_type = test::Assembler_Mock<Policy>;
assembler_type assembler;
using solver_type = Solver_Mock<Policy>;
solver_type solver;
......@@ -81,6 +80,8 @@ template <class Policy> struct DynamicSolver_Test : Test {
assembler_type::mesh_type::template fromConnectivity<
std::array<std::array<int, 1>, 1>>(1, {{{{0}}}}, 1, 2);
assembler_type assembler{&mesh};
using vector_type = typename dynamic_solver_type::vector_type;
using matrix_type = typename dynamic_solver_type::matrix_type;
......@@ -262,8 +263,8 @@ TYPED_TEST(DynamicSolver_Test, computes_correct_effective_forces) {
const auto full = TestFixture::vector_type::fromDistributed(forces);
EXPECT_THAT(full.unwrap(), SizeIs(2));
EXPECT_THAT(full(0), ScalarEq(-264.));
EXPECT_THAT(full(1), ScalarEq(-499.));
EXPECT_THAT(full(0), ScalarEq(-265.));
EXPECT_THAT(full(1), ScalarEq(-500.));
return TestFixture::vector_type::fromGlobalMesh(this->mesh);
};
......@@ -319,8 +320,8 @@ TYPED_TEST(DynamicSolver_Test,
const auto full = TestFixture::vector_type::fromDistributed(forces);
EXPECT_THAT(full.unwrap(), SizeIs(2));
EXPECT_THAT(full(0), ScalarEq(1200.));
EXPECT_THAT(full(1), ScalarEq(1747.));
EXPECT_THAT(full(0), ScalarEq(1197.));
EXPECT_THAT(full(1), ScalarEq(1743.));
return TestFixture::vector_type::fromGlobalMesh(this->mesh);
};
......@@ -343,10 +344,10 @@ TYPED_TEST(DynamicSolver_Test, computes_correct_effective_stiffness) {
auto matrix = TestFixture::matrix_type::fromMesh(this->mesh);
assemble(guess, time, &matrix);
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 0, -378.));
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 0, -379.));
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 1, 740.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 0, -1160.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 1, 1522.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 1, 1521.));
return TestFixture::vector_type::fromGlobalMesh(this->mesh);
};
......@@ -402,10 +403,10 @@ TYPED_TEST(DynamicSolver_Test,
assemble(probe, time, &matrix);
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 0, -378.));
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 0, -379.));
EXPECT_THAT(matrix, ScalarEqIfLocal(0, 1, 740.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 0, -1160.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 1, 1522.));
EXPECT_THAT(matrix, ScalarEqIfLocal(1, 1, 1521.));
return TestFixture::vector_type::fromGlobalMesh(this->mesh);
};
......
......@@ -29,7 +29,8 @@ namespace solve {
namespace test {
namespace {
template <class Policy> struct Assembler_Mock {
template <class Policy> class Assembler_Mock {
public:
static constexpr double constantTime = .77;
using policy_type = Policy;
......@@ -40,6 +41,8 @@ template <class Policy> struct Assembler_Mock {
using value_type = typename mesh_type::value_type;
using real_type = typename mesh_type::real_type;
explicit Assembler_Mock(const mesh_type *mesh) : mesh_(mesh) {}
/**
* @brief Computes |x - 1|^2 * |y - 2|^2 + 1
* @remark Expects to be called with the time constant.
......@@ -51,11 +54,12 @@ template <class Policy> struct Assembler_Mock {
EXPECT_THAT(time, ::testing::DoubleEq(constantTime));
if (displacements.unwrap().size() > 0) {
const auto x = displacements(0);
const auto y = displacements(1);
for (auto &&element : mesh_->localElements()) {
auto in = std::vector<value_type>(2);
element.copyElementData(displacements, &in);
*energy = std::norm(x - 1) + std::norm(y - 2) + 1.;
*energy += .5 * std::norm(in.at(0) - 1);
*energy += .5 * std::norm(in.at(1) - 2);
}
}
......@@ -71,13 +75,17 @@ template <class Policy> struct Assembler_Mock {
EXPECT_THAT(time, ::testing::DoubleEq(constantTime));
const auto replacer = force->unwrap().replace();
if (displacements.unwrap().size() > 0) {
const auto x = displacements(0);
const auto y = displacements(1);
for (auto &&element : mesh_->localElements()) {
auto in = std::vector<value_type>(1);
element.copyElementData(displacements, &in);
ASSERT_THAT(in, ::testing::SizeIs(2));
replacer(0) = 2. * (x - 1);
replacer(1) = 2. * (y - 2.);
auto out = std::vector<value_type>(2);
out.at(0) = in.at(0) - 1.;
out.at(1) = in.at(1) - 2.;
element.addElementData(out, force);
}
}
......@@ -86,21 +94,21 @@ template <class Policy> struct Assembler_Mock {
* @remark Expects to be called with the time constant.
* @remark Expects two degrees of freedom, both on the same rank.
*/
void
assembleStiffnessMatrix(const cpppetsc::local<vector_type> &displacements,
const double time, matrix_type *const matrix) const {
void assembleStiffnessMatrix(const cpppetsc::local<vector_type> &,
const double time,
matrix_type *const matrix) const {
assert(matrix);
EXPECT_THAT(time, ::testing::DoubleEq(constantTime));
const auto replacer = matrix->assemblyView().replace();
if (displacements.unwrap().size() > 0) {
replacer(0, 0) = 2.;
replacer(0, 1) = 0.;
replacer(1, 0) = 0.;
replacer(1, 1) = 2.;
for (auto &&element : mesh_->localElements()) {
const auto out = std::vector<value_type>{1., 0., 0., 1.};
element.addElementMatrix(out, matrix);
}
}
private:
const mesh_type *mesh_;
};
} // namespace
} // namespace test
......@@ -143,7 +151,7 @@ template <class TestConfiguration> struct Solver_Test : ::testing::Test {
1, {{{0, 1}, {0, 1}}}, 2, 1);
solver_type solver = solver_type{&mesh};
assembler_type assembler;
assembler_type assembler{&mesh};
};
TYPED_TEST_CASE_P(Solver_Test);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment