示例#1
0
    def _create(rows: int, columns: int):
        mesh2d = Mesh2dFactory.create_rectilinear_mesh(rows, columns)
        mk = MeshKernel()

        mk.mesh2d_set(mesh2d)

        return mk
示例#2
0
def test_mesh2d_get_smoothness_smooth_mesh2d():
    r"""Tests `mesh2d_get_smoothness` with a simple triangular Mesh2d.

      3---2
     / \ /
    0---1
    """

    mk = MeshKernel()

    node_x = np.array(
        [0.0, 4.0, 6.0, 2.0, 2.0],
        dtype=np.double,
    )
    node_y = np.array(
        [0.0, 0.0, 3.0, 3.0, 1.0],
        dtype=np.double,
    )
    edge_nodes = np.array(
        [0, 1, 1, 2, 2, 3, 3, 0, 1, 3],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    smoothness = mk.mesh2d_get_smoothness()

    assert smoothness.values.size == 5

    assert smoothness.values[0] == -999.0
    assert smoothness.values[1] == -999.0
    assert smoothness.values[2] == -999.0
    assert smoothness.values[3] == -999.0
    assert smoothness.values[4] == approx(0.0, abs=0.01)
示例#3
0
def test_mesh2d_get_orthogonality_orthogonal_mesh2d():
    """Tests `mesh2d_get_orthogonality` with an orthogonal 2x2 Mesh2d.
    6---7---8
    |   |   |
    3---4---5
    |   |   |
    0---1---2
    """

    mk = MeshKernel()
    mk.mesh2d_set(Mesh2dFactory.create_rectilinear_mesh(2, 2))

    orthogonality = mk.mesh2d_get_orthogonality()

    assert orthogonality.values.size == 12

    exp_orthogonality = np.array(
        [
            -999.0,
            0.0,
            -999.0,
            -999.0,
            0.0,
            -999.0,
            -999.0,
            -999.0,
            0.0,
            0.0,
            -999.0,
            -999.0,
        ],
        dtype=np.double,
    )

    assert_array_equal(orthogonality.values, exp_orthogonality)
def test_mesh2d_set_and_mesh2d_get():
    """Test to set a simple mesh and then get it again with new parameters

    3---2
    |   |
    0---1
    """
    mk = MeshKernel()

    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 0], dtype=np.int32)
    node_x = np.array([0.0, 1.0, 1.0, 0.0], dtype=np.double)
    node_y = np.array([0.0, 0.0, 1.0, 1.0], dtype=np.double)

    input_mesh2d = Mesh2d(node_x, node_y, edge_nodes)
    mk.mesh2d_set(input_mesh2d)

    output_mesh2d = mk.mesh2d_get()

    # Test if the input and output differs
    assert_array_equal(output_mesh2d.edge_nodes, input_mesh2d.edge_nodes)
    assert_array_equal(output_mesh2d.node_x, input_mesh2d.node_x)
    assert_array_equal(output_mesh2d.node_y, input_mesh2d.node_y)

    # Test if faces are correctly calculated
    assert_array_equal(output_mesh2d.face_nodes, np.array([0, 1, 2, 3]))
    assert_array_equal(output_mesh2d.nodes_per_face, np.array([4]))
    assert_array_equal(output_mesh2d.face_x, np.array([0.5]))
    assert_array_equal(output_mesh2d.face_y, np.array([0.5]))

    # Test if edges are correctly calculated
    assert_array_equal(output_mesh2d.edge_x, np.array([0.5, 1.0, 0.5, 0.0]))
    assert_array_equal(output_mesh2d.edge_y, np.array([0.0, 0.5, 1.0, 0.5]))
