If I create two marices from my variation forms, say matrix A and B, can I do the operation A+B or A*B?
Actually, I have tried and it seems I was allowed to do so. However, I am not sure whether it was right or wrong?
I am curious how FreeFEM implement this, because matrix A and B are sparse matrices, which have different structures. Is this marices plus and multiplication operation very slow?
Another question: can I foce B have the same non-zero element structure as A?
It’s a very standard sparse matrix operation. Different nonzero patterns are allowed. There is no way to day to enforce the same pattern, but this could be easily added. Do you have something specific in mind?
Thanks for your reply prj !
Yes, I use the plus and multiplication operators to implement a two-mesh fictitious domain method for fluid-structure interaction problems, which ends up with
A+P’BP=P’f,
where A is from discretisation of the fluid and fictitious fluid equation, B is from the solid equation and P is the interpolation matrix between two meshes.
The dimension of matrix B is usually much smaller than A. I realise that the scheme is more stable if we force P’BP the same non-zero pattern as A, in other words, neglecting the non-zero elements in P’BP that does not exits in A. Do you have any suggestions?
Thank you in advance!
Best,
Yongxing.
If the P’BP product is time consuming in your application, I’d suggest switching to PETSc MatPtAP routine, see this example. It’s parallel and highly scalable, since this routine is a cornerstone of most multigrid methods.