# Problem reading/writing mesh file

**URL:** <https://community.freefem.org/t/problem-reading-writing-mesh-file/455>\
**Category:** General Discussion\
**Created:** [June 3, 2020, 2:53pm UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455 "2020-06-03T14:53:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![david9333](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@david9333](https://community.freefem.org/u/david9333)\
**Post date:** [June 3, 2020, 2:53pm UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455/1 "2020-06-03T14:53:05Z")

</div>

Hi!  
I am working on both my computer and distant computing resources provided by my lab and I seem to have a compatibility issue. I have created a .mesh file in the distant computer (using what is called v.4.4-2-nopetsc). When I try to read it in my computer (v.4.4-3), I have the following error:

```auto
read mesh ok 1Mesh3, num Tetra:= 0, num Vertice:= 0 num boundary Triangles:= 0
  -- Mesh3::Mesh3 Erreur opening cylm10.mesh
  current line = 18
Assertion fail : (0)
	line :161, in file ../femlib/Mesh3dn.cpp
Assertion fail : (0)
	line :161, in file ../femlib/Mesh3dn.cpp

```

Yet my .mesh file begins with

```auto
MeshVersionFormatted 2

Dimension 3

Vertices
29355

```

I have tried to generate my own .mesh file to compare and try to understand the problem, but using

```auto
savemesh(Th,"cylm10_home.msh") // or .mesh

```

or

```auto
savevtk("cylm10_home.vtu",Th);

```

result in the error

```auto
Unable to open file cylm10_home.msh // or .mesh or .vtu

```

Do you have an idea on how I could read the mesh correctly? (and why I cannot save a mesh?)

Thanks!  
David

---

<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:** [June 3, 2020, 3:07pm UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455/2 "2020-06-03T15:07:11Z")

</div>

Please post your mesh file and your .edp.

---

<div class="post-metadata">

**Author:** ![david9333](https://avatars.discourse-cdn.com/v4/letter/d/65b543/32.png) [@david9333](https://community.freefem.org/u/david9333)\
**Post date:** [June 3, 2020, 3:23pm UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455/3 "2020-06-03T15:23:35Z")

</div>

After downloading again the distant mesh file, I cannot reproduce the error with readmesh3… sorry about that.

The writing problem remains but I cannot upload the file, so I copy it below:

```auto
load "msh3"
load "tetgen"
load "iovtk"

//DEFINITION DU MAILLAGE

real r00 = 9.00e-1; //rayon du cylindre
real L00 = 9.40; //longueur du cylindre

int m=10; //Nombre de noeuds au bord par cm
int nlayer = L00*m; //Nombre de couches dans le maillage

border c(t=0,2*pi){x=r00*cos(t);y=r00*sin(t);};
mesh cercle = buildmesh(c(2*pi*r00*m));

int[int] rup=[0,1], rdown=[0,2], rmid=[1,3];
mesh3 Th = buildlayers(cercle,nlayer,
  coef = 1.,
  zbound = [0,L00],
  labelmid = rmid,
  reffaceup = rup,
  reffacelow = rdown);

savemesh(Th,"cylm10_home.msh");
//savevtk("cylm10.vtu",Th);

```

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:** [June 3, 2020, 3:33pm UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455/4 "2020-06-03T15:33:06Z")

</div>

```auto
load "msh3"
load "tetgen"
load "iovtk"

//DEFINITION DU MAILLAGE

real r00 = 9.00e-1; //rayon du cylindre
real L00 = 9.40; //longueur du cylindre

int m=10; //Nombre de noeuds au bord par cm
int nlayer = L00*m; //Nombre de couches dans le maillage

border c(t=0,2*pi){x=r00*cos(t);y=r00*sin(t);};
mesh cercle = buildmesh(c(2*pi*r00*m));

int[int] rup=[0,1], rdown=[0,2], rmid=[1,3];
mesh3 Th = buildlayers(cercle,nlayer,
  coef = 1.,
  zbound = [0,L00],
  labelmid = rmid,
  reffaceup = rup,
  reffacelow = rdown);

savemesh(Th,"cylm10_home.mesh");
//savevtk("cylm10.vtu",Th);
mesh3 ThLoad = readmesh3("cylm10_home.mesh");

```

This works OK on my machine. If it doesn’t on yours, consider updating your FreeFEM installation.

---

<div class="post-metadata">

**Author:** ![Yangshen](https://avatars.discourse-cdn.com/v4/letter/y/838e76/32.png) [@Yangshen](https://community.freefem.org/u/Yangshen)\
**Post date:** [August 24, 2022, 10:51am UTC](https://community.freefem.org/t/problem-reading-writing-mesh-file/455/5 "2022-08-24T10:51:03Z")

</div>

I ran this code on my computer

But when I open the saved grid file, it is blank. I don’t no why.
