# Level set "distance" / Assertion fail

**URL:** <https://community.freefem.org/t/level-set-distance-assertion-fail/1646>\
**Category:** General Discussion\
**Created:** [April 5, 2022, 8:43am UTC](https://community.freefem.org/t/level-set-distance-assertion-fail/1646 "2022-04-05T08:43:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ffeppon](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ffeppon/32/1011_2.png) [@ffeppon](https://community.freefem.org/u/ffeppon)\
**Post date:** [April 5, 2022, 8:43am UTC](https://community.freefem.org/t/level-set-distance-assertion-fail/1646/1 "2022-04-05T08:43:01Z")

</div>

Dear developpers.

I am encountering a bug when I try to apply the function “distance” to a level set function on a 3D mesh:

```auto

load "medit";
load "distance";

real tclock;//For measuring time

mesh3 Th=readmesh3("Th.meshb");
fespace Fh1(Th,P1);
Fh1 phi;
phi[]=readsol("phi.sol");

Fh1 dOmega;
distance(Th, phi, dOmega[]);

```

which results, on my mesh and solution file as the following error:

```bash
  current line = 14
Assertion fail : (Norme2(AGG - AG) < 1e-6)
	line :189, in file distance.cpp
Assertion fail : (Norme2(AGG - AG) < 1e-6)
	line :189, in file distance.cpp
 err code 6 , mpirank 0

```

I attach the problematic example in PJ. Many thanks in advance for your help.

[test.zip](https://community.freefem.org/uploads/short-url/jbovlIyp0abYsignykNsMx4ecO0.zip) (2.2 MB)

---

<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 5, 2022, 11:42am UTC](https://community.freefem.org/t/level-set-distance-assertion-fail/1646/2 "2022-04-05T11:42:54Z")

</div>

Je vais regarder , Merci.

---

<div class="post-metadata">

**Author:** ![AntoniJ](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@AntoniJ](https://community.freefem.org/u/AntoniJ)\
**Post date:** [July 24, 2022, 8:30pm UTC](https://community.freefem.org/t/level-set-distance-assertion-fail/1646/3 "2022-07-24T20:30:21Z")

</div>

Hi,  
I am currently encountering the same problem trying to apply the distance function to a level-set. Is there something to do to avoid this bug?  
I temporarily solved the problem by precising the parameter _meshdist_, but now I run my scripts on really thin meshes and the issue reappeared. Do you have any idea how to solve this?  
Thanks in advance.

---

<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:** [July 27, 2022, 2:30pm UTC](https://community.freefem.org/t/level-set-distance-assertion-fail/1646/4 "2022-07-27T14:30:48Z")

</div>

I have to debug the distance code function, I think this is due to very bad mesh, but I am not sure.
