Exemplo n.º 1
0
def test_triangle_unstructured_grid():
    maximum_area = 30000.0
    extent = (214270.0, 221720.0, 4366610.0, 4373510.0)
    domainpoly = [
        (extent[0], extent[2]),
        (extent[1], extent[2]),
        (extent[1], extent[3]),
        (extent[0], extent[3]),
    ]
    tri = Triangle(maximum_area=maximum_area, angle=30, model_ws=tpth)
    tri.add_polygon(domainpoly)
    tri.build(verbose=False)
    verts = [[iv, x, y] for iv, (x, y) in enumerate(tri.verts)]
    iverts = tri.iverts
    xc, yc = tri.get_xcyc().T
    ncpl = np.array([len(iverts)])
    g = UnstructuredGrid(
        vertices=verts,
        iverts=iverts,
        ncpl=ncpl,
        xcenters=xc,
        ycenters=yc,
    )
    assert len(g.grid_lines) == 8190
    assert g.nnodes == g.ncpl == 2730
    return
Exemplo n.º 2
0
def get_tri_grid(angrot=0., xyoffset=0., triangle_exe=None):
    if not triangle_exe:
        cell2d = [[0, 16.666666666666668, 13.333333333333334, 3, 4, 2, 7],
                  [1, 3.3333333333333335, 6.666666666666667, 3, 4, 0, 5],
                  [2, 6.666666666666667, 16.666666666666668, 3, 1, 8, 4],
                  [3, 3.3333333333333335, 13.333333333333334, 3, 5, 1, 4],
                  [4, 6.666666666666667, 3.3333333333333335, 3, 6, 0, 4],
                  [5, 13.333333333333334, 3.3333333333333335, 3, 4, 3, 6],
                  [6, 16.666666666666668, 6.666666666666667, 3, 7, 3, 4],
                  [7, 13.333333333333334, 16.666666666666668, 3, 8, 2, 4]]
        vertices = [[0, 0.0, 0.0], [1, 0.0, 20.0], [2, 20.0, 20.0],
                    [3, 20.0, 0.0], [4, 10.0, 10.0], [5, 0.0, 10.0],
                    [6, 10.0, 0.0], [7, 20.0, 10.0], [8, 10.0, 20.0]]
    else:
        maximum_area = 50.
        x0, x1, y0, y1 = (0.0, 20.0, 0.0, 20.0)
        domainpoly = [(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
        tri = Triangle(maximum_area=maximum_area,
                       angle=45,
                       model_ws=".",
                       exe_name=triangle_exe)
        tri.add_polygon(domainpoly)
        tri.build(verbose=False)
        cell2d = tri.get_cell2d()
        vertices = tri.get_vertices()
    tgr = fgrid.VertexGrid(vertices,
                           cell2d,
                           botm=np.atleast_2d(np.zeros(len(cell2d))),
                           top=np.ones(len(cell2d)),
                           xoff=xyoffset,
                           yoff=xyoffset,
                           angrot=angrot)
    return tgr
Exemplo n.º 3
0
def create_mesh(layer, max_area=10000000, max_angle=30, saveFig=False):
    '''
    Function that create a triangular mesh based on a layer input.
    The max_area and max_angle parameter control the shape of the triangular shape.
    The saveFig parameter if True save the create mesh to pdf.
    The path to the triangular.exe must be change inside the function regarding the location.
    '''

    #Extract the points that compose the geometry
    layer_pts = []
    for x, y in zip(layer.geometry[0].boundary.xy[0],
                    layer.geometry[0].boundary.xy[1]):
        layer_pts.append((float(x), float(y)))

    #Create a directory to store the mesh/mf6 files
    path_ws = './mesh'
    if os.path.exists(path_ws):
        shutil.rmtree(path_ws)
    os.makedirs(path_ws)

    #Build the grid
    path_tri1 = '/mnt/c/Users/wdall/switchdrive/00_Institution/03_Code_Python/3.0/04_Trend/01_FloPy/MODFLOW/bin/triangle.exe'
    path_tri2 = '/home/valentin/ownCloud/00_Institution/03_Code_Python/3.0/04_Trend/01_FloPy/linux_bin/triangle'
    grid = Triangle(maximum_area=max_area,
                    angle=max_angle,
                    model_ws=path_ws,
                    exe_name=path_tri2)
    grid.add_polygon(layer_pts)
    grid.build()

    #Plot the grid
    fig = plt.figure(figsize=(5, 5))
    ax = plt.subplot(1, 1, 1, aspect='equal')
    pc = grid.plot()

    start, end = ax.get_xlim()
    locx = plticker.MultipleLocator(
        base=(end - start) /
        15)  # this locator puts ticks at regular intervals
    start, end = ax.get_ylim()
    locy = plticker.MultipleLocator(
        base=(end - start) /
        20)  # this locator puts ticks at regular intervals

    ax.xaxis.set_major_locator(locx)
    ax.yaxis.set_major_locator(locy)

    plt.xticks(rotation=90)

    #minor_ticks_x = np.arange(660000, 710000, (710000-660000)/25)
    #minor_ticks_y = np.arange(6150000, 6210000, (6210000-6150000)/30)
    #ax.set_xticks(minor_ticks_x, minor=True)
    #ax.set_yticks(minor_ticks_y, minor=True)
    ax.grid(c='lightblue', which='minor', alpha=0.8)
    ax.grid(c='tan', which='major')
    plt.tight_layout()
    if saveFig == True:
        fig.savefig('mesh.pdf')

    return layer_pts, grid
def get_tri_grid(angrot=0., xyoffset=0., triangle_exe=None):
    if not triangle_exe:
        return -1
    maximum_area = 50.
    x0, x1, y0, y1 = (0.0, 20.0, 0.0, 20.0)
    domainpoly = [(x0, y0), (x0, y1), (x1, y1), (x1, y0)]
    tri = Triangle(maximum_area=maximum_area,
                   angle=45,
                   model_ws=".",
                   exe_name=triangle_exe)
    tri.add_polygon(domainpoly)
    tri.build(verbose=False)
    cell2d = tri.get_cell2d()
    vertices = tri.get_vertices()
    tgr = fgrid.VertexGrid(vertices,
                           cell2d,
                           botm=np.atleast_2d(np.zeros(len(cell2d))),
                           top=np.ones(len(cell2d)),
                           xoff=xyoffset,
                           yoff=xyoffset,
                           angrot=angrot)
    return tgr
Exemplo n.º 5
0
def test_voronoi_vertex_grid():
    xmin = 0.0
    xmax = 2.0
    ymin = 0.0
    ymax = 1.0
    area_max = 0.05
    tri = Triangle(maximum_area=area_max, angle=30, model_ws=tpth)
    poly = np.array(((xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax)))
    tri.add_polygon(poly)
    tri.build(verbose=False)

    # create vor object and VertexGrid
    vor = VoronoiGrid(tri.verts)
    gridprops = vor.get_gridprops_vertexgrid()
    vgrid = VertexGrid(**gridprops, nlay=1)
    assert vgrid.is_valid

    # arguments for creating a mf6 disv package
    gridprops = vor.get_disv_gridprops()
    assert gridprops["ncpl"] == 43
    assert gridprops["nvert"] == 83
    assert len(gridprops["vertices"]) == 83
    assert len(gridprops["cell2d"]) == 43
    return
Exemplo n.º 6
0
def create_mesh(layer, max_area=10000000, max_angle=30, saveFig=False):
    '''
    Function that create a triangular mesh based on a layer input.
    The created mesh is then plot.
    The max_area and max_angle parameter control the shape of the triangular shape.
    The saveFig parameter if True save the create mesh to pdf.
    The path to the triangular.exe must be change inside the function regarding the location.
    
    Inputs : 
    -----------
    layer : geopanda layer geometry, created with the create_grid function
    max_area : maximum area of a cell
    max_angle : maximum angle of a cell
    saveFig : store the to pdf the created mesh (boolean).
    
    Outputs : 
    -----------
    layer_pts : coordinates of the points geometry.
    mesh : triangular mesh    
    '''

    #Extract the points that compose the geometry
    layer_pts = []
    for x, y in zip(layer.geometry[0].boundary.xy[0],
                    layer.geometry[0].boundary.xy[1]):
        layer_pts.append((float(x), float(y)))

    #Create a directory to store the mesh/mf6 files
    path_ws = './mesh'
    if os.path.exists(path_ws):
        shutil.rmtree(path_ws)
    os.makedirs(path_ws)

    #Build the mesh
    path_tri = './linux_bin/triangle'
    mesh = Triangle(maximum_area=max_area,
                    angle=max_angle,
                    model_ws=path_ws,
                    exe_name=path_tri)
    mesh.add_polygon(layer_pts)
    mesh.build()

    #Plot the mesh
    fig = plt.figure(figsize=(5, 5))
    ax = plt.subplot(1, 1, 1, aspect='equal')
    pc = mesh.plot()

    start, end = ax.get_xlim()
    locx = plticker.MultipleLocator(
        base=(end - start) /
        15)  # this locator puts ticks at regular intervals
    start, end = ax.get_ylim()
    locy = plticker.MultipleLocator(
        base=(end - start) /
        20)  # this locator puts ticks at regular intervals

    ax.xaxis.set_major_locator(locx)
    ax.yaxis.set_major_locator(locy)

    plt.xticks(rotation=90)
    ax.grid(c='lightblue', which='minor', alpha=0.8)
    ax.grid(c='tan', which='major')
    plt.tight_layout()

    if saveFig == True:
        fig.savefig('mesh.pdf')

    return layer_pts, mesh