# General issue with semantics of "fespace"

**URL:** <https://community.freefem.org/t/general-issue-with-semantics-of-fespace/2257>\
**Category:** General Discussion\
**Created:** [January 31, 2023, 12:47pm UTC](https://community.freefem.org/t/general-issue-with-semantics-of-fespace/2257 "2023-01-31T12:47:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marchywka](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@marchywka](https://community.freefem.org/u/marchywka)\
**Post date:** [January 31, 2023, 12:47pm UTC](https://community.freefem.org/t/general-issue-with-semantics-of-fespace/2257/1 "2023-01-31T12:47:31Z")

</div>

I’m trying to do a 2D diffusion problem with an adaptive mesh.  
Looking at the attache example,  
[exbigns.edp](https://community.freefem.org/uploads/short-url/kU6ELBJgDBbE5jGcdLh9LwIzYBS.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](https://community.freefem.org/uploads/short-url/to6l91odCwK6CPB8OcPnrHmHyVt.edp) (4.8 KB)

is this,

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

```auto

```
