# PETSc : integrate surface

**URL:** <https://community.freefem.org/t/petsc-integrate-surface/2760>\
**Category:** General Discussion\
**Created:** [October 26, 2023, 8:51am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760 "2023-10-26T08:51:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [October 26, 2023, 8:51am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/1 "2023-10-26T08:51:34Z")

</div>

Dear all,

I would like to calculate a surface with “int2d” but I have fews issues to find the good keyword to not take the overlap

> real Surf = int2d(Th3,1)( 1.0);

give the surface on each local mesh Th3

I try

> mpiAllReduce(Surf,SurfSum,mpiCommWorld, mpiSUM);

but this is sum the element overlap.

Thank you in advance

---

<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:** [October 26, 2023, 1:49pm UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/2 "2023-10-26T13:49:43Z")

</div>

You should either use the partition of unity or generate another mesh without ghost elements.

---

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [October 26, 2023, 2:45pm UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/3 "2023-10-26T14:45:32Z")

</div>

hi, thanks you for your answer.  
In fact, I had tested the solution with a global mesh and integrating only with processor 0

> if (mpirank == 0)  
> real SurfG = int2d(Th3Global,1)( 1. );

But I wanted to try with the partition of unity, and I didn’t know how to get started.

For my solution u, I huse the operator .D but for a real it didn’t works.

---

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [October 26, 2023, 3:44pm UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/4 "2023-10-26T15:44:09Z")

</div>

My objective is to calculate flows in a heat equation.

By operating on a global mesh, I get the right surface calculations. However, my flux calculation (function of dx(u)) is processor-dependent.  
(moreover even with one processor, I didn’t have exactly the same flux at the output as that imposed in my boundary conditions.)  
I’ve attached the code  
[231026\_Exemple.edp](https://community.freefem.org/uploads/short-url/sIvMiJETMDGvczDqPmy8afotv9X.edp) (3.4 KB)

Thank you in advance

---

<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:** [October 27, 2023, 6:01am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/5 "2023-10-27T06:01:09Z")

</div>

What is the issue in this script?

---

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [October 27, 2023, 7:50am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/6 "2023-10-27T07:50:08Z")

</div>

I impose a flow of 500,  
for post-processing calculation with 1 processor

> FluxGTh1 =int2d(Th3Global,101)(eKGlobal\* (dy(sum))  
> FluxGTh1/SurfG = -495.749 [W]

and with 4 processors

> FluxGTh1 =int2d(Th3Global,101)(eKGlobal\* (dy(sum))  
> FluxGTh1/SurfG = -481.749 [W]

I don’t understand why the two calculations give differents results.

---

<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:** [October 27, 2023, 9:58am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/7 "2023-10-27T09:58:51Z")

</div>

Use `-pc_type lu` and you’ll get the proper answer. In the beginning, there is no point in trying fancy preconditioners if you are not sure of what you are doing.

---

<div class="post-metadata">

**Author:** ![agTSL](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@agTSL](https://community.freefem.org/u/agTSL)\
**Post date:** [October 27, 2023, 10:03am UTC](https://community.freefem.org/t/petsc-integrate-surface/2760/8 "2023-10-27T10:03:41Z")

</div>

it works better that way. Thanks you
