# Composite spaces, on() and tgv=-1

**URL:** <https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579>\
**Category:** General Discussion\
**Created:** [November 13, 2024, 11:19am UTC](https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579 "2024-11-13T11:19:12Z")\
**Posts on this page:** 4\
**Page:** 1

<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:** [November 13, 2024, 11:19am UTC](https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579/1 "2024-11-13T11:19:12Z")

</div>

It seems that there is a bug on composite spaces when using them with Dirichlet BC set with on() and tgv=-1.  
In the example of “Stokes with P2-iso-P1 elements” given in the documentation, setting tgv=-1 gives a wrong result.  
Writing the matrix by blocks  
M=\pmatrix{A & B \\ B^T & C},  
the lines of A corresponding to an index i involved in the boundary condition are set correctly with 1 on the diagonal and zero otherwise.  
But the line i of B should be set to zero and it is not the case.

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [November 13, 2024, 12:10pm UTC](https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579/2 "2024-11-13T12:10:55Z")

</div>

That is indeed a bug, thank you for reporting it. I will let you know when it is fixed.

---

<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:** [November 13, 2024, 1:00pm UTC](https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579/3 "2024-11-13T13:00:48Z")

</div>

Thank you.  
Here is indeed a simplified test code to see the problem

```auto
int nn = 1; // number of edge in each direction
mesh Th=square(nn,nn);
//savemesh(Th,"mesh.msh");
//plot(Th,wait=true);

fespace Vh(Th,P1);
fespace Xh=Vh*Vh;

tgv=-1;
varf test(<[u],[p]>,<[v],[q]>)
=
//-int2d(Th)(u*v)
//int2d(Th)(p*q)
//int2d(Th)(-u*q)
int2d(Th)(-p*v)
+int2d(Th)(v-q)
+on(1,u=1)
;

matrix M = test(Xh,Xh);
real[int] b = test(0,Xh);
//set(M,solver=UMFPACK);

cout << "M= " << M << endl;
cout << "b= " << b << endl;

```

---

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [December 18, 2024, 7:28am UTC](https://community.freefem.org/t/composite-spaces-on-and-tgv-1/3579/4 "2024-12-18T07:28:58Z")

</div>

Hi professor,

Much thanks for this discussion that help me find the bugs when I do an ALE problem, I first use tgv=-1 and forget to enforce the boundary condition to the off-diagonal block of the Jacobian matrix, the convergency of Newton iteration is very slow.

My method is to set tgv=1e30, not exact Dirichlet boundary condition but the results are acceptable and easy to do parallel computation, not needed to update varf or Mat. Another way I find is to zero-out the corresponding rows in the off-diagonal block by hand, as in this post [https://community.freefem.org/t/preferred-way-to-construct-block-matrices-with-exact-dirichlet-bc-tgv-1/222/2](https://community.freefem.org/t/preferred-way-to-construct-block-matrices-with-exact-dirichlet-bc-tgv-1/222/2).
