# Please help me out! If possible, Could you tell me how to export gradient data?

**URL:** <https://community.freefem.org/t/please-help-me-out-if-possible-could-you-tell-me-how-to-export-gradient-data/1199>\
**Category:** General Discussion\
**Created:** [September 13, 2021, 2:54am UTC](https://community.freefem.org/t/please-help-me-out-if-possible-could-you-tell-me-how-to-export-gradient-data/1199 "2021-09-13T02:54:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sosome](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@sosome](https://community.freefem.org/u/sosome)\
**Post date:** [September 13, 2021, 2:54am UTC](https://community.freefem.org/t/please-help-me-out-if-possible-could-you-tell-me-how-to-export-gradient-data/1199/1 "2021-09-13T02:54:09Z")

</div>

Dear all,

I am trying to export gradient data from the required 2D poison’ equation, but I am not sure how to export the solution and gradient from the 2d poisson equation in document code.

I believe exporting dx(), dy() is the way to solve the problem, but I am not sure.

If possible, could you tell me the code?

[https://modules.freefem.org/modules/poisson/](https://modules.freefem.org/modules/poisson/)

```auto
// Parameters
func f = 1.;

// Mesh
int nn = 25;	//Mesh quality
mesh Th = square(nn, nn);

// Fespace
func Pk = P2;
fespace Uh(Th, Pk);
Uh u;

// Macro
macro grad(A) [dx(A), dy(A)] //

// Problem
varf vPoisson (u, uh)
	= int2d(Th)(
		  grad(u)' * grad(uh)
	)
	+ int2d(Th)(
		  f * uh
	)
	+ on(1, 2, 3, 4, u=0)
	;
matrix<real> Poisson = vPoisson(Uh, Uh, solver=sparsesolver);
real[int] PoissonBoundary = vPoisson(0, Uh);
u[] = Poisson^-1 * PoissonBoundary;

// Plot
plot(u, nbiso=30, fill=true, value=true, cmm="A");

```

---

<div class="post-metadata">

**Author:** ![Jamal](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/jamal/32/1527_2.png) [@Jamal](https://community.freefem.org/u/Jamal)\
**Post date:** [September 26, 2021, 7:29pm UTC](https://community.freefem.org/t/please-help-me-out-if-possible-could-you-tell-me-how-to-export-gradient-data/1199/2 "2021-09-26T19:29:40Z")

</div>

Vh dX=dx(u),dY=dy(u);  
Ofstream file(“gradient.txt”)  
for(int I=0;i\<Vh.ndof;i++)  
{  
file\<\<dX[][i]\<\<"\t"\<\<dY[][i]\<\<endl;  
}

---

<div class="post-metadata">

**Author:** ![sosome](https://avatars.discourse-cdn.com/v4/letter/s/2bfe46/32.png) [@sosome](https://community.freefem.org/u/sosome)\
**Post date:** [September 27, 2021, 10:43am UTC](https://community.freefem.org/t/please-help-me-out-if-possible-could-you-tell-me-how-to-export-gradient-data/1199/3 "2021-09-27T10:43:47Z")

</div>

I see. Thank you for your help.