def test_mesh2d_count_obtuse_triangles():
    r"""Tests `_mesh2d_count_obtuse_triangles` on a 3x3 mesh with two obtuse triangles.

    6---7---8
    | /   \ |
    3---4---5
    | \   / |
    0---1---2

    """
    mk = MeshKernel()

    # Mesh with obtuse triangles (4, 5, 7 and 1, 5, 4)
    node_x = np.array([0.0, 1.0, 2.0, 0.0, 1.5, 2.0, 0.0, 1.0, 2.0],
                      dtype=np.double)
    node_y = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0],
                      dtype=np.double)
    edge_nodes = np.array(
        [
            0,
            1,
            1,
            2,
            3,
            4,
            4,
            5,
            6,
            7,
            7,
            8,
            0,
            3,
            1,
            4,
            2,
            5,
            3,
            6,
            4,
            7,
            5,
            8,
            1,
            3,
            1,
            5,
            3,
            7,
            5,
            7,
        ],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    n_obtuse_triangles = mk._mesh2d_count_obtuse_triangles()

    assert n_obtuse_triangles == 2
def test_contacts_compute_with_polygons():
    """Tests `contacts_compute_with_polygons` with a 5x5 Mesh2d and a Mesh1d with 5 nodes.

    30--31--32--33--34--35
    |   |   |   |   | / |
    24--25--26--27--28--29
    |   |   |   | / |   |
    18--19--20--21--22--23
    |   |   | / |   |   |
    12--13--14--15--16--17
    |   | / |   |   |   |
    6---7---8---9---10--11
    | / |   |   |   |   |
    0---1---2---3---4---5
    """

    mk = MeshKernel()

    mesh2d = Mesh2dFactory.create_rectilinear_mesh(5, 5)

    node_x = np.array([0.5, 1.5, 2.5, 3.5, 4.5], dtype=np.double)
    node_y = np.array([0.5, 1.5, 2.5, 3.5, 4.5], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4], dtype=np.int32)
    mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)
    mk.mesh1d_set(mesh1d)

    node_mask = np.full(node_x.size, True)

    # Two polygons around Mesh2d nodes 4, 5, 23, 22 and 12, 13, 31, 30
    separator = -999.0
    polygon_x = np.array(
        [-0.1, 1.1, 1.1, -0.1, -0.1, separator, 3.9, 5.1, 5.1, 3.9, 3.9],
        dtype=np.double,
    )
    polygon_y = np.array(
        [1.9, 1.9, 5.1, 5.1, 1.9, separator, -0.1, -0.1, 3.1, 3.1, -0.1],
        dtype=np.double,
    )
    polygon = GeometryList(polygon_x, polygon_y)

    mk.contacts_compute_with_polygons(node_mask, polygon)

    contacts = mk.contacts_get()

    contacts = sort_contacts_by_mesh2d_indices(contacts)

    assert contacts.mesh1d_indices.size == 2
    assert contacts.mesh2d_indices.size == 2

    assert contacts.mesh1d_indices[0] == 1
    assert contacts.mesh1d_indices[1] == 3

    assert contacts.mesh2d_indices[0] == 10
    assert contacts.mesh2d_indices[1] == 14
def test_polygon_refine(start: int, end: int, length: float, exp_nodes: int):
    """Tests `polygon_refine` by refining a simple polygon."""

    mk = MeshKernel()

    # 3---2
    # |   |
    # 0---1
    x_coordinates = np.array([0.0, 60.0, 60.0, 0.0, 0.0], dtype=np.double)
    y_coordinates = np.array([0.0, 0.0, 60.0, 60.0, 0.0], dtype=np.double)
    polygon = GeometryList(x_coordinates, y_coordinates)

    geom = mk.polygon_refine(polygon, start, end, length)

    assert geom.x_coordinates.size == exp_nodes
