bempp.api.grid.grid

The basic grid class.

Module Contents

Classes

Grid

The Grid class.

GridDataDouble

A Numba container class for the grid data.

GridDataFloat

A Numba container class for the grid data.

ElementGeometry

Provides geometry information for an element.

Element

Provides a view onto an element of the grid.

Vertex

Provides a view onto a vertex of the grid.

EdgeGeometry

Implementation of a geometry for edges.

Edge

Provides a view onto an edge of the grid.

Functions

get_element_to_vertex_matrix(vertices, elements)

Return the sparse matrix mapping vertices to elements.

get_element_to_element_matrix(vertices, elements)

Return element to element matrix.

_compare_array_to_value(array, val)

Return i such that array[i] == val.

_find_first_common_array_index_pair_from_position(...)

Return first index pair (i, j) such that array1[i] = array2[j].

_find_two_common_array_index_pairs(array1, array2)

Return two index pairs (i, j) such that array1[i] = array2[j].

_get_shared_vertex_information_for_two_elements(...)

Return tuple (i, j).

_get_shared_edge_information_for_two_elements(...)

Return 2x2 array of int32 indices.

_find_vertex_adjacency(elements, test_indices, ...)

Return for element pairs the vertex adjacency.

_find_edge_adjacency(elements, elem0_indices, ...)

Return for element pairs the edge adjacency.

_get_element_to_element_vertex_count(...)

Return a tuple of arrays (elements1, elements2, nvertices).

_element_filter(elements1, elements2, nvertices, ...)

Return element pairs according to a filter condition.

_sort_values(val1, val2)

Return a tuple with the input values sorted.

_vertices_from_edge_index(element, local_index)

Return the vertices associated with an edge.

grid_from_segments(grid, segments)

Return new grid from segments of existing grid.

_create_barycentric_connectivity_array(vertices, ...)

Return the vertices and elements of refined barycentric grid.

barycentric_refinement(grid)

Return the barycentric refinement of a given grid.

union(grids[, domain_indices, swapped_normals])

Return the union of a given list of grids.

enumerate_vertex_adjacent_elements(grid, support_elements)

Enumerate in anti-clockwise order all elements adjacent to all vertices in support.

_numba_enumerate_edges(elements, edge_tuple_to_index)

Enumerate all edges in a given grid.

_grid_scatter_worker(grid_id, array_proxies)

Assign a new grid on the worker.

grid_to_points(grid_data, local_points)

Map a grid to an array of points.

Attributes

EDGES_ID

VERTICES_ID

_EDGE_LOCAL

VertexGeometry

bempp.api.grid.grid.EDGES_ID = 2
bempp.api.grid.grid.VERTICES_ID = 1
bempp.api.grid.grid._EDGE_LOCAL
class bempp.api.grid.grid.Grid(vertices, elements, domain_indices=None, grid_id=None, scatter=True)

Bases: object

The Grid class.

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.

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.

property element_to_vertex_matrix

Return the matrix mapping vertices to elements.

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.

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.

property number_of_vertices

Return number of vertices.

property number_of_edges

Return number of edges.

property number_of_elements

Return number of elements.

property vertices

Return vertices.

property elements

Return elements.

property edges

Return edges.

property centroids

Return the centroids of the elements.

property domain_indices

Return domain indices.

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.

property device_interfaces

Return the dictionary of device interfaces for the grid.

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)].

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).

property volumes

Return element volumes.

property diameters

Return element diameters.

property maximum_element_diameter

Return the maximum element diameter.

property minimum_element_diameter

Return the maximum element diameter.

property normals

Return normals.

property jacobians

Return Jacobians.

property integration_elements

Return integration elements.

property jacobian_inverse_transposed

Return the jacobian inverse transposed.

property vertex_on_boundary

Return vertex boundary information.

property edge_on_boundary

Return edge boundary information.

property edge_neighbors

Return for each edge the list of neighboring elements..

property vertex_neighbors

Return for each vertex the list of neighboring elements.

property barycentric_refinement

Return the barycentric refinement of this grid.

property id

Return a unique id for the grid.

data(precision='double')

