diff --git a/CMakeLists_files.cmake b/CMakeLists_files.cmake index 8a7f3098e..a70d16094 100644 --- a/CMakeLists_files.cmake +++ b/CMakeLists_files.cmake @@ -127,7 +127,7 @@ if(Boost_VERSION_STRING VERSION_GREATER 1.53) tests/cpgrid/lookUpCellCentroid_cpgrid_test.cpp tests/cpgrid/lookupdataCpGrid_test.cpp tests/cpgrid/shifted_cart_test.cpp - tests/test_graphofgrid.cpp + tests/test_graphofgrid.cpp ) endif() diff --git a/opm/grid/GraphOfGrid.cpp b/opm/grid/GraphOfGrid.cpp index 9005a5af4..d09d1c896 100644 --- a/opm/grid/GraphOfGrid.cpp +++ b/opm/grid/GraphOfGrid.cpp @@ -58,12 +58,6 @@ void GraphOfGrid::createGraph () template int GraphOfGrid::contractVertices (int gID1, int gID2) { - // ensure gID1& well, bool checkIntersection=true); @@ -154,6 +158,7 @@ class GraphOfGrid{ void createGraph (); // edge weight=1 /// \brief Identify the well containing the cell with this global ID + /// /// returns the smallest cell-ID in the well or /// returns -1 if no well contains given gID int wellID (int gID) const; diff --git a/opm/grid/GraphOfGridWrappers.hpp b/opm/grid/GraphOfGridWrappers.hpp index 840a1bb5c..4b2516161 100644 --- a/opm/grid/GraphOfGridWrappers.hpp +++ b/opm/grid/GraphOfGridWrappers.hpp @@ -39,7 +39,9 @@ namespace Opm { namespace { using ZOLTAN_ID_PTR = int*; } - /// \brief callback ftion for ZOLTAN_NUM_OBJ_FN + + /// \brief callback function for ZOLTAN_NUM_OBJ_FN + /// /// returns the number of vertices in the graph int getGraphOfGridNumVertices(void* pGraph, int *err) { @@ -50,10 +52,11 @@ namespace Opm { } /// \brief callback ftion for ZOLTAN_OBJ_LIST_FN + /// /// fills the vector gIDs with vertex global IDs /// and the vector objWeights with their weights void getGraphOfGridVerticesList(void* pGraph, - int dimGlobalID, + [[maybe_unused]] int dimGlobalID, [[maybe_unused]] int dimLocalID, ZOLTAN_ID_PTR gIDs, [[maybe_unused]] ZOLTAN_ID_PTR lIDs, @@ -76,10 +79,11 @@ namespace Opm { } /// \brief callback ftion for ZOLTAN_NUM_EDGES_MULTI_FN + /// /// takes the list of global IDs (gIDs) and fills (consecutively) /// vector numEdges with the number of their edges void getGraphOfGridNumEdges(void *pGraph, - int dimGlobalID, + [[maybe_unused]] int dimGlobalID, [[maybe_unused]] int dimLocalID, int numCells, ZOLTAN_ID_PTR gIDs, @@ -106,12 +110,14 @@ namespace Opm { } /// \brief callback ftion for ZOLTAN_EDGE_LIST_MULTI_FN + /// /// takes the list of global IDs (gIDs) and fills (consecutively): /// vector nborGIDs with the list of neighbors (all into 1 vector), /// vector nborProc with neighbors' process numbers, /// vector edgeWeights with edge weights. /// The vector numEdges provides the number of edges for each gID - void getGraphOfGridEdgeList(void *pGraph, int dimGlobalID, + void getGraphOfGridEdgeList(void *pGraph, + [[maybe_unused]] int dimGlobalID, [[maybe_unused]] int dimLocalID, int numCells, ZOLTAN_ID_PTR gIDs, @@ -151,8 +157,8 @@ namespace Opm { *err = ZOLTAN_OK; } - // Wells: /// \brief Adds well to the GraphOfGrid + /// /// Adding the well contracts vertices of the well into one vertex. void addFutureConnectionWells (GraphOfGrid& gog, const std::unordered_map>& wells) @@ -162,6 +168,7 @@ namespace Opm { } /// \brief Add well cells' global IDs to the list + /// /// Output of the partitioning is missing vertices that were contracted. /// This function fills in omitted gIDs and gives them the properties /// (like process number and ownership) of their representative cell (well ID). diff --git a/tests/test_graphofgrid.cpp b/tests/test_graphofgrid.cpp index b6bb9b99f..ff124bec9 100644 --- a/tests/test_graphofgrid.cpp +++ b/tests/test_graphofgrid.cpp @@ -1,3 +1,26 @@ +// -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +// vi: set et ts=4 sw=4 sts=4: +/* + This file is part of the Open Porous Media project (OPM). + + OPM is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + OPM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with OPM. If not, see . + + Consult the COPYING file in the top-level source directory of this + module for the precise wording of the license and the list of + copyright holders. +*/ + #include #include @@ -12,58 +35,64 @@ // basic test to check if the graph was constructed correctly BOOST_AUTO_TEST_CASE(SimpleGraph) { - Dune::CpGrid grid; - std::array dims{2,2,2}; - std::array size{2.,2.,2.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); - - BOOST_REQUIRE(gog.size()==8); // number of graph vertices - BOOST_REQUIRE(gog.numEdges(0)==3); // each vertex has 3 neighbors - - auto edgeL = gog.edgeList(2); - BOOST_REQUIRE(edgeL.size()==3); // neighbors of vertex 2 are: 0, 3, 6 - BOOST_REQUIRE(edgeL[0]==1.); - BOOST_REQUIRE(edgeL[3]==1.); - BOOST_REQUIRE(edgeL[6]==1.); - BOOST_REQUIRE(edgeL[4]==0.); // not a neighbor (edgeL's size increased) - - edgeL = gog.edgeList(10); // vertex 10 is not in the graph - BOOST_REQUIRE(edgeL.size()==0); + Dune::CpGrid grid; + std::array dims{2,2,2}; + std::array size{2.,2.,2.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); + + BOOST_REQUIRE(gog.size()==8); // number of graph vertices + BOOST_REQUIRE(gog.numEdges(0)==3); // each vertex has 3 neighbors + + auto edgeL = gog.edgeList(2); + BOOST_REQUIRE(edgeL.size()==3); // neighbors of vertex 2 are: 0, 3, 6 + BOOST_REQUIRE(edgeL[0]==1.); + BOOST_REQUIRE(edgeL[3]==1.); + BOOST_REQUIRE(edgeL[6]==1.); + BOOST_REQUIRE(edgeL[4]==0.); // not a neighbor (edgeL's size increased) + + edgeL = gog.edgeList(10); // vertex 10 is not in the graph + BOOST_REQUIRE(edgeL.size()==0); } // test vertex contraction on a simple graph BOOST_AUTO_TEST_CASE(SimpleGraphWithVertexContraction) { - Dune::CpGrid grid; - std::array dims{2,2,2}; - std::array size{2.,2.,2.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); - - auto edgeL = gog.edgeList(2); - gog.contractVertices(0,1); - BOOST_REQUIRE(gog.size()==7); - edgeL = gog.edgeList(0); - BOOST_REQUIRE(edgeL.size()==4); - BOOST_REQUIRE(edgeL[2]==1); // neighbor of 0 - BOOST_REQUIRE(edgeL[3]==1); // neighbor of 1 - - gog.contractVertices(0,2); - BOOST_REQUIRE(gog.size()==6); - BOOST_REQUIRE(gog.getVertex(0).weight==3.); - edgeL = gog.edgeList(0); - BOOST_REQUIRE(edgeL.size()==4); - BOOST_REQUIRE(edgeL[3]==2); - BOOST_REQUIRE(gog.edgeList(3).size()==2); - BOOST_REQUIRE(gog.edgeList(3)[0]==2); - BOOST_REQUIRE_MESSAGE(gog.getVertex(1).weight==0.,"Implementation detail: \ - Looking up vertex not present in GraphofGrid gives dummy with weight 0."); + Dune::CpGrid grid; + std::array dims{2,2,2}; + std::array size{2.,2.,2.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); + + auto edgeL = gog.edgeList(3); // std::map(gID,edgeWeight) + BOOST_REQUIRE(edgeL[1]==1); + BOOST_REQUIRE(edgeL[0]==0); + gog.contractVertices(0,1); + BOOST_REQUIRE(gog.size()==7); + edgeL = gog.edgeList(3); + BOOST_REQUIRE(edgeL[1]==0); + BOOST_REQUIRE(edgeL[0]==1); + edgeL = gog.edgeList(0); + BOOST_REQUIRE(edgeL.size()==4); + BOOST_REQUIRE(edgeL[2]==1); // neighbor of 0 + BOOST_REQUIRE(edgeL[3]==1); // neighbor of 1 + BOOST_REQUIRE(edgeL[1]==0); // removed vertex, former neighbor of 0 + + gog.contractVertices(0,2); + BOOST_REQUIRE(gog.size()==6); + BOOST_REQUIRE(gog.getVertex(0).weight==3.); + edgeL = gog.edgeList(0); + BOOST_REQUIRE(edgeL.size()==4); + BOOST_REQUIRE(edgeL[3]==2); + BOOST_REQUIRE(gog.edgeList(3).size()==2); + BOOST_REQUIRE(gog.edgeList(3)[0]==2); + BOOST_REQUIRE_MESSAGE(gog.getVertex(1).weight==0.,"Implementation detail: \ + Looking up vertex not present in GraphofGrid gives dummy with weight 0."); auto v5e = gog.getVertex(5).edges; - BOOST_REQUIRE(v5e==gog.edgeList(5)); - BOOST_REQUIRE(v5e==gog.edgeList(6)); // 5 and 6 have the same neighbors (1, 2 got merged) - BOOST_REQUIRE(v5e!=gog.edgeList(7)); + BOOST_REQUIRE(v5e==gog.edgeList(5)); + BOOST_REQUIRE(v5e==gog.edgeList(6)); // 5 and 6 have the same neighbors (1, 2 got merged) + BOOST_REQUIRE(v5e!=gog.edgeList(7)); } @@ -71,11 +100,11 @@ BOOST_AUTO_TEST_CASE(SimpleGraphWithVertexContraction) BOOST_AUTO_TEST_CASE(WrapperForZoltan) { - Dune::CpGrid grid; - std::array dims{5,4,3}; - std::array size{1.,1.,1.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); + Dune::CpGrid grid; + std::array dims{5,4,3}; + std::array size{1.,1.,1.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); int err; int nVer = getGraphOfGridNumVertices(&gog,&err); @@ -94,14 +123,14 @@ BOOST_AUTO_TEST_CASE(WrapperForZoltan) int nEdges=0; for (int i=0; i dims{5,4,3}; - std::array size{1.,1.,1.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); + Dune::CpGrid grid; + std::array dims{5,4,3}; + std::array size{1.,1.,1.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); std::unordered_map> wells{ - {"shape L on the front face", {5,10,15,35,55} }, - {"lying 8 on the right face", {20,1,41,22,3,43,24} }, - {"disconnected vertices", {58,12} } }; + {"shape L on the front face", {5,10,15,35,55} }, + {"lying 8 on the right face", {20,1,41,22,3,43,24} }, + {"disconnected vertices", {58,12} } }; addFutureConnectionWells(gog,wells); BOOST_REQUIRE(gog.getWells().size()==3); int err; @@ -140,37 +169,37 @@ BOOST_AUTO_TEST_CASE(GraphWithWell) BOOST_REQUIRE(err==ZOLTAN_OK); BOOST_REQUIRE(nVer == 49); - int gIDs[nVer], lIDs[0]; + int gIDs[nVer], lIDs[0]; float objWeights[nVer]; getGraphOfGridVerticesList(&gog, 1, 1, gIDs, lIDs, 1, objWeights, &err); BOOST_REQUIRE(err=ZOLTAN_OK); for (int i=0; i dims{5,4,3}; - std::array size{1.,1.,1.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); - - std::array,3> wells{std::set{0,1,2,3,4}, - std::set{52,32,12}, - std::set{59,48,37}}; - // later add std::set{37,38,39,34}, - // {2,8} and {2,38} - for (const auto& w : wells) - gog.addWell(w,false); + Dune::CpGrid grid; + std::array dims{5,4,3}; + std::array size{1.,1.,1.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); + + std::array,3> wells{std::set{0,1,2,3,4}, + std::set{52,32,12}, + std::set{59,48,37}}; + // later add std::set{37,38,39,34}, + // {2,8} and {2,38} + for (const auto& w : wells) + gog.addWell(w,false); BOOST_REQUIRE(gog.getWells().size()==3); int err; @@ -178,7 +207,7 @@ BOOST_AUTO_TEST_CASE(IntersectingWells) BOOST_REQUIRE(err==ZOLTAN_OK); BOOST_REQUIRE(nVer == 52); - gog.addWell(std::set{37,38,39,34}); // intersects with previous + gog.addWell(std::set{37,38,39,34}); // intersects with previous BOOST_REQUIRE(gog.getWells().size()==3); nVer = getGraphOfGridNumVertices(&gog,&err); BOOST_REQUIRE(err==ZOLTAN_OK); @@ -200,19 +229,19 @@ BOOST_AUTO_TEST_CASE(IntersectingWells) BOOST_REQUIRE(err==ZOLTAN_OK); BOOST_REQUIRE(nVer == 47); - int gIDs[nVer], lIDs[0]; + int gIDs[nVer], lIDs[0]; float objWeights[nVer]; getGraphOfGridVerticesList(&gog, 1, 1, gIDs, lIDs, 1, objWeights, &err); BOOST_REQUIRE(err=ZOLTAN_OK); for (int i=0; i well2{0,1,2,3,4,8,34,37,38,39,48,59}; if (wellList.begin()->size()==3) { - BOOST_REQUIRE( *wellList.begin()==well1 ); - BOOST_REQUIRE( *wellList.rbegin()==well2 ); + BOOST_REQUIRE( *wellList.begin()==well1 ); + BOOST_REQUIRE( *wellList.rbegin()==well2 ); } else { - BOOST_REQUIRE( *wellList.begin()==well2 ); - BOOST_REQUIRE( *wellList.rbegin()==well1 ); + BOOST_REQUIRE( *wellList.begin()==well2 ); + BOOST_REQUIRE( *wellList.rbegin()==well1 ); } } @@ -299,12 +328,12 @@ BOOST_AUTO_TEST_CASE(IntersectingWells) // other cells from wells need to be added. BOOST_AUTO_TEST_CASE(ImportExportListExpansion) { - // create a grid with wells - Dune::CpGrid grid; - std::array dims{2,3,2}; - std::array size{1.,1.,1.}; - grid.createCartesian(dims,size); - Opm::GraphOfGrid gog(grid); + // create a grid with wells + Dune::CpGrid grid; + std::array dims{2,3,2}; + std::array size{1.,1.,1.}; + grid.createCartesian(dims,size); + Opm::GraphOfGrid gog(grid); gog.addWell(std::set{0,1,2}); gog.addWell(std::set{5,8,11}); const auto& wells = gog.getWells(); @@ -313,7 +342,7 @@ BOOST_AUTO_TEST_CASE(ImportExportListExpansion) // mock import and export lists using importTuple = std::tuple; using exportTuple = std::tuple; - using AttributeSet = Dune::cpgrid::CpGridData::AttributeSet; + using AttributeSet = Dune::cpgrid::CpGridData::AttributeSet; std::vector imp(3); imp[0] = std::make_tuple(0,1,AttributeSet::owner,1);