def test_contacts_compute_with_points():
    """Tests `contacts_compute_with_points` with a 5x5 Mesh2d and a Mesh1d with 5 nodes.

    30--31--32--33--34--35
    |   |   |   |   | / |
    24--25--26--27--28--29
    |   |   |   | / |   |
    18--19--20--21--22--23
    |   |   | / |   |   |
    12--13--14--15--16--17
    |   | / |   |   |   |
    6---7---8---9---10--11
    | / |   |   |   |   |
    0---1---2---3---4---5
    """

    mk = MeshKernel()

    mesh2d = Mesh2dFactory.create_rectilinear_mesh(5, 5)

    node_x = np.array([0.5, 1.5, 2.5, 3.5, 4.5], dtype=np.double)
    node_y = np.array([0.5, 1.5, 2.5, 3.5, 4.5], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4], dtype=np.int32)
    mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)
    mk.mesh1d_set(mesh1d)

    node_mask = np.full(node_x.size, True)

    # Three points in Mesh2d faces 10, 8, 14
    points_x = np.array([0.5, 3.5, 4.5], dtype=np.double)
    points_y = np.array([2.5, 1.5, 2.5], dtype=np.double)
    points = GeometryList(points_x, points_y)

    mk.contacts_compute_with_points(node_mask, points)

    contacts = mk.contacts_get()

    contacts = sort_contacts_by_mesh2d_indices(contacts)

    assert contacts.mesh1d_indices.size == 3
    assert contacts.mesh2d_indices.size == 3

    assert contacts.mesh1d_indices[0] == 2
    assert contacts.mesh1d_indices[1] == 1
    assert contacts.mesh1d_indices[2] == 3

    assert contacts.mesh2d_indices[0] == 8
    assert contacts.mesh2d_indices[1] == 10
    assert contacts.mesh2d_indices[2] == 14
def test_polygon_get_included_points(selecting_x: np.array,
                                     selecting_y: np.array,
                                     exp_values: np.array):
    """Tests `polygon_get_included_points` with a simple polygon and various selecting polygons."""

    selecting_polygon = GeometryList(selecting_x, selecting_y)

    x_coordinates = np.array([1.0, 2.0, 2.0, 1.0, 1.0], dtype=np.double)
    y_coordinates = np.array([1.0, 1.0, 2.0, 2.0, 1.0], dtype=np.double)
    selected_polygon = GeometryList(x_coordinates, y_coordinates)

    mk = MeshKernel()

    selection = mk.polygon_get_included_points(selecting_polygon,
                                               selected_polygon)

    assert_array_equal(selection.values, exp_values)
示例#10
0
def test_mesh2d_merge_nodes(merging_distance: float, number_of_nodes: int):
    """Test if `mesh2d_merge_nodes` reduces the number of close nodes

    4---3
    |   |
    01--2
    """
    mk = MeshKernel()

    # Set up mesh
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4, 4, 0], dtype=np.int32)
    node_x = np.array([0.0, 1e-3, 1.0, 1.0, 0.0], dtype=np.double)
    node_y = np.array([0.0, 0.0, 0.0, 1.0, 1.0], dtype=np.double)
    input_mesh2d = Mesh2d(node_x, node_y, edge_nodes)
    mk.mesh2d_set(input_mesh2d)

    # Define polygon where we want to merge
    x_coordinates = np.array([-1.0, 2.0, 2.0, -1.0, -1.0], dtype=np.double)
    y_coordinates = np.array([-1.0, -1.0, 2.0, 2.0, -1.0], dtype=np.double)
    geometry_list = GeometryList(x_coordinates, y_coordinates)

    mk.mesh2d_merge_nodes(geometry_list, merging_distance)

    output_mesh2d = mk.mesh2d_get()

    assert output_mesh2d.node_x.size == number_of_nodes
示例#11
0
def test_mesh2d_delete_hanging_edges():
    """Tests `mesh2d_delete_hanging_edges` by deleting 2 hanging edges in a simple Mesh2d
    4*
    |
    3---2---5*
    |   |
    0---1
    """

    mk = MeshKernel()

    node_x = np.array([0.0, 1.0, 1.0, 0.0, 0.0, 2.0], dtype=np.double)
    node_y = np.array([0.0, 0.0, 1.0, 1.0, 2.0, 1.0], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 0, 3, 4, 2, 5], dtype=np.int32)

    mesh2d = Mesh2d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)

    mk.mesh2d_delete_hanging_edges()

    mesh2d = mk.mesh2d_get()

    assert mesh2d.node_x.size == 4
    assert mesh2d.edge_x.size == 4
    assert mesh2d.face_x.size == 1
