diff --git a/dune/tectonic/CMakeLists.txt b/dune/tectonic/CMakeLists.txt index 3c522fe25fe8e01f95d01b18bc1f7a77f15e695b..8b89df418ec7541fa15ae1a485e6b944ec4a904a 100644 --- a/dune/tectonic/CMakeLists.txt +++ b/dune/tectonic/CMakeLists.txt @@ -1,3 +1,5 @@ +add_subdirectory(test) + install(FILES body.hh frictiondata.hh diff --git a/dune/tectonic/test/CMakeLists.txt b/dune/tectonic/test/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..cb60237fc18e5617629ac26e1520ff96c6266259 --- /dev/null +++ b/dune/tectonic/test/CMakeLists.txt @@ -0,0 +1,9 @@ +set(TESTS test-polyhedral-minimisation) +foreach(_test ${TESTS}) + add_executable(${_test} EXCLUDE_FROM_ALL ${_test}.cc) + target_link_dune_default_libraries(${_test}) + add_test(${_test} ${_test}) +endforeach() + +add_directory_test_target(_test_target) +add_dependencies(${_test_target} ${TESTS}) diff --git a/dune/tectonic/test/test-polyhedral-minimisation.cc b/dune/tectonic/test/test-polyhedral-minimisation.cc new file mode 100644 index 0000000000000000000000000000000000000000..ecb85ac43bb70ccaa9c67a13b5f516da090b1f7d --- /dev/null +++ b/dune/tectonic/test/test-polyhedral-minimisation.cc @@ -0,0 +1,151 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <dune/common/fvector.hh> + +#include <dune/tectonic/polyhedrondistance.hh> + +int main() { + using LocalVector = Dune::FieldVector<double, 2>; + + auto const test = + [&](ConvexPolyhedron<LocalVector> const &p1, + ConvexPolyhedron<LocalVector> const &p2, double analyticalDistance) { + LocalVector target; + { + double const error = + std::abs(analyticalDistance - distance(p1, p2, 1e-12)); + std::cout << "error: " << error << std::endl; + assert(error < 1e-12); + } + }; + { + /* + * Calculate the distance between two triangles, where it is attained at a + * face-vertex pair + * + * O + * |\ + * | \ + * O O--O + * |\ + * | \ + * O--O + */ + double const analyticalDistance = std::sqrt(2.0); + LocalVector tmp; + + ConvexPolyhedron<LocalVector> bs1; + bs1.vertices.resize(3); + tmp[0] = 0; + tmp[1] = 0; + bs1.vertices[0] = tmp; + tmp[0] = 0; + tmp[1] = 2; + bs1.vertices[1] = tmp; + tmp[0] = 2; + tmp[1] = 0; + bs1.vertices[2] = tmp; + + ConvexPolyhedron<LocalVector> bs2; + bs2.vertices.resize(3); + tmp[0] = 2; + tmp[1] = 2; + bs2.vertices[0] = tmp; + tmp[0] = 2; + tmp[1] = 4; + bs2.vertices[1] = tmp; + tmp[0] = 4; + tmp[1] = 2; + bs2.vertices[2] = tmp; + + test(bs1, bs2, analyticalDistance); + } + + { + /* + * Calculate the distance between two triangles, where it is + * attained in a face-face pair + * + * O--O + * \ | + * \| + * O O + * |\ + * | \ + * O--O + */ + double const analyticalDistance = 2.0 * std::sqrt(2.0); + LocalVector tmp; + + ConvexPolyhedron<LocalVector> bs1; + bs1.vertices.resize(3); + tmp[0] = 0; + tmp[1] = 0; + bs1.vertices[0] = tmp; + tmp[0] = 0; + tmp[1] = 2; + bs1.vertices[1] = tmp; + tmp[0] = 2; + tmp[1] = 0; + bs1.vertices[2] = tmp; + + ConvexPolyhedron<LocalVector> bs2; + bs2.vertices.resize(3); + tmp[0] = 4; + tmp[1] = 4; + bs2.vertices[0] = tmp; + tmp[0] = 2; + tmp[1] = 4; + bs2.vertices[1] = tmp; + tmp[0] = 4; + tmp[1] = 2; + bs2.vertices[2] = tmp; + + test(bs1, bs2, analyticalDistance); + } + + { + /* + * Calculate the distance between two triangles, where it is + * attained in a vertex-vertex pair + * + * O + * |\ + * | \ + * O--O O--O + * \ | + * \| + * O + */ + double analyticalDistance = 2.0; + LocalVector tmp; + + ConvexPolyhedron<LocalVector> bs1; + bs1.vertices.resize(3); + tmp[0] = 2; + tmp[1] = 2; + bs1.vertices[0] = tmp; + tmp[0] = 0; + tmp[1] = 2; + bs1.vertices[1] = tmp; + tmp[0] = 2; + tmp[1] = 0; + bs1.vertices[2] = tmp; + + ConvexPolyhedron<LocalVector> bs2; + bs2.vertices.resize(3); + tmp[0] = 4; + tmp[1] = 2; + bs2.vertices[0] = tmp; + tmp[0] = 4; + tmp[1] = 4; + bs2.vertices[1] = tmp; + tmp[0] = 6; + tmp[1] = 2; + bs2.vertices[2] = tmp; + + test(bs1, bs2, analyticalDistance); + } +}