From 1b16a4f039546bf66e470f27e3434c36e07899d2 Mon Sep 17 00:00:00 2001 From: rube051 Date: Tue, 2 Feb 2021 11:41:22 +0100 Subject: [PATCH] Added grid tests to PolyhedralGrid Test embedded grids in higher dimensional domains --- opm/grid/polyhedralgrid/grid.hh | 2 +- tests/test_polyhedralgrid.cpp | 110 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/opm/grid/polyhedralgrid/grid.hh b/opm/grid/polyhedralgrid/grid.hh index dc25d6051..249d8d579 100644 --- a/opm/grid/polyhedralgrid/grid.hh +++ b/opm/grid/polyhedralgrid/grid.hh @@ -91,7 +91,7 @@ namespace Dune typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridGeometry > Geometry; typedef PolyhedralGridLocalGeometry< dimension-codim, dimensionworld, const Grid> LocalGeometryImpl; - typedef Dune::Geometry< dimension-codim, dimension, const Grid, PolyhedralGridLocalGeometry > LocalGeometry; + typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridLocalGeometry > LocalGeometry; typedef PolyhedralGridEntity< codim, dimension, const Grid > EntityImpl; typedef Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity; diff --git a/tests/test_polyhedralgrid.cpp b/tests/test_polyhedralgrid.cpp index f6178007b..32488a89a 100644 --- a/tests/test_polyhedralgrid.cpp +++ b/tests/test_polyhedralgrid.cpp @@ -340,5 +340,115 @@ int main(int argc, char** argv ) Dune::GridPtr< Grid > gridPtr( dgfFile ); gridcheck( *gridPtr ); } + + { + // Test 2D grid embedded in a 3D domain + const std::string gridFileName = "polyhedral_grid_test.txt"; + std::stringstream gridFile; + std::ofstream out(gridFileName); + + gridFile << "3 1 3 3 6 3 0 0" << std::endl; + gridFile << "0 0 0" << std::endl; + gridFile << "0.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 1.0" << std::endl; + gridFile << "0 2 4 6" << std::endl; + gridFile << "0 1 0 2 1 2" << std::endl; + gridFile << "0 -1 0 -1 0 -1" << std::endl; + gridFile << "1.4142135623730951 1.0 1.0" << std::endl; + gridFile << "0.0 0.5 0.5 0.0 0.5 1.0 0.0 1.0 0.5" << std::endl; + gridFile << "-1.1102230246251565e-16 -1.0 -1.0 1.1102230246251565e-16 0.0 1.0 0.0 1.0 0.0" << std::endl; + gridFile << "0 3" << std::endl; + gridFile << "0 1 2" << std::endl; + gridFile << "0.5" << std::endl; + gridFile << "0.0 0.6666666666666666 0.6666666666666666" << std::endl; + + out << gridFile.str(); + out.close(); + + const char* c_str = gridFileName.c_str(); + UnstructuredGrid* grid = read_grid(c_str); + std::remove(c_str); + + if (grid == nullptr) { + std::string msg = "RuntimeError: UnstructuredGrid could not read grid file"; + throw std::runtime_error(msg); + } + // check different coordinate field type here + typedef Dune::PolyhedralGrid< 2, 3, float > Grid; + Dune::GridPtr< Grid > gridPtr( new Grid(*grid) ); + gridcheck( *gridPtr ); + delete grid; + } + { + // Test 1D grid embedded in a 3D domain + const std::string gridFileName = "polyhedral_grid_test.txt"; + std::stringstream gridFile; + std::ofstream out(gridFileName); + gridFile << "3 2 3 3 3 4 0 0" << std::endl; + gridFile << "0 0 0" << std::endl; + gridFile << "0.0 0.0 0.0 0.5 0.5 1.0 1.0 1.0 2.0" << std::endl; + gridFile << "0 1 2 3" << std::endl; + gridFile << "0 1 2" << std::endl; + gridFile << "-1 0 0 1 1 -1" << std::endl; + gridFile << "1.0 1.0 1.0" << std::endl; + gridFile << "0.0 0.0 0.0 0.5 0.5 1.0 1.0 1.0 2.0" << std::endl; + gridFile << "0.4082482904638631 0.4082482904638631 0.8164965809277261 0.4082482904638631 0.4082482904638631 0.8164965809277261 0.4082482904638631 0.4082482904638631 0.8164965809277261" << std::endl; + gridFile << "0 2 4" << std::endl; + gridFile << "0 1 1 2" << std::endl; + gridFile << "1.224744871391589 1.224744871391589" << std::endl; + gridFile << "0.25 0.25 0.5 0.75 0.75 1.5" << std::endl; + + out << gridFile.str(); + out.close(); + + const char* c_str = gridFileName.c_str(); + UnstructuredGrid* grid = read_grid(c_str); + std::remove(c_str); + + if (grid == nullptr) { + std::string msg = "RuntimeError: UnstructuredGrid could not read grid file"; + throw std::runtime_error(msg); + } + // check different coordinate field type here + typedef Dune::PolyhedralGrid< 1, 3, float > Grid; + Dune::GridPtr< Grid > gridPtr( new Grid(*grid) ); + gridcheck( *gridPtr ); + delete grid; + } + { + // Test 1D grid embedded in a 2D domain + const std::string gridFileName = "polyhedral_grid_test.txt"; + std::stringstream gridFile; + std::ofstream out(gridFileName); + gridFile << "2 2 3 3 3 4 0 0" << std::endl; + gridFile << "0 0" << std::endl; + gridFile << "0.0 -0.0 0.5 -0.5 1.0 -1.0" << std::endl; + gridFile << "0 1 2 3" << std::endl; + gridFile << "0 1 2" << std::endl; + gridFile << "-1 0 0 1 1 -1" << std::endl; + gridFile << "1.0 1.0 1.0" << std::endl; + gridFile << "0.0 -0.0 0.5 -0.5 1.0 -1.0" << std::endl; + gridFile << "0.7071067811865475 -0.7071067811865475 0.7071067811865475 -0.7071067811865475 0.7071067811865475 -0.7071067811865475" << std::endl; + gridFile << "0 2 4" << std::endl; + gridFile << "0 1 1 2" << std::endl; + gridFile << "0.7071067811865476 0.7071067811865476" << std::endl; + gridFile << "0.25 -0.25 0.75 -0.75" << std::endl; + + out << gridFile.str(); + out.close(); + + const char* c_str = gridFileName.c_str(); + UnstructuredGrid* grid = read_grid(c_str); + std::remove(c_str); + + if (grid == nullptr) { + std::string msg = "RuntimeError: UnstructuredGrid could not read grid file"; + throw std::runtime_error(msg); + } + // check different coordinate field type here + typedef Dune::PolyhedralGrid< 1, 2, float > Grid; + Dune::GridPtr< Grid > gridPtr( new Grid(*grid) ); + gridcheck( *gridPtr ); + delete grid; + } return 0; }