# How to impose interface condition ∂u⁺/∂n = k ∂u⁻/∂n in FreeFem++

**URL:** https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084
**Category:** General Discussion
**Created:** [September 30, 2025, 3:48am UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084 "2025-09-30T03:48:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kamjd](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kamjd](https://community.freefem.org/u/Kamjd)
#### Post date: [September 30, 2025, 3:48am UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084/1 "2025-09-30T03:48:16Z")

</div>

Hello everyone,

I am solving a PDE on a domain Ω split into two sub-domains Ω⁺ and Ω⁻ separated by an interface Γ.

On Γ I need to impose the interface (flux) condition  
[  
\frac{\partial u^{+}}{\partial n} = k,\frac{\partial u^{-}}{\partial n}  
\quad \text{on } \Gamma,  
]  
where _k_ is a given constant (or function defined on Γ).

I can mesh the two sub-domains separately (or use a single mesh with a label for the interface), and I can write the weak form of the PDE in each sub-domain.  
However, I am not sure how to correctly enforce this interface condition in FreeFEM++.

Could someone provide guidance or a small example showing:

- how to write the weak formulation that incorporates this interface condition,

- or how to implement it using Lagrange multipliers or jump terms in FreeFEM++.

A minimal code example would be greatly appreciated.

Thank you in advance for your help!

---

<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: [September 30, 2025, 3:18pm UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084/2 "2025-09-30T15:18:25Z")

</div>

This is a classical problem, if you do heat equation, this two domain two thermal diffusivity k1,k2

the the boundary condition say the thermal flux is continuous , and the u is continuous and in this case the

$$ k\_1 \Delta u\_1 = f\_1 $$ on domain \\Omaga\_1 + BC on external boundary

$$ k\_2 \Delta u\_2 = f\_2 $$ on domain \\Omaga\_2 + BC on external boundary

and k\_1 \\frac{\\partial u\_1}{\\partial n} = k\_2 \\frac{\\partial u\_2}{\\partial n} on \\Gamma

if you call u the solution on \\Omega = \\Omega1 \\cup \\Omega2

k the discontinuous diffusivity of \\Omega

then the Varf is

find u (u given on \\partial \\Omega = g$)

$$ \forall v \H^1\_0(\Omega), int\_\Omega k \nabla u . \nabla v = int\_ f v$$

---

<div class="post-metadata">

### Author: ![Kamjd](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kamjd](https://community.freefem.org/u/Kamjd)
#### Post date: [October 3, 2025, 6:32am UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084/3 "2025-10-03T06:32:51Z")

</div>

Thank you for your answer.  
I’m working on a problem where  
[  
\Delta u^+ = 0 \quad \text{in } \Omega\_1  
]  
and  
[  
\Delta u^- = 0 \quad \text{in } \Omega\_2  
]  
with (\Omega\_1) being a square domain and (\Omega\_2) an ellipse inside (\Omega\_1).

On the interface (\Gamma = \partial\Omega\_2), I impose  
[  
u^+ = u^- \quad \text{on } \Gamma , \qquad  
k\_1 \frac{\partial u^+}{\partial n} = k\_2 \frac{\partial u^-}{\partial n}.  
]

So the solution is continuous across the interface, and the flux is continuous as well.

I tried to reproduce the discontinuity of (k) as suggested in the FreeFem++ documentation, using:

```c++
solve Poisson(u,v,solver=LU) =
    int2d(tout)(dx(u)*dx(v) + dy(u)*dy(v))
  - int1d(tout)(k*(nx*dx(u) + ny*dy(u))*v)
  + int2d(tout)(f*v)
  + on(1, u=0)
  + on(2, u=g);

```

and I defined (k) as follows:

```c++
// We create the variable k = 1 or -1
fespace V(tout,P0);
V pl = region;
int inside = pl((x1+x0)/2, (y1+y0)/2);
V chi = (inside == region);
V k = (1 - chi) * (-1) + 1 * chi;

```

I think this should be sufficient to achieve a good modeling of the problem.

---

<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: [October 3, 2025, 8:56am UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084/4 "2025-10-03T08:56:48Z")

</div>

[kamjd.edp](https://community.freefem.org/uploads/short-url/17ikIV7tAXdW1wZx48pMoeJIoc.edp) (571 Bytes)

I have build a small example

first a mesh Th of ]-2,2[^2 square with a ellipse inside label 2 on ellipse and label 1 on square.

```cpp
solve Poisson(u,v,solver=LU) =
    int2d(Th)(dx(u)*dx(v) + dy(u)*dy(v))
  - int1d(Th,2)(k*v)
  + int2d(Th)(f*v)
  + on(1, u=0);

The variationnal formulation is 

$$ \forall v \in H^1(\Omega_1), \int_\Omega \nabla u.\nabla v = \int_\Gamma (k_1-k_2) v$$
and $k = k_1-k_2$; 

```

---

<div class="post-metadata">

### Author: ![Kamjd](https://avatars.discourse-cdn.com/v4/letter/k/f1d935/32.png) [@Kamjd](https://community.freefem.org/u/Kamjd)
#### Post date: [October 13, 2025, 2:46am UTC](https://community.freefem.org/t/how-to-impose-interface-condition-u-n-k-u-n-in-freefem/4084/5 "2025-10-13T02:46:39Z")

</div>

Sorry for the late reply. Thank you very much for your help. I think I found the solution to my problem.
