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
def test_loading_argus_meshes(): datapth = os.path.join("..", "examples", "data", "unstructured") fnames = [fname for fname in os.listdir(datapth) if fname.endswith(".exp")] for fname in fnames: fname = os.path.join(datapth, fname) print("Loading Argus mesh ({}) into UnstructuredGrid".format(fname)) g = UnstructuredGrid.from_argus_export(fname) print(" Number of nodes: {}".format(g.nnodes))
def test_unstructured_grid_shell(): # constructor with no arguments. incomplete shell should exist g = UnstructuredGrid() assert g.nlay is None assert g.nnodes is None assert g.ncpl is None assert not g.grid_varies_by_layer assert not g.is_valid assert not g.is_complete return
def test_unstructured_grid_dimensions(): # constructor with just dimensions ncpl = [1, 10, 1] g = UnstructuredGrid(ncpl=ncpl) assert np.allclose(g.ncpl, ncpl) assert g.nlay == 3 assert g.nnodes == 12 assert not g.is_valid assert not g.is_complete assert not g.grid_varies_by_layer return
def test_unstructured_minimal_grid(): # pass in simple 2 cell minimal grid to make grid valid vertices = [ [0, 0.0, 1.0], [1, 1.0, 1.0], [2, 2.0, 1.0], [3, 0.0, 0.0], [4, 1.0, 0.0], [5, 2.0, 0.0], ] iverts = [[0, 1, 4, 3], [1, 2, 5, 4]] xcenters = [0.5, 1.5] ycenters = [0.5, 0.5] g = UnstructuredGrid( vertices=vertices, iverts=iverts, xcenters=xcenters, ycenters=ycenters ) assert np.allclose(g.ncpl, np.array([2], dtype=int)) assert g.nlay == 1 assert g.nnodes == 2 assert g.is_valid assert not g.is_complete assert not g.grid_varies_by_layer assert g._vertices == vertices assert g._iverts == iverts assert g._xc == xcenters assert g._yc == ycenters grid_lines = [ [(0.0, 0), (0.0, 1.0)], [(0.0, 1), (1.0, 1.0)], [(1.0, 1), (1.0, 0.0)], [(1.0, 0), (0.0, 0.0)], [(1.0, 0), (1.0, 1.0)], [(1.0, 1), (2.0, 1.0)], [(2.0, 1), (2.0, 0.0)], [(2.0, 0), (1.0, 0.0)], ] assert g.grid_lines == grid_lines, "\n{} \n /= \n{}".format( g.grid_lines, grid_lines ) assert g.extent == (0, 2, 0, 1) xv, yv, zv = g.xyzvertices assert xv == [[0, 1, 1, 0], [1, 2, 2, 1]] assert yv == [[1, 1, 0, 0], [1, 1, 0, 0]] assert zv is None return
def test_create_unstructured_grid_from_verts(): datapth = os.path.join("..", "examples", "data", "unstructured") # simple functions to load vertices and incidence lists def load_verts(fname): print("Loading vertices from: {}".format(fname)) verts = np.genfromtxt( fname, dtype=[int, float, float], names=["iv", "x", "y"] ) verts["iv"] -= 1 # zero based return verts def load_iverts(fname): print("Loading iverts from: {}".format(fname)) f = open(fname, "r") iverts = [] xc = [] yc = [] for line in f: ll = line.strip().split() iverts.append([int(i) - 1 for i in ll[4:]]) xc.append(float(ll[1])) yc.append(float(ll[2])) return iverts, np.array(xc), np.array(yc) # load vertices fname = os.path.join(datapth, "ugrid_verts.dat") verts = load_verts(fname) # load the incidence list into iverts fname = os.path.join(datapth, "ugrid_iverts.dat") iverts, xc, yc = load_iverts(fname) ncpl = np.array(5 * [len(iverts)]) g = UnstructuredGrid(verts, iverts, xc, yc, ncpl=ncpl) assert isinstance(g.grid_lines, list) assert np.allclose(g.ncpl, ncpl) assert g.extent == (0.0, 700.0, 0.0, 700.0) assert g._vertices.shape == (156,) assert g.nnodes == g.ncpl.sum() == 1090 return
def test_unstructured_complete_grid(): # pass in simple 2 cell complete grid to make grid valid, and put each # cell in a different layer vertices = [ [0, 0.0, 1.0], [1, 1.0, 1.0], [2, 2.0, 1.0], [3, 0.0, 0.0], [4, 1.0, 0.0], [5, 2.0, 0.0], ] iverts = [[0, 1, 4, 3], [1, 2, 5, 4]] xcenters = [0.5, 1.5] ycenters = [0.5, 0.5] ncpl = [1, 1] top = [1, 0] top = np.array(top) botm = [0, -1] botm = np.array(botm) g = UnstructuredGrid( vertices=vertices, iverts=iverts, xcenters=xcenters, ycenters=ycenters, ncpl=ncpl, top=top, botm=botm, ) assert np.allclose(g.ncpl, np.array([1, 1], dtype=int)) assert g.nlay == 2 assert g.nnodes == 2 assert g.is_valid assert not g.is_complete assert g.grid_varies_by_layer assert g._vertices == vertices assert g._iverts == iverts assert g._xc == xcenters assert g._yc == ycenters grid_lines = { 0: [ [(0.0, 0.0), (0.0, 1.0)], [(0.0, 1.0), (1.0, 1.0)], [(1.0, 1.0), (1.0, 0.0)], [(1.0, 0.0), (0.0, 0.0)], ], 1: [ [(1.0, 0.0), (1.0, 1.0)], [(1.0, 1.0), (2.0, 1.0)], [(2.0, 1.0), (2.0, 0.0)], [(2.0, 0.0), (1.0, 0.0)], ], } assert isinstance(g.grid_lines, dict) assert g.grid_lines == grid_lines, "\n{} \n /= \n{}".format( g.grid_lines, grid_lines ) assert g.extent == (0, 2, 0, 1) xv, yv, zv = g.xyzvertices assert xv == [[0, 1, 1, 0], [1, 2, 2, 1]] assert yv == [[1, 1, 0, 0], [1, 1, 0, 0]] assert np.allclose(zv, np.array([[1, 0], [0, -1]])) return
def __new__(cls, sr=None, ax=None, model=None, dis=None, layer=0, extent=None, xul=None, yul=None, xll=None, yll=None, rotation=None, length_multiplier=None): from ..utils.reference import SpatialReferenceUnstructured from ..plot.plotbase import DeprecatedMapView err_msg = "ModelMap will be replaced by " \ "PlotMapView(); Calling PlotMapView()" warnings.warn(err_msg, PendingDeprecationWarning) modelgrid = None if model is not None: if (xul, yul, xll, yll, rotation) != (None, None, None, None, None): modelgrid = plotutil._set_coord_info(model.modelgrid, xul, yul, xll, yll, rotation) elif sr is not None: if length_multiplier is not None: sr.length_multiplier = length_multiplier if (xul, yul, xll, yll, rotation) != (None, None, None, None, None): sr.set_spatialreference(xul, yul, xll, yll, rotation) if isinstance(sr, SpatialReferenceUnstructured): if dis is not None: modelgrid = UnstructuredGrid(vertices=sr.verts, iverts=sr.iverts, xcenters=sr.xc, ycenters=sr.yc, top=dis.top.array, botm=dis.botm.array, ncpl=sr.ncpl) else: modelgrid = UnstructuredGrid(vertices=sr.verts, iverts=sr.iverts, xcenters=sr.xc, ycenters=sr.yc, ncpl=sr.ncpl) elif dis is not None: modelgrid = StructuredGrid(delc=sr.delc, delr=sr.delr, top=dis.top.array, botm=dis.botm.array, xoff=sr.xll, yoff=sr.yll, angrot=sr.rotation) else: modelgrid = StructuredGrid(delc=sr.delc, delr=sr.delr, xoff=sr.xll, yoff=sr.yll, angrot=sr.rotation) else: pass return DeprecatedMapView(model=model, modelgrid=modelgrid, ax=ax, layer=layer, extent=extent)
def test_unstructured_thick(): nlay = 3 ncpl = [5, 5, 5] vertices = [ [0, 0.0, 3.0], [1, 1.0, 3.0], [2, 2.0, 3.0], [3, 0.0, 2.0], [4, 1.0, 2.0], [5, 2.0, 2.0], [6, 0.0, 1.0], [7, 1.0, 1.0], [8, 2.0, 1.0], [9, 0.0, 0.0], [10, 1.0, 0.0], ] iverts = [ [0, 0, 1, 4, 3], [1, 1, 2, 5, 4], [2, 3, 4, 7, 6], [3, 4, 5, 8, 7], [4, 6, 7, 10, 9], [5, 0, 1, 4, 3], [6, 1, 2, 5, 4], [7, 3, 4, 7, 6], [8, 4, 5, 8, 7], [9, 6, 7, 10, 9], [10, 0, 1, 4, 3], [11, 1, 2, 5, 4], [12, 3, 4, 7, 6], [13, 4, 5, 8, 7], [14, 6, 7, 10, 9], ] xcenters = [ 0.5, 1.5, 0.5, 1.5, 0.5, ] ycenters = [ 2.5, 2.5, 1.5, 1.5, 0.5, ] top = np.ones((nlay, 5), dtype=float) top[0, :] = 10.0 top[1, :] = 5.0 top[2, :] = 0.0 botm = np.zeros((nlay, 5), dtype=float) botm[0, :] = 5.0 botm[1, :] = 0.0 botm[2, :] = -5.0 grid = UnstructuredGrid( vertices=vertices, iverts=iverts, xcenters=xcenters, ycenters=ycenters, ncpl=ncpl, top=top.flatten(), botm=botm.flatten(), ) thick = grid.thick assert np.allclose(thick, 5.0), "thicknesses != 5." sat_thick = grid.saturated_thick(grid.botm + 10.0) assert np.allclose(sat_thick, thick), "saturated thicknesses != 5." sat_thick = grid.saturated_thick(grid.botm + 5.0) assert np.allclose(sat_thick, thick), "saturated thicknesses != 5." sat_thick = grid.saturated_thick(grid.botm + 2.5) assert np.allclose(sat_thick, 2.5), "saturated thicknesses != 2.5" sat_thick = grid.saturated_thick(grid.botm) assert np.allclose(sat_thick, 0.0), "saturated thicknesses != 0." sat_thick = grid.saturated_thick(grid.botm - 100.0) assert np.allclose(sat_thick, 0.0), "saturated thicknesses != 0." return