# Minimum/maximum edge length of the mesh in the entire domain

**URL:** <https://community.freefem.org/t/minimum-maximum-edge-length-of-the-mesh-in-the-entire-domain/731>\
**Category:** General Discussion\
**Created:** [January 7, 2021, 2:36am UTC](https://community.freefem.org/t/minimum-maximum-edge-length-of-the-mesh-in-the-entire-domain/731 "2021-01-07T02:36:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hezl09](https://avatars.discourse-cdn.com/v4/letter/h/f07891/32.png) [@hezl09](https://community.freefem.org/u/hezl09)\
**Post date:** [January 7, 2021, 2:36am UTC](https://community.freefem.org/t/minimum-maximum-edge-length-of-the-mesh-in-the-entire-domain/731/1 "2021-01-07T02:36:58Z")

</div>

Hi everyone, I need help from you. I’m trying to find the minimum/maximum edge length of the mesh in the entire domain. I tried the following two options but neither of them worked well for my test case, see the figure below as well as the code copied at the end (sorry as new user I cannot upload file). My test case is a 1 by 1 square where the vertical edge is uniformly divided into four parts while horizontal one into two parts. For me, the minimum edge should be 0.25 and maximum should be sqrt(0.25^2+0.5^2) = 0.559.

 ![testcase](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/f234973ac293cda706877dec0ee862e9bc57a08f.jpeg)

In method 1 I use the following codes

Vh0 h1 = hTriangle;  
real hmax = h1[].max;  
real hmin = h1[].min;

However, both hmax and hmin have the value of 0.559. I cannot get the correct minimum edge length.

In method 2 I use the macro provided by the FreeFEM document with the name MeshSizecomputation ([Static problems](https://doc.freefem.org/models/static-problems.html#adaptation-using-residual-error-indicator)), while it gives me the minimum edge length of 0.375 and maximum edge length of 0.467, neither of which is correct.

If you can provide any help that will be much appreciated!

below is my code.

/\* working domain \*/  
real x0 = 0;  
real x1 = 1;  
real y0 = 0;  
real y1 = 1;  
mesh Th = square(2,4,[x0+(x1-x0)\*x,y0+(y1-y0)\*y]);  
plot(Th);

/\* Finite Element spaces \*/  
fespace Vh(Th,P1);  
fespace Vh0(Th,P0);

/\* meshsize, method 1 _/  
Vh0 h1 = hTriangle;  
real hmax = h1[].max; /_ maximum mesh size _/  
real hmin = h1[].min; /_ minimun mesh size \*/  
cout \<\< "hmax = " \<\< hmax \<\< ", hmin = " \<\< hmin \<\< endl;

/\* meshsize, method 2 \*/  
macro MeshSizecomputation (Th, Vh, h)  
{  
real[int] count(Th.nv);  
/_mesh size (lenEdge = integral(e) 1 ds)_/  
varf vmeshsizen (u, v) = intalledges(Th, qfnbpE=1)(v);  
/_number of edges per vertex_/  
varf vedgecount (u, v) = intalledges(Th, qfnbpE=1)(v/lenEdge);  
/_mesh size_/  
count = vedgecount(0, Vh);  
h[] = 0.;  
h[] = vmeshsizen(0, Vh);  
cout \<\< "count min = " \<\< count.min \<\< " max = " \<\< count.max \<\< endl;  
h[] = h[]./count;  
cout \<\< "-- bound meshsize = " \<\< h[].min \<\< " " \<\< h[].max \<\< endl;  
} //

Vh h;  
MeshSizecomputation(Th, Vh, h)

---

<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:** [December 6, 2021, 12:49pm UTC](https://community.freefem.org/t/minimum-maximum-edge-length-of-the-mesh-in-the-entire-domain/731/2 "2021-12-06T12:49:41Z")

</div>

Remark, They exist a Finite element call P0Edge to defined a constant value on each edge  
fespace Ph(Th,P0Edge);  
varf vlenedge(u,v) = intalledges(Th)(1\*v/nTonEdge);

Ph le;  
le[]= vlenedge(0,Ph);

and  
le[][Ph(k,i)]  
gives the size of edge i of triangle k .

---

<div class="post-metadata">

**Author:** ![m.lbolok](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@m.lbolok](https://community.freefem.org/u/m.lbolok)\
**Post date:** [March 17, 2024, 9:28pm UTC](https://community.freefem.org/t/minimum-maximum-edge-length-of-the-mesh-in-the-entire-domain/731/3 "2024-03-17T21:28:59Z")

</div>

for me, it works by:  
fespace Ph(Th,P0edge); //instead of P0Edge
