# Vectorial PDE, conditions, stiffness matrix

**URL:** <https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543>\
**Category:** General Discussion\
**Created:** [October 12, 2024, 12:31pm UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543 "2024-10-12T12:31:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pi.3.141etc](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pi.3.141etc](https://community.freefem.org/u/pi.3.141etc)\
**Post date:** [October 12, 2024, 12:31pm UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/1 "2024-10-12T12:31:06Z")

</div>

Hello FreeFem community,  
I am looking for how to impose conditions in vectorial PDE problems.

More preciesely, I am working on a NS problem. Assuming my variables are [u,v,p], in a domain, say [0,2]x[0,1], I look for how to impose conditions like:

- u=A in [1,2]x[0,1],
- v=B in [0,1]x[0,1],
- p=C on the segment [0,0]-[2,1],

where A, B, C are constants (or functions; these conditions are just for the purpose of presenting the question and we let aside any related mathematical issue).

For scalar problems. say wrt u, I can easily impose my condition - by identifying the index of nodes involved in the condition for u and modifying accordingly the stiffness matrix M and the Rhs vector.

For vectorial problems I can proceed similarly, but I need to know the precise structure of M. For example, to set

- u(X(i))=A,
- v(X(j))=B,
- p(X(k))=C.

Namely, is the matrix organised as N blocks of 3, or 3 blocs of N? So should I do:

- M(3_i,3_i) = M(3_j+1,3_j+1) = M(3_k+2,3_k+2) = tgv,
- M(i,i) = M(N+j,N+j) = M(2_N+k,2_N+k) = tgv,
- or ?

Here, N=number of nodes (so M is a (3_N)x(3_N) matrix).

Thank you for your help.

ps: For convenience, here is a piece of code I use  
// domain, mesh, FE spaces  
//  
mesh Th = square(20,10, [2\*x, y]); // rectangle [0,2]x[0,1]  
fespace Vh(Th,P1b);  
fespace Qh(Th,P1);  
fespace Zh(Thf,[P1b,P1b,P1]);  
//  
varf a([u,v,p],[uh,vh,ph])  
= int2d(Th)(…) + on(1, u=Cu) + on(2,v=Cb)+…;  
//  
matrix A(Zh,Zh);  
//////  
A(i,i)=tgv; // ?  
// … ?

---

<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:** [October 14, 2024, 6:38am UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/2 "2024-10-14T06:38:27Z")

</div>

Degrees of freedom are interleaved, so it’s like `N blocks of 3`, but not exactly, because you are using different `fespace`s for the velocities and pressure.

---

<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:** [October 14, 2024, 6:40am UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/3 "2024-10-14T06:40:58Z")

</div>

Also, don’t forget to do a search on the forum before posting, this is a recurring question with many available answers, e.g., [Order of variables in matrix generated with varf with a [P1, P1, P0] fespace](https://community.freefem.org/t/order-of-variables-in-matrix-generated-with-varf-with-a-p1-p1-p0-fespace/3489/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:** [October 14, 2024, 6:45am UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/4 "2024-10-14T06:45:48Z")

</div>

Hello,  
Here you can do simply as adding in your varf  
`+int2d(Th,labreg)(tgv*u*uh)`  
and a similar term for the rhs, where `labreg` is the label of your region.

If you don’t like to define region labels you can do (for the left region x\<1)

```auto
fespace Vh0(Th,P0);
Vh0 regl;
regl=(x<1. ? 1. : 0.);

```

and use  
`+int2d(Th)(tgv*u*uh*regl)`

It is not easy to handle what happens close to the interface between the regions, since usually u is in a space imposing continuity.

---

<div class="post-metadata">

**Author:** ![pi.3.141etc](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pi.3.141etc](https://community.freefem.org/u/pi.3.141etc)\
**Post date:** [October 14, 2024, 10:53am UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/5 "2024-10-14T10:53:57Z")

</div>

Thank you for suggesting this elegant solution.

---

<div class="post-metadata">

**Author:** ![pi.3.141etc](https://avatars.discourse-cdn.com/v4/letter/p/ac8455/32.png) [@pi.3.141etc](https://community.freefem.org/u/pi.3.141etc)\
**Post date:** [October 14, 2024, 10:56am UTC](https://community.freefem.org/t/vectorial-pde-conditions-stiffness-matrix/3543/6 "2024-10-14T10:56:42Z")

</div>

Thank you for the answer and the references.