Return Numba container with all relevant grid data.

_scatter()

Initialise the grid on all workers.

entity_count(codim)

Return the number of entities of given codimension.

plot()

Plot the grid.

get_element(index)

Return element with a given index.

entity_iterator(codim)

Return an iterator for a given codim.

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

orderInteger

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.

refine()

Return a new grid with all elements refined.

_compute_vertex_neighbors()

Return all elements adjacent to a given vertex.

_normalize_and_assign_input(vertices, elements, domain_indices)

Convert input into the right form.

_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.

_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).

_compute_geometric_quantities()

Compute geometric quantities for the grid.

_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.

_compute_edge_neighbors()

Get the neighbors of each edge.

class bempp.api.grid.grid.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: object

A Numba container class for the grid data.

local2global(elem_index, local_coords)

Map local to global coordinates.

class bempp.api.grid.grid.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: object

A Numba container class for the grid data.

local2global(elem_index, local_coords)

Map local to global coordinates.

class bempp.api.grid.grid.ElementGeometry(grid, index)

Bases: object

Provides geometry information for an element.

property corners

Return corners.

property jacobian

Return jacobian.

property integration_element

Return integration element.

property jacobian_inverse_transposed

Return Jacobian inverse transposed.

property normal

Return normal.

property volume

Return volume.

property diameter

Return the diameter of the circumcircle.

property centroid

Return the centroid of the element.

local2global(points)

Map points in local coordinates to global.

class bempp.api.grid.grid.Element(grid, index)

Bases: object

Provides a view onto an element of the grid.

property index

Index of the element.

property grid

Associated grid.

property geometry

Return geometry.

property domain_index

Return the domain index.

sub_entity_iterator(codim)

Return iterator over subentitites.

__eq__(other)

Check if elements are equal.

bempp.api.grid.grid.VertexGeometry
class bempp.api.grid.grid.Vertex(grid, index)

Bases: object

Provides a view onto a vertex of the grid.

property index

Index of the vertex.

property geometry

Return geometry.

class bempp.api.grid.grid.EdgeGeometry(corners)

Bases: object

Implementation of a geometry for edges.

property corners

Return the corners.

property volume

Return length of the edge.

class bempp.api.grid.grid.Edge(grid, index)

Bases: object

Provides a view onto an edge of the grid.

property index

Return the index of the edge.

property geometry

Return geometry.

bempp.api.grid.grid.get_element_to_vertex_matrix(vertices, elements)

Return the sparse matrix mapping vertices to elements.

bempp.api.grid.grid.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.

bempp.api.grid.grid._compare_array_to_value(array, val)

Return i such that array[i] == val.

If val not found return -1

bempp.api.grid.grid._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.

bempp.api.grid.grid._find_two_common_array_index_pairs(array1, array2)

Return two index pairs (i, j) such that array1[i] = array2[j].

bempp.api.grid.grid._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]

bempp.api.grid.grid._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]

bempp.api.grid.grid._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).

bempp.api.grid.grid._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).

bempp.api.grid.grid._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.

bempp.api.grid.grid._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).

bempp.api.grid.grid._sort_values(val1, val2)

Return a tuple with the input values sorted.

bempp.api.grid.grid._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.

bempp.api.grid.grid.grid_from_segments(grid, segments)

Return new grid from segments of existing grid.

bempp.api.grid.grid._create_barycentric_connectivity_array(vertices, elements, element_edges, edges, number_of_edges)

Return the vertices and elements of refined barycentric grid.

bempp.api.grid.grid.barycentric_refinement(grid)

Return the barycentric refinement of a given grid.

bempp.api.grid.grid.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_indiceslist

Attach a list of domain indices to the new grid such that grid[j] received the domain index domain_indices[j]

swapped_normalslist 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.

bempp.api.grid.grid.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.

bempp.api.grid.grid._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.

bempp.api.grid.grid._grid_scatter_worker(grid_id, array_proxies)

Assign a new grid on the worker.

bempp.api.grid.grid.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_dataGridData

A Bempp GridData object.

local_pointsnp.ndarray

(2, M) array of local coordinates.