# La matrice de raideur lorsque la solution est un champ vectoriel

**URL:** <https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884>\
**Category:** General Discussion\
**Created:** [April 25, 2025, 9:17pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884 "2025-04-25T21:17:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![redaAkhdi](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@redaAkhdi](https://community.freefem.org/u/redaAkhdi)\
**Post date:** [April 25, 2025, 9:17pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/1 "2025-04-25T21:17:05Z")

</div>

comment recuperer la matrice de raideur lorsque la solution est un champ vectoriel ?  
voila mon code que je developpe  
// Définir la forme variationnelle pour la matrice de raideur  
varf a([u, v], [w, s]) = int2d(th)(  
lambda \* div(w, s) \* div(u, v)  
+ 2. \* mu \* ( epsilon(w, s)’ \* epsilon(u, v) )  
)  
+ on(4, u = 0, v = 0);

// Définir la forme variationnelle pour le vecteur de charges  
varf L([uu, vv], [w, s]) = int1d(th, 2)(P \* w);

---

<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:** [April 26, 2025, 10:03am UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/2 "2025-04-26T10:03:08Z")

</div>

Hello,  
You have an example here:

> [@Traction Forces - BilinearOperator NM error](https://community.freefem.org/t/traction-forces-bilinearoperator-nm-error/3857/4):
>
> The problem is that the space Vh you give in matrix A = avar(Vh, Vh, tgv = -1) has not the right size, since varf avar([ur, uz], [vr, vz]) has two unknowns ur,uz. You have to set fespace Vh2(Th,[P1,P1]); Vh2 [u1,u2]; The space Vh2 has the right size. Then you correct your system resolution by matrix A = avar(Vh2, Vh2, tgv = -1); // System matrix real[int] b = Lrhs(0, Vh2); // Right-hand side vector set(A, solver = sparsesolver); real[int] sol = A^-1 \* b; u1[]=sol;// dist…

---

<div class="post-metadata">

**Author:** ![redaAkhdi](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@redaAkhdi](https://community.freefem.org/u/redaAkhdi)\
**Post date:** [April 26, 2025, 10:36am UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/3 "2025-04-26T10:36:05Z")

</div>

// Paramètres  
int n = 100;  
real rayon = 5;  
real E = 210; // en GPa  
real sigma = 0.2;  
real P = 1.; // traction en MPa

// Bords du carré (sens trigonométrique)  
border a(t = -20, 20){ x = t; y = -20; label = 1; } // bas  
border b(t = -20, 20){ x = 20; y = t; label = 2; } // droite  
border c(t = 20, -20){ x = t; y = 20; label = 3; } // haut  
border d(t = 20, -20){ x = -20; y = t; label = 4; } // gauche

// Trou circulaire au centre (sens horaire pour le trou intérieur)  
border cercle(t = 0, 2\*pi){ x = rayon \* cos(t); y = rayon \* sin(t); label = 5; }

mesh th = buildmesh(b(n) + c(n) + d(n) + a(n) + cercle(-n));

// Espace  
fespace Vh(th, [P1, P1]);

// Déformation & divergence  
real sqrt2 = sqrt(2.);  
macro epsilon(u1, u2) [dx(u1), dy(u2), (dy(u1)+dx(u2))/sqrt2] //  
macro div(u,v) (dx(u) + dy(v)) //

// Paramètres matériaux  
real mu = E/(2\*(1+sigma));  
real lambda = E_sigma/((1+sigma)_(1-2\*sigma));

// Définir la forme variationnelle pour la matrice de raideur  
varf a([u, v], [w, s]) = int2d(th)(  
lambda \* div(w, s) \* div(u, v)

- 
  1. 
    - mu \* ( epsilon(w, s)’ \* epsilon(u, v) )  
)

- on(4, u = 0, v = 0);

// Définir la forme variationnelle pour le vecteur de charges  
varf L([uu, vv], [w, s]) = int1d(th, 2)(P \* w);

// Assemblage  
matrix K = avar(Vh2, Vh2, tgv = -1); // Matrice du système  
real[int] b = Lrhs(0, Vh2); // Vecteur second membre

// Export K vers fichier CSV  
ofstream fk(“kk.csv”);  
for (int i = 0; i \< K.n; ++i)  
for (int j = 0; j \< K.n; ++j)  
if (abs(K(i,j)) \> 1e-14) // ignorer les zéros  
fk \<\< i \<\< " " \<\< j \<\< " " \<\< K(i,j) \<\< endl;

// Export rhs vers fichier CSV  
ofstream fp(“pp.csv”);  
for (int i = 0; i \< rhs.n; ++i)  
fp \<\< b[i] \<\< endl;

// Exporter les coordonnées des sommets  
ofstream fxy(“xy.csv”);  
for (int i = 0; i \< th.nv; ++i) {  
fxy \<\< th(i).x \<\< " " \<\< th(i).y \<\< endl;  
}  
il me donne une erreur de compilation à la ligne 36 a cause d,un point virgule !  
aidez moi s’il vous plais

---

<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:** [April 26, 2025, 5:28pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/4 "2025-04-26T17:28:25Z")

</div>

the error message says “The identifier a exists”.  
Your varf needs another name instead of “a” because “a” is a border in your code.  
 → call it “avar” “`varf avar([u, v], [w, s]) =`…”  
Then the name “Vh2” has to be replaced by “Vh”  
“Lrhs” has to be replaced by “L”  
“b” needs also another name that you need to choose, different from the variables you already have in your code (“b” is a border in your code).

---

<div class="post-metadata">

**Author:** ![redaAkhdi](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@redaAkhdi](https://community.freefem.org/u/redaAkhdi)\
**Post date:** [April 26, 2025, 7:02pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/5 "2025-04-26T19:02:39Z")

</div>

Merciiiiiii merciiiiiii beaucoup 🙏🏻🤍

---

<div class="post-metadata">

**Author:** ![redaAkhdi](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@redaAkhdi](https://community.freefem.org/u/redaAkhdi)\
**Post date:** [April 30, 2025, 8:20pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/6 "2025-04-30T20:20:59Z")

</div>

Bonjour Mr  
j’espère que vous allez bien et en bon santé  
Si je veux récupérer la matrice de raideur, quelle est la différence entre :

varf avar([u, v], [w, s]) = int2d(th)(  
lambda \* div(w, s) \* div(u, v)

- 
  1. 
    - mu \* (epsilon(w, s)’ \* epsilon(u, v))  
)

- on(1, u = 0, v = -1)
- on(5, u = 0, v = 0);

// Assemblage  
matrix K = avar(Vh, Vh, tgv = -1); // Matrice du système

(((((( et les cas où tgv = 1 et tgv = 0 ? )))))))

---

<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:** [May 1, 2025, 2:39pm UTC](https://community.freefem.org/t/la-matrice-de-raideur-lorsque-la-solution-est-un-champ-vectoriel/3884/7 "2025-05-01T14:39:51Z")

</div>

The effect of the value of `tgv` for Dirichlet boundary condition is explained in the documentation

> **[Finite element](https://doc.freefem.org/documentation/finite-element.html#weak-form-and-boundary-condition)**

in the “Note” just before the section “Numerical Integration”.  
`tgv=-1` is the most accurate, it replaces the lines of the linear system corresponding to degrees of freedom of the test function on the considered boundary, by the exact equation u=Dirichlet value.  
tgv=large value (1e30 is the default) uses a penalty term similar to tgv\*\int\_\Gamma (u-u\_D)\*w, where w is the test function.
