# Derivative of solution at solution points

**URL:** <https://pyfr.discourse.group/t/derivative-of-solution-at-solution-points/963>\
**Category:** Development\
**Created:** [31 October 2023 08:43 UTC](https://pyfr.discourse.group/t/derivative-of-solution-at-solution-points/963 "2023-10-31T08:43:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fei](https://avatars.discourse-cdn.com/v4/letter/f/59ef9b/32.png) [@fei](https://pyfr.discourse.group/u/fei)\
**Post date:** [31 October 2023 08:43 UTC](https://pyfr.discourse.group/t/derivative-of-solution-at-solution-points/963/1 "2023-10-31T08:43:32Z")

</div>

Hello, everyone,

I want to obtain the derivative of all the solution points. And I am confused about something.

In the navstokes/elements.py, velocity gradients, pressure gradient and density gradient are presented, but I did’t see where to use it. and Where does grad\_cons pass from?

```auto
  @staticmethod
    def grad_con_to_pri(cons, grad_cons, cfg):
        rho, *rhouvw = cons[:-1]
        grad_rho, *grad_rhouvw, grad_E = grad_cons
        # Divide momentum components by ρ
        uvw = [rhov / rho for rhov in rhouvw]
        # Velocity gradients:
        grad_uvw = [(grad_rhov - v*grad_rho) / rho for grad_rhov, v in zip(grad_rhouvw, uvw)]        
    # Pressure gradient: 
        gamma = cfg.getfloat('constants', 'gamma')
        grad_p = grad_E - 0.5*(np.einsum('ijk,iljk->ljk', uvw, grad_rhouvw) + np.einsum('ijk,iljk->ljk', rhouvw, grad_uvw))                       
        grad_p *= (gamma - 1)
        return [grad_rho] + grad_uvw + [grad_p]

```

Second, in the navstokes/inters.py, gradul=self.\_vect\_lhs, \_vect\_lhs is views matrix, I know that the views used by the interface flux calculation are views onto data at flux points. And I didn’t see any derivative operations in \_vect\_view matrix. Could someone have some idea about these quesions?

---

<div class="post-metadata">

**Author:** ![WillT](https://avatars.discourse-cdn.com/v4/letter/w/bc79bd/32.png) [@WillT](https://pyfr.discourse.group/u/WillT)\
**Post date:** [31 October 2023 09:06 UTC](https://pyfr.discourse.group/t/derivative-of-solution-at-solution-points/963/2 "2023-10-31T09:06:36Z")

</div>

The function `grad_con_to_pri` is only really used in the plugins where it is preferable to use the gradient of the primitives rather than the gradients of the conserved variables. Depending on where you want to access the gradients, the easiest way is probably to use the `grad_soln` in the integration class.

The `_vect_lhs` and `_vect_rhs` define the interfaces for the flux point vector memory and is defined by calling `get_vect_fpts_for_inter` in the `solver.base.elements` base class. That memory doesn’t have to be used exclusively for the gradient, and the view itself is just a tuple that includes pointer and no operations. The kernels acting on the memory are all defined in the various elements.py and the operation graph is built in the relevant system.py.
