# Heaviside function integration

**URL:** <https://community.freefem.org/t/heaviside-function-integration/1584>\
**Category:** General Discussion\
**Created:** [March 7, 2022, 3:43pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584 "2022-03-07T15:43:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ygorschka](https://avatars.discourse-cdn.com/v4/letter/y/e95f7d/32.png) [@ygorschka](https://community.freefem.org/u/ygorschka)\
**Post date:** [March 7, 2022, 3:43pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584/1 "2022-03-07T15:43:50Z")

</div>

Dear all,

I try to integrate (H o u(x))\*v where H is Heaviside function in a 2D mesh by using:

Uh(Th, P1);  
varf a(uu,vv) = int2d(Th)((uu == 0. ? 0.5 : (uu\>0. ? 1. : 0.))\*vv);  
matrix Ah = a(Uh,Uh);

However, Freefem raise the following error. I also get the same error with a macro : Heaviside(u) ((u == 0.) ? 0.5 : ((u\>0.) ? 1. : 0.)).

varf tesths(uu,vv) = int2d(Th)(((uu == 0.)  
error operator == \<10LinearCombI7MGauche4C\_F0E\>, List of choices ( **: , ) ( : \<10GlgElementIN5Fem2D5MeshLEE\>, \<10GlgElementIN5Fem2D5MeshLEE\> ) ( : \<10GlgElementIN5Fem2D5MeshSEE\>, \<10GlgElementIN5Fem2D5MeshSEE\> ) ( : \<10GlgElementIN5Fem2D5Mesh3EE\>, \<10GlgElementIN5Fem2D5Mesh3EE\> ) ( : \<N12\_GLOBAL\_\_N\_19lgElementE\>, \<N12\_GLOBAL\_\_N\_19lgElementE\> ) ( : \<NSt7\_\_cxx1112basic\_stringIcSt11char\_traitsIcESaIcEEE\>, \<NSt7\_\_cxx1112basic\_stringIcSt11char\_traitsIcESaIcEEE\> ) ( : , ) ( : , )**

 

Does anyone know what is wrong here? Thank you.

---

<div class="post-metadata">

**Author:** ![SamuelJosephs](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/samueljosephs/32/1046_2.png) [@SamuelJosephs](https://community.freefem.org/u/SamuelJosephs)\
**Post date:** [March 7, 2022, 7:17pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584/2 "2022-03-07T19:17:04Z")

</div>

So directly what is wrong is that the == operator is not defined for the combination of types you are asking it to take as input. What exactly are you trying to do? There may be an easier way to go about it.

---

<div class="post-metadata">

**Author:** ![ygorschka](https://avatars.discourse-cdn.com/v4/letter/y/e95f7d/32.png) [@ygorschka](https://community.freefem.org/u/ygorschka)\
**Post date:** [March 8, 2022, 8:19am UTC](https://community.freefem.org/t/heaviside-function-integration/1584/3 "2022-03-08T08:19:05Z")

</div>

I am trying to evaluate  
 ![problème](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/3970b1bd68dc9949ae85533c53516c33f236df50.png)  
where H is the function of Heaviside. It is motivated by a contact problem using Nitsche’s method.

---

<div class="post-metadata">

**Author:** ![ygorschka](https://avatars.discourse-cdn.com/v4/letter/y/e95f7d/32.png) [@ygorschka](https://community.freefem.org/u/ygorschka)\
**Post date:** [March 8, 2022, 8:29am UTC](https://community.freefem.org/t/heaviside-function-integration/1584/4 "2022-03-08T08:29:47Z")

</div>

More precisely, I have  
 ![problème2](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/ac788c7907af5d150d79a8803ee1f20693833672.png)  
I understand that Freefem is trying to evaluate u == 0 and it is a nonsense but u(x,y) == 0 makes sense.

---

<div class="post-metadata">

**Author:** ![SamuelJosephs](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/samueljosephs/32/1046_2.png) [@SamuelJosephs](https://community.freefem.org/u/SamuelJosephs)\
**Post date:** [March 8, 2022, 2:26pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584/5 "2022-03-08T14:26:43Z")

</div>

So with int2d you are integrating over \Omega not \partial \Omega .  
My understanding is that integral will always be 0 as v(x,y) (The test function) evaluated at the boundary is always 0.

---

<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:** [March 8, 2022, 4:28pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584/6 "2022-03-08T16:28:42Z")

</div>

Remark, your problem is cleary nolinear and freefem++ is not magic,  
You must linearize you problem to solve it !!! with a a fixe point method for exemple  
for exemple you can do something like:

set  
macro H(u) real (u\>0)//  
Vh Hu;

Hu = H(u) ;

// you can use Hu

compute Hu and update u form Hu …

---

<div class="post-metadata">

**Author:** ![ygorschka](https://avatars.discourse-cdn.com/v4/letter/y/e95f7d/32.png) [@ygorschka](https://community.freefem.org/u/ygorschka)\
**Post date:** [March 10, 2022, 1:32pm UTC](https://community.freefem.org/t/heaviside-function-integration/1584/7 "2022-03-10T13:32:17Z")

</div>

Ok I see the problem, thank you very much for you answer.
