# How to use mean-zero pressure space in FreeFem

**URL:** <https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570>\
**Category:** General Discussion\
**Created:** [November 2, 2024, 7:02am UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570 "2024-11-02T07:02:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [November 2, 2024, 7:02am UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/1 "2024-11-02T07:02:22Z")

</div>

![Space](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/e/ec4e391b79dcd626e8e0f9ddd33ef5c52124b8e3.png)  
It will be very helpful if anyone can explain how to use mean-zero pressure space in Free Fem. I am talking about the space M\_h0 in the attached file.

---

<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 2, 2024, 10:56am UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/2 "2024-11-02T10:56:43Z")

</div>

You have to use a constraint and a Lagrange multiplier,  
as in [Error convergence on Stokes problem](https://community.freefem.org/t/error-convergence-on-stokes-problem/3550)  
The Lagrange multiplier \lambda is a constant in space, and \mu is the associated test constant, that sets the constraint. To do it correctly you have to define a block matrix as in the FreeFem doc p.671 “Lagrange Multipliers”.

---

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [November 2, 2024, 12:30pm UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/3 "2024-11-02T12:30:27Z")

</div>

Is there any other way of doing it, without defining a block matrix?, like adding -int2d(Th)(eps p q) where eps=1e-6.

---

<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 2, 2024, 3:36pm UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/4 "2024-11-02T15:36:42Z")

</div>

Yes, this determines a unique pressure, in a stable way. But it is not equivalent to setting \int p=0. The two methods give two pressures p\_1 and p\_2, such that p\_2-p\_1=cst\not=0.  
If you like you can then subtract to the pressure its average value, so that you get a pressure with vanishing integral at the end.

---

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [November 4, 2024, 12:34pm UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/5 "2024-11-04T12:34:12Z")

</div>

```auto
problem PHI(phi,q)=
	int2d(Th)(dt*(dx(phi)*dx(q)+dy(phi)*dy(q)))
	+intalledges(Th)(dt*(nTonEdge-1)*(dx(phi)*N.x+dy(phi)*N.y)*jump(q)/nTonEdge)
	+intalledges(Th)(dt*(nTonEdge-1)*(dx(q)*N.x+dy(q)*N.y)*jump(phi)/nTonEdge)
	+intalledges(Th)(dt*(nTonEdge-1)*(pena1/lenEdge)*jump(phi)*jump(q))
	-int2d(Th) (eps*phi*q)

```

This is a portion of the code I am working on. Here phi and q belong to M\_h0 space; I have added that term I mentioned earlier but didn’t get the part where you said to subtract it’s average value. And I also think we need to do it for q also, right?

---

<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 4, 2024, 5:35pm UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/6 "2024-11-04T17:35:09Z")

</div>

I thought that you were dealing with a Stokes like problem, but it is not the case.  
For your problem, you simply put  
`+int2d(Th) (eps*phi*q)`  
with a “+” sign, it gives directly your solution phi with vanishing integral.  
There is nothing to modify for q, because adding a constant to q encodes the property that \int\phi=0.

---

<div class="post-metadata">

**Author:** ![Ravi](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/ravi/32/2468_2.png) [@Ravi](https://community.freefem.org/u/Ravi)\
**Post date:** [December 9, 2024, 8:43am UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/7 "2024-12-09T08:43:12Z")

</div>

Actually, sir, I am using this in the pressure projection method for the incompressible Navier-Stokes equation. This is an intermediate step to solve phi. Will this still be okay?

---

<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:** [December 9, 2024, 9:20am UTC](https://community.freefem.org/t/how-to-use-mean-zero-pressure-space-in-freefem/3570/8 "2024-12-09T09:20:13Z")

</div>

Yes, I don’t see any possible problem.
