# Parallelize Navier Stokes with moving boundary

**URL:** <https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904>\
**Category:** General Discussion\
**Created:** [May 6, 2025, 1:18pm UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904 "2025-05-06T13:18:26Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 6, 2025, 1:18pm UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/1 "2025-05-06T13:18:26Z")

</div>

Dear all,

I already implement the sequential version of NS equation with moving boundary in FreeFem++, the code is  
[sequential\_moving\_boundary.edp](https://community.freefem.org/uploads/short-url/rSany5pi0kxo4Scg40PQNx3qwsm.edp) (2.4 KB)

Now I want to parallelize it using PETSc, just change little, for example changing matrix to Mat. And it shows error like this on my Windows machine

 ![c1bb8c642a48815c8c64dfe72fe8d0d](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/7/78a5430a1839ce0e3d70551a8b000e751bc4bab4.png)

and the parallel version code is  
[parallel\_moving\_boundary.edp](https://community.freefem.org/uploads/short-url/lTqPrIJKrevzEnqYvdmXyuFYj0b.edp) (2.5 KB)

Can anyone give me any advice? Many thanks.

---

<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:** [May 7, 2025, 5:58pm UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/2 "2025-05-07T17:58:38Z")

</div>

Your `A` is uninitialized line 59, so you need to fix that.

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 8, 2025, 1:07am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/3 "2025-05-08T01:07:49Z")

</div>

Thank you for your reminder, Professor. It’s a stupid mistake. I have fixed the initialization of Mat like this

 ![478ce636f6282860726af331927f13d](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/9/933795a23be038fb93e486c427aa335b54afb1df.png)

However, there still exists error as shown below

 ![55fda1e1b5b2c1399e7a51dc1b076fb](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/a2e7307cba48147b5e8a999403f6ccd8ccfd260d.png)

Do you know what’s wrong? Thanks a lot.  
[parallel\_moving\_boundary\_2.edp](https://community.freefem.org/uploads/short-url/bsRZZ249cm8TTPq2Vas1zvssugW.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:** [May 8, 2025, 7:18am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/4 "2025-05-08T07:18:11Z")

</div>

You are trying to initialize with the same macro a `Mat` with two fields and another one with three fields, hence the error.

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 12:46am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/5 "2025-05-10T00:46:27Z")

</div>

Sorry for my late reply. Thank you very much for your reply. It’s another stupid mistake. Now I fix it as following

 ![aa02dfd0a5f492276e21a117fea2dc6](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/1/14f1c45e806957c589b7a5ad1fa00639dfda4205.png)

And it’s the latest code  
[parallel\_moving\_boundary\_3.edp](https://community.freefem.org/uploads/short-url/u1PFHdfze3nTxuxirza1aHNIkSE.edp) (2.7 KB)

However, there still exists error shown as

 ![caca6189208655252ba486e6d51f2d7](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/309b34d13d3b4e816ad7836b61ef84563ac924a4.png)

Do you know the reason?

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 12:56am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/6 "2025-05-10T00:56:30Z")

</div>

Sorry, I know the reason for the last error. It was because I entered the wrong file name. This time, the specific error occurred as the following

 ![caca6189208655252ba486e6d51f2d7](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/309b34d13d3b4e816ad7836b61ef84563ac924a4.png)

Do you know its reason?

---

<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:** [May 10, 2025, 5:41am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/7 "2025-05-10T05:41:42Z")

</div>

This is the exact same error.

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 6:02am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/8 "2025-05-10T06:02:27Z")

</div>

Thank you very much for your reply. Now my code can be run  
[parallel\_moving\_boundary\_3.edp](https://community.freefem.org/uploads/short-url/nqw0fPYVer4XfVZEg8gTP4FKtBl.edp) (2.7 KB)  
But it looks not converge

Apptainer\> ff-mpirun -n 10 parallel\_moving\_boundary\_3.edp -wg -v 0  
‘/usr/freefem/ff-petsc/r/bin/mpiexec’ -n 10 /usr/freefem/bin/FreeFem+±mpi -nw ‘parallel\_moving\_boundary\_3.edp’ -wg -v 0  
KSP final norm of residual 4.42545e+15  
KSP final norm of residual 2.2619e+15  
NS Time: 0.001  
KSP final norm of residual 1.03851e+16  
KSP final norm of residual 3.69771e+15  
NS Time: 0.002  
KSP final norm of residual 1.58529e+16  
KSP final norm of residual 7.00204e+15

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 6:07am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/9 "2025-05-10T06:07:11Z")

</div>

It can be run in my Linux machine with’ff-mpirun’, but it still exists errors on my computer machine with ‘mpiexec -n freefem+±mpi’

---

<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:** [May 10, 2025, 6:35am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/10 "2025-05-10T06:35:53Z")

</div>

Probably because you are using the default `tgv` value.

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 7:39am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/11 "2025-05-10T07:39:22Z")

</div>

Thank you very much, professsor. I change ‘tgv=-1’, and then it truly converges

 ![Screenshot from 2025-05-10 08-39-04](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/a4792bd25cecb466fb7200546d9aa1fd0ca97c14.png)

---

<div class="post-metadata">

**Author:** ![zxss](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zxss](https://community.freefem.org/u/zxss)\
**Post date:** [May 10, 2025, 7:12pm UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/12 "2025-05-10T19:12:37Z")

</div>

Dear professor, I have one last question, that is I find it calculates very slowly with ‘-pc\_type lu’, is there other options can accelerate?

---

<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:** [May 11, 2025, 5:07am UTC](https://community.freefem.org/t/parallelize-navier-stokes-with-moving-boundary/3904/13 "2025-05-11T05:07:40Z")

</div>

A proper preconditioner could help things out.