示例#12
0
def test_mesh2d_delete_small_flow_edges_and_small_triangles_delete_small_triangles(
):
    r"""Tests `mesh2d_get_small_flow_edge_centers` with a simple mesh with one small triangle.

    3---4---5\
    |   |   | 6
    0---1---2/
    """

    mk = MeshKernel()

    node_x = np.array(
        [0.0, 1.0, 2.0, 0.0, 1.0, 2.0, 2.1],
        dtype=np.double,
    )
    node_y = np.array(
        [0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.5],
        dtype=np.double,
    )
    edge_nodes = np.array(
        [0, 1, 1, 2, 3, 4, 4, 5, 0, 3, 1, 4, 2, 5, 5, 6, 6, 2],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    mk.mesh2d_delete_small_flow_edges_and_small_triangles(1.0, 0.01)

    mesh2d = mk.mesh2d_get()

    assert mesh2d.node_x.size == 7
    assert mesh2d.edge_x.size == 8
    assert mesh2d.face_x.size == 2
示例#13
0
def test_mesh2d_get_orthogonality_not_orthogonal_mesh2d():
    """Tests `mesh2d_get_orthogonality` with a non-orthogonal 3x3 Mesh2d.
    6---7---8
    |   |   |
    3---4*--5
    |   |   |
    0---1---2
    """

    mk = MeshKernel()

    node_x = np.array(
        [0.0, 1.0, 2.0, 0.0, 1.8, 2.0, 0.0, 1.0, 2.0],
        dtype=np.double,
    )
    node_y = np.array(
        [0.0, 0.0, 0.0, 1.0, 1.8, 1.0, 2.0, 2.0, 2.0],
        dtype=np.double,
    )
    edge_nodes = np.array(
        [
            0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 0, 3, 1, 4, 2, 5, 3, 6, 4, 7,
            5, 8
        ],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    orthogonality = mk.mesh2d_get_orthogonality()

    assert orthogonality.values.size == 12

    assert orthogonality.values[0] == -999.0
    assert orthogonality.values[1] == -999.0
    assert orthogonality.values[2] > 0.0
    assert orthogonality.values[3] > 0.0
    assert orthogonality.values[4] == -999.0
    assert orthogonality.values[5] == -999.0
    assert orthogonality.values[6] == -999.0
    assert orthogonality.values[7] > 0.0
    assert orthogonality.values[8] == -999.0
    assert orthogonality.values[9] == -999.0
    assert orthogonality.values[10] > 0.0
    assert orthogonality.values[11] == -999.0
示例#14
0
def test_get_splines(
    number_of_points_between_nodes: int,
    x_coordinates: np.ndarray,
    y_coordinates: np.ndarray,
):
    """Test `get_splines` by checking if the dimensions of the generated spline are correct"""
    mk = MeshKernel()
    geometry_list_in = GeometryList(x_coordinates, y_coordinates)

    geometry_list_out = mk.get_splines(geometry_list_in,
                                       number_of_points_between_nodes)

    original_number_of_coordinates = geometry_list_in.x_coordinates.size
    expected_new_number_of_coordinates = (
        original_number_of_coordinates * number_of_points_between_nodes -
        number_of_points_between_nodes + original_number_of_coordinates + 1)

    assert expected_new_number_of_coordinates == geometry_list_out.x_coordinates.size
示例#15
0
def test_contacts_compute_single():
    """Tests `contacts_compute_single` with a 5x5 Mesh2d and a Mesh1d with 5 nodes.

    30--31--32--33--34--35
    |   |   |   |   |  /|
    24--25--26--27--28--29
    |   |   |   |  /|   |
    18--19--20--21--22--23
    |   |   |  /|   |   |
    12--13--14--15--16--17
    |   |  /|   |   |   |
    6---7---8---9---10--11
    |  /|   |   |   |   |
    0---1---2---3---4---5
    """

    mk = MeshKernel()

    mesh2d = Mesh2dFactory.create_rectilinear_mesh(5, 5)

    node_x = np.array([0.75, 1.75, 2.75, 3.75, 4.75], dtype=np.double)
    node_y = np.array([0.25, 1.25, 2.25, 3.25, 4.25], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4], dtype=np.int32)
    mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)
    mk.mesh1d_set(mesh1d)

    node_mask = np.full(node_x.size, True)

    polygon_x = np.array([-1.0, 6.0, 6.0, -1.0, -1.0], dtype=np.double)
    polygon_y = np.array([-1.0, -1.0, 6.0, 6.0, -1.0], dtype=np.double)
    polygon = GeometryList(polygon_x, polygon_y)

    mk.contacts_compute_single(node_mask, polygon)

    contacts = mk.contacts_get()
    contacts = sort_contacts_by_mesh2d_indices(contacts)

    assert contacts.mesh1d_indices.size == 3
    assert contacts.mesh2d_indices.size == 3

    assert contacts.mesh1d_indices[0] == 1
    assert contacts.mesh1d_indices[1] == 2
    assert contacts.mesh1d_indices[2] == 3

    assert contacts.mesh2d_indices[0] == 6
    assert contacts.mesh2d_indices[1] == 12
    assert contacts.mesh2d_indices[2] == 18
