# Mixed problems involving 2D meshes and 1D lineic meshes

**URL:** <https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594>\
**Category:** General Discussion\
**Created:** [September 24, 2020, 1:05pm UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594 "2020-09-24T13:05:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.fabre](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@david.fabre](https://community.freefem.org/u/david.fabre)\
**Post date:** [September 24, 2020, 1:05pm UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/1 "2020-09-24T13:05:24Z")

</div>

Dear all  
We are experimenting with the newly introduced 1d lineic meshes.  
We have cases where we have to build matrix block where variable is lineic and test function is surfacic or vice versa.

The first situation works correctly but not the second one… see attached example.

```
 load "isoline"
load "msh3"

// Generating a 2D mesh for a half disk

real R = 1;
border axis(t=-R,R){x=t; y=0;label=6;};
border surface(t=0,pi){x=R*cos(t); y=R*sin(t);label=7;};
mesh Th = buildmesh(axis(20)+surface(30));
plot(Th);

// Extracting the 1D mesh corresponding to the half circle

int[int] l7=[7]; 
meshL Thlin = extract(Th,refedge=l7); //lineic mesh corresponding to boundary 7

// test of mixed problems

fespace Vh(Th,P1); 
fespace Vhlin(Thlin,P1); 

Vh f,g;
Vhlin flin,glin;

varf Test1(flin,g) = int1d(Thlin)(flin*g); 
matrix Mtest1 = Test1(Vhlin,Vh); 

varf Test2(f,glin) = int1d(Thlin)(f*glin);
matrix Mtest2 = Test2(Vh,Vhlin);

```

The error is as follows :  
matrix Mtest2 = Test2(Vh,Vhlin) error operator \<6C\_args\>, \<PP5v\_fes\>, \<PP6v\_fesL\>  
List of choices  
( \<15Call\_FormLinearIN5Fem2D4MeshE5v\_fesE\> : \<6C\_args\>, , \<PP5v\_fes\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshSE6v\_fesS5v\_fesE\> : \<6C\_args\>, \<PP6v\_fesS\>, \<PP5v\_fes\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshLE6v\_fesL5v\_fesE\> : \<6C\_args\>, \<PP6v\_fesL\>, \<PP5v\_fes\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshLE6v\_fesL6v\_fesSE\> : \<6C\_args\>, \<PP6v\_fesL\>, \<PP6v\_fesS\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshSE6v\_fesS6v\_fesLE\> : \<6C\_args\>, \<PP6v\_fesS\>, \<PP6v\_fesL\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshLE6v\_fesLS2\_E\> : \<6C\_args\>, \<PP6v\_fesL\>, \<PP6v\_fesL\> )  
( \<15Call\_FormLinearIN5Fem2D5MeshLE6v\_fesLE\> : \<6C\_args\>, , \<PP6v\_fesL\> )  
( \<17Call\_FormBilinearIN5Fem2D5MeshSE6v\_fesSS2\_E\> : \<6C\_args\>, \<PP6v\_fesS\>, \<PP6v\_fesS\> )  
( \<15Call\_FormLinearIN5Fem2D5MeshSE6v\_fesSE\> : \<6C\_args\>, , \<PP6v\_fesS\> )  
( \<17Call\_FormBilinearIN5Fem2D5Mesh3E6v\_fes3S2\_E\> : \<6C\_args\>, \<PP6v\_fes3\>, \<PP6v\_fes3\> )  
( \<15Call\_FormLinearIN5Fem2D5Mesh3E6v\_fes3E\> : \<6C\_args\>, , \<PP6v\_fes3\> )  
( \<17Call\_FormBilinearIN5Fem2D4MeshE5v\_fesS2\_E\> : \<6C\_args\>, \<PP5v\_fes\>, \<PP5v\_fes\> )

```
 Error line number 29, in file Test_meshL_MixedFormulations.edp, before token )

  current line = 29
Compile error : 
	line number :29, )
error Compile error : 
	line number :29, )
 code = 1 mpirank: 0

```

Thanks for help !  
David & Nabil

---

<div class="post-metadata">

**Author:** ![nabil3achour](https://avatars.discourse-cdn.com/v4/letter/n/f19dbf/32.png) [@nabil3achour](https://community.freefem.org/u/nabil3achour)\
**Post date:** [September 24, 2020, 1:18pm UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/2 "2020-09-24T13:18:10Z")

</div>

Just for information. When we do :

```auto
varf Test2(f,glin) = int1d(Th,7)(f*glin);
matrix Mtest2 = Test2(Vh,Vhlin);

```

We have the same error message.

---

<div class="post-metadata">

**Author:** ![phtournier](https://avatars.discourse-cdn.com/v4/letter/p/3da27b/32.png) [@phtournier](https://community.freefem.org/u/phtournier)\
**Post date:** [September 25, 2020, 8:10am UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/3 "2020-09-25T08:10:03Z")

</div>

Sorry, building matrices from two finite element spaces defined on different mesh types is currently not possible, although it is in the works.  
What you can do however, is define a restriction matrix from the 2D to the 1D finite element space, and use that matrix to define the off-diagonal blocks of your coupled problem:

```auto
load "isoline"
load "msh3"

// Generating a 2D mesh for a half disk

real R = 1;
border axis(t=-R,R){x=t; y=0;label=6;};
border surface(t=0,pi){x=R*cos(t); y=R*sin(t);label=7;};
mesh Th = buildmesh(axis(20)+surface(30));
plot(Th);

// Extracting the 1D mesh corresponding to the half circle

int[int] l7=[7]; 
meshL Thlin = extract(Th,refedge=l7); //lineic mesh corresponding to boundary 7

// test of mixed problems

fespace Vh(Th,P1); 
fespace Vhlin(Thlin,P1); 

Vh f,g;
Vhlin flin,glin;

varf v(f,g) = int2d(Th)(f*g);
varf vlin(flin,glin) = int1d(Thlin)(flin*glin);

matrix A = v(Vh,Vh);
matrix Alin = vlin(Vhlin,Vhlin);

matrix M = interpolate(Vhlin,Vh);

matrix B = M'*Alin;

matrix Block = [[A, B], [B',Alin]];

display(Block);

```

Edit: Since the first situation works, you can also simply take the transpose of Mtest1 for the other off-diagonal block

---

<div class="post-metadata">

**Author:** ![david.fabre](https://avatars.discourse-cdn.com/v4/letter/d/8e8cbc/32.png) [@david.fabre](https://community.freefem.org/u/david.fabre)\
**Post date:** [September 28, 2020, 7:08am UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/4 "2020-09-28T07:08:34Z")

</div>

Thanks for the tip !  
I also realised that I can simply build it in the other way and transpose.  
The ‘interpolate’ solution is fine too ! Some years ago we designed some ugly macros to build such interpolation matrices. Glad to see that it is now built-in.

---

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [September 30, 2024, 3:19am UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/5 "2024-09-30T03:19:55Z")

</div>

Hi, very thanks for your tip with interpolate method to link 1D and 2D finite element space!  
But I meet another problem here… I have a fespace Xh(Th,[P2,P1]) and Xh [u,p], I want to calculate: **varf Test2(flin,[u,p]) = int1d(Thlin)(flin\*p)**

However, I meet the error that:

**Error line number 23, in file test.edp, before token )**  
\*\* Must have 1 or 2 array, one for unknown functions, one for test functions\*\*  
\*\* current line = 23\*\*  
**Compile error : Must have 1 or 2 array, one for unknown functions, one for test**

So I use interpolate method as in this minimal example to calculate Mtest3. But I still have a little puzzle that whether matrix Mtest3 is just what I want as matrix Mtest2?

> load “isoline”  
> load “msh3”  
> // Generating a 2D mesh for a half disk  
> real R = 1;  
> border axis(t=-R,R){x=t; y=0;label=6;};  
> border surface(t=0,pi){x=R_cos(t); y=R_sin(t);label=7;};  
> mesh Th = buildmesh(axis(20)+surface(30));  
> plot(Th);  
> // Extracting the 1D mesh corresponding to the half circle  
> int[int] l7=[7];  
> meshL Thlin = extract(Th,refedge=l7); //lineic mesh corresponding to boundary 7  
> // test of mixed problems  
> fespace Vh(Th,P1);  
> fespace Xh(Th,[P2,P1]);  
> fespace Vhlin(Thlin,P1);  
> Vh f,g;  
> Xh [u,p];  
> Xh [vu,vp];  
> Vhlin flin,glin;  
> varf Test1(flin,g) = int1d(Thlin)(flin\*g);  
> matrix Mtest1 = Test1(Vhlin,Vh);
> 
> //varf Test2(flin,[u,p]) = int1d(Thlin)(flin\*p);  
> //matrix Mtest2 = Test2(Vhlin,Xh);
> 
> varf Test31(flin,glin) = int1d(Thlin)(flin \* glin);  
> varf Test32([u,p],[vu,vp]) = int2d(Th)(p \* vp);  
> matrix Mtest31 = Test31(Vhlin,Vhlin);  
> matrix Mtest32 = Test32(Xh,Xh);  
> matrix M1 = interpolate(Vhlin,Xh);  
> matrix M2 = M1\*Mtest32;  
> matrix Mtest3 = M2’\*Mtest31;

Thanks very much~ (Maybe I should try composite element, but now I want to know more about this detail first)

---

<div class="post-metadata">

**Author:** ![clthu](https://avatars.discourse-cdn.com/v4/letter/c/f04885/32.png) [@clthu](https://community.freefem.org/u/clthu)\
**Post date:** [September 30, 2024, 5:38am UTC](https://community.freefem.org/t/mixed-problems-involving-2d-meshes-and-1d-lineic-meshes/594/6 "2024-09-30T05:38:48Z")

</div>

Hi, this problem is solved. If I use (with “[” and “]”)

> varf Test2([flin],[u,p]) = int1d(Thlin)(flin\*p);  
> matrix Mtest2 = Test2(Vhlin,Xh);

instead of

> varf Test2(flin,[u,p]) = int1d(Thlin)(flin\*p);  
> matrix Mtest2 = Test2(Vhlin,Xh);

then no error message.

Thanks again~
