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

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?

// 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");

Vh dX=dx(u),dY=dy(u);
Ofstream file(“gradient.txt”)
for(int I=0;i<Vh.ndof;i++)

1 Like

I see. Thank you for your help.