# Mixed finite element(PETSc),how to solve

**URL:** <https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960>\
**Category:** General Discussion\
**Created:** [August 24, 2022, 1:15pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960 "2022-08-24T13:15:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 24, 2022, 1:15pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/1 "2022-08-24T13:15:46Z")

</div>

Hello, I have seen the following example of mixed finite element. In fact, there are two unknowns, u and p, but this example does not solve p,

varf vMixedLaplace([u1, u2, p], [v1, v2, q]) = int2d(Th)(u1 \* v1 + u2 \* v2 + p\*(dx(v1) +  
dy(v2)) + (dx(u1) + dy(u2))_q)  
+ int2d(Th)(q)  
- int1d(Th, 1, 2, 3)(v1_N.x + v2\*N.y)  
+ on(4, u1 = 1.0, u2 = 1.0);

real[int] rhs = vMixedLaplace(0, Wh, tgv = -1);  
Mat A(Wh.ndof, intersection, D);  
A = vMixedLaplace(Wh, Wh, tgv = -1);  
set(A, sparams =“-pc\_type lu”);  
Wh def(u);  
u = A^-1 \* rhs;  
[laplace-RT-2d-PETSc.edp](https://community.freefem.org/uploads/short-url/vpNjGPuAIMZLzfSPfFaX5UZfpXZ.edp) (2.6 KB)

---

<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:** [August 24, 2022, 1:17pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/2 "2022-08-24T13:17:24Z")

</div>

It does solve u, v, and p at the same time.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 24, 2022, 1:22pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/3 "2022-08-24T13:22:32Z")

</div>

> [@Qianrui](#):
>
> u = A^-1 \* rhs

Thank you for your answer. The command u = A ^ - 1 \* rhs. Is u here an unknown quantity or an array of u, v and p? Or p = A ^ - 1 \* rhs?

---

<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:** [August 24, 2022, 1:24pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/4 "2022-08-24T13:24:47Z")

</div>

Using `u[]` or `p[]` will result in the same thing. Please read the documentation to understand how to handle mixed finite elements in FreeFEM and how to retrieve a single component.

---

<div class="post-metadata">

**Author:** ![Qianrui](https://avatars.discourse-cdn.com/v4/letter/q/9fc348/32.png) [@Qianrui](https://community.freefem.org/u/Qianrui)\
**Post date:** [August 25, 2022, 12:57am UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/5 "2022-08-25T00:57:28Z")

</div>

Hello, I read **FreeFem Documentation Release 4.8**. On page 539, I read Poisson with mixed finite, but the mixed finite element solution uses **problem** , and I can’t find the mixed finite element solution using **varf**.

.

---

<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:** [August 30, 2022, 6:12pm UTC](https://community.freefem.org/t/mixed-finite-element-petsc-how-to-solve/1960/6 "2022-08-30T18:12:19Z")

</div>

Just look at the examples, e.g., [FreeFem-sources/natural-convection-fieldsplit-2d-PETSc.edp at master · FreeFem/FreeFem-sources · GitHub](https://github.com/FreeFem/FreeFem-sources/blob/master/examples/hpddm/natural-convection-fieldsplit-2d-PETSc.edp#L112).