示例#16
0
def test_mesh2d_get_hanging_edges(node_x: np.ndarray, node_y: np.ndarray,
                                  edge_nodes: np.ndarray, expected: int):
    """Tests `mesh2d_get_hanging_edges` by comparing the returned hanging edges with the expected ones
    4*
    |
    3---2---5*
    |   |
    0---1
    """

    mk = MeshKernel()

    mesh2d = Mesh2d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)

    result = mk.mesh2d_get_hanging_edges()

    assert_array_equal(result, expected)
示例#17
0
def test_mesh2d_flip_edges(triangulate: bool):
    """Tests `mesh2d_flip_edges` with a simple triangular mesh (heptagon)."""

    mk = MeshKernel()

    node_x = np.array([0, -8, -10, -4, 4, 10, 8, 0], dtype=np.double)
    node_y = np.array([10, 6, -2, -9, -9, -2, 6, -5], dtype=np.double)
    edge_nodes = np.array(
        [
            0,
            1,
            1,
            2,
            2,
            3,
            3,
            4,
            4,
            5,
            5,
            6,
            6,
            0,
            0,
            7,
            1,
            7,
            2,
            7,
            3,
            7,
            4,
            7,
            5,
            7,
            6,
            7,
        ],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    polygon_x = np.array([-11, 11, 11, -11, -11], dtype=np.double)
    polygon_y = np.array([-11, -11, 11, 11, -11], dtype=np.double)
    polygon = GeometryList(polygon_x, polygon_y)

    land_boundaries_x = np.array([-10, -4, 4, 10], dtype=np.double)
    land_boundaries_y = np.array([-2, -9, -9, -2], dtype=np.double)
    land_boundaries = GeometryList(land_boundaries_x, land_boundaries_y)

    mk.mesh2d_flip_edges(triangulate, False, polygon, land_boundaries)

    mesh2d = mk.mesh2d_get()

    assert mesh2d.node_x.size == 8
    assert mesh2d.edge_x.size == 14
    assert mesh2d.face_x.size == 7
示例#18
0
def test_create_2d():

    # Define polygon
    bbox = (1.0, -2.0, 3.0, 4.0)

    mesh2d = Mesh2d(meshkernel=MeshKernel())
    mesh2d.create_rectilinear(extent=bbox, dx=0.5, dy=0.75)

    mesh2d_output = mesh2d.get_mesh2d()
    assert mesh2d_output.node_x.size == 45
    assert mesh2d_output.edge_nodes.size == 152
示例#19
0
def test_mesh2d_make_mesh_from_samples():
    """Tests `mesh2d_make_mesh_from_samples` by creating a mesh2d from six sample points."""

    mk = MeshKernel()

    #  5  4
    # 0    3
    #  1  2
    x_coordinates = np.array([0.0, 0.5, 1.5, 2.0, 1.5, 0.5, 0.0],
                             dtype=np.double)
    y_coordinates = np.array([1.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0],
                             dtype=np.double)
    polygon = GeometryList(x_coordinates, y_coordinates)

    mk.mesh2d_make_mesh_from_samples(polygon)

    mesh2d = mk.mesh2d_get()

    assert mesh2d.node_x.size == 6
    assert mesh2d.edge_x.size == 9
    assert mesh2d.face_x.size == 4
示例#20
0
def test_mesh1d_get():
    r"""Tests `mesh1d_set` and `mesh1d_get` to set and get a simple mesh.

      1   3
     / \ /
    0   2
    """
    mk = MeshKernel()

    node_x = np.array([0.0, 1.0, 2.0, 3.0], dtype=np.double)
    node_y = np.array([0.0, 1.0, 0.0, 1.0], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3], dtype=np.int32)
    input_mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh1d_set(input_mesh1d)

    output_mesh1d = mk.mesh1d_get()

    # Test if the input and output differs
    assert_array_equal(output_mesh1d.edge_nodes, input_mesh1d.edge_nodes)
    assert_array_equal(output_mesh1d.node_x, input_mesh1d.node_x)
    assert_array_equal(output_mesh1d.node_y, input_mesh1d.node_y)
