Skip to content

Commit 1b16a4f

Browse files
author
rube051
committed
Added grid tests to PolyhedralGrid
Test embedded grids in higher dimensional domains
1 parent e27e001 commit 1b16a4f

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

opm/grid/polyhedralgrid/grid.hh

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ namespace Dune
9191
typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridGeometry > Geometry;
9292

9393
typedef PolyhedralGridLocalGeometry< dimension-codim, dimensionworld, const Grid> LocalGeometryImpl;
94-
typedef Dune::Geometry< dimension-codim, dimension, const Grid, PolyhedralGridLocalGeometry > LocalGeometry;
94+
typedef Dune::Geometry< dimension-codim, dimensionworld, const Grid, PolyhedralGridLocalGeometry > LocalGeometry;
9595

9696
typedef PolyhedralGridEntity< codim, dimension, const Grid > EntityImpl;
9797
typedef Dune::Entity< codim, dimension, const Grid, PolyhedralGridEntity > Entity;

tests/test_polyhedralgrid.cpp

+110
Original file line numberDiff line numberDiff line change
@@ -340,5 +340,115 @@ int main(int argc, char** argv )
340340
Dune::GridPtr< Grid > gridPtr( dgfFile );
341341
gridcheck( *gridPtr );
342342
}
343+
344+
{
345+
// Test 2D grid embedded in a 3D domain
346+
const std::string gridFileName = "polyhedral_grid_test.txt";
347+
std::stringstream gridFile;
348+
std::ofstream out(gridFileName);
349+
350+
gridFile << "3 1 3 3 6 3 0 0" << std::endl;
351+
gridFile << "0 0 0" << std::endl;
352+
gridFile << "0.0 0.0 1.0 0.0 1.0 0.0 0.0 1.0 1.0" << std::endl;
353+
gridFile << "0 2 4 6" << std::endl;
354+
gridFile << "0 1 0 2 1 2" << std::endl;
355+
gridFile << "0 -1 0 -1 0 -1" << std::endl;
356+
gridFile << "1.4142135623730951 1.0 1.0" << std::endl;
357+
gridFile << "0.0 0.5 0.5 0.0 0.5 1.0 0.0 1.0 0.5" << std::endl;
358+
gridFile << "-1.1102230246251565e-16 -1.0 -1.0 1.1102230246251565e-16 0.0 1.0 0.0 1.0 0.0" << std::endl;
359+
gridFile << "0 3" << std::endl;
360+
gridFile << "0 1 2" << std::endl;
361+
gridFile << "0.5" << std::endl;
362+
gridFile << "0.0 0.6666666666666666 0.6666666666666666" << std::endl;
363+
364+
out << gridFile.str();
365+
out.close();
366+
367+
const char* c_str = gridFileName.c_str();
368+
UnstructuredGrid* grid = read_grid(c_str);
369+
std::remove(c_str);
370+
371+
if (grid == nullptr) {
372+
std::string msg = "RuntimeError: UnstructuredGrid could not read grid file";
373+
throw std::runtime_error(msg);
374+
}
375+
// check different coordinate field type here
376+
typedef Dune::PolyhedralGrid< 2, 3, float > Grid;
377+
Dune::GridPtr< Grid > gridPtr( new Grid(*grid) );
378+
gridcheck( *gridPtr );
379+
delete grid;
380+
}
381+
{
382+
// Test 1D grid embedded in a 3D domain
383+
const std::string gridFileName = "polyhedral_grid_test.txt";
384+
std::stringstream gridFile;
385+
std::ofstream out(gridFileName);
386+
gridFile << "3 2 3 3 3 4 0 0" << std::endl;
387+
gridFile << "0 0 0" << std::endl;
388+
gridFile << "0.0 0.0 0.0 0.5 0.5 1.0 1.0 1.0 2.0" << std::endl;
389+
gridFile << "0 1 2 3" << std::endl;
390+
gridFile << "0 1 2" << std::endl;
391+
gridFile << "-1 0 0 1 1 -1" << std::endl;
392+
gridFile << "1.0 1.0 1.0" << std::endl;
393+
gridFile << "0.0 0.0 0.0 0.5 0.5 1.0 1.0 1.0 2.0" << std::endl;
394+
gridFile << "0.4082482904638631 0.4082482904638631 0.8164965809277261 0.4082482904638631 0.4082482904638631 0.8164965809277261 0.4082482904638631 0.4082482904638631 0.8164965809277261" << std::endl;
395+
gridFile << "0 2 4" << std::endl;
396+
gridFile << "0 1 1 2" << std::endl;
397+
gridFile << "1.224744871391589 1.224744871391589" << std::endl;
398+
gridFile << "0.25 0.25 0.5 0.75 0.75 1.5" << std::endl;
399+
400+
out << gridFile.str();
401+
out.close();
402+
403+
const char* c_str = gridFileName.c_str();
404+
UnstructuredGrid* grid = read_grid(c_str);
405+
std::remove(c_str);
406+
407+
if (grid == nullptr) {
408+
std::string msg = "RuntimeError: UnstructuredGrid could not read grid file";
409+
throw std::runtime_error(msg);
410+
}
411+
// check different coordinate field type here
412+
typedef Dune::PolyhedralGrid< 1, 3, float > Grid;
413+
Dune::GridPtr< Grid > gridPtr( new Grid(*grid) );
414+
gridcheck( *gridPtr );
415+
delete grid;
416+
}
417+
{
418+
// Test 1D grid embedded in a 2D domain
419+
const std::string gridFileName = "polyhedral_grid_test.txt";
420+
std::stringstream gridFile;
421+
std::ofstream out(gridFileName);
422+
gridFile << "2 2 3 3 3 4 0 0" << std::endl;
423+
gridFile << "0 0" << std::endl;
424+
gridFile << "0.0 -0.0 0.5 -0.5 1.0 -1.0" << std::endl;
425+
gridFile << "0 1 2 3" << std::endl;
426+
gridFile << "0 1 2" << std::endl;
427+
gridFile << "-1 0 0 1 1 -1" << std::endl;
428+
gridFile << "1.0 1.0 1.0" << std::endl;
429+
gridFile << "0.0 -0.0 0.5 -0.5 1.0 -1.0" << std::endl;
430+
gridFile << "0.7071067811865475 -0.7071067811865475 0.7071067811865475 -0.7071067811865475 0.7071067811865475 -0.7071067811865475" << std::endl;
431+
gridFile << "0 2 4" << std::endl;
432+
gridFile << "0 1 1 2" << std::endl;
433+
gridFile << "0.7071067811865476 0.7071067811865476" << std::endl;
434+
gridFile << "0.25 -0.25 0.75 -0.75" << std::endl;
435+
436+
out << gridFile.str();
437+
out.close();
438+
439+
const char* c_str = gridFileName.c_str();
440+
UnstructuredGrid* grid = read_grid(c_str);
441+
std::remove(c_str);
442+
443+
if (grid == nullptr) {
444+
std::string msg = "RuntimeError: UnstructuredGrid could not read grid file";
445+
throw std::runtime_error(msg);
446+
}
447+
// check different coordinate field type here
448+
typedef Dune::PolyhedralGrid< 1, 2, float > Grid;
449+
Dune::GridPtr< Grid > gridPtr( new Grid(*grid) );
450+
gridcheck( *gridPtr );
451+
delete grid;
452+
}
343453
return 0;
344454
}

0 commit comments

Comments
 (0)