How to find the relation between local index and global index?


294
views
0
11 months ago by
I want to evaluate all the basic functions at a given point. I used the code in this post https://fenicsproject.org/qa/8627/how-to-evaluate-basis-function-at-points-of-cell . But the result is at local index, what should I do to find the corresponding global index of the basic function?
Community: FEniCS Project

1 Answer


3
10 months ago by
Hi,

consider the following two MWE's.

You can get the global dof indices (albeit local to the process!) of a cell as follows:
from dolfin import *
import numpy as np

mesh = UnitSquareMesh(2,2)

V = VectorFunctionSpace(mesh,"CG",1)

# Print cell dof indices
for cell in cells(mesh):
    dofs = V.dofmap().cell_dofs(cell.index())
    print('Cell '+str(cell.index())+' has global dofs '+np.array_str(dofs))​

If you want to evaluate all the basis functions at a given point, I recommend using evaluate_basis_all (modified from the post you mentioned):
from dolfin import *
import numpy as np

mesh = UnitSquareMesh(2,2)
V    = VectorFunctionSpace(mesh, "CG", 1)

# Get function space info
el = V.element()
space_dimension = el.space_dimension()
num_subspaces   = el.num_sub_elements()

# Initialize basis matrix, given func. space info
if num_subspaces == 0:
    basis_matrix = np.zeros(space_dimension, dtype=float)
else:
    basis_matrix = np.zeros((space_dimension,num_subspaces),\
                dtype=float)

# Define point for later evaluation
x = np.array([0.33, 0.55])
x_point = Point(*x)

# Return hosting cell (by index)
cell_id = mesh.bounding_box_tree().compute_first_entity_collision(x_point)

# Instantiate Cell (by index)
cell = Cell(mesh, cell_id)   
coordinate_dofs = cell.get_vertex_coordinates()

el.evaluate_basis_all(basis_matrix,x,coordinate_dofs, cell.orientation())
print(basis_matrix)​

Hope this helps
Please login to add an answer/comment or follow this question.

Similar posts:
Search »