# Redefine mesh and fespace

**URL:** <https://community.freefem.org/t/redefine-mesh-and-fespace/1902>\
**Category:** General Discussion\
**Created:** [July 20, 2022, 7:40am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902 "2022-07-20T07:40:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)\
**Post date:** [July 20, 2022, 7:40am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902/1 "2022-07-20T07:40:51Z")

</div>

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:

```auto
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:

```auto
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,

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [July 20, 2022, 8:18am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902/2 "2022-07-20T08:18:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)\
**Post date:** [July 20, 2022, 8:47am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902/3 "2022-07-20T08:47:03Z")

</div>

with

```auto
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

```auto
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.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [July 20, 2022, 8:58am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902/4 "2022-07-20T08:58:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![miguelpicos](https://avatars.discourse-cdn.com/v4/letter/m/8797f3/32.png) [@miguelpicos](https://community.freefem.org/u/miguelpicos)\
**Post date:** [July 20, 2022, 10:04am UTC](https://community.freefem.org/t/redefine-mesh-and-fespace/1902/5 "2022-07-20T10:04:47Z")

</div>

That works, thank you.
