# Preferred way to construct block matrices with exact Dirichlet BC (tgv = -1)?

Hello,

I have a composite system with several overlapping FE spaces which I construct in blocks using independent variational forms for each space and then assembling them all into a large block matrix. I would like to enforce exact Dirichlet conditions without penalization (e.g. by using tgv = -1). However, the best way I can think of doing this is after the matrix assembly by “zeroing out” all of the rows associated with boundary DOF’s where Dirichlet conditions are enforced and then setting the diagonal terms to 1.

I would really prefer to use the “on()” function to do this without having to do all the bookkeeping for the boundary DOF’s. Is there a way to use “on()” to enforce zero rows in rectangular matrices? Or is there another preferred way to construct block matrices with Dirichlet BC’s?

Thanks!

1 Like

What bookkeeping are you talking about? We could add a new `tgv = -3` to handle this (I wanted to do this for a long time), but in the meantime, you can just impose on your off-diagonal blocks something like:

``````varf vGamma(u, v) = on(gamma, u = 1);
real[int] marker = vGamma(0, Vh, tgv = -1);
for[i,j,v : offdiagonal] if(marker[i] > 0.1)) v = 0.0;
``````
1 Like

Also relevant, look at this post:
https://community.freefem.org/t/implementation-of-dirichlet-boundary-condition-when-tgv-1/113

1 Like

Thanks @prj! The “bookkeeping” I was referring to is what your solution addresses. Namely, defining extra vectors to flag the row indices associated with Dirichlet BC’s and then looping back through each matrix block to zero out the flagged rows.