General issue with semantics of "fespace"

I’m trying to do a 2D diffusion problem with an adaptive mesh.
Looking at the attache example,
exbigns.edp (4.0 KB)
it looks like the fespaces all change automatically if the mesh is
redefined or adapted. This example seems to run just fine. However, in my own
code, I can see the mesh adapte and become finer around desired areas.
Subsequent iterations fail however while running just fine without adaptvation.
Unsure of what was going on, I wanted to write a function to save one mesh and
result and then reload it into a new mesh for the next iteration.
So, a function makes sense but there were problems there too. First,
I could not figure out how to put the “result” into the function signature.
Then, passing a mesh seemed to create problems too.
The function “sampled” in
glue.edp (4.8 KB)

is this,

  105 : // the adapted mesh just does not work right.
  106 : // try to save and reload into new mesh. 
  107 : 
  108 : Xh f; 
  109 : func int  sampled( mesh Th2, string nm)
  110 : {
  111 : mesh Thread = readmesh("refMesh.mesh");
  112 : fespace Vh2(Th2, P2) typeFESpace:: bug dim: maes/EZFv mesh dim :-1 type FE 5
  current line = 112
Assertion fail : (0)
	line :7225, in file lgfem.cpp
error Assertion fail : (0)
	line :7225, in file lgfem.cpp
 code = 6 mpirank: 0


// the adapted mesh just does not work right.
// try to save and reload into new mesh.

Xh f;
func int sampled( mesh Th2, string nm)
{
mesh Thread = readmesh(“refMesh.mesh”);
fespace Vh2(Th2, P2);
//Vh2 f;
fespace Vh(Thread, P2);
Vh uread;
uread = readsol(“ref.”+nm+“.sol”);
for(int i=0; i<Th2.nv; ++i)
{
real xp=Th2[i].x;
real yp=Th2[i].y;
f[i]=uread(xp,yp);
}

return 1;
} // samples

I guess I just am not sure what happens with “feapace Vh(Th,P1); Vh x;” and the
state of x after Th changes. Should the size of “x” adapt automtically if Th changes?

Thanks.