示例#21
0
def test_mesh2d_make_mesh_from_polygon():
    """Tests `mesh2d_make_mesh_from_polygon` by creating a mesh2d from a simple hexagon."""

    mk = MeshKernel()

    #   5__4
    #  /    \
    # 0      3
    #  \1__2/
    x_coordinates = np.array([0.0, 0.5, 1.5, 2.0, 1.5, 0.5, 0.0],
                             dtype=np.double)
    y_coordinates = np.array([1.0, 0.0, 0.0, 1.0, 2.0, 2.0, 1.0],
                             dtype=np.double)
    polygon = GeometryList(x_coordinates, y_coordinates)

    mk.mesh2d_make_mesh_from_polygon(polygon)

    mesh2d = mk.mesh2d_get()

    assert mesh2d.node_x.size == 7
    assert mesh2d.edge_x.size == 12
    assert mesh2d.face_x.size == 6
示例#22
0
def test_contacts_compute_multiple():
    """Tests `contacts_compute_multiple` with a 5x5 Mesh2d and a Mesh1d with 5 nodes.

    30--31--32--33--34--35
    |   |   |   |   |  /|
    24--25--26--27--28--29
    |   |   |   |  /|   |
    18--19--20--21--22--23
    |   |   |  /|   |   |
    12--13--14--15--16--17
    |   |  /|   |   |   |
    6---7---8---9---10--11
    |  /|   |   |   |   |
    0---1---2---3---4---5
    """

    mk = MeshKernel()

    mesh2d = Mesh2dFactory.create_rectilinear_mesh(5, 5)

    node_x = np.array([0.7, 1.5, 2.6, 3.9, 4.8], dtype=np.double)
    node_y = np.array([0.3, 1.4, 2.6, 3.2, 4.2], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4], dtype=np.int32)
    mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)
    mk.mesh1d_set(mesh1d)

    node_mask = np.full(node_x.size, True)

    mk.contacts_compute_multiple(node_mask)

    contacts = mk.contacts_get()

    contacts = sort_contacts_by_mesh2d_indices(contacts)

    assert contacts.mesh1d_indices.size == 9
    assert contacts.mesh2d_indices.size == 9

    assert_array_equal(contacts.mesh1d_indices, [0, 0, 1, 1, 2, 3, 3, 3, 4])
    assert_array_equal(contacts.mesh2d_indices,
                       [0, 1, 6, 7, 12, 13, 18, 19, 24])
