Skip to content

Commit

Permalink
Added grid tests to PolyhedralGrid
Browse files Browse the repository at this point in the history
Test embedded grids in higher dimensional domains
  • Loading branch information
rube051 committed Feb 2, 2021
1 parent e27e001 commit 1b16a4f
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
2 changes: 1 addition & 1 deletion opm/grid/polyhedralgrid/grid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
110 changes: 110 additions & 0 deletions tests/test_polyhedralgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 1b16a4f

Please sign in to comment.