cbeam.FEval#
The FEval submodule enables faster evaluation of finite element fields at locations not coincident with the mesh nodes, and can also compute the gradients of fields. There are also some convenience functions for working with meshes. This submodule wraps Julia code.
functions#
- cbeam.FEval.create_tree(points, connections)#
from an array of mesh points and an index array of (quadratic) triangle connections, construct a bounding volume hierarchy (BVH) tree, which will be used to evaluate fields define on the mesh nodes.
- Parameters:
points – an array of the (x,y) positions of the mesh nodes, dimension N x 2 for N nodes.
connections – an array containing each triangle in the mesh; each triangle is represented as 6 indices, corresponding to 6 points
- Returns:
the BVH tree for the given mesh points and connections.
- Return type:
bvhtree
- cbeam.FEval.create_tree_from_mesh(mesh)#
create a BVH tree directly from a finite element mesh object.
- Parameters:
mesh – a meshio object representing a finite element mesh
- Returns:
the BVH tree for the given mesh points and connections.
- Return type:
bvhtree
- cbeam.FEval.evaluate(point, field, tree)#
evaluate a field sampled over a finite element mesh at a given point.
- Parameters:
point – an [x,y] point, or an Nx2 array of points
field – a real-valued field represented on a finite-element mesh
tree – a BVH tree that stores the triangles of field’s finite-element mesh.
- Returns:
the field evaluated at point(s)
- Return type:
(float or vector)
- cbeam.FEval.evaluate_grid(pointsx, pointsy, field, tree)#
evaluate a field defined over a finite element mesh on a cartesian grid.
- Parameters:
pointsx – a 1D array of x points
pointsy – a 1D array of y points
field – a real-valued field represented on a finite-element mesh
tree – a BVH tree that stores the triangles of field’s finite-element mesh
- Returns:
a 2D array corresponding to field, evaluated on the grid.
- Return type:
(array)
- cbeam.FEval.get_points(mesh)#
get the point array in a mesh.
- Parameters:
mesh – a meshio object, e.g. the output of Waveguide.make_mesh()
- Returns:
Mx2 or Mx3 array of point coordinates; first two columns are x and y coordinates; you can ignore the third columnn if it exists.
- Return type:
(array)
- cbeam.FEval.get_triangles(mesh)#
get the triangles in a mesh.
- Parameters:
mesh – a meshio object, e.g. the output of Waveguide.make_mesh()
- Returns:
Nx6 array of triangles, each row contains the 6 indices of one (quadratic) triangle element. The indices each identify a point in the mesh.
- Return type:
(array)
- cbeam.FEval.query(point, tree)#
find the index of the triangle in the mesh that contains the given point.
- Parameters:
point – an array [x,y] corresponding to the query point..
tree – the BVH tree for the mesh of interest.
- Returns:
the index of the triangle containing point in the mesh.
- Return type:
(int)
- cbeam.FEval.resample(field, mesh, newmesh)#
resample a finite element field onto a new mesh
- Parameters:
field – the finite element field to be resampled.
mesh – the finite element mesh on which <field> is defined.
newmesh – the new finite element mesh <field> should be sampled on.
- cbeam.FEval.sort_mesh(mesh)#
create a BVH tree for
meshand pass it into tomesh.tree
- cbeam.FEval.transverse_gradient(field, tris, points)#
compute the gradient of a real-valued finite element field with respect to x,y
- Parameters:
field – a real-valued field represented on a finite-element mesh
tris – an Nx6 array of triangles, each row contains the 6 indices of one (quadratic) triangle element
points – an Mx2 array of [x,y] points representing the mesh nodes.
- Returns:
dimensions are dim(field) x 2; the last axis contains the x and y derivatives.
- Return type:
(array)