# Second derivative of shape functions in JuAFEM

**URL:** <https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160>\
**Category:** Modelling & Simulations\
**Tags:** question, package\
**Created:** [January 11, 2021, 2:15pm UTC](https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160 "2021-01-11T14:15:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![FrootLoops](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FrootLoops](https://discourse.julialang.org/u/FrootLoops)\
**Post date:** [January 11, 2021, 2:15pm UTC](https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160/1 "2021-01-11T14:15:05Z")

</div>

Hi,  
is there already a implemented function, which computes the second derivatives of the shape function at a given point?

I am working with PDEs of higher-order and therefore need high order derivates of the used ansatz functions. I tried to combine the `shape_divergence` with `shape_gradient` function, but failed so far.

---

<div class="post-metadata">

**Author:** ![koehlerson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/koehlerson/32/13108_2.png) [@koehlerson](https://discourse.julialang.org/u/koehlerson)\
**Post date:** [January 11, 2021, 3:37pm UTC](https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160/2 "2021-01-11T15:37:49Z")

</div>

A closer look at `shape_gradient` and `shape_divergence` reveals, that it just calls `cv.dNdx[basefunc, q_point]` and `shape_divergence` is `sum(cv.dNdx[basefunc, q_point])`. These values are a [combination of `cv.dNdξ` and the inverse of the jacobian](https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell_values.jl#L161). The first is a precomputed value (only depends on the gauss point location) and the latter is computed in `reinit!` for each cell.

So ideally, you’d like to subtype `CellValues` and extend it with `dNdx²` and `dNdξ²` which saves the second order derivative information at a given gauss point.  
you’d need to specify a constructor, something like: [https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell\_values.jl#L99-L141](https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell_values.jl#L99-L141)  
[https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell\_values.jl#L120](https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell_values.jl#L120) this line would need to be changed to something like  
`dNdξ²_temp, dNdξ_temp, N_temp = hessian(ξ -> value(func_interpol, basefunc, ξ), ξ, :all)`

and further implement a `reinit!` that updates the `cv.dNdx²` in the same fashion `cv.dNdx` is updated here: [https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell\_values.jl#L143-L164](https://github.com/KristofferC/JuAFEM.jl/blob/master/src/FEValues/cell_values.jl#L143-L164)

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [January 11, 2021, 4:33pm UTC](https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160/3 "2021-01-11T16:33:29Z")

</div>

The basis functions may be only continuous. Then if we differentiate, the derivatives have inter-element jumps, which CANNOT be differentiated through again.

---

<div class="post-metadata">

**Author:** ![FrootLoops](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@FrootLoops](https://discourse.julialang.org/u/FrootLoops)\
**Post date:** [January 12, 2021, 8:56am UTC](https://discourse.julialang.org/t/second-derivative-of-shape-functions-in-juafem/53160/5 "2021-01-12T08:56:23Z")

</div>

Thank you.  
I actually had the same idea but I thought maybe someone already implemented something similiar.

To avoid the differentiation problem I would work with Splines, so normally with high order Basis.
