# Lagrange multiplier and Dirichlet boundary condition

**URL:** <https://community.freefem.org/t/lagrange-multiplier-and-dirichlet-boundary-condition/3829>\
**Category:** General Discussion\
**Created:** [April 1, 2025, 10:41pm UTC](https://community.freefem.org/t/lagrange-multiplier-and-dirichlet-boundary-condition/3829 "2025-04-01T22:41:33Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)\
**Post date:** [April 2, 2025, 9:05am UTC](https://community.freefem.org/t/lagrange-multiplier-and-dirichlet-boundary-condition/3829/2 "2025-04-02T09:05:24Z")

</div>

Dear Hemanta,  
Your matrix is singular if `g1,g2,t1,t2` are in a fespace over the whole mesh Lh (I don’t have this information from your post), because the value of `g1,g2` is not determined inside the domain. A way to cure this is to add a small term  
`+int2d(Lh)(1.e-8*(g1*t1+g2*t2))` making the problem well-posed inside the domain, without perturbing your boundary formulation.  
Otherwise a more clear formulation is to take `g1,g2,t1,t2` defined only on the boundary \Gamma. An example doing this is here

> [@Lagrange multiplier for Dirichlet boundary condition](https://community.freefem.org/t/lagrange-multiplier-for-dirichlet-boundary-condition/2402/7):
>
> Dear @cmd @marchywka , thank you both for your previous help and I have made good process about using Lagrange multiplier to implement Dirichlet BC. However, there are problems when I try to parallelise my code. It seems FreeFemm++ and ff-mpirun -n 1 … compile code differently. I found the fowllowing three operations are not allowed using ff-mpirun -n 1…, while it works well for FreeFem++ 1. int[int] labs = [1]; ThS = extract(ThG, label=labs); 2. matrix UAtemp = ua(Vh,Sh); 3. createMat(ThS…

as `stokes_lagrange.edp`  
There the matrix is built by blocks. Probably you can do also by using a composite space.

---

_[View the full topic](https://community.freefem.org/t/lagrange-multiplier-and-dirichlet-boundary-condition/3829)._
