Blockmatrix to basematrix

Dear All,

I’m solving a weak formulation of a PDE system in an explicit way where I need to set up the matrix A manually which is a blocked one and the A_{2,2} block is another block matrix. However, GMRES and CG solvers don’t admit a nested blocked matrix. I also can’t use matvec() to convert a blockmatrix to basematrix.

Do you know how to resolve this issue?

Best regards.

Not sure if I understand you correctly. you could just use a numberspace for the first block and build the compound matrix. you can write manually in the 1,1 block after assembling.

Or am I misunderstanding something? Can you post a mwe with what you want to do?

Hi Christopher,

Thanks for your reply. I’m trying to implement a FEM-BEM code, and my A_{1,1},A_{1,2},A_{2,1} blocks are FEM spare matrices and A_{2,2} block is a BEM H-matrix whose subblocks \{A_{2,2}\}_{i,j},i,j=1,2 are standard integral operators. Firstly I defined A_{2,2} as a block matrix, but when I invoke GMRES, it said bad::cast. But I made it though by defining a 4\times 4 huge block matrix…

Ah are you trying to use the cpp gmres? Use the python implementation in ngsolve.krylovspace. this should work

Here V_mat is a blocked BEM H-matrix, and all others are sparse FEM matrices.

from ngsolve.krylovspace import CG, GMRes

m_id = IdentityMatrix(fesV.ndof, complex=False)
rhs_vec = BlockVector([f_vec,0*f_vec,0*f_vec])
lhs_mat = BlockMatrix([[a1_mat,-a2_mat,None],\
                           [a3_mat,None,-a4_mat],\
                           [None,m_id,V_mat]])
sol_sym = GMRes(A=lhs_mat, b=rhs_vec, pre=pre, tol=1e-8, maxsteps=400, printrates=False)

It seems GMRES only admits a blockmatrix whose blocks are usual basematrices. So it doesn’t work for a nested blockmatrix.

do you have a minimal standalone example that reproduces this? then I can have a look to fix it.

block test simple.ipynb (18.2 KB)

Thanks a lot!! I’m also confused about the .ToDense() function. It seems it doesn’t return the corresponding dense matrix representation. I also include a demonstrating code snippet in the file. Could you also have a look?