# How to impose Dirichlet boundary conditions by Lagrange multipliers

**URL:** https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330
**Category:** General Discussion
**Created:** [March 14, 2023, 6:33am UTC](https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330 "2023-03-14T06:33:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zhugp123](https://avatars.discourse-cdn.com/v4/letter/z/71e660/32.png) [@zhugp123](https://community.freefem.org/u/zhugp123)
#### Post date: [March 14, 2023, 6:33am UTC](https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330/1 "2023-03-14T06:33:46Z")

</div>

Hi, I want to impose Dirichlet boundary conditions by using the Lagrange multiplier method.

The governing equation for heat transfer is \Delta T = 0, where T is the temperature. The boundary conditions are shown in the following picture.

I know how to solve this problem in FreeFEM. However, I try to impose constant temperature on the top and bottom boundaries by using a Lagrange multiplier method, and the weak form is shown below:

\Biggl\{ \begin{array} -\int \nabla T \cdot \nabla w \; \text{d} \Gamma+\int w \mathbf{n} \cdot \nabla T \text{d} \Gamma + \int \lambda w \; \text{d} \Gamma &= 0, \\ \int \hat{\lambda} \left( T - T\_c \right) \; \text{d} \Gamma &= 0, \end{array}

where w and \hat{\lambda} is the test function for temperature T and Lagrange multiplier \lambda. **Note that here \lambda is a scalar field defined on the top and bottom boundaries.**

The FreeFEM provides a Lagrange multiplier example (Poisson equation with a global constraint). In this example, we only need to introduce a scalar to enforce the global constraint, which is different from our case.

Does FreeFEM have a similar case that enforces boundary constraints by introducing a Lagrange multiplier?

Can FreeFEM define a finite element space for the Lagrange multiplier defined on the specific boundary ?

Thanks in advance.

![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/5/5001d61ef607954633f770a43d4b1e1a0076796b.png)

---

<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 19, 2023, 3:00pm UTC](https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330/2 "2023-03-19T15:00:33Z")

</div>

Theoretically you can do that with 2 finite element one on Th (the 2 d mesh) and one one 1d mesh of the border, if we miss no operator.

---

<div class="post-metadata">

### Author: ![zhugp123](https://avatars.discourse-cdn.com/v4/letter/z/71e660/32.png) [@zhugp123](https://community.freefem.org/u/zhugp123)
#### Post date: [March 22, 2023, 1:27am UTC](https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330/3 "2023-03-22T01:27:47Z")

</div>

Dear Profeesor,  
I checked the whole FreeFEM document and only found 2D and 3D finite space defined on Th. On possible operator for 1d mesh is `emptymesh`. Could you kindly give me some advice on how to define finite element space on 1d mesh of the border. Thanks in advance.

Best

---

<div class="post-metadata">

### Author: ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)
#### Post date: [March 22, 2023, 11:03am UTC](https://community.freefem.org/t/how-to-impose-dirichlet-boundary-conditions-by-lagrange-multipliers/2330/4 "2023-03-22T11:03:08Z")

</div>

I think for the 1D at the border, you just do int1d(Th,\Gamma). That should do it.
