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;

/* 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;

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!

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:

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

// 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[];
}
// 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);
U = U;
V = V;
W = W;
Metri=Metri;
Visco = Visco;
PrMean = PrMean;
}