I am encountering what looks to be a bug when using ChangeNumbering with a nested block matrix corresponding to the discretization of the stokes system.
In the example attached, I create a Stokes PETSc matrix A and I supply a matrix of right hand-sides RHS2. I display the infinity norm. Then I call ChangeNumbering to convert this matrix to a new one RHSB and I observe that the infinity norm is zero.
Trying them to solve the Stokes system with multiple right hand sides then returns zero, due to this zero right hand side. What is weird is that the problem arises only if the matrix with multiple right-hand side is of dimension larger than 4.
Did I miss something?
disp("RHS2.linfty="+RHS2.linfty); //Should show 1
ChangeNumbering(A, RHS2, RHSB);
disp("RHSB.linfty="+RHSB.linfty); //Should show 1 but shows zero
set(A, sparams = "-ksp_type preonly -pc_type lu -ksp_monitor -ksp_view -pc_mat_solver_type mumps");
KSPSolve(A,RHSB,X); //Returns zero
Edit: I found a solution by calling ChangeNumbering on the subarrays corresponding to the block submatrices of the stokes system. I can then solve the linear system with multiple right-hand sides and call ChangeNumbering back on the sub arrays of the solution.
So I guess ChangeNumbering does not support nested block matrices yet.
it is not possible to use ChangeNumbering() with a MatNest for which all diagonal blocks are not coming from a MatCreate() (I think this answers your question as to why your code what initially failing since you have 0s on the diagonal);
Thanks for your reply and the explanation @prj !
I tried your solution but it seems it does not work if solV and solP are of types real[int,int].
I get this error:
Right, they must be of single dimension, I didn’t catch that you were using two-dimensional arrays. I can try to have a look to see how difficult it would be to add support for two-dimensional arrays.
The file run/ffimport/matrix_rhs2 is missing from your latest .zip. I see at least two issues:
you are not initializing RHSPPetsc, so there may be nan in the RHS, you should add an explicit RHSPPetsc = 0
solPPetsc = X(AAstokes.n:X.n-1,0:RHS2.m-1); should read solPPetsc = X(AAstokes.n:X.n-2,0:RHS2.m-1);
If you send me an updated (and running) code, I can make sure the new ChangeNumbering() (with real[int, int] is functioning properly – the code is there but it’s not pushed yet).
Dear @prj, thanks a lot, indeed these were mistakes, and this resolved a bug in my application.
I was confused with the initialization because the syntax
real[int] RHSPPetsc(Fhp.ndof) = 0;
is invalid.
Here is an updated running code: example.zip (3.0 MB) (run with ff-mpirun -np 1 run/stokes.edp)