def test_2dmesher_SDF():
    """Unit disk"""
    hmin = 0.2
    bbox = (-1.0, 1.0, -1.0, 1.0)

    disk = geometry.Disk([0.0, 0.0], 1)

    def EF(p):
        d = disk.eval(p)
        return hmin - d * 0.15

    points, cells = generate_mesh(
        bbox=bbox,
        domain=disk,
        h0=hmin,
        edge_length=EF,
        max_iter=100,
    )

    # print(len(points), len(cells))
    assert allclose([len(points), len(cells)], [63, 93], atol=10)
    assert allclose(sum(geometry.simp_vol(points, cells)), 3.14, atol=hmin)

    import meshio

    meshio.write_points_cells(
        "blah.vtk",
        points[:, [1, 0]] / 1000,
        [("triangle", cells)],
        file_format="vtk",
    )
예제 #2
0
def test_3dmesher_par_adapt():

    fname = os.path.join(os.path.dirname(__file__), "test3D.bin")
    nz, nx, ny = 20, 10, 10
    bbox = (-2000.0, 0.0, 0.0, 1000.0, 0.0, 1000.0)
    cube = Cube(bbox)
    hmin = 50
    wl = 10
    freq = 4
    grade = 0.15
    ef = get_sizing_function_from_segy(
        fname,
        bbox,
        hmin=hmin,
        wl=wl,
        freq=freq,
        grade=grade,
        nx=nx,
        ny=ny,
        nz=nz,
        byte_order="little",
    )

    points, cells = generate_mesh(
        cube,
        ef,
        max_iter=10,
    )

    points = comm.bcast(points, 0)

    points, cells = generate_mesh(
        points=points,
        domain=cube,
        edge_length=ef,
        axis=1,
        max_iter=10,
    )

    points = comm.bcast(points, 0)

    points, cells = generate_mesh(
        points=points,
        edge_length=ef,
        domain=cube,
        axis=2,
        max_iter=10,
    )

    if comm.rank == 0:
        import meshio

        meshio.write_points_cells(
            "foo3D_V3.vtk",
            points,
            [("tetra", cells)],
        )

        vol = geometry.simp_vol(points / 1000, cells)
        assert np.abs(2 - np.sum(vol)) < 0.10  # km2
예제 #3
0
def test_3dmesher_par():

    fname = os.path.join(os.path.dirname(__file__), "test3D.bin")
    nz, nx, ny = 20, 10, 10
    bbox = (-2e3, 0.0, 0.0, 1e3, 0.0, 1e3)

    hmin = 50
    wl = 10
    freq = 4
    grade = 0.15
    grad = 50.0
    cube = Cube(bbox)
    ef = get_sizing_function_from_segy(
        fname,
        bbox,
        hmin=hmin,
        grade=grade,
        grad=grad,
        wl=wl,
        freq=freq,
        nz=nz,
        nx=nx,
        ny=ny,
        byte_order="little",
        axes_order=(2, 0,
                    1),  # order for EAGE (x, y, z) to default order (z,x,y)
    )

    points, cells = generate_mesh(
        h0=hmin,
        edge_length=ef,
        domain=cube,
        perform_checks=False,
    )

    points, cells = sliver_removal(
        points=points,
        domain=cube,
        edge_length=ef,
        h0=hmin,
        perform_checks=False,
    )

    if comm.rank == 0:
        import meshio

        meshio.write_points_cells(
            "foo3D_V3.vtk",
            points,
            [("tetra", cells)],
        )

        vol = geometry.simp_vol(points / 1000, cells)
        assert np.abs(2 - np.sum(vol)) < 0.10  # km2
        print(len(points), len(cells))
        assert np.abs(9220 - len(points)) < 5000
        assert np.abs(49156 - len(cells)) < 5000
