Redefine mesh and fespace

Hello,

I’m working on a problem where I have to redefine the mesh and its fespace asociated. Right now I’m rebuilding everything at every step and it works. As you may deduce this is not efficient so I would like to use a criteria in order to redefine or not at that time step. I did get into sintax problems when i try to redefine the mesh and its fespace, I wrote a simple code to show the problem. If i use something like this:

for(int i=0; i<2; i++){
   mesh Th = square(10*(i+1), 10*(i+1));
   fespace Vh(Th,P1);
}

It works as espected but if I do:

mesh Th = square(10,10); 
fespace Vh(Th,P1);

mesh Th = square(20,20);
fespace Vh(Th,P1);

I get syntax error. I’m not sure why this happens because it should be the same code.

Is there a way to delete a existing mesh and fespace so I can name a new one with the same name? I think i could get over this problem wiht that.

Thanks,

What the syntax error tells you? Isn’t the message clear enough?

with

mesh Th =square(10,10);
fespace Vh(Th,P1);

mesh Th =square(20,20);

I get:
The identifier Th exists
the existing type is < PPKN5Fem2D4MeshE>
the new type is < PPKN5Fem2D4MeshE>

and with

mesh Th =square(10,10); 
fespace Vh(Th,P1);
fespace Vh(Th,P1);

Error line number 5, in file .\Redefinefespace.edp, before token Vh
syntax error

I can´t just change the name of the mesh and fespace because that will be inside a loop so I need a way to use the same names and redefine its meshes and fespaces.

So don’t redefine the variable but change its value.

That works, thank you.