Skip to content

Commit

Permalink
GRIDEDIT-953 Added two unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BillSenior committed Jun 17, 2024
1 parent 1fad686 commit 94007c3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,6 @@ void meshkernel::CurvilinearGridSplineToGrid::DetermineSplineOrientation(const S
splineInteraction[i][0] = maxm;
}

// splineInteraction.col(1).fill(0);
// splineInteraction.col(2).fill(0);

for (UInt i = 0; i < splines.GetNumSplines(); ++i)
{
splineInteraction[i][1] = 0;
Expand Down
58 changes: 58 additions & 0 deletions libs/MeshKernel/tests/src/CurvilinearGridFromSplinesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1350,3 +1350,61 @@ TEST(CurvilinearGridFromSplines, GenerateGridWithDisconectedSpline)

EXPECT_THROW(splinesToGrid.Compute(*splines, curvilinearParameters, grid), mk::AlgorithmError);
}

TEST(CurvilinearGridFromSplines, GenerateGridWithThreeSplines)
{
// Attempt to generate a grid with 3 splines
// Should raise a ConstraintError exception.
// At least four splines are required to generate a curvilinear grid

namespace mk = meshkernel;

std::vector<mk::Point> spline1{{-1.0, 0.0}, {11.0, 0.0}};
std::vector<mk::Point> spline2{{10.0, -1.0}, {10.0, 11.0}};
std::vector<mk::Point> spline3{{11.0, 10.0}, {-1.0, 10.0}};

auto splines = std::make_shared<Splines>(Projection::cartesian);
splines->AddSpline(spline1);
splines->AddSpline(spline2);
splines->AddSpline(spline3);

mk::CurvilinearParameters curvilinearParameters;

curvilinearParameters.m_refinement = 5;
curvilinearParameters.n_refinement = 5;

mk::CurvilinearGridSplineToGrid splinesToGrid;
mk::CurvilinearGrid grid(Projection::cartesian);

EXPECT_THROW(splinesToGrid.Compute(*splines, curvilinearParameters, grid), mk::ConstraintError);
}

TEST(CurvilinearGridFromSplines, GenerateGridWithSplinesTooShort)
{
// Attempt to generate a grid with 4 splines, 1 of which has only a single point
// Should raise a ConstraintError exception.
// All splines are required to have at least 2 points in order to generate a curvilinear grid

namespace mk = meshkernel;

std::vector<mk::Point> spline1{{-1.0, 0.0}, {11.0, 0.0}};
std::vector<mk::Point> spline2{{10.0, -1.0}, {10.0, 11.0}};
std::vector<mk::Point> spline3{{11.0, 10.0}, {-1.0, 10.0}};
std::vector<mk::Point> spline4{{0.0, 11.0}};

auto splines = std::make_shared<Splines>(Projection::cartesian);
splines->AddSpline(spline1);
splines->AddSpline(spline2);
splines->AddSpline(spline3);
splines->AddSpline(spline4);

mk::CurvilinearParameters curvilinearParameters;

curvilinearParameters.m_refinement = 5;
curvilinearParameters.n_refinement = 5;

mk::CurvilinearGridSplineToGrid splinesToGrid;
mk::CurvilinearGrid grid(Projection::cartesian);

EXPECT_THROW(splinesToGrid.Compute(*splines, curvilinearParameters, grid), mk::ConstraintError);
}

0 comments on commit 94007c3

Please sign in to comment.