Esempio n. 1
0
def test_2dmesher():

    fname = os.path.join(os.path.dirname(__file__), "testing.segy")
    bbox = (-10000.0, 0.0, 0.0, 10000.0)
    wl = 5
    freq = 5.0
    hmin = 100
    hmax = 10e6
    grade = 0.005
    grad = 50.0
    rectangle = Rectangle(bbox)
    ef = get_sizing_function_from_segy(
        fname,
        bbox=bbox,
        grade=grade,
        grad=grad,
        wl=wl,
        freq=freq,
        hmin=hmin,
        hmax=hmax,
    )
    plot_sizing_function(ef)
    write_velocity_model(fname)

    points, cells = generate_mesh(
        rectangle,
        ef,
        h0=hmin,
        perform_checks=True,
    )
    # should have: 7690 vertices and 15045 cells
    print(len(points), len(cells))
    allclose([len(points), len(cells)], [7690, 15045], atol=100)
Esempio n. 2
0
def test_3dmesher_domain_extension(style_answer):
    style, answer = style_answer
    fname = os.path.join(os.path.dirname(__file__), "test3D.bin")
    wl = 5
    freq = 2
    hmin = 150
    grade = 0.005
    bbox = (-2e3, 0.0, 0.0, 1e3, 0.0, 1e3)
    cube = Cube(bbox)
    ef = get_sizing_function_from_segy(
        fname,
        bbox,
        grade=grade,
        grad=hmin,
        freq=freq,
        wl=wl,
        hmin=hmin,
        nz=20,
        nx=10,
        ny=10,
        byte_order="little",
        domain_pad=200,
        pad_style=style,
        axes_order=(2, 0, 1),
    )

    write_velocity_model(fname,
                         nz=20,
                         nx=10,
                         ny=10,
                         byte_order="little",
                         ofname="testing",
                         bbox=bbox)

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

    points, cells = sliver_removal(points=points,
                                   domain=cube,
                                   edge_length=ef,
                                   h0=hmin)
    print(len(points), len(cells))
    allclose([len(points), len(cells)], answer, atol=100)

    import meshio

    meshio.write_points_cells("foo3D" + style + ".vtk", points,
                              [("tetra", cells)])
Esempio n. 3
0
def test_read_and_write_segy():
    vp_name = "velocity_models/test"
    segy_file = vp_name + ".segy"
    hdf5_file = vp_name + ".hdf5"
    mesh = fire.UnitSquareMesh(10, 10)
    mesh.coordinates.dat.data[:, 0] *= -1

    V = fire.FunctionSpace(mesh, 'CG', 3)
    x, y = fire.SpatialCoordinate(mesh)
    r = 0.2
    xc = -0.5
    yc = 0.5

    vp = fire.Function(V)

    c = fire.conditional((x - xc)**2 + (y - yc)**2 < r**2, 3.0, 1.5)

    vp.interpolate(c)

    xi, yi, zi = spyro.io.write_function_to_grid(vp, V, 10.0 / 1000.0)
    spyro.io.create_segy(zi, segy_file)
    write_velocity_model(segy_file, vp_name)

    model = {}

    model["opts"] = {
        "method": "CG",  # either CG or KMV
        "quadrature": "CG",  # Equi or KMV
        "degree": 3,  # p order
        "dimension": 2,  # dimension
    }
    model["mesh"] = {
        "Lz": 1.0,  # depth in km - always positive
        "Lx": 1.0,  # width in km - always positive
        "Ly": 0.0,  # thickness in km - always positive
        "meshfile": None,
        "initmodel": None,
        "truemodel": hdf5_file,
    }
    model["BCs"] = {
        "status": False,
    }

    vp_read = spyro.io.interpolate(model, mesh, V, guess=False)

    fire.File("velocity_models/test.pvd").write(vp_read)

    value_at_center = vp_read.at(xc, yc)
    test1 = math.isclose(value_at_center, 3.0)
    value_outside_circle = vp_read.at(xc + r + 0.1, yc)
    test2 = math.isclose(value_outside_circle, 1.5)
    assert all([test1, test2])
def test_3dmesher():

    fname = os.path.join(os.path.dirname(__file__), "test3D.bin")

    wl = 10
    freq = 2
    hmin = 50
    grade = 0.005
    bbox = (-2e3, 0.0, 0.0, 1e3, 0.0, 1e3)
    cube = Cube(bbox)
    ef = get_sizing_function_from_segy(
        fname,
        bbox,
        grade=grade,
        grad=hmin,
        freq=freq,
        wl=wl,
        hmin=hmin,
        nz=20,
        nx=10,
        ny=10,
        byte_order="little",
        domain_pad=0.0,
        axes_order=(2, 0, 1),
    )

    write_velocity_model(fname,
                         nz=20,
                         nx=10,
                         ny=10,
                         byte_order="little",
                         ofname="testing")

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

    points, cells = sliver_removal(points=points,
                                   edge_length=ef,
                                   domain=cube,
                                   h0=hmin)
    print(len(points), len(cells))
    allclose([len(points), len(cells)], [16459, 89240], atol=100)
Esempio n. 5
0
def test_2dmesher_domain_extension(style_answer):
    style, answer = style_answer
    fname = os.path.join(os.path.dirname(__file__), "testing.segy")
    bbox = (-10e3, 0.0, 0.0, 10e3)
    wl = 5
    freq = 5.0
    hmin = 100
    hmax = 10e6
    grade = 0.005
    grad = 50.0
    rectangle = Rectangle(bbox)
    ef = get_sizing_function_from_segy(
        fname,
        bbox=bbox,
        grade=grade,
        grad=grad,
        stencil_size=100,
        wl=wl,
        freq=freq,
        hmin=hmin,
        hmax=hmax,
        pad_style=style,
        domain_pad=1e3,
    )
    plot_sizing_function(ef)
    write_velocity_model(fname, bbox=bbox)

    points, cells = generate_mesh(
        rectangle,
        ef,
        h0=hmin,
        perform_checks=True,
    )
    # import meshio

    # meshio.write_points_cells(
    #    "TEST.vtk", points, [("triangle", cells)], file_format="vtk"
    # )
    print(len(points), len(cells))
    assert allclose([len(points), len(cells)], answer, atol=100)