# Derivative and integration of physical variable over Boundary

**URL:** https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976
**Category:** General Discussion
**Created:** [May 14, 2021, 12:32pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976 "2021-05-14T12:32:56Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sumantkr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumantkr/32/2681_2.png) [@sumantkr](https://community.freefem.org/u/sumantkr)
#### Post date: [May 14, 2021, 12:32pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976/1 "2021-05-14T12:32:56Z")

</div>

Dear all,  
I am trying to compute the heat flux and cumulative heat flux over a boundary section of the square.

I have tried with writing the code as : `flux = int1d(Th, 4)(-dx(T)*N.x)`

but each time I am getting the same real number for different grid sizes.

Also, please comment on getting the list of values of `(-dx(T)*N.x)` over a specific boundary.

I am worried a lot about getting these values.

Thanks

---

<div class="post-metadata">

### Author: ![Daoudi](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daoudi](https://community.freefem.org/u/Daoudi)
#### Post date: [May 14, 2021, 2:15pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976/2 "2021-05-14T14:15:08Z")

</div>

Try these  
Vh T,v;  
varf Flux (T,v)= int1d(Th, 4)((-dx(T)\*N.x)\*v);  
Real [int] FLUX=Flux(0,Vh);  
cout\<\<" FLUX "\<\<FLUX\<\<endl;

---

<div class="post-metadata">

### Author: ![sumantkr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumantkr/32/2681_2.png) [@sumantkr](https://community.freefem.org/u/sumantkr)
#### Post date: [May 14, 2021, 2:49pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976/3 "2021-05-14T14:49:48Z")

</div>

> [@Daoudi](#):
>
> Vh T,v;  
> varf Flux (T,v)= int1d(Th, 4)((-dx(T)\*N.x)\*v);  
> Real [int] FLUX=Flux(0,Vh);  
> cout\<\<" FLUX "\<\<FLUX\<\<endl;

Thanks @Daoudi for your help.

with little modification, it is compatible with my code script.  
Vh v;  
varf Flux (unused,v)= int1d(Th, 4)((-dx(T)\*N.x)\*v);  
real [int] FLUX=Flux(0,Vh);  
cout\<\<" FLUX "\<\<FLUX\<\<endl;

I am surprised after getting the result in (n x 4) matrix form.

Further, I was trying to export the data for `heat_flux = (-dx(T)*N.x)`  
on the boundary ( x=0, 0\<= y \<= 1) that has named as 4 in the script .

For this purpose, I have followed a similar pattern of coding which is showing errors while compilation.

`Vh v1; varf flux (unused,v1)= ((-dx(T)*N.x)*v1); real [int] flux11 = flux(0,Vh); cout<<" flux"<<flux11<<endl; `

Also, for exporting the data I have gone through the script below which I have again no luck this time.

```
ofstream ff5("testcase1.csv");
for(real p1 = 0.0; p1<1.01; p1 = p1 + 0.01)
{
ff5<< 0.0<<","<< p1 << ","<< FLUX(0.0, p1)<<endl;
}

```

---

<div class="post-metadata">

### Author: ![Daoudi](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daoudi](https://community.freefem.org/u/Daoudi)
#### Post date: [May 14, 2021, 3:12pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976/4 "2021-05-14T15:12:23Z")

</div>

mesh Th=square(np,np);  
fespace Vh(Th,P2);  
Vh Flux  
N.x= -1.; //Because your domain is a square  
Flux=-dx(T);  
real [int] Flux11=Flux[];  
ofstream ff5(“testcase1.txt”)  
{  
for (int I=0;I\<np+1;I++)  
ff5\<\<Flux11(I\*(np+1))\<\<endl;  
}

---

<div class="post-metadata">

### Author: ![sumantkr](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumantkr/32/2681_2.png) [@sumantkr](https://community.freefem.org/u/sumantkr)
#### Post date: [May 14, 2021, 4:14pm UTC](https://community.freefem.org/t/derivative-and-integration-of-physical-variable-over-boundary/976/5 "2021-05-14T16:14:07Z")

</div>

It works and serves my purposes.

Thanks @Daoudi .

I am an absolute learner in FreeFEM field.

So, will you mind if I ask you for supporting material that deals with such an operation in FreeFEM?

Should, I thoroughly learn the C++ coding or only basic study may help me to pick these ideas and scripts of FreeFEM.
