:py:mod:`bempp.api.grid.grid` ============================= .. py:module:: bempp.api.grid.grid .. autoapi-nested-parse:: The basic grid class. Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: bempp.api.grid.grid.Grid bempp.api.grid.grid.GridDataDouble bempp.api.grid.grid.GridDataFloat bempp.api.grid.grid.ElementGeometry bempp.api.grid.grid.Element bempp.api.grid.grid.Vertex bempp.api.grid.grid.EdgeGeometry bempp.api.grid.grid.Edge Functions ~~~~~~~~~ .. autoapisummary:: bempp.api.grid.grid.get_element_to_vertex_matrix bempp.api.grid.grid.get_element_to_element_matrix bempp.api.grid.grid._compare_array_to_value bempp.api.grid.grid._find_first_common_array_index_pair_from_position bempp.api.grid.grid._find_two_common_array_index_pairs bempp.api.grid.grid._get_shared_vertex_information_for_two_elements bempp.api.grid.grid._get_shared_edge_information_for_two_elements bempp.api.grid.grid._find_vertex_adjacency bempp.api.grid.grid._find_edge_adjacency bempp.api.grid.grid._get_element_to_element_vertex_count bempp.api.grid.grid._element_filter bempp.api.grid.grid._sort_values bempp.api.grid.grid._vertices_from_edge_index bempp.api.grid.grid.grid_from_segments bempp.api.grid.grid._create_barycentric_connectivity_array bempp.api.grid.grid.barycentric_refinement bempp.api.grid.grid.union bempp.api.grid.grid.enumerate_vertex_adjacent_elements bempp.api.grid.grid._numba_enumerate_edges bempp.api.grid.grid._grid_scatter_worker bempp.api.grid.grid.grid_to_points Attributes ~~~~~~~~~~ .. autoapisummary:: bempp.api.grid.grid.EDGES_ID bempp.api.grid.grid.VERTICES_ID bempp.api.grid.grid._EDGE_LOCAL bempp.api.grid.grid.VertexGeometry .. py:data:: EDGES_ID :value: 2 .. py:data:: VERTICES_ID :value: 1 .. py:data:: _EDGE_LOCAL .. py:class:: Grid(vertices, elements, domain_indices=None, grid_id=None, scatter=True) Bases: :py:obj:`object` The Grid class. .. py:property:: vertex_adjacency Vertex adjacency information. Returns a matrix with 4 rows. Each column has the entries e0, e1, ind0, ind1, which means that element e0 is connected to element e1 via local vertex index ind0 in e0 and ind1 in e1. Only returnes connectivity via a single vertex. For connectivity via edges see edge_adjacency. .. py:property:: edge_adjacency Edge adjacency information. Returns a matrix with 6 rows. Each column has the entries e0, e1, v00, v01, v11, v12, which means that element e0 is connected to element e1. Vertex v00 in element e0 is identical to vertex v11 in element e1, and vertex v01 in element 0 is identical to vertex v12 in element e1. .. py:property:: element_to_vertex_matrix Return the matrix mapping vertices to elements. .. py:property:: element_to_element_matrix Return element to element matrix. If entry (i,j) has the value n > 0, element i and element j are connected via n vertices. .. py:property:: element_neighbors Return named tuple (indices, indexptr). The neighbors of element i are given as element_neighbors.indices[ element_neighbors.indptr[i] : element_neighbors.indptr[i +1]]. Note that the element i is contained in the list of neighbors. .. py:property:: number_of_vertices Return number of vertices. .. py:property:: number_of_edges Return number of edges. .. py:property:: number_of_elements Return number of elements. .. py:property:: vertices Return vertices. .. py:property:: elements Return elements. .. py:property:: edges Return edges. .. py:property:: centroids Return the centroids of the elements. .. py:property:: domain_indices Return domain indices. .. py:property:: element_edges Return an array of edge indices for each element. element_edges[i, j] is the index of the ith edge in the jth element. .. py:property:: device_interfaces Return the dictionary of device interfaces for the grid. .. py:property:: as_array Convert the grid to an array. For a grid with N elements returns a 1d array with 9 * N entries. The three nodes for element with index e can be found in [9 * e, 9 * (e + 1)]. .. py:property:: bounding_box Return the bounding box for the grid. The bounding box is a 3x2 array box such that box[:, 0] contains (xmin, ymin, zmin) and box[:, 1] contains (xmax, ymax, zmax). .. py:property:: volumes Return element volumes. .. py:property:: diameters Return element diameters. .. py:property:: maximum_element_diameter Return the maximum element diameter. .. py:property:: minimum_element_diameter Return the maximum element diameter. .. py:property:: normals Return normals. .. py:property:: jacobians Return Jacobians. .. py:property:: integration_elements Return integration elements. .. py:property:: jacobian_inverse_transposed Return the jacobian inverse transposed. .. py:property:: vertex_on_boundary Return vertex boundary information. .. py:property:: edge_on_boundary Return edge boundary information. .. py:property:: edge_neighbors Return for each edge the list of neighboring elements.. .. py:property:: vertex_neighbors Return for each vertex the list of neighboring elements. .. py:property:: barycentric_refinement Return the barycentric refinement of this grid. .. py:property:: id Return a unique id for the grid. .. py:method:: data(precision='double') Return Numba container with all relevant grid data. .. py:method:: _scatter() Initialise the grid on all workers. .. py:method:: entity_count(codim) Return the number of entities of given codimension. .. py:method:: plot() Plot the grid. .. py:method:: get_element(index) Return element with a given index. .. py:method:: entity_iterator(codim) Return an iterator for a given codim. .. py:method:: map_to_point_cloud(order=None, local_points=None, precision='double') Return a point cloud representation of the grid on quadratur points. Return a representation of the grid as a point cloud using points on each element either defined through a triangle Gauss qudrature order or by directly specifying an array of local points. Parameters ---------- order : Integer Optional parameter. Specify a quadrature order for the point cloud generation. local_points: Numpy array A 2 x N array of N points in local reference coordinates that specify the points to use for each triangle. precision: String Either 'single' or 'double'. If neither order nor local_points is specified the quadrature order is obtained from the global parameters. Returns a M x 3 array of M points that represent the grid on the specified points. .. py:method:: refine() Return a new grid with all elements refined. .. py:method:: _compute_vertex_neighbors() Return all elements adjacent to a given vertex. .. py:method:: _normalize_and_assign_input(vertices, elements, domain_indices) Convert input into the right form. .. py:method:: _enumerate_edges() Enumerate all edges in a given grid. Assigns a tuple (edges, element_edges) to self._edges and self._element_edges. element_edges is an array a such that a[i, j] is the index of the ith edge in the jth elements, and edges is a 2 x nedges array such that the jth column stores the two nodes associated with the jth edge. .. py:method:: _get_element_adjacency_for_edges_and_vertices() Get element adjacency. The array edge_adjacency has 6 rows, such that for index j the element edge_adjacency[0, j] is connected with element edge_adjacency[1, j] via the vertices edge_adjacency[2:4, j] in the first element and the vertices edge_adjacency[4:6, j] in the second element. The vertex numbers here are local numbers (0, 1 or 2). The array vertex_adjacency has 4 rows, such that for index j the element vertex_adjacency[0, j] is connected with vertex_adjacency[1, j] via the vertex vertex_adjacency[2, j] in the first element and the vertex vertex_adjacency[3, j] in the second element. The vertex numbers here are local numbers (0, 1 or 2). .. py:method:: _compute_geometric_quantities() Compute geometric quantities for the grid. .. py:method:: _compute_boundary_information() Return a boolean array with boundary information. Computes arr0, arr1 such that arr0[j] is True if vertex j lies on the boundary and arr1[i] is True if edge i lies on the boundary. .. py:method:: _compute_edge_neighbors() Get the neighbors of each edge. .. py:class:: GridDataDouble(vertices, elements, edges, element_edges, volumes, normals, jacobians, jac_inv_trans, diameters, integration_elements, centroids, domain_indices, vertex_on_boundary, element_neighbor_indices, element_neighbor_indexptr) Bases: :py:obj:`object` A Numba container class for the grid data. .. py:method:: local2global(elem_index, local_coords) Map local to global coordinates. .. py:class:: GridDataFloat(vertices, elements, edges, element_edges, volumes, normals, jacobians, jac_inv_trans, diameters, integration_elements, centroids, domain_indices, vertex_on_boundary, element_neighbor_indices, element_neighbor_indexptr) Bases: :py:obj:`object` A Numba container class for the grid data. .. py:method:: local2global(elem_index, local_coords) Map local to global coordinates. .. py:class:: ElementGeometry(grid, index) Bases: :py:obj:`object` Provides geometry information for an element. .. py:property:: corners Return corners. .. py:property:: jacobian Return jacobian. .. py:property:: integration_element Return integration element. .. py:property:: jacobian_inverse_transposed Return Jacobian inverse transposed. .. py:property:: normal Return normal. .. py:property:: volume Return volume. .. py:property:: diameter Return the diameter of the circumcircle. .. py:property:: centroid Return the centroid of the element. .. py:method:: local2global(points) Map points in local coordinates to global. .. py:class:: Element(grid, index) Bases: :py:obj:`object` Provides a view onto an element of the grid. .. py:property:: index Index of the element. .. py:property:: grid Associated grid. .. py:property:: geometry Return geometry. .. py:property:: domain_index Return the domain index. .. py:method:: sub_entity_iterator(codim) Return iterator over subentitites. .. py:method:: __eq__(other) Check if elements are equal. .. py:data:: VertexGeometry .. py:class:: Vertex(grid, index) Bases: :py:obj:`object` Provides a view onto a vertex of the grid. .. py:property:: index Index of the vertex. .. py:property:: geometry Return geometry. .. py:class:: EdgeGeometry(corners) Bases: :py:obj:`object` Implementation of a geometry for edges. .. py:property:: corners Return the corners. .. py:property:: volume Return length of the edge. .. py:class:: Edge(grid, index) Bases: :py:obj:`object` Provides a view onto an edge of the grid. .. py:property:: index Return the index of the edge. .. py:property:: geometry Return geometry. .. py:function:: get_element_to_vertex_matrix(vertices, elements) Return the sparse matrix mapping vertices to elements. .. py:function:: get_element_to_element_matrix(vertices, elements) Return element to element matrix. If entry (i,j) has the value n > 0, element i and element j are connected via n vertices. .. py:function:: _compare_array_to_value(array, val) Return i such that array[i] == val. If val not found return -1 .. py:function:: _find_first_common_array_index_pair_from_position(array1, array2, start=0) Return first index pair (i, j) such that array1[i] = array2[j]. Assumes that one index pair satisfying the equality always exists. Method checks in array1 from position start onwards. .. py:function:: _find_two_common_array_index_pairs(array1, array2) Return two index pairs (i, j) such that array1[i] = array2[j]. .. py:function:: _get_shared_vertex_information_for_two_elements(elements, elem0, elem1) Return tuple (i, j). The tuple has the property elements[i, elem0] == elements[j, elem1] .. py:function:: _get_shared_edge_information_for_two_elements(elements, elem0, elem1) Return 2x2 array of int32 indices. Each column in the return indices as a pair (i, j) such that elements[i, elem0] = elements[j, elem1] .. py:function:: _find_vertex_adjacency(elements, test_indices, trial_indices) Return for element pairs the vertex adjacency. The return array vertex_adjacency has 4 rows, such that for index j the element vertex_adjacency[0, j] is connected with vertex_adjacency[1, j] via the vertex vertex_adjacency[2, j] in the first element and the vertex vertex_adjacency[3, j] in the second element. The vertex numbers here are local numbers (0, 1 or 2). .. py:function:: _find_edge_adjacency(elements, elem0_indices, elem1_indices) Return for element pairs the edge adjacency. The return array edge_adjacency has 6 rows, such that for index j the element edge_adjacency[0, j] is connected with edge_adjacency[1, j] via the two vertices edge_adjacency[2:4, j] in the first element and the vertices edge_adjacency[4:6, j] in the second element. The vertex numbers here are local numbers (0, 1 or 2). .. py:function:: _get_element_to_element_vertex_count(element_to_element_matrix) Return a tuple of arrays (elements1, elements2, nvertices). The element elements1[i] is connected with elements2[i] via nvertices[i] vertices. .. py:function:: _element_filter(elements1, elements2, nvertices, filter_type) Return element pairs according to a filter condition. Takes an array (elements1, elements2, nvertices) such that elements1[i] and elements2[i] are connected via nvertices[i] vertices and returns a tuple (new_elem1, new_elem2) of all element pairs connected via vertices (filter_type=VERTICES) or edges (filter_type=EDGES). .. py:function:: _sort_values(val1, val2) Return a tuple with the input values sorted. .. py:function:: _vertices_from_edge_index(element, local_index) Return the vertices associated with an edge. Element is 3-tupel with the vertex indices. Sorts the returned vertices in ascending order. .. py:function:: grid_from_segments(grid, segments) Return new grid from segments of existing grid. .. py:function:: _create_barycentric_connectivity_array(vertices, elements, element_edges, edges, number_of_edges) Return the vertices and elements of refined barycentric grid. .. py:function:: barycentric_refinement(grid) Return the barycentric refinement of a given grid. .. py:function:: union(grids, domain_indices=None, swapped_normals=None) Return the union of a given list of grids. Parameters ---------- grids: list A list of grid objects. domain_indices : list Attach a list of domain indices to the new grid such that grid[j] received the domain index domain_indices[j] swapped_normals : list of boolean A list of the form [False, True, ...], that specifies for each grid if the normals should be swapped (True) or not (False). This is helpful if one grid is defined to be inside another grid. This method returns a new grid object, which is the union of the input grid objects. .. py:function:: enumerate_vertex_adjacent_elements(grid, support_elements, swapped_normals=None) Enumerate in anti-clockwise order all elements adjacent to all vertices in support. Returns a list [neighbors_0, neighbors_1, ...], where neighbors_i is a list [(elem_index, local_ind1, local_ind2), ...] of tuples, where elem_index is an element in the support that as connected with vertex i. local_ind1 and local_ind2 are the local indices of the two edges that are adjacent to vertex i. They are sorted in anti-clockwise order with respect to the natural normal directions of the elements. Moreover, all tuples represent elements in anti-clockwise order. .. py:function:: _numba_enumerate_edges(elements, edge_tuple_to_index) Enumerate all edges in a given grid. Assigns a tuple (edges, element_edges) to self._edges and self._element_edges. element_edges is an array a such that a[i, j] is the index of the ith edge in the jth elements, and edges is a 2 x nedges array such that the jth column stores the two nodes associated with the jth edge. .. py:function:: _grid_scatter_worker(grid_id, array_proxies) Assign a new grid on the worker. .. py:function:: grid_to_points(grid_data, local_points) Map a grid to an array of points. Returns a (N, 3) point array that stores the global vertices associated with the local points in each triangle. Points are stored in consecutive order for each element in the support_elements list. Hence, the returned array is of the form [ v_1^1, v_2^1, ..., v_M^1, v_1^2, v_2^2, ...], where v_i^j is the ith point in the jth element in the support_elements list. Parameters ---------- grid_data : GridData A Bempp GridData object. local_points : np.ndarray (2, M) array of local coordinates.