# Issue with ghost elements

**URL:** <https://community.freefem.org/t/issue-with-ghost-elements/715>\
**Category:** General Discussion\
**Created:** [December 30, 2020, 1:22pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715 "2020-12-30T13:22:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 30, 2020, 1:22pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/1 "2020-12-30T13:22:47Z")

</div>

Dear All,

I am having an issue with the transfer of my variable from one iteration to the next while implementing a number of processes (n)\>1.  
My problem has the addition of material and moving heat source with each iteration. From the youtube videos of freefem, I got to know about some highly efficient functionality such as ‘’’ **restrict & macro Th1N2O() myn2o**// ‘’’ . However, what I lack currently in my code is a way to handle the **ghost nodes in my global solution**.  
With n=1, I am getting good results, whereas, with n=4 as soon my heat source is coming near the ghost nodes, its giving some faulty results.  
Is there some macros or function that can be implemented to handle this?

I am writing some important sections of my code for your understanding.  
Thank you in advance for your help.

Sincerely,

> ThGlobal= readmesh3(“Global.mesh”); // Global Mesh
> 
> Material addition for loop {  
> mesh3 Th1 = trunc(ThGlobal…  
> mesh3 backupTh=Th1;
> 
> fespace Vhbackup(backupTh,P1);  
> int[int] subIDx1=restrict(Vhbackup,Vhglobal,n2o);  
> Vhbackup Tbackup;  
> Tbackup=Tglobal;
> 
> macro dimension()3// EOM  
> include “macro\_ddm.idp”  
> int[int] myn2o;  
> macro Th1N2O() myn2o//  
> buildDmesh(Th1)  
> fespace Vh(Th1,P1);
> 
> int[int] subIDx2=restrict(Vh,Vhbackup,myn2o);  
> Vh T, TT;  
> T=Tbackup;
> 
> load “PETSc”  
> Mat A;  
> createMat(Th1,A,P1)  
> T = A^-1\*b;  
> Tbackup=T;  
> Tglobal=Tbackup;  
> }

---

<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:** [December 30, 2020, 4:02pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/2 "2020-12-30T16:02:21Z")

</div>

Could you please copy/paste a fully runnable example? I think I get what you want to do, but it will much faster for me to help you out if I can actually run your code.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [December 30, 2020, 4:55pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/3 "2020-12-30T16:55:16Z")

</div>

Thank you for your reply.  
I hereby attach the link for my .edp and mesh file.

> **[test - Google Drive](https://drive.google.com/drive/folders/1HqET3tPE17oOCXi7qfBu1XJyHxLP01dx)**

Let me know if the files are not properly shared;

Regards,

---

<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:** [January 2, 2021, 2:02pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/4 "2021-01-02T14:02:17Z")

</div>

Right, you are missing the partition of unity. You can check [this](https://youtu.be/-Aw2O46V2bo?t=5713) tutorial which explains this. If you don’t succeed at applying this to your code, let me know and I’ll do it myself. Thanks.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [January 4, 2021, 1:23pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/5 "2021-01-04T13:23:03Z")

</div>

Dear Prj,  
Thank you for your reply. I have added the partition of unity to my problem and thanks to the partition of unity, ghost nodes are not giving me any issue.  
However, I believe I am having a problem when I am storing the data (in this case T ) from my previous iteration.  
In my case, my _T from the previous iteration acts as an initial condition for my next iteration and there is also an addition of elements at each iteration._

When I compare my result from the iter=0 to the initial condition at iter=1, I am getting a completely different T. Normally, both of them should be equal except for the elements that I added to encounter the material addition.  
When I run for the number of processors (n) 1, the initial condition of my current iteration (Tcurrent.vtu) is the same as my results from the previous iteration (Tbackup.vtu).  
However, for n other than 1, giving faulty result.  
I am certain that it is something trivial issue, I must be doing something foolish.  
Would you be able to see this issue and tell me where I am doing wrong?

Here is the link to my .edp and .mesh file.

> **[test - Google Drive](https://drive.google.com/drive/folders/1HqET3tPE17oOCXi7qfBu1XJyHxLP01dx?usp=sharing)**

Regards

---

<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:** [January 4, 2021, 1:35pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/6 "2021-01-04T13:35:07Z")

</div>

You are missing a reduction operation, which I believe is covered in the video tutorial I sent earlier.

```auto
T[].*=A.D;
Tbackup[](subIDx2)=T[];

```

should become something like

```auto
T[].*=A.D;
real[int] reduction(Tbackup[].n);
reduction(subIDx2)=T[];
mpiAllReduce(reduction,Tbackup[],mpiCommWorld,mpiSUM);

```

Otherwise, the processes don’t share the same values (when `mpisize > 1`) and you get garbage for the next iteration.

---

<div class="post-metadata">

**Author:** ![Mik](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@Mik](https://community.freefem.org/u/Mik)\
**Post date:** [January 4, 2021, 2:26pm UTC](https://community.freefem.org/t/issue-with-ghost-elements/715/7 "2021-01-04T14:26:40Z")

</div>

**Thanks a lot for your quick reply.** Indeed, I missed the reduction operator.

**Thank you for your help, everything is working perfectly.**

Have a good day ahead. Sincere Regards.
