Mesh based on breast image using P2 finite elements

Hello everyone.
I used the image-based mesh generation code (Lemanlake example in the Freefem documentation, p. 194) to generate a breast mesh using P1 finite elements. I want the same thing with P2 finite elements. However, FreeFem has stopped working if I replace P1 with P2. Please help me fix what’s wrong with P2.

Thank you very much for your help.

BreastMesh-P2.zip (87.9 KB)

string legende;
int m=10;
load “ppm2rnm”
load “isoline”
real L=3;
string sein = “breast05.pgm”;
real AreaLac = 500.03;
real hsize =0.2;
real[int, int] Curves(3, 2);
int[int] be(1);
int nc;
{
real[int, int] ff1(sein);
int nx = ff1.n, ny = ff1.m;
mesh Th = square(nx-1, ny-1, [(nx-1)(x)/(20L), (ny-1)(1-y)/(20L)]);
fespace Vh(Th, P2); ////////////////////////////////////////// (I changed P1 to P2)/////////////////////////////
Vh f1;
f1 = ff1;
nc = isoline(Th, f1, iso=0.25, close=1, Curves, beginend=be, smoothing=.1, ratio=0.25);
}
int ic0 = be(0), ic1 = be(1)-1;
int NC = Curves(2, ic1)/hsize;
border G(t=0, 1){P=Curve(Curves, ic0, ic1, t);}
mesh Th=buildmesh(G(NC));
plot(Th);

The mesh with P1 is below. What if I want the same mesh with P2 finite elements ?

Hello,
You have a mesh. Thus you can define P1 or P2 elements on this mesh. I don’t see really what is your problem, it depends what you want to do with this mesh.

1 Like

Hello,
Thank you very much for your response. Since the mesh is defined using P1, I would like to know if it is possible to use P2 instead. To ensure consistency with the mesh, I attempted to redefine it as P2 by replacing P1 with P2 in Th, but that approach did not work, I understand. I appreciate the clarity of your response. Thank you again.

The space P1 is used to build the mesh. But once you have the mesh, you can use P2 elements (or any other elements) on this mesh if you like.

1 Like