def add_data(gb, domain, kf): """ Define the permeability, apertures, boundary conditions """ gb.add_node_props(['param']) tol = 1e-5 a = 1e-4 for g, d in gb: param = Parameters(g) # Permeability kxx = np.ones(g.num_cells) * np.power(kf, g.dim < gb.dim_max()) if g.dim == 2: perm = tensor.SecondOrderTensor(3, kxx=kxx, kyy=kxx, kzz=1) else: perm = tensor.SecondOrderTensor(3, kxx=kxx, kyy=1, kzz=1) if g.dim == 1: R = cg.project_line_matrix(g.nodes, reference=[1, 0, 0]) perm.rotate(R) param.set_tensor("flow", perm) # Source term param.set_source("flow", np.zeros(g.num_cells)) # Assign apertures aperture = np.power(a, gb.dim_max() - g.dim) param.set_aperture(np.ones(g.num_cells) * aperture) # Boundaries bound_faces = g.tags['domain_boundary_faces'].nonzero()[0] if bound_faces.size != 0: bound_face_centers = g.face_centers[:, bound_faces] left = bound_face_centers[0, :] < domain['xmin'] + tol right = bound_face_centers[0, :] > domain['xmax'] - tol labels = np.array(['neu'] * bound_faces.size) labels[right] = 'dir' bc_val = np.zeros(g.num_faces) bc_val[bound_faces[left]] = -aperture \ * g.face_areas[bound_faces[left]] bc_val[bound_faces[right]] = 1 param.set_bc("flow", BoundaryCondition(g, bound_faces, labels)) param.set_bc_val("flow", bc_val) else: param.set_bc("flow", BoundaryCondition(g, np.empty(0), np.empty(0))) d['param'] = param # Assign coupling permeability gb.add_edge_prop('kn') for e, d in gb.edges_props(): gn = gb.sorted_nodes_of_edge(e) aperture = np.power(a, gb.dim_max() - gn[0].dim) d['kn'] = np.ones(gn[0].num_cells) * kf / aperture
def create_embedded_line_grid(loc_coord, glob_id, tol=1e-4): loc_center = np.mean(loc_coord, axis=1).reshape((-1, 1)) loc_coord -= loc_center # Check that the points indeed form a line if not cg.is_collinear(loc_coord, tol): raise ValueError("Elements are not colinear") # Find the tangent of the line tangent = cg.compute_tangent(loc_coord) # Projection matrix rot = cg.project_line_matrix(loc_coord, tangent) loc_coord_1d = rot.dot(loc_coord) # The points are now 1d along one of the coordinate axis, but we # don't know which yet. Find this. sum_coord = np.sum(np.abs(loc_coord_1d), axis=1) sum_coord /= np.amax(sum_coord) active_dimension = np.logical_not( np.isclose(sum_coord, 0, atol=tol, rtol=0)) # Check that we are indeed in 1d assert np.sum(active_dimension) == 1 # Sort nodes, and create grid coord_1d = loc_coord_1d[active_dimension] sort_ind = np.argsort(coord_1d)[0] sorted_coord = coord_1d[0, sort_ind] g = structured.TensorGrid(sorted_coord) # Project back to active dimension nodes = np.zeros(g.nodes.shape) nodes[active_dimension] = g.nodes[0] g.nodes = nodes # Project back again to 3d coordinates irot = rot.transpose() g.nodes = irot.dot(g.nodes) g.nodes += loc_center # Add mapping to global point numbers g.global_point_ind = glob_id[sort_ind] return g
def add_data(gb, domain, kf): """ Define the permeability, apertures, boundary conditions """ gb.add_node_props(['param']) tol = 1e-5 a = 1e-3 for g, d in gb: param = Parameters(g) # Permeability kxx = np.ones(g.num_cells) * np.power(kf, g.dim < gb.dim_max()) if g.dim == 2: perm = tensor.SecondOrderTensor(3, kxx=kxx, kyy=kxx, kzz=1) else: perm = tensor.SecondOrderTensor(3, kxx=kxx, kyy=1, kzz=1) if g.dim == 1: R = cg.project_line_matrix(g.nodes, reference=[1, 0, 0]) perm.rotate(R) param.set_tensor("flow", perm) # Source term param.set_source("flow", np.zeros(g.num_cells)) # Assign apertures aperture = np.power(a, gb.dim_max() - g.dim) param.set_aperture(np.ones(g.num_cells) * aperture) # Boundaries bound_faces = g.tags['domain_boundary_faces'].nonzero()[0] if bound_faces.size != 0: bound_face_centers = g.face_centers[:, bound_faces] bottom_corner = np.logical_and(bound_face_centers[0, :] < 0.1, bound_face_centers[1, :] < 0.1) top_corner = np.logical_and(bound_face_centers[0, :] > 0.9, bound_face_centers[1, :] > 0.9) labels = np.array(['neu'] * bound_faces.size) dir_faces = np.logical_or(bottom_corner, top_corner) labels[dir_faces] = 'dir' bc_val = np.zeros(g.num_faces) bc_val[bound_faces[bottom_corner]] = 1 bc_val[bound_faces[top_corner]] = -1 param.set_bc("flow", BoundaryCondition(g, bound_faces, labels)) param.set_bc_val("flow", bc_val) else: param.set_bc("flow", BoundaryCondition(g, np.empty(0), np.empty(0))) d['param'] = param # Assign coupling permeability gb.add_edge_prop('kn') for e, d in gb.edges_props(): g = gb.sorted_nodes_of_edge(e)[0] d['kn'] = kf / gb.node_prop(g, 'param').get_aperture()