Commit 58c59ecd authored by Timo Koch's avatar Timo Koch
Browse files

[test] Add scaling tests with different magnitudes

parent e826db6b
......@@ -79,7 +79,7 @@ void permutatePointsAndTest(const std::vector<GlobalPosition>& cornerPoints,
std::cout << "point " << p << " lies within the quadrilateral" << std::endl;
}
else
DUNE_THROW(Dune::InvalidStateException, "Check for point inside geometry failed. Point " << p << " does not lie within the geometry!");
DUNE_THROW(Dune::InvalidStateException, "False negative: Check for point " << p << " which is inside the geometry failed");
}
for(const auto& p : pointsOutsideGeometry)
......@@ -90,7 +90,7 @@ void permutatePointsAndTest(const std::vector<GlobalPosition>& cornerPoints,
std::cout << "point " << p << " lies outside of the quadrilateral" << std::endl;
}
else
DUNE_THROW(Dune::InvalidStateException, "Check for point outside geometry failed. Point " << p << " does lie within the geometry!");
DUNE_THROW(Dune::InvalidStateException, "False positive: Check for point " << p << " which is outside the geometry failed");
}
} while(std::next_permutation(s.begin(), s.end()));
......@@ -100,20 +100,21 @@ template<class GlobalPosition>
void checkAxisAlignedGeometry(std::vector<GlobalPosition>& cornerPoints,
std::vector<GlobalPosition>& pointsWithinGeometry,
std::vector<GlobalPosition>& pointsOutsideGeometry,
const int normalDirection)
const int normalDirection,
const typename GlobalPosition::value_type scale)
{
static const char dim[]= "xyz";
std::cout << "testing for quadrilateral with normal in " << dim[normalDirection] << " direction" << std::endl;
// check if points are coplanar
if(!Dumux::pointsAreCoplanar(cornerPoints))
DUNE_THROW(Dune::InvalidStateException, "False positive, points are actually coplanar!");
DUNE_THROW(Dune::InvalidStateException, "False negative, points are actually coplanar!");
cornerPoints[0][normalDirection] += 1e-9;
cornerPoints[0][normalDirection] += 1e-5*scale; // we make them non-coplanar
if(Dumux::pointsAreCoplanar(cornerPoints))
DUNE_THROW(Dune::InvalidStateException, "Points are not coplanar!");
DUNE_THROW(Dune::InvalidStateException, "False positive, points are actually not coplanar!");
cornerPoints[0][normalDirection] -= 1e-9;
cornerPoints[0][normalDirection] -= 1e-5*scale;
permutatePointsAndTest(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry);
......@@ -122,19 +123,22 @@ void checkAxisAlignedGeometry(std::vector<GlobalPosition>& cornerPoints,
std::vector<GlobalPosition> pointsWithinGeometryForRandomTest = { {0.6, 0.6, 0.6},
{0.4, 0.4, 0.4} };
for(auto& p : pointsWithinGeometryForRandomTest)
{
p *= scale;
p[normalDirection] = 0.0;
}
auto pointsOutsideGeometryForRandomTest = pointsOutsideGeometry;
pointsOutsideGeometryForRandomTest[0] = {1.5, 1.5, 1.5};
pointsOutsideGeometryForRandomTest[0] = {1.5*scale, 1.5*scale, 1.5*scale};
pointsOutsideGeometryForRandomTest[0][normalDirection] = 0.0;
for(int i = 0; i< 10; i++)
{
// uniform random number generator
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_real_distribution<> uniformdist(-0.3, 0.3);
// uniform random number generator
std::random_device rd;
std::mt19937 generator(rd());
std::uniform_real_distribution<> uniformdist(-0.3*scale, 0.3*scale);
for(int i = 0; i < 10; i++)
{
for(auto&& p : cornerPoints)
{
for(int x = 0; x < p.size(); ++x)
......@@ -148,8 +152,6 @@ void checkAxisAlignedGeometry(std::vector<GlobalPosition>& cornerPoints,
cornerPoints = origCornerPoints;
}
}
int main(int argc, char** argv) try
......@@ -157,50 +159,59 @@ int main(int argc, char** argv) try
using namespace Dumux;
using GlobalPosition = Dune::FieldVector<double, 3>;
GlobalPosition p0 = {0,0,0};
GlobalPosition p1 = {1,0,0};
GlobalPosition p2 = {0,1,0};
GlobalPosition p3 = {1,1,0};
std::array<double, 3> scaling{{1e-12, 1.0, 1e12}};
std::vector<GlobalPosition> cornerPoints = {p0, p1, p2, p3};
for (const double scale : scaling)
{
const double size = 1.0*scale;
const double half = 0.5*scale;
const double small = 1e-3*scale;
std::vector<GlobalPosition> pointsWithinGeometry = { GlobalPosition{0.5, 0.5, 0.0},
GlobalPosition{cornerPoints[0][0] + 1e-3, cornerPoints[0][1] + 1e-3, 0.0},
GlobalPosition{cornerPoints[3][0] - 1e-3, cornerPoints[3][1] - 1e-3, 0.0} };
GlobalPosition p0 = {0, 0, 0};
GlobalPosition p1 = {size, 0, 0};
GlobalPosition p2 = {0, size, 0};
GlobalPosition p3 = {size, size, 0};
std::vector<GlobalPosition> pointsOutsideGeometry = { GlobalPosition{cornerPoints[0][0] - 1e-3, cornerPoints[0][1] - 1e-3, 0.0},
GlobalPosition{0.5, 0.5, 1e-3} };
std::vector<GlobalPosition> cornerPoints = {p0, p1, p2, p3};
// do the checks for a quadrilateral parallel to the x and y axis
checkAxisAlignedGeometry(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry, 2);
std::vector<GlobalPosition> pointsWithinGeometry = { GlobalPosition{half, half, 0.0},
GlobalPosition{cornerPoints[0][0] + small, cornerPoints[0][1] + small, 0.0},
GlobalPosition{cornerPoints[3][0] - small, cornerPoints[3][1] - small, 0.0} };
// rotate the quadrilateral to make it parallel to the other axes and test again
for(int i = 1; i >=0; --i)
{
for(auto& p : cornerPoints)
std::rotate(p.begin(), p.begin() + 1, p.end());
for(auto& p : pointsWithinGeometry)
std::rotate(p.begin(), p.begin() + 1, p.end());
for(auto& p : pointsOutsideGeometry)
std::rotate(p.begin(), p.begin() + 1, p.end());
checkAxisAlignedGeometry(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry, i);
}
std::vector<GlobalPosition> pointsOutsideGeometry = { GlobalPosition{cornerPoints[0][0] - small, cornerPoints[0][1] - small, 0.0},
GlobalPosition{half, half, small} };
std::cout << "testing for non axis-aligned quadrilateral" << std::endl;
// do the checks for a quadrilateral parallel to the x and y axis
checkAxisAlignedGeometry(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry, 2, size);
cornerPoints[0][0] += 0.5;
cornerPoints[1][0] -= 0.5;
cornerPoints[2][0] += 0.5;
cornerPoints[3][0] -= 0.5;
// rotate the quadrilateral to make it parallel to the other axes and test again
for(int i = 1; i >=0; --i)
{
for(auto& p : cornerPoints)
std::rotate(p.begin(), p.begin() + 1, p.end());
for(auto& p : pointsWithinGeometry)
std::rotate(p.begin(), p.begin() + 1, p.end());
for(auto& p : pointsOutsideGeometry)
std::rotate(p.begin(), p.begin() + 1, p.end());
checkAxisAlignedGeometry(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry, i, size);
}
GlobalPosition pointToCheck5 = {0.0, 0.5, 0.5};
std::cout << "testing for non axis-aligned quadrilateral" << std::endl;
pointsWithinGeometry = {pointToCheck5};
cornerPoints[0][0] += half;
cornerPoints[1][0] -= half;
cornerPoints[2][0] += half;
cornerPoints[3][0] -= half;
pointsOutsideGeometry[1] = pointsOutsideGeometry[0];
GlobalPosition pointToCheck5 = {0.0, half, half};
permutatePointsAndTest(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry);
pointsWithinGeometry = {pointToCheck5};
pointsOutsideGeometry[1] = pointsOutsideGeometry[0];
permutatePointsAndTest(cornerPoints, pointsWithinGeometry, pointsOutsideGeometry);
}
return 0;
}
......
Supports Markdown
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