<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">Hello, <br><br>I want to obtain the inverse of a matrix, even though it's not advised by the FAQ ;-) and I have a problem that earlier responses didn't solve for me. Simply speaking : the inverse matrix that is a result of DI=Dinv as told by the FAQ, is empty for me. Here is my code(the significant part) :<br><br> ierr = MatCreate(PETSC_COMM_WORLD,&D);CHKERRQ(ierr);<br> ierr = MatSetSizes(D,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);<br> ierr = MatSetFromOptions(D);CHKERRQ(ierr);<br><br> ierr = MatCreate(PETSC_COMM_WORLD,&Dinv);CHKERRQ(ierr);<br> ierr = MatSetSizes(Dinv,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);<br> ierr = MatSetFromOptions(Dinv);CHKERRQ(ierr);<br><br> ierr = MatCreate(PETSC_COMM_WORLD,&I);CHKERRQ(ierr);<br> ierr =
MatSetSizes(I,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr);<br> ierr = MatSetFromOptions(I);CHKERRQ(ierr);<br><br>(...)<br><br> ierr = MatAssemblyEnd(D,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> ierr = MatAssemblyEnd(I,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br> ierr = MatAssemblyEnd(Dinv,MAT_FINAL_ASSEMBLY);CHKERRQ(ierr);<br><br> MatView(D,PETSC_VIEWER_STDOUT_SELF);<br> <br> ierr = MatGetOrdering(D, MATORDERING_NATURAL, &perm, &iperm); CHKERRQ(ierr); <br> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr);<br> ierr = MatLUFactor(D, perm, iperm, &info); CHKERRQ(ierr);<br><br> MatView(D,PETSC_VIEWER_STDOUT_SELF);<br> MatView(I,PETSC_VIEWER_STDOUT_SELF);<br> <br> ierr = MatMatSolve(D,I,Dinv); CHKERRQ(ierr);<br><br> MatView(Dinv,PETSC_VIEWER_STDOUT_SELF);<br><br>// Results in such output:<br><br>//====
MATRIX D<br>row 0: (0, 2) <br>row 1: (1, 1) <br>row 2: (2, 1) <br>row 3: (3, 1) <br><br>//==== MATRIX D after LU decomposition<br>row 0: (0, 0.5) <br>row 1: (1, 1) <br>row 2: (2, 1) <br>row 3: (3, 1) <br><br>//==== Identity matrix<br>row 0: (0, 1) <br>row 1: (1, 1) <br>row 2: (2, 1) <br>row 3: (3, 1) <br><br>//==== inverse of D (result of MatMatSolve(D,I,Dinv))<br>row 0:<br>row 1:<br>row 2:<br>row 3:<br><br><br>The approach with :<br><br> ierr = MatGetOrdering(D, MATORDERING_NATURAL, &perm, &iperm); CHKERRQ(ierr); <br> ierr = MatGetFactor(D, MAT_SOLVER_PETSC, MAT_FACTOR_LU,&F);<br> ierr = MatFactorInfoInitialize(&info); CHKERRQ(ierr);<br> ierr = MatLUFactorSymbolic(F,D,perm,iperm,&info);CHKERRQ(ierr);<br> ierr = MatLUFactorNumeric(F,D,&info);CHKERRQ(ierr);<br> ierr = MatLUFactor(D,
perm, iperm, &info); CHKERRQ(ierr);<br><br>Provides same output<br><br>Thank You for Your help.<br><br></td></tr></table>