示例#23
0
def test_contacts_compute_boundary(node_mask: ndarray,
                                   exp_mesh1d_indices: ndarray,
                                   exp_mesh2d_indices: ndarray):
    """Tests `contacts_compute_boundary` with a 2x2 Mesh2d and a Mesh1d with 5 nodes.


       ---3---4
     2
    |   6---7---8
    1   |   |   |
    |   3---4---5
    0   |   |   |
        0---1---2
    """

    mk = MeshKernel()

    mesh2d = Mesh2dFactory.create_rectilinear_mesh(2, 2)

    node_x = np.array([-1.0, -1.0, -0.5, 0.5, 1.5], dtype=np.double)
    node_y = np.array([0.5, 1.5, 2.5, 3.0, 3.0], dtype=np.double)
    edge_nodes = np.array([0, 1, 1, 2, 2, 3, 3, 4], dtype=np.int32)
    mesh1d = Mesh1d(node_x, node_y, edge_nodes)

    mk.mesh2d_set(mesh2d)
    mk.mesh1d_set(mesh1d)

    polygon_x = np.array([-1.1, 3.1, 3.1, -1.1, -1.1], dtype=np.double)
    polygon_y = np.array([-0.1, -0.1, 3.1, 3.1, -0.1], dtype=np.double)
    polygon = GeometryList(polygon_x, polygon_y)

    mk.contacts_compute_boundary(node_mask, polygon, 2.0)

    contacts = mk.contacts_get()

    contacts = sort_contacts_by_mesh2d_indices(contacts)

    assert_array_equal(contacts.mesh1d_indices, exp_mesh1d_indices)
    assert_array_equal(contacts.mesh2d_indices, exp_mesh2d_indices)
示例#24
0
def test_create_clip_2d():

    polygon = GeometryList(
        x_coordinates=np.array([0.0, 6.0, 4.0, 2.0, 0.0]),
        y_coordinates=np.array([0.0, 2.0, 7.0, 6.0, 0.0]),
    )

    # Define polygon
    bbox = (1.0, -2.0, 3.0, 4.0)
    mesh2d = Mesh2d(meshkernel=MeshKernel())
    mesh2d.create_rectilinear(extent=bbox, dx=0.5, dy=0.75)
    mesh2d.clip(polygon)

    mesh2d_output = mesh2d.get_mesh2d()

    assert mesh2d_output.node_x.size == 28
    assert mesh2d_output.edge_nodes.size == 90
