function visualize(p)

% visualize(p)
%   calculates the 2d magnetostatic state problem for the design p
%   which involves the following partial differential equation:
%   -div((1/mu(x))*grad(u(x))) = J(x) in Omega
%                         u(x) = 0    on Gamma_D
%              grad(u(x))*n(x) = 0    on Gamma_N

xl = -0.2;
xt = 0.1;
xpl = -0.02;
xpt = 0.02;
xyl = -0.16;
xyr = -0.04;
xyt = 0.04;
xcl = -0.12;
xcr = -0.08;
xct = 0.08;

h = 0.01;

[x,e,ep,ey,ec,ID,IN,Ishape,Ip,Iy,Ic,IDD,IDD1,IDD2] = discret(xl,xt,xpl,xpt,xyl,xyr,xyt,xcl,xcr,xct,h);

shapeDisplacement = designMap(Ishape,p);
gridDisplacement = shapeMap(x,e,IDD,IDD1,IDD2,Ishape,shapeDisplacement);
plotgrid(x+gridDisplacement,e);

[A,b] = assemble(ey,ec,x+gridDisplacement,e,ID,IN);
u = A\b;

B = curl(x+gridDisplacement,e,u);

[X,Y,U] = postprocU(x+gridDisplacement,u,-xl/h+1,xt/h+1);
drawU(xl,xt,xpl,xpt,xyl,xyr,xyt,xcl,xcr,xct,Ishape,p,h,X,Y,U);

[XB,YB,Bx,By] = postprocB(x+gridDisplacement,e,B,-xl/h+1,xt/h+1);
drawB(xl,xt,xpl,xpt,xyl,xyr,xyt,xcl,xcr,xct,Ishape,p,h,XB,YB,Bx,By);
