diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b30cb10f7e2850ec22ab1fe41f4fcd7e4fc0a448..2598b25290389620ddbb88c0a6ee6d78f188e544 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1 +1,2 @@ -dune_add_test(SOURCES testvolume.cc) \ No newline at end of file +dune_add_test(SOURCES testvolume.cc) +dune_add_test(SOURCES testnumentities.cc) \ No newline at end of file diff --git a/test/testnumentities.cc b/test/testnumentities.cc new file mode 100644 index 0000000000000000000000000000000000000000..cffecd394a83bb2b856a176bf49a19afd3c8f84e --- /dev/null +++ b/test/testnumentities.cc @@ -0,0 +1,58 @@ +// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +// vi: set et ts=4 sw=2 sts=2: + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include +#include +#include + +#include + +#include + +using namespace Dune; + +template +void test_dim(Test& test) +{ + FieldVector lower; lower = -1.5; + FieldVector upper; upper = 1.5; + auto num_elements = filledArray(2); + + using HostGrid = YaspGrid>; + MultiMesh grid(3, lower, upper, num_elements); + + grid[0].globalRefine(2); + grid[1].globalRefine(1); + grid[2].globalRefine(3); + + for (auto const& entities : elements(grid.leafGridView())) { + test.check(entities.size() == grid.size()); + for (auto const& entity : entities) + test.check(entity.isLeaf()); + } + + for (auto const& entities : elements(grid.levelGridView(1))) { + test.check(entities.size() == grid.size()); + for (auto const& entity : entities) + test.check(entity.level() == 1); + } +} + +int main(int argc, char** argv) +{ + MPIHelper::instance(argc, argv); + + Dune::TestSuite test; + test_dim<1>(test); + test_dim<2>(test); + test_dim<3>(test); + return test.exit(); +} diff --git a/test/testvolume.cc b/test/testvolume.cc index a38f235d2ab3ffa6c5f1bf4acf92d26f77e67e07..fa645812e2c2274a3823770b9daddb7723f03223 100644 --- a/test/testvolume.cc +++ b/test/testvolume.cc @@ -11,6 +11,7 @@ #include #include +#include #include @@ -18,8 +19,8 @@ using namespace Dune; -template -bool test_dim() +template +bool test_dim(Test& test) { FieldVector lower; lower = -1.5; FieldVector upper; upper = 1.5; @@ -38,27 +39,35 @@ bool test_dim() grid[2].globalRefine(3); // calculate volume by summing up the entity volumes of the smalles leaf entities - double volume = 0.0; + double volume_leaf = 0.0; for (auto const& entities : elements(grid.leafGridView())) { auto it_small = std::max_element(entities.begin(), entities.end(), [](auto const& e1, auto const& e2) { return e1.level() < e2.level(); }); auto geo_small = it_small->geometry(); - volume += geo_small.volume(); + volume_leaf += geo_small.volume(); } - std::cout << "volume(elements<" << dim << ">) = " << volume << "\n"; + std::cout << "volume_leaf(elements<" << dim << ">) = " << volume_leaf << "\n"; + test.check(std::abs(volume_leaf - domain) < 1.e-10); - if (std::abs(volume - domain) > 1.e-10) - return false; - else - return true; + // calculate volume by summing up the entity volumes of the level=1 entities + double volume_level = 0.0; + for (auto const& entities : elements(grid.levelGridView(1))) { + auto geo = entities[0].geometry(); + volume_level += geo.volume(); + } + std::cout << "volume_level(elements<" << dim << ">) = " << volume_level << "\n"; + test.check(std::abs(volume_level - domain) < 1.e-10); } int main(int argc, char** argv) { MPIHelper::instance(argc, argv); - bool b1 = test_dim<1>(); - bool b2 = test_dim<2>(); - bool b3 = test_dim<3>(); - return b1 && b2 && b3 ? 0 : 1; + + Dune::TestSuite test; + test_dim<1>(test); + test_dim<2>(test); + test_dim<3>(test); + + return test.exit(); }