# Tensors.jl and upper convective derivative - Oldroyd - b constitutive model

**URL:** <https://discourse.julialang.org/t/tensors-jl-and-upper-convective-derivative-oldroyd-b-constitutive-model/128341>\
**Category:** General Usage\
**Created:** [April 23, 2025, 6:17pm UTC](https://discourse.julialang.org/t/tensors-jl-and-upper-convective-derivative-oldroyd-b-constitutive-model/128341 "2025-04-23T18:17:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [April 23, 2025, 6:17pm UTC](https://discourse.julialang.org/t/tensors-jl-and-upper-convective-derivative-oldroyd-b-constitutive-model/128341/1 "2025-04-23T18:17:13Z")

</div>

Any experience here using Tensors.jl to implement the uppper-convective derivative? Thx.

---

<div class="post-metadata">

**Author:** ![KnutAM](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knutam/32/37720_2.png) [@KnutAM](https://discourse.julialang.org/u/KnutAM)\
**Post date:** [May 2, 2025, 2:27pm UTC](https://discourse.julialang.org/t/tensors-jl-and-upper-convective-derivative-oldroyd-b-constitutive-model/128341/2 "2025-05-02T14:27:16Z")

</div>

Typically, you will need more than `Tensors.jl` to do that, since you will need some description of the velocity field. Assuming that you have that, e.g. you have functions for the flow velocity, `v = foo(x::Vec, t::Real)`, and the tensor to be differentiated, `A = bar(x::Vec, t::Real)`, where `x` are the current coordinates and `t` the time, then you can calculate the upper-convected time derivative (based on [Upper-convected time derivative - Wikipedia](https://en.wikipedia.org/wiki/Upper-convected_time_derivative))

\stackrel{\nabla}{\boldsymbol{A}} = \dot{\boldsymbol{A}} - \mathrm{grad}(\boldsymbol{v}) \cdot \boldsymbol{A} - \boldsymbol{A} \cdot \mathrm{grad}(\boldsymbol{v})^\mathrm{T} = \left.\frac{\partial\boldsymbol{A}}{\partial t}\right\vert\_\boldsymbol{x} + \boldsymbol{A} \cdot \boldsymbol{v} - \mathrm{grad}(\boldsymbol{v}) \cdot \boldsymbol{A} - \boldsymbol{A} \cdot \mathrm{grad}(\boldsymbol{v})^\mathrm{T}

as

```julia
∂A∂t, A = gradient(tt -> bar(x, tt), t, :all)
∇v, v = gradient(xx -> foo(xx, t), x, :all)
Auc = ∂A∂t + A ⋅ v - ∇v ⋅ A - A ⋅ ∇v'

```

(Tensors use the standard [\mathrm{grad}(\boldsymbol{v})]\_{ij} = \partial v\_i / \partial x\_j notation).

(Edit: flipped `foo` and `bar`)

---

<div class="post-metadata">

**Author:** ![ziolai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ziolai/32/23422_2.png) [@ziolai](https://discourse.julialang.org/u/ziolai)\
**Post date:** [May 2, 2025, 2:37pm UTC](https://discourse.julialang.org/t/tensors-jl-and-upper-convective-derivative-oldroyd-b-constitutive-model/128341/3 "2025-05-02T14:37:58Z")

</div>

I see. Thank you so much.
