# How to use evaluate\_basis\_derivatives\_all function?

**URL:** https://fenicsproject.discourse.group/t/how-to-use-evaluate-basis-derivatives-all-function/1350
**Category:** Uncategorized
**Created:** [August 18, 2019, 4:26pm UTC](https://fenicsproject.discourse.group/t/how-to-use-evaluate-basis-derivatives-all-function/1350 "2019-08-18T16:26:37Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Kiri](https://avatars.discourse-cdn.com/v4/letter/k/a183cd/32.png) [@Kiri](https://fenicsproject.discourse.group/u/Kiri)
#### Post date: [August 18, 2019, 4:26pm UTC](https://fenicsproject.discourse.group/t/how-to-use-evaluate-basis-derivatives-all-function/1350/1 "2019-08-18T16:26:37Z")

</div>

Hello,

I am trying to compute the derivatives of the shape functions at every node in a mesh for a ‘CG1’ vector function space. Looking at previous questions ([derivative at a point](https://fenicsproject.org/qa/8394/how-to-evaluate-higher-derivative-of-a-function-at-a-point/), [Basis function evaluations](https://fenicsproject.org/qa/13655/derivative-of-a-function-wrt-expansion-coefficients/)) and the source code, I think the function ‘evaluate\_basis\_derivatives\_all’, is what I need.

For a vector function space with CG1 tetrahedral elements I think there should be 12 dofs per element (4x3) with 4 basis functions and 12 derivative terms (dN/dx, dN/dy/,dN/dz per basis function). However, the function evaluate\_basis\_all returns an array of length 36 and the derivative function returns an array of length 108.

```
from fenics import *
import numpy as np
parameters["form_compiler"]["no-evaluate_basis_derivatives"] = False
mesh = BoxMesh(Point(0, 0, 0), Point(1, 1, 1),10,10,10)
V = VectorFunctionSpace(mesh, 'CG', 1)
points = V.tabulate_dof_coordinates().reshape((V.dim(), -1))
element = V.element()

dmap = V.dofmap()
tree = mesh.bounding_box_tree()
Num_elem = mesh.num_cells()
Derivative_matrix = np.zeros((Num_elem,12))
for row, pt in enumerate(points):
    cell_id = tree.compute_first_entity_collision(Point(*pt))
    cell = Cell(mesh, cell_id)
    vertex_coordinates = cell.get_vertex_coordinates()
    cell_orientation = cell.orientation()

    Basis_func_values = element.evaluate_basis_all(pt, vertex_coordinates, cell_orientation)
    
    # reshaped derivatives - [dN/dx, dNdy, dNdz]
    Basis_func_derivatives = element.evaluate_basis_derivatives_all(1,pt, vertex_coordinates, cell_orientation).reshape(-1,3)    
    
    #Extract 12 derivatives from Basis_func_derivatives (dN1/dx,dN1/dy,dN1/dz,...,dN4/dz)
    #Map N1,....N4 to verticies of cell
    
    #Derivative_matrix[cell_id] = [mapped derivative data]

```

How can I extract the 12 terms (dN1/dx, dN1/dy,dN1/dz… dN4/dz) and how do I map these shape function to the correct vertex for the given cell?

Thanks a lot in advance!
