# An issue for h-adaptation in FreeFem++

**URL:** https://community.freefem.org/t/an-issue-for-h-adaptation-in-freefem/33
**Category:** General Discussion
**Created:** [April 25, 2019, 3:12pm UTC](https://community.freefem.org/t/an-issue-for-h-adaptation-in-freefem/33 "2019-04-25T15:12:04Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zhaog6](https://avatars.discourse-cdn.com/v4/letter/z/4af34b/32.png) [@zhaog6](https://community.freefem.org/u/zhaog6)
#### Post date: [April 25, 2019, 3:12pm UTC](https://community.freefem.org/t/an-issue-for-h-adaptation-in-freefem/33/1 "2019-04-25T15:12:04Z")

</div>

Hello,

I’d like to implement h-adaptation on structured grids. I find the mesh quality doesn’t seem to be good when using `splitmesh` to refine mesh locally, because `splitmesh(...)` is not based on the partition principle of the longest edge of the grid elements. I wonder if there is any way to improve it.  
For example:

```auto
macro grad(u) [dx(u), dy(u)] //

//----------------------+
// Exact Solution |
//----------------------+
func f = 1;
func g = 0;

//---------------+
// Mesh |
//---------------+
int nn = 1;
int[int] labs = [1, 2, 3, 4];
border bd1(t = 0, 1) {x = t; y = 0; label=1;}
border bd2(t = 0, 1) {x = 1; y = t/2.; label=1;}
border bd3(t = 0, 1) {x = 1-t/2.; y = 0.5; label=1;}
border bd4(t = 0, 1) {x = 0.5; y = t/2.+0.5; label=1;}
border bd5(t = 0, 1) {x = 0.5-t/2.; y = 1; label=1;}
border bd6(t = 0, 1) {x = 0; y = 1-t; label=1;}
mesh Th = buildmesh(bd1(2*nn) + bd2(nn) + bd3(nn) + bd4(nn) + bd5(nn) + bd6(2*nn));
/*
for (int it = 0; it < 10; ++it)
{
	Th = adaptmesh(Th, 1./nn, IsMetric=1, nbvx=1e+5);
}
*/
//mesh Th = square(nn, nn);
plot(Th, cmm="Initial Mesh", wait=1);

//----------------------------+
// Finite Element Space |
//----------------------------+
fespace Vh(Th, P1), Ph(Th, P0);
Vh uh;
Vh xx = x, yy = y;
Ph etaK;

//----------------------------------------------------+
// Solve Poisson Equations by h-adaptive Methods |
//----------------------------------------------------+
varf vA(u, v) = int2d(Th) (grad(u)'*grad(v)) + on(labs, u=g);
varf vl(unused, v) = int2d(Th) (f * v) + on(labs, unused=g);
varf vetaK(unused, chiK) = intalledges(Th) ( chiK * lenEdge * square(jump(grad(uh)'*[N.x, N.y])) )
	+ int2d(Th) ( chiK * square(hTriangle * (f + dxx(uh) + dyy(uh))) );
matrix A;
for (int it = 0; it < 100; ++it)
{
	etaK[] = vetaK(0, Ph);
	Th = splitmesh(Th, 1+(etaK>1.25e-4/2^it));
	uh = uh;
	etaK = etaK;
	A = vA(Vh, Vh);
	real[int] b = vl(0, Vh);
	uh[] = A^-1 * b;
	plot(Th, cmm="Refine Mesh", wait=1);
}

```

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