# Apply a geometric constraint on the boundary

**URL:** <https://fenicsproject.discourse.group/t/apply-a-geometric-constraint-on-the-boundary/1810>\
**Category:** variational formulation\
**Created:** [October 31, 2019, 11:26am UTC](https://fenicsproject.discourse.group/t/apply-a-geometric-constraint-on-the-boundary/1810 "2019-10-31T11:26:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lclaire](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/lclaire/32/1615_2.png) [@lclaire](https://fenicsproject.discourse.group/u/lclaire)\
**Post date:** [October 31, 2019, 11:26am UTC](https://fenicsproject.discourse.group/t/apply-a-geometric-constraint-on-the-boundary/1810/1 "2019-10-31T11:26:05Z")

</div>

Dear Fenics community,

I would like to apply a geometric constraint on a PDE defined over a 2D domain [0, R]x[0,L], namely u\_1(L, x\_2) = u\_1(L, 0) for all x\_2 . I introduced a lagrange multiplier p and wrote the following code:

- definition of the mesh and the functionspaces:

- element of area to include informations about the boundary condition:  
class Boundary(SubDomain):  
def inside(self, x, on\_boundary):  
return x[0]\>L-R/20. and on\_boundary

- expression assigned to 0 in the interior of the domain (the Lagrange multiplier p acts only on the surface):  
Exp = Expression(‘x[0] \< L ? 1. : 0.0001’, degree = 1)

- energy with Lagrange multiplier:  
bulk\_energy = bulk\_energy\_density(u) + Exp\*inner(p,p))\*dx  
surface\_energy = inner(p,(u[0] - u[0](L, 0)))\*my\_ds(3)

However, the syntax of the last line is wrong, and I wonder what the right syntax would be ?

thank you in advance for your help,

Kind regards,

Claire

---

<div class="post-metadata">

**Author:** ![kamensky](https://avatars.discourse-cdn.com/v4/letter/k/e95f7d/32.png) [@kamensky](https://fenicsproject.discourse.group/u/kamensky)\
**Post date:** [October 31, 2019, 11:39pm UTC](https://fenicsproject.discourse.group/t/apply-a-geometric-constraint-on-the-boundary/1810/2 "2019-10-31T23:39:26Z")

</div>

If I understand correctly, an equivalent local constraint would be

\partial\_{x\_2}u\_1(\mathbf{x}) = 0~~~\forall\mathbf{x}\in\{L\}\times(0,R)\text{ ,}

i.e., that u\_1 doesn’t vary w.r.t. x\_2 on that edge of the domain. Then you do not need to include a point evaluation of the function in your variational problem. Some other notes:

- If you’re satisfied with a regularization of the constraint (as caused by `Exp` from your example code), it would be simpler to just add a quadratic penalty term to the energy. Then you don’t need to worry about adding a Lagrange multiplier (or choosing a stable space for it).

- If you do want to use the multiplier, there are some nicer solutions for solving problems with unknown fields that are only supported on the boundary. See @francesco-ballarin’s library [multiphenics](https://github.com/mathLab/multiphenics) or @cdaversin’s [mixed dimension branch](https://bitbucket.org/fenics-project/dolfin/src/3ff4b37bbb5628c75081c0f09a83bf5b9f703776/?at=cecile%2Fmixed-dimensional).
