Skip to content
Snippets Groups Projects
Commit cb5235ab authored by Samuel Burbulla's avatar Samuel Burbulla Committed by Timo Koch
Browse files

[test] Add a unit test for boundary segments.

parent 033e7a92
No related branches found
No related tags found
1 merge request!59[gridfactory] Implement insertBoundarySegment.
Point(1) = {0, 0, 0, 1.0};
Point(2) = {1, 1, 0, 1.0};
Point(3) = {-1, 0, 0, 1.0};
Point(4) = {-2, 0, 0, 1.0};
Point(5) = {-3, 1, 0, 1.0};
Line(1) = {3, 1};
Line(2) = {1, 2};
Line(3) = {3, 4};
Line(4) = {4, 5};
Physical Line(1) = {1:4};
Physical Point(42) = {2};
$MeshFormat
2.2 0 8
$EndMeshFormat
$Nodes
5
1 0 0 0
2 1 1 0
3 -1 0 0
4 -2 0 0
5 -3 1 0
$EndNodes
$Elements
5
1 15 2 42 2 2
2 1 2 1 1 3 1
3 1 2 1 2 1 2
4 1 2 1 3 3 4
5 1 2 1 4 4 5
$EndElements
......@@ -11,6 +11,7 @@ else()
dune_add_test(SOURCES local-refine-test.cc)
endif()
dune_add_test(SOURCES boundary-segment-test.cc)
dune_add_test(SOURCES global-refine-test.cc)
dune_add_test(SOURCES growth-test-1d.cc)
dune_add_test(SOURCES growth-test-2d.cc)
......
#include <config.h>
#include <iostream>
#include <memory>
#include <string>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/exceptions.hh>
#include <dune/grid/io/file/gmshreader.hh>
#include <dune/grid/test/gridcheck.hh>
#include <dune/grid/test/checkintersectionit.hh>
#include <dune/foamgrid/foamgrid.hh>
template<class Grid>
void checkBoundarySegments(const Grid& grid,
const Dune::GridFactory<Grid>& factory,
const std::vector<int>& boundaryMarkers,
int boundaryIntersectionsExpected,
int insertedBoundariesExpected,
int numIntersectionsExpected,
int boundaryIdExpected = 42)
{
std::cout << " Checking boundary segment indices" << std::endl;
int numIntersections = 0;
int boundaryIntersections = 0;
int insertedBoundaries = 0;
for ( const auto& element : elements(grid.leafGridView()) )
{
for ( const auto& intersection : intersections(grid.leafGridView(), element) )
{
numIntersections++;
if ( intersection.boundary() )
{
boundaryIntersections++;
if ( factory.wasInserted( intersection ) )
{
insertedBoundaries++;
const int bndsegIdx = intersection.boundarySegmentIndex();
const int bndId = boundaryMarkers[bndsegIdx];
if (bndId != boundaryIdExpected)
DUNE_THROW(Dune::GridError, "Wrong boundary ID. Expected " << boundaryIdExpected << " got " << bndId);
}
}
}
}
// sanity checks
if (boundaryIntersections != boundaryIntersectionsExpected)
DUNE_THROW(Dune::GridError, "Wrong number of boundary intersections. Expected " << boundaryIntersectionsExpected << " got " << boundaryIntersections);
if (insertedBoundaries != insertedBoundariesExpected)
DUNE_THROW(Dune::GridError, "Wrong number of inserted boundaries. Expected " << insertedBoundariesExpected << " got " << insertedBoundaries);
if (numIntersections != numIntersectionsExpected)
DUNE_THROW(Dune::GridError, "Wrong number of intersections. Expected " << numIntersectionsExpected << " got " << numIntersections);
}
int main (int argc, char *argv[]) try
{
using namespace Dune;
Dune::MPIHelper::instance(argc, argv);
// paths to gmsh test files
const std::string dune_foamgrid_path = std::string(DUNE_FOAMGRID_EXAMPLE_GRIDS_PATH) + "gmsh/";
{
std::cout << "\n################################################\n";
std::cout << "Checking FoamGrid<1, 2> (1d in 2d grid)\n";
std::cout << "################################################\n\n";
std::cout << " Creating grid" << std::endl;
using Grid = FoamGrid<1, 2>;
GridFactory<Grid> factory;
std::vector<int> boundaryMarkers, elementMarkers;
GmshReader<Grid>::read(factory, dune_foamgrid_path + "line1d2dbseg.msh", boundaryMarkers, elementMarkers, /*verbose*/ true, /*insertBoundarySegments*/ true);
auto grid = std::shared_ptr<Grid>(factory.createGrid());
// check the boundary segments
checkBoundarySegments(*grid, factory,boundaryMarkers, 2, 1, 8);
}
}
// //////////////////////////////////
// Error handler
// /////////////////////////////////
catch (const Dune::Exception& e) {
std::cout << e << std::endl;
return 1;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment