diff --git a/test/common/boundingboxtree/CMakeLists.txt b/test/common/boundingboxtree/CMakeLists.txt index 13754bafd48e41b89159ca4d075071c721af1781..f13fc75df0813e1e4117bed110139f0151e8fc2c 100644 --- a/test/common/boundingboxtree/CMakeLists.txt +++ b/test/common/boundingboxtree/CMakeLists.txt @@ -12,7 +12,7 @@ dune_add_test(NAME test_bboxtree_dim3 COMPILE_DEFINITIONS WORLD_DIMENSION=3) # symlink the input file in the build directory -dune_symlink_to_source_files(FILES "network1d.msh") +dune_symlink_to_source_files(FILES "network1d.msh" "network2d.msh") #install sources install(FILES diff --git a/test/common/boundingboxtree/network2d.geo b/test/common/boundingboxtree/network2d.geo new file mode 100644 index 0000000000000000000000000000000000000000..d48f373da384679ea07b3bd7f50f732851530150 --- /dev/null +++ b/test/common/boundingboxtree/network2d.geo @@ -0,0 +1,12 @@ +cl_ = 0.5; + +Point(1) = {0.1, 0.1, 0.1, cl_}; +Point(2) = {0.78, 0.1, 0.1, cl_}; +Point(3) = {0.1, 0.78, 0.78, cl_}; +Point(4) = {0.78, 0.78, 0.78, cl_}; +Line(1) = {1, 3}; +Line(2) = {3, 4}; +Line(3) = {4, 2}; +Line(4) = {2, 1}; +Line Loop(5) = {4, 1, 2, 3}; +Plane Surface(6) = {5}; diff --git a/test/common/boundingboxtree/network2d.msh b/test/common/boundingboxtree/network2d.msh new file mode 100644 index 0000000000000000000000000000000000000000..ca4f5a01099bd7229e50e15bbf0af895f30896b8 --- /dev/null +++ b/test/common/boundingboxtree/network2d.msh @@ -0,0 +1,44 @@ +$MeshFormat +2.2 0 8 +$EndMeshFormat +$Nodes +11 +1 0.1 0.1 0.1 +2 0.78 0.1 0.1 +3 0.1 0.78 0.78 +4 0.78 0.78 0.78 +5 0.1 0.4399999999991414 0.4399999999991414 +6 0.4399999999991407 0.78 0.78 +7 0.78 0.4400000000008126 0.4400000000008126 +8 0.4400000000008131 0.1 0.1 +9 0.4399999999998759 0.5336734693877463 0.5336734693877463 +10 0.5420000000002191 0.2887346938776259 0.2887346938776259 +11 0.2977551020411081 0.2814702207410666 0.2814702207410666 +$EndNodes +$Elements +24 +1 15 2 0 1 1 +2 15 2 0 2 2 +3 15 2 0 3 3 +4 15 2 0 4 4 +5 1 2 0 1 1 5 +6 1 2 0 1 5 3 +7 1 2 0 2 3 6 +8 1 2 0 2 6 4 +9 1 2 0 3 4 7 +10 1 2 0 3 7 2 +11 1 2 0 4 2 8 +12 1 2 0 4 8 1 +13 2 2 0 6 3 6 9 +14 2 2 0 6 4 9 6 +15 2 2 0 6 3 9 5 +16 2 2 0 6 4 7 9 +17 2 2 0 6 2 10 7 +18 2 2 0 6 1 5 11 +19 2 2 0 6 9 10 11 +20 2 2 0 6 1 11 8 +21 2 2 0 6 2 8 10 +22 2 2 0 6 8 11 10 +23 2 2 0 6 5 9 11 +24 2 2 0 6 7 10 9 +$EndElements diff --git a/test/common/boundingboxtree/test_bboxtree.cc b/test/common/boundingboxtree/test_bboxtree.cc index cff08c9c82ee59db25a054c7c35ef78427fe683f..b89f7490e8f1019f6c6c957a5968ef9f00d51797 100644 --- a/test/common/boundingboxtree/test_bboxtree.cc +++ b/test/common/boundingboxtree/test_bboxtree.cc @@ -23,6 +23,7 @@ #include <dumux/common/geometry/boundingboxtree.hh> #include <dumux/common/geometry/geometricentityset.hh> #include <dumux/common/geometry/intersectingentities.hh> +#include <test/common/geometry/writetriangulation.hh> namespace Dumux { @@ -70,7 +71,9 @@ public: const OtherGridView& otherGridView, std::size_t expectedUniqueIntersections, bool checkTotalIntersections = false, - std::size_t expectedIntersections = 0) + std::size_t expectedIntersections = 0, + bool writeVTKPolyData = false, + int runIdx = 0) { Dune::Timer timer; const auto intersections = intersectingEntities(*tree_, otherTree); @@ -106,6 +109,9 @@ public: } } + if (writeVTKPolyData) + writeVTKPolyDataTriangle(uniqueIntersections, "unique_" + std::to_string(runIdx)); + std::cout << "Found " << uniqueIntersections.size() << " unique intersections " << "in " << timer.elapsed() << std::endl; @@ -142,6 +148,7 @@ int main (int argc, char *argv[]) try std::vector<int> returns; Dumux::BBoxTreeTests<Grid> test; + int runIdx = 0; for (const auto scaling : {1e10, 1.0, 1e-3, 1e-10}) { std::cout << std::endl @@ -169,6 +176,12 @@ int main (int argc, char *argv[]) try } #if HAVE_DUNE_FOAMGRID && WORLD_DIMENSION == 3 + + /////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + /// 1D-3D TESTS /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// { const GlobalPosition lowerLeft(0.0); const GlobalPosition upperRight(1.0*scaling); @@ -269,7 +282,61 @@ int main (int argc, char *argv[]) try returns.push_back(test.intersectTree(networkTree, networkGrid->leafGridView(), 10, true, 40)); } } + + /////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + /// 2D-3D TESTS /////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////// + { + const GlobalPosition lowerLeft(0.0); + const GlobalPosition upperRight(1.0*scaling); + constexpr int numCellsX = 10; + std::array<unsigned int, dim> elems; elems.fill(numCellsX); + auto grid = Dune::StructuredGridFactory<Grid>::createCubeGrid(lowerLeft, upperRight, elems); + + Dune::VTKWriter<Grid::LeafGridView> vtkWriter(grid->leafGridView()); + vtkWriter.write("grid_dim" + std::to_string(dimworld) + "_" + std::to_string(runIdx), Dune::VTK::ascii); + + using NetworkGrid = Dune::FoamGrid<2, dimworld>; + using NetworkGridView = NetworkGrid::LeafGridView; + using EntitySet = Dumux::GridViewGeometricEntitySet<NetworkGridView, 0>; + Dumux::BoundingBoxTree<EntitySet> networkTree; + + { + std::cout << std::endl + << "Intersect with other bounding box tree:" << std::endl + << "***************************************" + << std::endl; + + // create a network grid from gmsh + auto networkGrid = std::shared_ptr<NetworkGrid>(Dune::GmshReader<NetworkGrid>::read("network2d.msh", false, false)); + + // scaling + for (const auto& vertex : vertices(networkGrid->leafGridView())) + { + auto newPos = vertex.geometry().corner(0); + newPos *= scaling; + networkGrid->setPosition(vertex, newPos); + } + + Dune::VTKWriter<NetworkGridView> lowDimVtkWriter(networkGrid->leafGridView()); + lowDimVtkWriter.write("network_" + std::to_string(runIdx), Dune::VTK::ascii); + + std::cout << "Constructed 2d network grid with " << networkGrid->leafGridView().size(0) << " elements." << std::endl; + + // build the bulk grid bounding box tree + returns.push_back(test.build(grid->leafGridView())); + + // build the network grid bounding box tree + networkTree.build(std::make_shared<EntitySet>(networkGrid->leafGridView())); + + // intersect the two bounding box trees + returns.push_back(test.intersectTree(networkTree, networkGrid->leafGridView(), 342, true, 342, true, runIdx)); + } + } #endif + ++runIdx; } std::cout << std::endl;