# How to use union of two different meshes in a single integration? Where I am doing the mistake?

**URL:** <https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841>\
**Category:** General Discussion\
**Created:** [December 21, 2023, 11:34am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841 "2023-12-21T11:34:16Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 21, 2023, 11:34am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/1 "2023-12-21T11:34:16Z")

</div>

int n=32;  
int m=ceil(2_n/pi);  
border C1(t=0,pi){x=cos(t); y=sin(t);label=1;}  
border C2(t=-1,1) {x=t;y=0;}  
border C3(t=-1,1) {x=-t;y=0;}  
border C4(t=pi,2_pi){x=cos(t); y=sin(t);label=2;}  
mesh Th1 = buildmesh(C1(n)+C2(m));  
mesh Th2 = buildmesh(C3(m)+C4(n));  
mesh Th = Th1+Th2;  
plot (Th1,wait=true);  
plot (Th2,wait=true);  
plot (Th,wait=true);  
fespace Vh(Th, P1);  
Vh u, v;// Define u and v as piecewise-P1 continuous functions  
func f= x\*y;  
// Define the PDE  
solve Poisson(u, v, solver=LU)  
= int2d(Th1)(dx(u)\*dx(v)+dy(u)\*dy(v))  
+ int2d(Th2)(dx(u)_dx(v)+dy(u)dy(v))  
- int2d(Th1)(fv)  
- int2d(Th2)(f_v)  
+ on(1,2, u=0); // The Dirichlet boundary condition

// Plot the result  
plot(u,dim=3,value=true,fill=true,ShowAxes=0,ColorScheme =1);

---

<div class="post-metadata">

**Author:** ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)\
**Post date:** [December 22, 2023, 1:15pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/2 "2023-12-22T13:15:36Z")

</div>

No way to compute bilinear form with integrale of on mesh test or unkown function defined on an other mesh. I suggest this to you:

int n=32;  
int m=ceil(2_n/pi);  
border C1(t=0,pi){x=cos(t); y=sin(t);label=1;}  
border C2(t=-1,1) {x=t;y=0;}  
border C3(t=-1,1) {x=-t;y=0;}  
border C4(t=pi,2_pi){x=cos(t); y=sin(t);label=2;}  
mesh Th1 = buildmesh(C1(n)+C2(m));  
mesh Th2 = buildmesh(C3(m)+C4(n));  
mesh Th = Th1+Th2;  
plot (Th1,wait=true);  
plot (Th2,wait=true);  
plot (Th,wait=true);

fespace Vh1(Th1,P1);  
fespace Vh2(Th2,P1);

fespace Vh(Th, P1);  
Vh u, v;

// Define u and v as piecewise-P1 continuous functions  
func f= x\*y;  
// Define the PDE  
solve Poisson(u, v, solver=LU)  
= int2d(Th)(dx(u)\*dx(v)+dy(u)\*dy(v))

- int2d(Th)(dx(u)\*dx(v)+dy(u)\*dy(v))

- int2d(Th1)(f\*v)
- int2d(Th2)(f\*v)

- on(1,2, u=0); // The Dirichlet boundary condition

// Plot the result  
plot(u,dim=3,value=true,fill=true,ShowAxes=0,ColorScheme =1);

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 22, 2023, 1:29pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/3 "2023-12-22T13:29:41Z")

</div>

What are those black dots ? It is not working.  
Still I am getting this error–  
No way to compute bilinear form with integrale of on mesh test or unkown function defined on an other mesh! sorry to hard.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 22, 2023, 1:31pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/4 "2023-12-22T13:31:36Z")

</div>

I want to split the mesh so that I can use different transformations for different sub meshes Th1 and Th2 of Th.

---

<div class="post-metadata">

**Author:** ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)\
**Post date:** [December 22, 2023, 1:44pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/5 "2023-12-22T13:44:34Z")

</div>

sorry it’s the sign “+” and “-”

---

<div class="post-metadata">

**Author:** ![lassounon](https://avatars.discourse-cdn.com/v4/letter/l/bbe5ce/32.png) [@lassounon](https://community.freefem.org/u/lassounon)\
**Post date:** [December 22, 2023, 1:48pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/6 "2023-12-22T13:48:40Z")

</div>

define two subspaces Vh1 and Vh2 of test functions and your solution u=(u1,u2) such that u1 is the restriction of u in Vh1 and u2 the restriction of u in Vh2.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 22, 2023, 1:55pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/7 "2023-12-22T13:55:28Z")

</div>

Dear, I think you haven’t understood my query. Take this example  
int n=32;int m=ceil(n/sqrt(2));  
border C1(t=0,-1){x=t; y=1-t;}  
border C2(t=2,0) {x=-1;y=t;}  
border C3(t=-1,0) {x=t;y=-t-1;}  
border C4(t=-1,1){x=0; y=t;}

