# Strange behavior on the overlapping region

**URL:** <https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916>\
**Category:** General Discussion\
**Created:** [May 14, 2025, 12:28pm UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916 "2025-05-14T12:28:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![quentin](https://avatars.discourse-cdn.com/v4/letter/q/e47c2d/32.png) [@quentin](https://community.freefem.org/u/quentin)\
**Post date:** [May 14, 2025, 12:28pm UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/1 "2025-05-14T12:28:40Z")

</div>

I am trying to solve a 2D lid-driven cavity in parallel to test numerical schemes. The result sometimes looks strange in the overlapping region. For instance, the code diverges quickly running with `-n 4`, but shows a plausible result with non-overlapping mesh(`-n 0`).

 ![snapshot: run with ff-mpirun -n 4](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/3/33f3a589319c3fc221efdbaa5d822acef84de92a.png)  
Such discrepancies always lead to a divergence.  
I am not sure the reason. suggestions would be appreciated.  
Best regards.

---

<div class="post-metadata">

**Author:** ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)\
**Post date:** [May 14, 2025, 11:05pm UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/2 "2025-05-14T23:05:21Z")

</div>

Such things can happen easily by improperly handling the overlapping parts. However, without the code, it is impossible to help.

---

<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 15, 2025, 5:21am UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/3 "2025-05-15T05:21:49Z")

</div>

See, e.g., the role of the function `exchange()` in [FreeFem-tutorial - Section 8 - example2.edp](https://joliv.et/FreeFem-tutorial/section_8/example2.edp.html) and the named parameter `exchange` in the function `ChangeNumbering()` described slide 50 of [https://joliv.et/FreeFem-tutorial/main.pdf](https://joliv.et/FreeFem-tutorial/main.pdf)

---

<div class="post-metadata">

**Author:** ![quentin](https://avatars.discourse-cdn.com/v4/letter/q/e47c2d/32.png) [@quentin](https://community.freefem.org/u/quentin)\
**Post date:** [May 15, 2025, 7:47am UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/4 "2025-05-15T07:47:19Z")

</div>

Thank you for all your helpful comments.  
I put part of my code below because the whole code is too long:

```auto
    /* u1[]=Au1^-1*rhsu1;
    u2[]=Au2^-1*rhsu2; */
    ChangeNumbering(Au1,rhsu1,u1PETSc);
    ChangeNumbering(Au2,rhsu2,u2PETSc);
    KSPSolve(Au1,u1PETSc,u1xPETSc);
    KSPSolve(Au2,u2PETSc,u2xPETSc);
    ChangeNumbering(Au1,u1[],u1xPETSc, inverse = true, exchange = true);
    ChangeNumbering(Au2,u2[],u2xPETSc, inverse = true, exchange = true);

    UpdateVecDk(u)
    real[int] rhsp=PRHS(0,Mh,tgv=-1);
    /* phi[]=Ap^-1*rhsp; */
    
    ChangeNumbering(Ap,rhsp,pPETSc);
    KSPSolve(Ap,pPETSc,pxPETSc);
    ChangeNumbering(Ap,phi[],pxPETSc, inverse = true, exchange = true);

    dxu1=nu*dx(u1p);
    dyu2=nu*dy(u2p);
    //update p by p=\phi+2p^{n}-p^{n-1}-\nu div(1.5u^{n+1}-2u^{n}+0.5u{n-1})
    p[]=phi[];
    p[]+=pe[];
    p[]-=dxu1[];
    p[]-=dyu2[];

```

The complete code is attached also:  
[Cavity2D.edp](https://community.freefem.org/uploads/short-url/3oUsrSf1HLOT1SEh3U0ZghzOAMz.edp) (6.2 KB)

I think the `exchange=true` argument should make the solution consistent, but the issue remains.

---

<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 15, 2025, 8:01am UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/5 "2025-05-15T08:01:19Z")

</div>

The derivatives won’t be consistent, so you need to exchange those values.

---

<div class="post-metadata">

**Author:** ![quentin](https://avatars.discourse-cdn.com/v4/letter/q/e47c2d/32.png) [@quentin](https://community.freefem.org/u/quentin)\
**Post date:** [May 15, 2025, 10:41am UTC](https://community.freefem.org/t/strange-behavior-on-the-overlapping-region/3916/6 "2025-05-15T10:41:04Z")

</div>

You are right. It is essential to ensure every involved variable to be consistent.  
Now these derivatives are exchanged:

```auto
    dxu1=nu*dx(u1p);
    dyu2=nu*dy(u2p);
    exchange(Ap,dxu1[]);
    exchange(Ap,dyu2[]);

```

Thanks for your insight.