def test_3dmesher_SDF():
    """Unit cylinder"""

    hmin = 0.10
    bbox = (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0)

    def cylinder(p):
        r, z = sqrt(p[:, 0] ** 2 + p[:, 1] ** 2), p[:, 2]
        d1, d2, d3 = r - 1.0, z - 1.0, -z - 1.0
        d4, d5 = sqrt(d1 ** 2 + d2 ** 2), sqrt(d1 ** 2 + d3 ** 2)
        d = maximum.reduce([d1, d2, d3])
        ix = (d1 > 0) * (d2 > 0)
        d[ix] = d4[ix]
        ix = (d1 > 0) * (d3 > 0)
        d[ix] = d5[ix]
        return d

    def EF(p):
        return array(
            [
                hmin,
            ]
            * len(p)
        )

    points, cells = generate_mesh(
        bbox=bbox,
        domain=cylinder,
        h0=hmin,
        edge_length=EF,
        max_iter=100,
    )

    points, cells = sliver_removal(
        points=points, domain=cylinder, edge_length=EF, h0=hmin, bbox=bbox
    )

    assert allclose(sum(geometry.simp_vol(points, cells)), 6.28, atol=hmin)

    print(len(points), len(cells))
    allclose([len(points), len(cells)], [6825, 36206], atol=100)

    import meshio

    meshio.write_points_cells(
        "blah.vtk",
        points / 1000,
        [("tetra", cells)],
        file_format="vtk",
    )
예제 #5
0
def test_geometry():

    # tetraheadrals in a unit cube with l, w, h of 2 units
    points = np.array(
        [
            [-1, -1, -1],
            [1, -1, -1],
            [1, 1, -1],
            [-1, 1, -1],
            [-1, -1, 1],
            [1, -1, 1],
            [1, 1, 1],
            [-1, 1, 1],
            [0, 0, 0],  # point in the center of it
        ],
        dtype=np.float,
    )

    cells = np.array(
        [
            [3, 4, 0, 8],
            [3, 7, 8, 2],
            [6, 8, 7, 2],
            [6, 5, 8, 2],
            [6, 5, 7, 8],
            [8, 7, 4, 5],
            [3, 7, 4, 8],
            [3, 8, 1, 2],
            [8, 5, 1, 2],
            [8, 4, 1, 5],
            [8, 4, 0, 1],
            [3, 8, 0, 1],
        ],
        dtype=np.int,
    )

    facets = geo.get_facets(cells)
    assert len(facets) == (12 * 4)

    boundary_facets = geo.get_boundary_facets(cells)
    boundary_facets = np.sort(boundary_facets, axis=1)
    boundary_facets = np.unique(boundary_facets, axis=1)
    assert len(boundary_facets) == 12

    boundary_vertices = geo.get_boundary_vertices(cells, dim=3)
    assert len(boundary_vertices) == 8

    vol = geo.simp_vol(points, cells)
    assert np.sum(vol) == 8.0
def test_2dmesher_par_adapt():
    fname = os.path.join(os.path.dirname(__file__), "testing.segy")
    bbox = (-10e3, 0.0, 0.0, 10e3)
    wl = 5
    freq = 5
    hmin = 100
    grade = 0.005
    ef = get_sizing_function_from_segy(
        fname,
        bbox,
        hmin=hmin,
        wl=wl,
        freq=freq,
        grade=grade,
    )

    rectangle = Rectangle(bbox)

    points, cells = generate_mesh(
        edge_length=ef,
        domain=rectangle,
        h0=hmin,
        perform_checks=False,
    )
    points = comm.bcast(points, 0)

    # pass the points and restart with a different axis
    points, cells = generate_mesh(
        points=points,
        edge_length=ef,
        h0=hmin,
        domain=rectangle,
        perform_checks=False,
    )

    if comm.rank == 0:
        import meshio

        meshio.write_points_cells("test2d.vtk",
                                  points / 1000, [("triangle", cells)],
                                  file_format="vtk")
        area = geometry.simp_vol(points / 1000, cells)
        assert np.abs(100 - np.sum(area)) < 0.60  # km2
예제 #7
0
def test_2dmesher_par():

    fname = os.path.join(os.path.dirname(__file__), "testing.segy")
    bbox = (-10e3, 0.0, 0.0, 10e3)
    freq = 2
    wl = 10
    hmin = 75
    grade = 0.005

    rectangle = Rectangle(bbox)
    ef = get_sizing_function_from_segy(fname,
                                       bbox,
                                       hmin=hmin,
                                       wl=wl,
                                       freq=freq,
                                       grade=grade)

    points, cells = generate_mesh(
        rectangle,
        ef,
        h0=hmin,
        max_iter=100,
        perform_checks=False,
    )

    if comm.rank == 0:
        import meshio

        meshio.write_points_cells(
            "test2d.vtk",
            points / 1000,
            [("triangle", cells)],
            file_format="vtk",
        )
        area = geometry.simp_vol(points / 1000, cells)
        assert np.abs(100 - np.sum(area)) < 0.50  # km2