border C5(t=1,0){x=t; y=t+1;}  
border C6(t=1,-1) {x=0;y=t;}  
border C7(t=0,1) {x=t;y=t-1;}  
border C8(t=0,2){x=1; y=t;}

mesh Sh1 = buildmesh(C1(m)+C2(n)+C3(m)+C4(n));  
mesh Sh2 = buildmesh(C5(m)+C6(n)+C7(m)+C8(n));  
mesh Sh = Sh1+Sh2;

plot(Sh,wait=true);

mesh Th1 = movemesh(Sh1,[x, y+x]);  
mesh Th2 = movemesh(Sh2,[x, y-x]);  
mesh Th = Th1+Th2;  
plot(Th,wait=true);

Suppose the original problem is to solve the poisson equation in Sh. Now I have splitted Sh into Sh1 and Sh2. I have transformed Sh1 into Th1 and Sh2 into Th2. Now Th1+Th2=Th is a square. I want to solve the poisson equation in a single integral setup. Integration is closure under addition. int\_(Sh1+Sh2)=int\_(Sh1)+int(Sh2). Now you have suggested to use Sh inplace of Sh1 and Sh2. Then how can I use different transformations for Sh1 and Sh2? Remember that border goes to border. Please help.

---

<div class="post-metadata">

**Author:** ![julienG](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/julieng/32/222_2.png) [@julienG](https://community.freefem.org/u/julienG)\
**Post date:** [December 23, 2023, 9:59am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/8 "2023-12-23T09:59:36Z")

</div>

You can use composite finite element spaces: see in the [documentation](https://doc.freefem.org/documentation/composite.html#composite-finite-element-spaces-new). The Stokes problem is on 2 different meshes.

You’ll need version \> 4.13

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [December 24, 2023, 3:47pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/9 "2023-12-24T15:47:36Z")

</div>

To do that you need to user the matrix form through varf.  
See the documentation for more information.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 25, 2023, 10:22pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/10 "2023-12-25T22:22:25Z")

</div>

I am using ffcs-14.3-Win64.exe . You can see here  
[https://www.ljll.math.upmc.fr/lehyaric/ffcs/install.htm](https://www.ljll.math.upmc.fr/lehyaric/ffcs/install.htm)  
Can I use composite fem on freefem cs integrated.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 25, 2023, 10:23pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/11 "2023-12-25T22:23:02Z")

</div>

I am using ffcs-14.3-Win64.exe . You can see here  
[https://www.ljll.math.upmc.fr/lehyaric/ffcs/install.htm](https://www.ljll.math.upmc.fr/lehyaric/ffcs/install.htm)  
Can I use composite fem on freefem cs integrated. Please reply.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [December 26, 2023, 10:31am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/12 "2023-12-26T10:31:48Z")

</div>

This version is very very old, so no!

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [December 27, 2023, 6:46am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/14 "2023-12-27T06:46:18Z")

</div>

Hello Sir,  
I have tried this code in FreeFem version 4.13. Still I am getting error in line number 21.  
[poissonmeshpartition.edp](https://community.freefem.org/uploads/short-url/mAdS1gbiKBY6K9cVXkvcH95SZzZ.edp) (776 Bytes)

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [December 27, 2023, 3:22pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/15 "2023-12-27T15:22:49Z")

</div>

Yes it normal because  
(dx(u1)\*dx(v1) is non linear  
u1, v1 are unknowns fields !

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [January 1, 2024, 6:23am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/16 "2024-01-01T06:23:48Z")

</div>

Dear sir,  
[Poissonwithoutpartition.edp](https://community.freefem.org/uploads/short-url/tHyMBDh5RRKkn7p1Xvyp8pwDudG.edp) (799 Bytes)  
If you look at the above code there is also the non linear term (dx(u)\*dx(v)). But it’s not creating the problem there. u is the finite element solution to be approximated in the fespace Vh and v is the test function in the fespace. Can you please modify the below code of mesh partition  
[poissonmeshpartition.edp](https://community.freefem.org/uploads/short-url/mAdS1gbiKBY6K9cVXkvcH95SZzZ.edp) (776 Bytes)  
It will be a great help if you can help me with this code of mesh partition.

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [January 2, 2024, 1:03pm UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/17 "2024-01-02T13:03:08Z")

</div>

the correction is  
solve Poisson(\<[u1],[u2]\>, \<[v1],[v2]\>)

the first bock in unknown \<[u1],[u2]\> function and the second block \<[v1],[v2]\> is the test functions.

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [January 5, 2024, 1:09am UTC](https://community.freefem.org/t/how-to-use-union-of-two-different-meshes-in-a-single-integration-where-i-am-doing-the-mistake/2841/18 "2024-01-05T01:09:37Z")

</div>

Thank you sir. Now it’s working.
