Commit 408d93d3 authored by Carsten Gräser's avatar Carsten Gräser

[test][bugfix] Update makerefinedsimplexgeometrytest

Modernize test:

* Don't use hard cast to pointer in grid factory
* Pass transformation function using new interface
* Use `Dune::TestSuite` to get individual error messages for checks.

Fix failing test:

The test used hard coded values for the transformed coordinates.
These values are (now) incorrect and in fact permuted. Assuming
that this was once correct, the failure can be explained if
at one point the factory for AluGrid deciced to permute vertices
during grid construction. Then the hard coded values are no
longer OK. Instead of re-computing them manually the target
values are now derived from the transformation map which whould
work in any case and is less error prone.
parent 3c4c716b
Pipeline #28150 canceled with stage
in 10 minutes and 3 seconds
......@@ -6,6 +6,7 @@
#include <dune/common/exceptions.hh>
#include <dune/common/parallel/mpihelper.hh>
#include <dune/common/test/testsuite.hh>
#if HAVE_DUNE_ALUGRID
#include <dune/grid/common/gridfactory.hh>
......@@ -25,21 +26,12 @@ class MakeRefinedSimplexGeometryTestSuite
{}
bool check()
Dune::TestSuite test()
{
return check_makeRefinedSimplexGeometry();
}
private:
bool check_makeRefinedSimplexGeometry()
{
bool passed = true;
Dune::TestSuite test;
#if HAVE_DUNE_ALUGRID
typedef Dune::ALUGrid<2,3,Dune::simplex, Dune::conforming> GridType;
GridType* grid;
Dune::GridFactory<GridType> factory;
std::vector<WorldCoords> vertices(3);
......@@ -61,66 +53,55 @@ class MakeRefinedSimplexGeometryTestSuite
factory.insertElement(Dune::GeometryType(Dune::GeometryType::simplex,2),face);
}
grid = factory.createGrid();
auto grid = factory.createGrid();
auto eltIt = grid->leafGridView().begin<0>();
MapToSphere<WorldCoords,WorldCoords> parameterization;
auto transformation = [] (const WorldCoords& x) {
WorldCoords y = x;
y /= x.two_norm();
return y;
};
RefinedSimplexGeometry<typename GridType::ctype, 2,3> refinedGeometry = makeRefinedSimplexGeometry(*eltIt,parameterization);
RefinedSimplexGeometry<typename GridType::ctype, 2,3> refinedGeometry = makeRefinedSimplexGeometry(*eltIt,transformation);
{
WorldCoords testPoint{-sqrt_two/4, 0 , sqrt_two/2}, sollResult(testPoint);
sollResult /= testPoint.two_norm();
passed = passed and
isCloseDune(sollResult,
refinedGeometry.global(LocalCoords{0, 0.5}));
auto xLocal = LocalCoords{0.0, 0.5};
auto xGlobal = eltIt->geometry().global(xLocal);
auto xMappedGlobal = transformation(xGlobal);
test.check(isCloseDune(xMappedGlobal, refinedGeometry.global(xLocal)))
<< "Edge center (" << xLocal << ") has wrong global coordinate. Should be (" << xMappedGlobal << ") but is (" << refinedGeometry.global(xLocal) << ").";
}
{
auto xLocal = LocalCoords{0.5, 0.5};
auto xGlobal = eltIt->geometry().global(xLocal);
auto xMappedGlobal = transformation(xGlobal);
test.check(isCloseDune(xMappedGlobal, refinedGeometry.global(xLocal)))
<< "Edge center (" << xLocal << ") has wrong global coordinate. Should be (" << xMappedGlobal << ") but is (" << refinedGeometry.global(xLocal) << ").";
}
{
WorldCoords testPoint{sqrt_two/8, sqrt_six/8 , sqrt_two/2}, sollResult(testPoint);
sollResult /= testPoint.two_norm();
passed = passed and
isCloseDune(sollResult,
refinedGeometry.global(LocalCoords{0.5, 0.5}));
auto xLocal = LocalCoords{0.5, 0.0};
auto xGlobal = eltIt->geometry().global(xLocal);
auto xMappedGlobal = transformation(xGlobal);
test.check(isCloseDune(xMappedGlobal, refinedGeometry.global(xLocal)))
<< "Edge center (" << xLocal << ") has wrong global coordinate. Should be (" << xMappedGlobal << ") but is (" << refinedGeometry.global(xLocal) << ").";
}
{
WorldCoords testPoint{sqrt_two/8, -sqrt_six/8 , sqrt_two/2}, sollResult(testPoint);
sollResult /= testPoint.two_norm();
passed = passed and
isCloseDune(sollResult,
refinedGeometry.global(LocalCoords{0.5, 0}));
WorldCoords testPoint2{0, 0 , sqrt_two/2}, sollResult2(sollResult);
sollResult2[0] = sollResult2[1] = 0;
passed = passed and isCloseDune(sollResult2,
refinedGeometry.global(LocalCoords{
1.0 / 3.0, 1.0 / 3.0}));
auto xLocal = LocalCoords{1.0/3.0, 1.0/3.0};
// Center of element should be the center of refined sub-element
// spanned by the transfomed edge midpoints.
auto xMappedGlobal = WorldCoords{0.0,0.0,0.0};
xMappedGlobal += transformation(eltIt->geometry().global(LocalCoords{0.0, 0.5}));
xMappedGlobal += transformation(eltIt->geometry().global(LocalCoords{0.5, 0.5}));
xMappedGlobal += transformation(eltIt->geometry().global(LocalCoords{0.5, 0.0}));
xMappedGlobal /= 3.0;
test.check(isCloseDune(xMappedGlobal, refinedGeometry.global(xLocal)))
<< "Element center (" << xLocal << ") has wrong global coordinate. Should be (" << xMappedGlobal << ") but is (" << refinedGeometry.global(xLocal) << ").";
}
#endif
return passed;
return test;
}
template <class DomainVector, class RangeVector>
class MapToSphere
{
private:
const double radius_;
const DomainVector center_;
public:
MapToSphere(const double radius=1.0, const DomainVector& center=DomainVector{0,0,0}):
radius_(radius),
center_(center)
{}
void evaluate( const DomainVector &x, RangeVector &y ) const
{
y = x;
y -= center_;
y /= x.two_norm()/radius_;
y += center_;
}
};
};
int main (int argc, char *argv[])
......@@ -128,7 +109,7 @@ int main (int argc, char *argv[])
Dune::MPIHelper::instance(argc, argv);
MakeRefinedSimplexGeometryTestSuite testSuite;
#if HAVE_DUNE_ALUGRID
return testSuite.check() ? 0 : 1;
return testSuite.test().exit();
#else
return 77;
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment