# Application of Dirichlet BCs

**URL:** <https://community.freefem.org/t/application-of-dirichlet-bcs/467>\
**Category:** General Discussion\
**Created:** [June 13, 2020, 4:03pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467 "2020-06-13T16:03:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chenna](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/chenna/32/183_2.png) [@chenna](https://community.freefem.org/u/chenna)\
**Post date:** [June 13, 2020, 4:03pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/1 "2020-06-13T16:03:00Z")

</div>

Hello FreeFem community,

I started using FreeFEM. I find it very easy to understand and use. I started liking it and considering to integrate it into my research workflow. I am looking for some clarification regarding the application of boundary conditions.

I read in the FreeFEM documentation that Dirichlet boundary conditions are imposed using the penalty method using a very high value (10^30) for the penalty constant.

My experience indicates that such an approach results in ill-conditioned matrices and poses many issues in the modal analysis (eigenvalue problems) and buckling analysis due to the sensitivity of results to the penalty constant.

I am wondering you have any plans for implementing the elimination approach for imposing Dirichlet BCs in FreeFEM in the future.

Thanks,  
Chenna

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 13, 2020, 4:17pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/2 "2020-06-13T16:17:11Z")

</div>

Hello Chenna,  
Please have a look at [these](http://jolivet.perso.enseeiht.fr/FreeFem-tutorial/#pf14) slides. You can do unsymmetric elimination (tgv = -1) or symmetric elimination (tgv = -2) for homogenous Dirichlet boundary conditions.

---

<div class="post-metadata">

**Author:** ![chenna](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/chenna/32/183_2.png) [@chenna](https://community.freefem.org/u/chenna)\
**Post date:** [June 13, 2020, 4:48pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/3 "2020-06-13T16:48:05Z")

</div>

Hello prj,  
Thank you! Very much appreciate your prompt response!

---

<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:** [June 16, 2020, 11:06am UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/4 "2020-06-16T11:06:56Z")

</div>

remark,

when you compute generalize eigen value problem  
the problem this find smallest eigen value (not all) of  
A u = lambda B u  
if you use generalize inverse mode you compute eigen value  
of compute eigen value of  
A^-1 B u = lambda^-1 u

to remove this problem you just put  
tgv trick on A and no boundary condition on B then you get correct results with non problem.

if you add tgv=-2 on both matrix A, B then you get a lot of eigen values 1 form boundary part,  
and so you have to remove value.

Form me, the tgv technique is very simple and in fact they do not change the condition number a level of  
floating point number.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 16, 2020, 11:42am UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/5 "2020-06-16T11:42:26Z")

</div>

That is not correct to put `tgv = -2` on B, I think. If you put `tgv = -20` on B, then you won’t have spurious eigenvalues.  
Reminder: `tgv = -20` =\> put the complete row and column to 0 (dangerous, singular symmetric system), `tgv = -10` =\> put the complete row to 0 (dangerous, singular nonsymmetric system).

Also, if you solve block systems iteratively, e.g., [[A, B]; [C, D]], and don’t impose Dirichlet boundary conditions exactly, it’s a nightmare with penalization. If you put `tgv = -1` on A and D, and `tgv = -10` on B and C, then no problem.

---

<div class="post-metadata">

**Author:** ![chenna](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/chenna/32/183_2.png) [@chenna](https://community.freefem.org/u/chenna)\
**Post date:** [June 17, 2020, 2:57pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/6 "2020-06-17T14:57:47Z")

</div>

Hello @frederichecht and @prj ,  
Thank you very much for your comments!

I must say that this increased my confusion. I will go through the presentation to understand how these different options work.

I think a cleaner implementation in which only the unknown DOFs are solved would be good idea. Having said that, I can understand that you might have your reasons for following the approach you have implemented now.

---

<div class="post-metadata">

**Author:** ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)\
**Post date:** [June 17, 2020, 3:35pm UTC](https://community.freefem.org/t/application-of-dirichlet-bcs/467/7 "2020-06-17T15:35:38Z")

</div>

Don’t worry, if you want to do elimination, just use `tgv = -1`. The issue raised by Frédéric can be bypassed by some other tgv values, but this is really for power-user.

Just a small remark, Dirichlet unknowns are actual unknowns. If you are referring to an implementation where we’d actually remove the associated rows/columns from the coefficient matrix, then this is usually a bad idea. It requires a lot of bookkeeping (because you need to modify the sparsity pattern of the systems, which is sparse, and operations on sparse matrices are usually slow), for almost zero advantages.
