//  created with md2edp examples/examples/membrane.md
func z = x;
// Mesh
real theta = 4.*pi/3.;
real a = 2., b = 1.; // Half the length of the major and minor axis
border Gamma1(t=0, theta)    {x=a*cos(t); y=b*sin(t);}
border Gamma2(t=theta, 2*pi) {x=a*cos(t); y=b*sin(t);}
mesh Th = buildmesh(Gamma1(100) + Gamma2(50));
// Fespace
fespace Vh(Th,P2); // P2 conforming triangular finite element space
Vh phi, w, f = 1;
solve Laplace(phi, w)
       =int2d(Th)(  dx(phi)*dx(w) + dy(phi)*dy(w))
       - int2d(Th)(f*w) + on(Gamma1, phi=z);

// Plot
plot(Th,phi, wait=true, fill=true,dim=3,ps="membrane.ps");
{
  ofstream ff("graph.txt");
  for (int i = 0; i < Th.nt; i++) {
    for (int j = 0; j < 3; j++)
      ff << Th[i][j].x  << "    " << Th[i][j].y << "  " << phi[][Vh(i,j)] << endl;
  ff << Th[i][0].x << "    " << Th[i][0].y << "  " << phi[][Vh(i,0)] << endl << endl << endl;
  }
}
// Save the mesh. Could be reused in another script with readmesh
savemesh(Th, "Th.msh");
