# Call PETSc matrix operator MatDiagonalSet (…)

**URL:** <https://community.freefem.org/t/call-petsc-matrix-operator-matdiagonalset/1050>\
**Category:** General Discussion\
**Created:** [June 21, 2021, 12:41pm UTC](https://community.freefem.org/t/call-petsc-matrix-operator-matdiagonalset/1050 "2021-06-21T12:41:33Z")\
**Posts on this page:** 1\
**Showing post:** 28

<div class="post-metadata">

**Author:** ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)\
**Post date:** [June 29, 2021, 4:00pm UTC](https://community.freefem.org/t/call-petsc-matrix-operator-matdiagonalset/1050/28 "2021-06-29T16:00:41Z")

</div>

It seems I always have to do the following code **together** (inside the time loop) in order to compute the interpolation matrix P ( **mesh Ths is moving but Th is static** )

createMat(Th, A, PV1)|  
createMat(Ths, B, PV1)|  
transferMat(Th, PV1, A, Ths, PV1, B, P)  
A = fluid(Rh, Rh);  
B = solid(Rhs,Rhs)

One problem is I quickly ran out of memory because of (I guess) calling createMat() again and again.

Another problem is matrix A is static, It’s better to put it outside the time loop. However, when I do this, it shows the following error:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/1X/f30570a83503a472a57c948e8a78cf157e5cc76f.png)

Can I somehow only **put the following two lines inside the time loop, and all the other three lines outside the time loop** because only Ths and matrix B change as the time involves ?

transferMat(Th, PV1, A, Ths, PV1, B, P)  
B = solid(Rhs,Rhs)

---

_[View the full topic](https://community.freefem.org/t/call-petsc-matrix-operator-matdiagonalset/1050)._
