A problem with adaptmesh?

Dear all,
I am trying to run an example involving the resolution of several time-dependent pdes on meshes adapted at each time step, and I very soon get stuck with problems related to bad memory allocation. After some checks, I found a weird behavior related to the adaptmesh function which might explain my troubles: the finite element functions defined on the mesh are not automatically resized (or they are sometimes, but a little bit unpredicatably…).

Here is a minimal example:

/* Mesh of the domain */
border left(t=0.0,1.5){x=0.0; y=1.5-t; label=0;};
border bot(t=0.0,1.0){x=t; y=0; label=1;};
border right(t=0.0,1.5){x=1.0; y=t; label=0;};
border top(t=0.0,1.0){x=1.0-t; y=1.5; label=1;};

mesh Th = buildmesh(left(75)+bot(50)+right(75)+top(50));
/* Finite element spaces */
fespace Ph(Th,P1);
fespace Ph0(Th,P0);

/* Finite element functions */
Ph u;
Ph0 p;

/* Before adaptation; the number of vertices coincide from both sources */
cout<<"Number of vertices “<<Th.nv<<” in u "<<u[].n<<endl;
cout<<"Number of trias “<<Th.nt<<” in p "<<p[].n<<endl;

/* Adaptation */
Th = adaptmesh(Th,hmin=0.01,hmax=0.01,nbvx=30000,iso=1);

/* After adaptation; the size of u and p is not changed (in some of my examples, it is
quite randomly */
cout<<"Number of vertices “<<Th.nv<<” in u "<<u[].n<<endl;
cout<<"Number of trias “<<Th.nt<<” in p "<<p[].n<<endl;

Is there something I am missing about this?
Thank you so much for your help in advance, and have a good day!

Hi,

You have to interpolate your variables just after the adaptmesh function:

u = u;
p = p;

I think that fix your issue.

Best

1 Like

Thanks a lot! That solves my problem!
Thanks again for your help!

Dear all,

I am also having trouble with adaptmesh. I am trying to create a mesh from a metric but the results is not very smooth as shown in the picture attached. Note that I have tried to increase the number of points and the number of iterations of the smoothing procedure but nothing changes…

Here is my code:

// read the parameters
real m = 1;
string meshname = getARGV("-mesh", “BASE/ffem-mesh.msh”);
string urname = getARGV("-ur", “BASE/ffem-ur.dat”);
string utname = getARGV("-ut", “BASE/ffem-ut.dat”);
string uxname = getARGV("-ux", “BASE/ffem-ux.dat”);
string nuname = getARGV("-nu", “BASE/ffem-nu.dat”);
string metricname = getARGV("-metric", “BASE/ffem-metric.dat”);
string prefix = getARGV("-prefix", “BASE/ffem-”);
string suffix = getARGV("-suffix", “.dat”);
string lindir = getARGV("-lin", “LIN”);
int refine = getARGV("-refine", 0);
real cRatio = getARGV("-ratio", 1.2);
real cHmax = getARGV("-hmax", 5.0e-03);
int nol = getARGV("-nol", 1);

// import dimensionless mesh
mesh Th = readmesh(meshname);

// prepare the vector spaces
fespace Xh(Th, P2);
fespace Mh(Th, P1);

// import meanfields on P1 space
Mh ur, ut, ux, nu, metric;
{
ifstream fid(urname);
fid >> ur[];
}
{
ifstream fid(utname);
fid >> ut[];
}
{
ifstream fid(uxname);
fid >> ux[];
}
{
ifstream fid(nuname);
fid >> nu[];
}

{
ifstream fid(metricname);
fid >> metric[];
}
plot(Th,ps=“mesh_read.eps”,wait=true);
// interpolate implicitely on P2 space
Xh U=ur, V=ut, W=ux, Visco=nu, Metri=metric;
Mh PrMean;
real h=0.3e-3;
//real h=1e-4;
// adapt mesh to velocity field
cout << " – max min metric = " <<Metri[].min << " " << Metri[].max << endl;

if(refine == 1) {
cout << “refinement”<< endl;
// Th = adaptmesh(Th,h, nbvx=1e7, IsMetric=true);
Th = adaptmesh(Th,Metri, nbvx=2e7,nbsmooth=20);
// Th = adaptmesh(Th,Metri, nbvx=1e7,IsMetric=true);
U = U;
V = V;
W = W;
Metri=Metri;
Visco = Visco;
PrMean = PrMean;
}
Thank you for your help in advance

Matthieu

49

Hi,

you could try to force the adaptmesh to create isotropic meshes. Add the following keyword:
adaptmesh(…, iso=true, …);
and see if this helps.

Best,
Ugis

Dear all.
I want to know whether the function adpatmesh in freefem++ can adapt the specific elements based on the initial mesh fixed or not. That is to say, can AdaptMesh refine mesh cells that meet certain error requirements while keeping the original mesh unchanged? I’m looking forward to your reply. Thank you very much!