# Explicit calculation of gradient of a scalar field

**URL:** <https://community.freefem.org/t/explicit-calculation-of-gradient-of-a-scalar-field/212>\
**Category:** General Discussion\
**Created:** [January 8, 2020, 1:55pm UTC](https://community.freefem.org/t/explicit-calculation-of-gradient-of-a-scalar-field/212 "2020-01-08T13:55:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![distractor](https://avatars.discourse-cdn.com/v4/letter/d/57b2e6/32.png) [@distractor](https://community.freefem.org/u/distractor)\
**Post date:** [January 8, 2020, 1:55pm UTC](https://community.freefem.org/t/explicit-calculation-of-gradient-of-a-scalar-field/212/1 "2020-01-08T13:55:45Z")

</div>

So my whole problem consists of two stages:  
First a heat equation is solved:

```auto
problem Heat(T2,v) = int3d(Th)(T2 * v) + int3d(Th)(dt * nu * Grad(T2)' * Grad(v)) - int3d(Th)(T1 * v)
                    +int3d(Th, 1, 2, 3, 4, 6)(epsilon * stefConst * (pow(T1, 4.) - pow(Tamb + 273., 4.)) * v)
                    +on(5, T2 = Ttable + 273.)
                    ;

```

After the calculated temperature T2 should be passed to the following problem

```auto
problem Navier([u1, u2, u3], [v1, v2, v3]) = int3d(Th)(lambda * Div(u1, u2, u3) * Div(v1, v2, v3))
                                        +int3d(Th)(2. * mu * (Epsilon(u1, u2, u3)' * Epsilon(v1, v2, v3)))
                                        -int3d(Th)(beta * [v1, v2, v3]' * [0., 0., 0.])
                                        +on(5, u1 = 0, u2 = 0, u3 =0)
                                        ;

```

The array [0., 0., 0.] should be replaced by gradient of T2. Yet I am not completely sure how to explicitly calculate the gradient of a given scalar field. Here

```auto
macro Grad(u) [dx(u), dy(u), dz(u)] //EOM
macro Div(u1,u2,u3) (dx(u1) + dy(u2) + dz(u3)) // EOM
macro Epsilon(u1,u2,u3) [dx(u1), dy(u2), dz(u3), (dz(u2) + dy(u3)) / sqrt2, (dz(u1) + dx(u3)) / sqrt2, (dy(u1) + dx(u2)) / sqrt2] // EOM

```

Could anyone help?
