# Partition matrices for a coupled problem

**URL:** <https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375>\
**Category:** General Discussion\
**Created:** [April 29, 2020, 8:52am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375 "2020-04-29T08:52:45Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [April 29, 2020, 8:52am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/1 "2020-04-29T08:52:45Z")

</div>

Hi,

I want to solve a coupled problem of vibro-acoustic. The variationnal formulation gives me 5 matrices, (K,M) for elasticity, (H,Q) for acoustic and C the coupled matrix. Then we obtain two global matrices :  
Kglob = [K -C]  
[0 H]  
Mglob = [M 0]  
[C’ Q]

And we solve :  
Kglob -omega^2\*Mglob = RHS

To solve that I tried to proceed as follows:

%----------------------------------------------------------------------------------  
//Th is load from gmsh 3d

fespace VhS(Th, [P1,P1,P1]); // elasticity  
VhS [u1,u2,u3], [v1,v2,v3];

fespace VhF(Th, P1); // acoustic  
VhF p,v;

//Solid  
varf k([u1,u2,u3], [v1,v2,v3]) = int3d(Th, 5)( … ); //5 refers to elastic medium  
varf m(…) = …

varf h(p, v) = int3d(Th, 4)( … );  
varf q(…) = …

matrix K = k(VhS, VhS);  
matrix M = …

matrix H = h(VhF, VhF)  
matrix Q = …  
%----------------------------------------------------------------------------------

Then I export the matrices but the shape of each matrix is (n x ndof,n x ndof) (n = 3 for elasticity and n = 1 for acoustic). The problem is that ui = 0 in air medium, the same for pressure in elastic medium…which creates a singular LHS after assembly.

My question : Is there a way to build the matrices on their respective medium and only get interesting nodes values, not all the nodes of the mesh ? This way to proceed implies to extract the nodes of each medium by the way…

Maybe there’s an easier way to proceed ?

I hope this is clear enought…

Thank you,  
Julien

---

<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:** [April 29, 2020, 3:20pm UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/2 "2020-04-29T15:20:58Z")

</div>

It is possible. For example, you can use `trunc` to get only the mesh for the elastic medium, and assemble K and M there using another `fespace`. If you want help to run this in parallel, I can write this for you if you’re OK that I put the script on FreeFEM GitHub afterwards. Here is for example such a [coupling](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/hpddm/helmholtz-coupled-2d-PETSc-complex.edp#L171-L172) done in parallel.

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [April 29, 2020, 7:27pm UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/3 "2020-04-29T19:27:24Z")

</div>

Thank you for this quick answer !

the function “trunc” can be difficult to use in my case given the fact that I could not be able to define the boolean function required.

Is it possible to define a boolean function just with a label (the one of the medium) ?

Concerning the parallelization, it would be really interesting given the fact that I will have to test some case with more than 1 000 000 dof. I will look at the script for the parallelization, thank you !

PS : the system will be solved with Matlab, only the matrices are calculated with FreeFem.

In case anyone need, the file is here : [https://github.com/GrinCa/vibroacoustic](https://github.com/GrinCa/vibroacoustic)

---

<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:** [April 29, 2020, 7:39pm UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/4 "2020-04-29T19:39:57Z")

</div>

How do you solve your system? Why don’t you use FreeFEM to solve the linear system?  
You can just do `trunc(ThS, region == 4)`, for example.

You problem is actually solved in [this](https://doc.freefem.org/models/fluid-structure-coupled-problem.html) example. I thought you had a more difficult discretisation.

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [April 30, 2020, 5:45am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/5 "2020-04-30T05:45:38Z")

</div>

There a model reduction order implemented on Matlab, which implies to calculate symbolic derivatives, that’s why I use Matlab. This variationnal formulation aim to be more complex, with damping model for both elaticity and acousic…

Thank you for this precious help !

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [May 14, 2020, 7:22am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/6 "2020-05-14T07:22:54Z")

</div>

Dear prj,

I tried to trunc my mesh but I get this error at the compilation :

Assertion fail : (ie == nbe)  
line :7364, in file msh3.cpp  
Assertion fail : (ie == nbe)  
line :7364, in file msh3.cpp  
err code 6 , mpirank 0

The beggining of my code is :

load “msh3” //  
load “gmsh” //  
load “iovtk” //

mesh3 Th = gmshload3(“Plate.msh”);

int embedding = 1;  
int coupling = 2;  
int extpressure = 3;  
int acoustic = 4;  
int elastic = 5;

mesh3 Th3 = trunc(Th, region==acoustic);

I also tried to replace acoustic by its number 4, but it still doesn’t work. I check the label as well, FreeFem can calculate integrals with these labels.

Could you enlighten me please ?

---

<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 14, 2020, 8:16am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/7 "2020-05-14T08:16:48Z")

</div>

Could you share your `.geo` or `.msh`, please?

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [May 14, 2020, 8:43am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/8 "2020-05-14T08:43:57Z")

</div>

Here you can find the .geo file : [https://github.com/GrinCa/vibroacoustic/tree/master](https://github.com/GrinCa/vibroacoustic/tree/master)

Gmsh version : 3.0.6  
FreeFem version : 4.1

---

<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 14, 2020, 9:14am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/9 "2020-05-14T09:14:56Z")

</div>

You do not have a surface label for the `acoustic` volume so FreeFEM can’t process the mesh.

---

<div class="post-metadata">

**Author:** ![Julien](https://avatars.discourse-cdn.com/v4/letter/j/71e660/32.png) [@Julien](https://community.freefem.org/u/Julien)\
**Post date:** [May 14, 2020, 9:27am UTC](https://community.freefem.org/t/partition-matrices-for-a-coupled-problem/375/10 "2020-05-14T09:27:01Z")

</div>

Thank you @prj for this precious help !

Best regards !  
Julien
