def setup_2d(): grid_list = [] # Unstructured perturbation nx = np.array([2, 2]) g_cart_unpert = structured.CartGrid(nx) g_cart_unpert.compute_geometry() grid_list.append(g_cart_unpert) # Structured perturbation g_cart_spert = structured.CartGrid(nx) g_cart_spert.nodes[0, 4] = 1.5 g_cart_spert.compute_geometry() grid_list.append(g_cart_spert) # Larger grid, random perturbations nx = np.array([3, 3]) g_cart_rpert = structured.CartGrid(nx) dx = 1 pert = .4 rand = np.vstack((np.random.rand(g_cart_rpert.dim, g_cart_rpert.num_nodes), np.repeat(0., g_cart_rpert.num_nodes))) g_cart_rpert.nodes = g_cart_rpert.nodes + dx * pert * \ (0.5 - rand) g_cart_rpert.compute_geometry() grid_list.append(g_cart_rpert) return grid_list
def coarsening_example0(**kwargs): ####################### # Simple 2d coarsening based on tpfa for Cartesian grids # isotropic permeability ####################### Nx = Ny = 7 g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() if kwargs['visualize']: plot_grid(g, info="all", alpha=0) part = create_partition(tpfa_matrix(g)) g = generate_coarse_grid(g, part) g.compute_geometry(is_starshaped=True) if kwargs['visualize']: plot_grid(g, info="all", alpha=0) g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() part = create_partition(tpfa_matrix(g), cdepth=3) g = generate_coarse_grid(g, part) g.compute_geometry(is_starshaped=True) if kwargs['visualize']: plot_grid(g, info="all", alpha=0)
def test_cart_3d(self): g = structured.CartGrid([4, 3, 3]) g.nodes = g.nodes + 0.2 * np.random.random((g.dim, g.nodes.shape[1])) g.compute_geometry() # Pick out cells (0, 0, 0), (1, 0, 0), (0, 1, 0), (0, 0, 1), (0, 0, 2), (1, 0, 2) c = np.array([0, 1, 4, 12, 24, 25]) h, sub_f, sub_n = partition.extract_subgrid(g, c) # There are 20 nodes in each layer nodes_0 = np.array([0, 1, 2, 5, 6, 7, 10, 11]) nodes_1 = nodes_0 + 20 nodes_2 = np.array([0, 1, 2, 5, 6, 7]) + 40 nodes_3 = nodes_2 + 20 true_nodes = np.hstack((nodes_0, nodes_1, nodes_2, nodes_3)) faces_x = np.array([0, 1, 2, 5, 6, 15, 16, 30, 31, 32]) # y-faces start on 45 faces_y = np.array([45, 46, 49, 50, 53, 61, 65, 77, 78, 81, 82]) # z-faces start on 93 faces_z = np.array([93, 94, 97, 105, 106, 109, 117, 118, 129, 130]) true_faces = np.hstack((faces_x, faces_y, faces_z)) assert np.array_equal(true_nodes, sub_n) assert np.array_equal(true_faces, sub_f) self.compare_grid_geometries(g, h, c, true_faces, true_nodes)
def test_coarse_grid_2d( self ): g = structured.CartGrid([3, 2]) g = generate_coarse_grid( g, [5, 2, 2, 5, 2, 2] ) assert g.num_cells == 2 assert g.num_faces == 12 assert g.num_nodes == 11 pt = np.tile(np.array([2,1,0]), (g.nodes.shape[1],1) ).T find = np.isclose( pt, g.nodes ).all( axis = 0 ) assert find.any() == False faces_cell0, _, orient_cell0 = sps.find( g.cell_faces[:,0] ) assert np.array_equal( faces_cell0, [1, 2, 4, 5, 7, 8, 10, 11] ) assert np.array_equal( orient_cell0, [-1, 1, -1, 1, -1, -1, 1, 1] ) faces_cell1, _, orient_cell1 = sps.find( g.cell_faces[:,1] ) assert np.array_equal( faces_cell1, [0, 1, 3, 4, 6, 9] ) assert np.array_equal( orient_cell1, [-1, 1, -1, 1, -1, 1] ) known = np.array( [ [0, 4], [1, 5], [3, 6], [4, 7], [5, 8], [6, 10], [0, 1], [1, 2], [2, 3], [7, 8], [8, 9], [9, 10] ] ) for f in np.arange( g.num_faces ): assert np.array_equal( sps.find( g.face_nodes[:,f] )[0], known[f,:] )
def setUp(self): self.tol = set_tol() nc = np.array([2, 2]) g = structured.CartGrid(nc) g.nodes[0, 4] = 1.5 g.compute_geometry() self.g = g
def cart_grid_2d(fracs, nx, physdims=None): """ Create grids for a domain with possibly intersecting fractures in 2d. Based on lines describing the individual fractures, the method constructs grids in 2d (whole domain), 1d (individual fracture), and 0d (fracture intersections). Parameters: fracs (list of np.ndarray, each 2x2): Vertexes of the line for each fracture. The fracture lines must align to the coordinat axis. The fractures will snap to the closest grid nodes. nx (np.ndarray): Number of cells in each direction. Should be 2D. physdims (np.ndarray): Physical dimensions in each direction. Defaults to same as nx, that is, cells of unit size. Returns: list (length 3): For each dimension (2 -> 0), a list of all grids in that dimension. """ nx = np.asarray(nx) if physdims is None: physdims = nx elif np.asarray(physdims).size != nx.size: raise ValueError('Physical dimension must equal grid dimension') else: physdims = np.asarray(physdims) g_2d = structured.CartGrid(nx, physdims=physdims) g_2d.global_point_ind = np.arange(g_2d.num_nodes) g_2d.compute_geometry() g_1d = [] g_0d = [] # 1D grids: shared_nodes = np.zeros(g_2d.num_nodes) for f in fracs: is_x_frac = f[1, 0] == f[1, 1] is_y_frac = f[0, 0] == f[0, 1] assert is_x_frac != is_y_frac, 'Fracture must align to x- or y-axis' if f.shape[0] == 2: f = np.vstack((f, np.zeros(f.shape[1]))) nodes = _find_nodes_on_line(g_2d, nx, f[:, 0], f[:, 1]) #nodes = np.unique(nodes) loc_coord = g_2d.nodes[:, nodes] g = mesh_2_grid.create_embedded_line_grid(loc_coord, nodes) g_1d.append(g) shared_nodes[nodes] += 1 # Create 0-D grids if np.any(shared_nodes > 1): for global_node in np.where(shared_nodes > 1): g = point_grid.PointGrid(g_2d.nodes[:, global_node]) g.global_point_ind = np.asarray(global_node) g_0d.append(g) grids = [[g_2d], g_1d, g_0d] return grids
def test_overlap_2_layers(self): g = structured.CartGrid([5, 5]) ci = np.array([0, 1, 5, 6]) ci_overlap = np.array([0, 1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 15, 16, 17, 18]) assert np.array_equal(partition.overlap(g, ci, 2), ci_overlap)
def test_create_partition_3d_cart(self): g = structured.CartGrid([4,4,4]) g.compute_geometry() part = create_partition(tpfa_matrix(g)) known = np.array([1,1,1,1,2,4,1,3,2,2,3,3,2,2,3,3,5,4,1,6,4,4,4,3,2,4,7, 3,8,8,3,3,5,5,6,6,5,4,7,6,8,7,7,7,8,8,7,9,5,5,6,6,5,5, 6,6,8,8,7,9,8,8,9,9])-1 assert np.array_equal(part, known)
def upwind_example2(**kwargs): ####################### # Simple 2d upwind problem with explicit Euler scheme in time coupled with # a Darcy problem ####################### T = 2 Nx, Ny = 10, 10 g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() kxx = np.ones(g.num_cells) perm = second_order_tensor.SecondOrderTensor(g.dim, kxx) def funp_ex(pt): return -np.sin(pt[0]) * np.sin(pt[1]) - pt[0] f = np.zeros(g.num_cells) b_faces = g.get_boundary_faces() bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size) bnd_val = {'dir': funp_ex(g.face_centers[:, b_faces])} solver = dual.DualVEM() data = {'k': perm, 'f': f, 'bc': bnd, 'bc_val': bnd_val} D, rhs = solver.matrix_rhs(g, data) up = sps.linalg.spsolve(D, rhs) beta_n = solver.extractU(g, up) u, p = solver.extractU(g, up), solver.extractP(g, up) P0u = solver.projectU(g, u, data) export_vtk(g, "darcy", {"p": p, "P0u": P0u}) advect = upwind.Upwind() bnd_val = {'dir': np.hstack(([1], np.zeros(b_faces.size - 1)))} data = {'beta_n': beta_n, 'bc': bnd, 'bc_val': bnd_val} U, rhs = advect.matrix_rhs(g, data) data = {'deltaT': advect.cfl(g, data)} M, _ = mass_matrix.Mass().matrix_rhs(g, data) conc = np.zeros(g.num_cells) M_minus_U = M - U invM, _ = mass_matrix.InvMass().matrix_rhs(g, data) # Loop over the time Nt = int(T / data['deltaT']) time = np.empty(Nt) for i in np.arange(Nt): # Update the solution conc = invM.dot((M_minus_U).dot(conc) + rhs) time[i] = data['deltaT'] * i export_vtk(g, "conc_darcy", {"conc": conc}, time_step=i) export_pvd(g, "conc_darcy", time)
def test_create_partition_2d_cart_cdepth4(self): g = structured.CartGrid([10, 10]) g.compute_geometry() part = create_partition(tpfa_matrix(g), cdepth=4) known = 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,1,1,1, 1,1,2,1,1,1,1,1,1,1,1,2,2,3,1,1,1,1,1,1,1,2,2,3,3,1,1, 1,1,1,2,2,2,3,3,3,1,1,1,1,2,2,2,3,3,3,3,1,1,2,2,2,2,3, 3,3,3,3,2,2,2,2,2,3,3,3,3,3,2,2,2,2,2])-1 assert np.array_equal(part, known)
def test_uniform_flow_cart_2d(): nx = np.array([13, 13]) g = structured.CartGrid(nx) g.compute_geometry() kxx = np.ones(g.num_cells) perm = second_order_tensor.SecondOrderTensor(g.dim, kxx) bound_faces = np.argwhere(np.abs(g.cell_faces).sum(axis=1).A.ravel(1) == 1) bound = bc.BoundaryCondition(g, bound_faces, ['dir'] * bound_faces.size) flux = tpfa.tpfa(g, perm, bound)
def test_tpfa_cart_2d(): """ Apply TPFA on Cartesian grid, should obtain Laplacian stencil. """ # Set up 3 X 3 Cartesian grid nx = np.array([3, 3]) g = structured.CartGrid(nx) g.compute_geometry() kxx = np.ones(g.num_cells) perm = second_order_tensor.SecondOrderTensor(g.dim, kxx) bound_faces = np.array([0, 3, 12]) bound = bc.BoundaryCondition(g, bound_faces, ['dir'] * bound_faces.size) trm, bound_flux = tpfa.tpfa(g, perm, bound) div = g.cell_faces.T a = div * trm b = (div * bound_flux).A print(b) # Checks on interior cell mid = 4 assert a[mid, mid] == 4 assert a[mid - 1, mid] == -1 assert a[mid + 1, mid] == -1 assert a[mid - 3, mid] == -1 assert a[mid + 3, mid] == -1 assert np.all(b[mid, :] == 0) # The first cell should have two Dirichlet bnds assert a[0, 0] == 6 assert a[0, 1] == -1 assert a[0, 3] == -1 assert b[0, 0] == 2 assert b[0, 12] == 2 # Cell 3 has one Dirichlet, one Neumann face assert a[2, 2] == 4 assert a[2, 1] == -1 assert a[2, 5] == -1 assert b[2, 3] == 2 assert b[2, 14] == 1 # Cell 2 has one Neumann face assert a[1, 1] == 3 assert a[1, 0] == -1 assert a[1, 2] == -1 assert a[1, 4] == -1 assert b[1, 13] == 1 return a
def coarsening_example2(**kwargs): ####################### # Simple 2d coarsening based on tpfa for Cartesian grids # anisotropic permeability ####################### Nx = Ny = 7 g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() if kwargs['visualize']: plot_grid(g, info="all", alpha=0) kxx = 3 * np.ones(g.num_cells) kyy = np.ones(g.num_cells) perm = second_order_tensor.SecondOrderTensor(g.dim, kxx=kxx, kyy=kyy) part = create_partition(tpfa_matrix(g, perm=perm)) g = generate_coarse_grid(g, part) g.compute_geometry(is_starshaped=True) if kwargs['visualize']: plot_grid(g, info="all", alpha=0) g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() part = create_partition(tpfa_matrix(g, perm=perm), cdepth=3) g = generate_coarse_grid(g, part) g.compute_geometry(is_starshaped=True) if kwargs['visualize']: plot_grid(g, info="all", alpha=0) g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() part = create_partition(tpfa_matrix(g, perm=perm), cdepth=2, epsilon=1e-2) g = generate_coarse_grid(g, part) g.compute_geometry(is_starshaped=True) if kwargs['visualize']: plot_grid(g, info="all", alpha=0)
def test_cart_2d(self): g = structured.CartGrid([3, 2]) g.nodes = g.nodes + 0.2 * np.random.random(g.nodes.shape) g.compute_geometry() c = np.array([0, 1, 3]) h, sub_f, sub_n = partition.extract_subgrid(g, c) true_nodes = np.array([0, 1, 2, 4, 5, 6, 8, 9]) true_faces = np.array([0, 1, 2, 4, 5, 8, 9, 11, 12, 14]) assert np.array_equal(true_nodes, sub_n) assert np.array_equal(true_faces, sub_f) self.compare_grid_geometries(g, h, c, true_faces, true_nodes)
def test_2d_coarse_dims_specified(self): g = structured.CartGrid([4, 10]) coarse_dims = np.array([2, 3]) p = partition.partition_structured(g, coarse_dims) p_known = np.array([[ 0., 0., 1., 1.], [ 0., 0., 1., 1.], [ 0., 0., 1., 1.], [ 2., 2., 3., 3.], [ 2., 2., 3., 3.], [ 2., 2., 3., 3.], [ 4., 4., 5., 5.], [ 4., 4., 5., 5.], [ 4., 4., 5., 5.], [ 4., 4., 5., 5.]], dtype='int').ravel('C') assert np.allclose(p, p_known)
def test_upwind_1d_beta_negative(self): g = structured.CartGrid(3, 1) g.compute_geometry() solver = upwind.Upwind() data = {'beta_n': solver.beta_n(g, [-1, 0, 0])} M = solver.matrix_rhs(g, data)[0].todense() deltaT = solver.cfl(g, data) M_known = np.array([[1, -1, 0], [0, 1, -1], [0, 0, 0]]) deltaT_known = 1 / 3 rtol = 1e-15 atol = rtol assert np.allclose(M, M_known, rtol, atol) assert np.allclose(deltaT, deltaT_known, rtol, atol)
def test_upwind_2d_cart_beta_positive(self): g = structured.CartGrid([3, 2], [1, 1]) g.compute_geometry() solver = upwind.Upwind() data = {'beta_n': solver.beta_n(g, [1, 0, 0])} M = solver.matrix_rhs(g, data)[0].todense() deltaT = solver.cfl(g, data) M_known = 0.5 * np.array([[0, 0, 0, 0, 0, 0], [-1, 1, 0, 0, 0, 0], [0, -1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, -1, 1, 0], [0, 0, 0, 0, -1, 1]]) deltaT_known = 1 / 6 rtol = 1e-15 atol = rtol assert np.allclose(M, M_known, rtol, atol) assert np.allclose(deltaT, deltaT_known, rtol, atol)
def test_upwind_1d_surf_beta_negative(self): g = structured.CartGrid(3, 1) R = cg.rot(-np.pi / 8., [-1, 1, -1]) g.nodes = np.dot(R, g.nodes) g.compute_geometry(is_embedded=True) solver = upwind.Upwind() data = {'beta_n': solver.beta_n(g, np.dot(R, [-1, 0, 0]))} M = solver.matrix_rhs(g, data)[0].todense() deltaT = solver.cfl(g, data) M_known = np.array([[1, -1, 0], [0, 1, -1], [0, 0, 0]]) deltaT_known = 1 / 3 rtol = 1e-15 atol = rtol assert np.allclose(M, M_known, rtol, atol) assert np.allclose(deltaT, deltaT_known, rtol, atol)
def test_3d_coarse_dims_specified_unequal_size(self): g = structured.CartGrid(np.array([6, 5, 4])) coarse_dims = np.array([3, 2, 2]) p = partition.partition_structured(g, coarse_dims) # This just happens to be correct p_known = np.array([0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5, 0, 0, 1, 1, 2, 2, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 9, 9, 10, 10, 11, 11, 9, 9, 10, 10, 11, 11, 6, 6, 7, 7, 8, 8, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 9, 9, 10, 10, 11, 11, 9, 9, 10, 10, 11, 11]) assert np.allclose(p, p_known)
def test_subcell_topology_2d_cart_1(): x = np.ones(2) g = structured.CartGrid(x) subcell_topology = fvutils.SubcellTopology(g) assert np.all(subcell_topology.cno == 0) ncum = np.bincount(subcell_topology.nno, weights=np.ones(subcell_topology.nno.size)) assert np.all(ncum == 2) fcum = np.bincount(subcell_topology.fno, weights=np.ones(subcell_topology.fno.size)) assert np.all(fcum == 2) # There is only one cell, thus only unique subfno usubfno = np.unique(subcell_topology.subfno) assert usubfno.size == subcell_topology.subfno.size assert np.all(np.in1d(subcell_topology.subfno, subcell_topology.subhfno))
def test_coarse_grid_3d( self ): g = structured.CartGrid([2, 2, 2]) g = generate_coarse_grid( g, [0, 0, 0, 0, 1, 1, 2, 2] ) assert g.num_cells == 3 assert g.num_faces == 30 assert g.num_nodes == 27 faces_cell0, _, orient_cell0 = sps.find( g.cell_faces[:,0] ) known = [0, 1, 2, 3, 8, 9, 10, 11, 18, 19, 20, 21, 22, 23, 24, 25] assert np.array_equal( faces_cell0, known ) known = [-1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1] assert np.array_equal( orient_cell0, known ) faces_cell1, _, orient_cell1 = sps.find( g.cell_faces[:,1] ) known = [4, 5, 12, 13, 14, 15, 22, 23, 26, 27] assert np.array_equal( faces_cell1, known ) known = [-1, 1, -1, -1, 1, 1, -1, -1, 1, 1] assert np.array_equal( orient_cell1, known ) faces_cell2, _, orient_cell2 = sps.find( g.cell_faces[:,2] ) known = [6, 7, 14, 15, 16, 17, 24, 25, 28, 29] assert np.array_equal( faces_cell2, known ) known = [-1, 1, -1, -1, 1, 1, -1, -1, 1, 1] assert np.array_equal( orient_cell2, known ) known = np.array( [ [0, 3, 9, 12], [2, 5, 11, 14], [3, 6, 12, 15], [5, 8, 14, 17], [9, 12, 18, 21], [11, 14, 20, 23], [12, 15, 21, 24], [14, 17, 23, 26], [0, 1, 9, 10], [1, 2, 10, 11], [6, 7, 15, 16], [7, 8, 16, 17], [9, 10, 18, 19], [10, 11, 19, 20], [12, 13, 21, 22], [13, 14, 22, 23], [15, 16, 24, 25], [16, 17, 25, 26], [0, 1, 3, 4], [1, 2, 4, 5], [3, 4, 6, 7], [4, 5, 7, 8], [9, 10, 12, 13], [10, 11, 13, 14], [12, 13, 15, 16], [13, 14, 16, 17], [18, 19, 21, 22], [19, 20, 22, 23], [21, 22, 24, 25], [22, 23, 25, 26] ] ) for f in np.arange( g.num_faces ): assert np.array_equal( sps.find( g.face_nodes[:,f] )[0], known[f,:] )
def upwind_example1(**kwargs): ####################### # Simple 2d upwind problem with implicit Euler scheme in time ####################### T = 1 Nx, Ny = 10, 1 g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() advect = upwind.Upwind() beta_n = advect.beta_n(g, [1, 0, 0]) b_faces = g.get_boundary_faces() bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size) bnd_val = {'dir': np.hstack(([1], np.zeros(b_faces.size - 1)))} data = {'beta_n': beta_n, 'bc': bnd, 'bc_val': bnd_val} U, rhs = advect.matrix_rhs(g, data) data = {'deltaT': 2 * advect.cfl(g, data)} M, _ = mass_matrix.Mass().matrix_rhs(g, data) conc = np.zeros(g.num_cells) # Perform an LU factorization to speedup the solver IE_solver = sps.linalg.factorized((M + U).tocsc()) # Loop over the time Nt = int(T / data['deltaT']) time = np.empty(Nt) for i in np.arange(Nt): # Update the solution # Backward and forward substitution to solve the system conc = IE_solver(M.dot(conc) + rhs) time[i] = data['deltaT'] * i export_vtk(g, "conc_IE", {"conc": conc}, time_step=i) export_pvd(g, "conc_IE", time)
def test_3d_coarse_dims_specified(self): g = structured.CartGrid([4, 4, 4]) coarse_dims = np.array([2, 2, 2]) p = partition.partition_structured(g, coarse_dims) p_known = np.array([[0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3], [0, 0, 1, 1], [0, 0, 1, 1], [2, 2, 3, 3], [2, 2, 3, 3], [4, 4, 5, 5], [4, 4, 5, 5], [6, 6, 7, 7], [6, 6, 7, 7], [4, 4, 5, 5], [4, 4, 5, 5], [6, 6, 7, 7], [6, 6, 7, 7]]).ravel('C') assert np.allclose(p, p_known)
def upwind_example0(**kwargs): ####################### # Simple 2d upwind problem with explicit Euler scheme in time ####################### T = 1 Nx, Ny = 10, 1 g = structured.CartGrid([Nx, Ny], [1, 1]) g.compute_geometry() advect = upwind.Upwind() beta_n = advect.beta_n(g, [1, 0, 0]) b_faces = g.get_boundary_faces() bnd = bc.BoundaryCondition(g, b_faces, ['dir'] * b_faces.size) bnd_val = {'dir': np.hstack(([1], np.zeros(b_faces.size - 1)))} data = {'beta_n': beta_n, 'bc': bnd, 'bc_val': bnd_val} U, rhs = advect.matrix_rhs(g, data) data = {'deltaT': advect.cfl(g, data)} M, _ = mass_matrix.Mass().matrix_rhs(g, data) conc = np.zeros(g.num_cells) M_minus_U = M - U invM, _ = mass_matrix.InvMass().matrix_rhs(g, data) # Loop over the time Nt = int(T / data['deltaT']) time = np.empty(Nt) for i in np.arange(Nt): # Update the solution conc = invM.dot((M_minus_U).dot(conc) + rhs) time[i] = data['deltaT'] * i export_vtk(g, "conc_EE", {"conc": conc}, time_step=i) export_pvd(g, "conc_EE", time)
def test_cell_diameters_2d(self): g = structured.CartGrid([3, 2], [1, 1]) cell_diameters = g.cell_diameters() known = np.repeat(np.sqrt(0.5**2 + 1. / 3.**2), g.num_cells) assert np.allclose(cell_diameters, known)
def setup(self): g = structured.CartGrid([4, 4]) p = partition.partition_structured(g, np.array([2, 2])) return g, p
def test_overlap_1_layer(self): g = structured.CartGrid([5, 5]) ci = np.array([0, 1, 5, 6]) ci_overlap = np.array([0, 1, 2, 5, 6, 7, 10, 11, 12]) assert np.array_equal(partition.overlap(g, ci, 1), ci_overlap)
def test_create_partition_2d_cart(self): g = structured.CartGrid([5, 5]) g.compute_geometry() part = create_partition(tpfa_matrix(g)) known = np.array([0,0,0,1,1,0,0,2,1,1,3,2,2,2,1,3,3,2,4,4,3,3,4,4,4]) assert np.array_equal(part, known)
def test_cell_diameters_3d(self): g = structured.CartGrid([3, 2, 1]) cell_diameters = g.cell_diameters() known = np.repeat(np.sqrt(3), g.num_cells) assert np.allclose(cell_diameters, known)
def make_grid(grid, grid_dims, domain, dim): if grid.lower() == 'cart' or grid.lower() == 'cartesian': return structured.CartGrid(grid_dims, domain) elif (grid.lower() == 'simplex' and dim == 2) \ or grid.lower() == 'triangular': return simplex.StructuredTriangleGrid(grid_dims, domain)