示例#25
0
def test_mesh2d_compute_orthogonalization():
    """Tests `mesh2d_compute_orthogonalization` with a 3x3 Mesh2d with an uncentered middle node.
    6---7---8
    |   |   |
    3---4*--5
    |   |   |
    0---1---2
    """

    mk = MeshKernel()

    node_x = np.array(
        [0.0, 1.0, 2.0, 0.0, 1.3, 2.0, 0.0, 1.0, 2.0],
        dtype=np.double,
    )
    node_y = np.array(
        [0.0, 0.0, 0.0, 1.0, 1.3, 1.0, 2.0, 2.0, 2.0],
        dtype=np.double,
    )
    edge_nodes = np.array(
        [
            0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 0, 3, 1, 4, 2, 5, 3, 6, 4, 7,
            5, 8
        ],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    polygon_x = np.array([-0.1, 2.1, 2.1, -0.1, -0.1], dtype=np.double)
    polygon_y = np.array([-0.1, -0.1, 2.1, 2.1, -0.1], dtype=np.double)
    polygon = GeometryList(polygon_x, polygon_y)

    land_boundary_x = np.array([0.0, 1.0, 2.0], dtype=np.double)
    land_boundary_y = np.array([0.0, 0.0, 0.0], dtype=np.double)
    land_boundary = GeometryList(land_boundary_x, land_boundary_y)

    mk.mesh2d_compute_orthogonalization(
        0, OrthogonalizationParameters(outer_iterations=10), polygon,
        land_boundary)

    mesh2d = mk.mesh2d_get()

    assert 1.0 <= mesh2d.node_x[4] < 1.3
    assert 1.0 <= mesh2d.node_y[4] < 1.3
示例#26
0
def test_create_refine_2d():

    polygon = GeometryList(
        x_coordinates=np.array([0.0, 6.0, 4.0, 2.0, 0.0]),
        y_coordinates=np.array([0.0, 2.0, 7.0, 6.0, 0.0]),
    )

    # Define polygon
    bbox = (1.0, -2.0, 3.0, 4.0)
    # Create instance
    mesh2d = Mesh2d(meshkernel=MeshKernel())
    # Create within bounding box
    mesh2d.create_rectilinear(extent=bbox, dx=0.5, dy=0.75)
    # Refine
    mesh2d.refine(polygon, 1)

    mesh2d_output = mesh2d.get_mesh2d()

    assert mesh2d_output.node_x.size == 114
    assert mesh2d_output.edge_nodes.size == 426
示例#27
0
def test_get_meshkernelpy_version():
    """Tests if we can get the version of MeshKernelPy through the API"""
    mk = MeshKernel()
    meshkernelpy_version = mk.get_meshkernelpy_version()
    assert meshkernelpy_version == __version__
示例#28
0
def test_get_meshkernel_version():
    """Tests if we can get the version of MeshKernel through the API"""
    mk = MeshKernel()
    meshkernel_version = mk.get_meshkernel_version()
    assert len(meshkernel_version) > 0
示例#29
0
def test_different_instances_have_different_ids():
    """Test if the meshkernelid of two instances differs"""
    mk_1 = MeshKernel()
    mk_2 = MeshKernel()

    assert mk_1._meshkernelid != mk_2._meshkernelid
示例#30
0
def test_mesh2d_get_obtuse_triangles_mass_centers():
    r"""Tests `mesh2d_get_obtuse_triangles_mass_centers` on a 3x3 mesh with two obtuse triangles.

    6---7---8
    | /   \ |
    3---4---5
    | \   / |
    0---1---2

    """
    mk = MeshKernel()

    # Mesh with obtuse triangles (4, 5, 7 and 1, 5, 4)
    node_x = np.array([0.0, 1.0, 2.0, 0.0, 1.5, 2.0, 0.0, 1.0, 2.0],
                      dtype=np.double)
    node_y = np.array([0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0],
                      dtype=np.double)
    edge_nodes = np.array(
        [
            0,
            1,
            1,
            2,
            3,
            4,
            4,
            5,
            6,
            7,
            7,
            8,
            0,
            3,
            1,
            4,
            2,
            5,
            3,
            6,
            4,
            7,
            5,
            8,
            1,
            3,
            1,
            5,
            3,
            7,
            5,
            7,
        ],
        dtype=np.int32,
    )

    mk.mesh2d_set(Mesh2d(node_x, node_y, edge_nodes))

    obtuse_triangles = mk.mesh2d_get_obtuse_triangles_mass_centers()

    assert obtuse_triangles.x_coordinates.size == 2

    assert obtuse_triangles.x_coordinates[0] == 1.5
    assert obtuse_triangles.y_coordinates[0] == approx(0.666, 0.01)

    assert obtuse_triangles.x_coordinates[1] == 1.5
    assert obtuse_triangles.y_coordinates[1] == approx(1.333, 0.01)