# Mesh generation from a geometry

**URL:** <https://community.freefem.org/t/mesh-generation-from-a-geometry/362>\
**Category:** General Discussion\
**Created:** [April 21, 2020, 4:28pm UTC](https://community.freefem.org/t/mesh-generation-from-a-geometry/362 "2020-04-21T16:28:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)\
**Post date:** [April 21, 2020, 4:28pm UTC](https://community.freefem.org/t/mesh-generation-from-a-geometry/362/1 "2020-04-21T16:28:19Z")

</div>

Hi,

Regarding the documentation it seems not possible to generate a mesh from a geometry model, as the geo gmsh file, directly in freefem ?

PS : A geometry model is composed with :

- a list of vertices
- list of edges
- list of domains
- a domain is defined by a list of boundaries
- a boundary is defined by a list of oriented edges

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [April 21, 2020, 5:00pm UTC](https://community.freefem.org/t/mesh-generation-from-a-geometry/362/2 "2020-04-21T17:00:42Z")

</div>

In 2d you can do:

```
{
 // build from bamg geometrie

  { // build the geom file
    ofstream ff("g.mesh");
    int n = 8;
    real h = 0.1;
    ff <<"MeshVersionFormatted 0\n";
    ff <<"AngleOfCornerBound 46\n";
    ff <<"Dimension 2 \n";
    ff << "Vertices "<< n << endl;
    for (int i=0;i<n;i++)
      ff << cos(i*pi*2./n) << " " << sin(i*pi*2./n) << " 1\n"; 

    ff << "Edges "<< n<< endl;
    for (int i=0;i<n;i++)
      ff << i+1 << " " << (i+1)%n +1 << " 1\n";

    ff << "hVertices"<< endl;
    for (int i=0;i<n;i++)
      ff << h << endl;
  }

  mesh Th=buildmesh("g.mesh",nbvx=100000);
  plot(Th,wait=1);
}
```

---

<div class="post-metadata">

**Author:** ![mrbenson](https://avatars.discourse-cdn.com/v4/letter/m/d07c76/32.png) [@mrbenson](https://community.freefem.org/u/mrbenson)\
**Post date:** [April 21, 2020, 8:11pm UTC](https://community.freefem.org/t/mesh-generation-from-a-geometry/362/3 "2020-04-21T20:11:25Z")

</div>

Thanks,

It seems that medit mesh file can’t handle geometries with holes cause that file format was firstly designed as a mesh file format.  
For instance how to define a geometry composed of two concentric circles :

{  
// build from bamg geometrie

{ // build the geom file  
ofstream ff(“g.mesh”);  
int n = 8;  
real h = 0.1;  
ff \<\<“MeshVersionFormatted 0\n”;  
ff \<\<“AngleOfCornerBound 46\n”;  
ff \<\<“Dimension 2 \n”;

```
ff << "Vertices "<< 2*n << endl;
for (int i=0;i<n;i++)
  ff << cos(i*pi*2./n) << " " << sin(i*pi*2./n) << " 1\n";
for (int i=0;i<n;i++)
  ff << 0.5*cos(i*pi*2./n) << " " << 0.5*sin(i*pi*2./n) << " 1\n"; 	  

ff << "Edges "<< 2*n<< endl;
for (int i=0;i<n;i++)
  ff << i+1 << " " << (i+1)%(n) +1 << " "<<i+1 <<" \n";

for (int i=0;i<n;i++)
  ff << (i+1)%+n +1+n << " " << (i+1+n) <<" "<< i+1+n<<" \n";  
  
ff << "hVertices"<< endl;
for (int i=0;i<2*n;i++)
  ff << h << endl;

```

}

mesh Th=buildmesh(“g.mesh”,nbvx=100000);  
plot(Th,wait=1);  
}
