# Implementation of Dirichlet boundary condition when tgv=-1

**URL:** <https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113>\
**Category:** Feature Request\
**Created:** [August 19, 2019, 6:51pm UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113 "2019-08-19T18:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)\
**Post date:** [August 19, 2019, 6:51pm UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113/1 "2019-08-19T18:51:01Z")

</div>

As far as I read, when using tgv=-1, freefem doesn’t apply dirichlet BC in a symmetric way.

The symmetric way would look like this:

![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/80c5138a4ddeea0d486e1bf46fbfc74976dfd6a8.png)  
 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/dd0d601c7d81a92a4cc6dfc1e911dcbd92c0611a.png)

The asymmetric way only modifies the third row without setting the column values to zero which freefem is actually doing now(?)

This could be good to be implemented, and let user select e.g tgv=-1 is asymmetric and tgv=0 symmetric strategy…

---

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [August 20, 2019, 5:12pm UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113/2 "2019-08-20T17:12:37Z")

</div>

Dear @arousta,

According to [About the functions LinearCG](https://community.freefem.org/t/about-the-functions-linearcg/54/8) a symmetric elimination is possible with `tgv=-2`, although I never tried myself, and it is not available for the rhs, as far as I remember. On the other hand, the implementation is not that hard; at [Exact Dirichlet BC](https://community.freefem.org/t/exact-dirichlet-bc/52) I have presented a naive implementation at the level of FreeFEM itself.

Regards,  
/Fotios Kasolis

---

<div class="post-metadata">

**Author:** ![arousta](https://avatars.discourse-cdn.com/v4/letter/a/838e76/32.png) [@arousta](https://community.freefem.org/u/arousta)\
**Post date:** [August 21, 2019, 12:42am UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113/3 "2019-08-21T00:42:36Z")

</div>

Dear Fotios,

Thanks for your info. So I tried tgv=-2 and it does what you said! Interesting, but this is no where mentioned in the documentation and I would assume it a hidden utility? (But don’t know why hidden 🙂)

And tgv=-2 doesn’t do anything on rhs as you said but can do a fix. I don’t like to write too many nested loops in freefem so I do this to implement the rhs needed for the symmetric matrix:

```
border C(t=0,2*pi){ x=sin(t); y=cos(t); label=1; }
mesh Th = buildmesh(C(-6));
fespace Vh(Th,P1);
macro BC on(1,u=1) //
varf a(u,v) = int2d(Th)( dx(u)*dx(v)+dy(u)*dy(v) ) +int2d(Th)(v) +BC;
Vh uA, uS; // A: Asymmetric, S:Symmetric

matrix MA = a(Vh,Vh,tgv=-1);
real[int] rhsA = a(0,Vh,tgv=-1.);
uA[] = MA^-1*rhsA;
plot(uA,wait=1);

varf dirichletBC(u,v) = BC;
real[int] bc = dirichletBC(0,Vh,tgv=-1);
matrix MS = a(Vh,Vh,tgv=-2.);
matrix MD = MS-MA;
real[int] rhsS = MD*bc;
rhsS += rhsA;
uS[] = MS^-1*rhsS;
plot(uS);

```

If you look at the two figures in the opening post, MD is just the matrix (a13, a23) and we multiply it by the dirichlet bc values to get the final rhs.

But this is actually a horrible way of doing this, as I am using two extra matrices (MD & MS) to achieve such a simple thing. It would be much much better if the tgv=-2 becomes a built-in feature.

---

<div class="post-metadata">

**Author:** ![simon.garnotel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/simon.garnotel/32/11_2.png) [@simon.garnotel](https://community.freefem.org/u/simon.garnotel)\
**Post date:** [August 21, 2019, 8:13am UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113/4 "2019-08-21T08:13:59Z")

</div>

Thanks for your feedback!

I have opened an issue to add more infos about tgv values in the documentation ([https://github.com/FreeFem/FreeFem-doc/issues/21](https://github.com/FreeFem/FreeFem-doc/issues/21)).

---

<div class="post-metadata">

**Author:** ![LucasPa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/lucaspa/32/347_2.png) [@LucasPa](https://community.freefem.org/u/LucasPa)\
**Post date:** [August 19, 2021, 7:37am UTC](https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113/5 "2021-08-19T07:37:11Z")

</div>

Hi,

I know it is not proper documentation but the pdf [http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/main.pdf](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/main.pdf) might help. Slides 18 to 20 (page 9 of the document) define symetric/nonsymetric elimination and penalization. Slide 34 (page 17 of the document) shows the corresponding values of tgv.

Best,

Lucas
