# Use of restriction on a meshL and matrix free operator

**URL:** https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862
**Category:** General Discussion
**Created:** [March 18, 2021, 3:34pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862 "2021-03-18T15:34:26Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![LucasPa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/lucaspa/32/347_2.png) [@LucasPa](https://community.freefem.org/u/LucasPa)
#### Post date: [March 18, 2021, 3:34pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/1 "2021-03-18T15:34:26Z")

</div>

Hi,

I would like to define a square matrix-free operator which dimension corresponds to the size of the restricted space that corresponds to the left boundary of the 2d domain. So basically the operator behaves as:  
another\_vector\_on\_1D\_space = matrix\_on\_1D\_space \* input\_vector\_on\_1D\_space  
vector\_on\_2D\_space = prolongation\_matrix \* another\_vector\_on\_1D\_space  
another\_vector\_on\_2D\_space = matrix\_on\_2D\_space \* vector\_on\_2D\_space  
return\_vector\_on\_1D\_space = restrictionMatrix \* another\_vector\_on\_2D\_space

I started to implement this in the following script: [meshL\_2d\_SLEPc.edp](https://community.freefem.org/uploads/short-url/hG2uHfHnyEizbSULoN2xPlDdGUC.edp) (1.5 KB)  
Obviously there is something I do not understand, I guess I have non consistent operator sizes.

Could someone please help me here ?

Best,

Lucas

PS: It is not clear to me why A.n is different from Vh.ndof. Could someone please explain me why?

---

<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: [March 18, 2021, 4:14pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/2 "2021-03-18T16:14:41Z")

</div>

I’ll look into your script, but first.

> PS: It is not clear to me why A.n is different from Vh.ndof. Could someone please explain me why?

`A.n` is the local size of the PETSc `Mat` (without overlapping unknown), while `Vh.ndof` is the local size of the FreeFEM `fespace) (with overlapping unknowns).

---

<div class="post-metadata">

### Author: ![LucasPa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/lucaspa/32/347_2.png) [@LucasPa](https://community.freefem.org/u/LucasPa)
#### Post date: [March 18, 2021, 4:36pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/3 "2021-03-18T16:36:59Z")

</div>

Thanks for this explanation.

Knowing this I may be able to correct something in the script, I will do that tomorrow.

---

<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: [March 18, 2021, 4:46pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/4 "2021-03-18T16:46:32Z")

</div>

In fact, your script is correct, just the sizes are wrong. You are using FreeFEM notation (`*`) instead of `MatMult`, so you need to use FreeFEM lengths, like this:

```auto
  real[int] u(VhL.ndof), v(VhL.ndof), w(Vh.ndof), vv(Vh.ndof);

```

I now get a consistent result with an increasing number of processes.

```auto
$ mpirun -n 1 FreeFem++-mpi meshL_2d_SLEPc.edp -eps_view_values -v 0
Mat Object: 1 MPI processes
  type: shell
  rows=41, cols=41
Eigenvalues =
   0.02498
$ mpirun -n 4 FreeFem++-mpi meshL_2d_SLEPc.edp -eps_view_values -v 0                                                                           
Mat Object: 4 MPI processes
  type: shell
  rows=41, cols=41
Eigenvalues =
   0.02498

```

---

<div class="post-metadata">

### Author: ![LucasPa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/lucaspa/32/347_2.png) [@LucasPa](https://community.freefem.org/u/LucasPa)
#### Post date: [March 23, 2021, 1:43pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/5 "2021-03-23T13:43:41Z")

</div>

And one additional question on that point: what does happen if the boundary labelled 1 is partitioned on multiple procs? Do I have something to do then ? Communicating the ghost values ?

Best,

Lucas

---

<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: [March 23, 2021, 2:01pm UTC](https://community.freefem.org/t/use-of-restriction-on-a-meshl-and-matrix-free-operator/862/6 "2021-03-23T14:01:17Z")

</div>

It should be done for you, unless something else is broken.
