<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">That solved the problem, thank you very much!<br>Afterall, it ocurred that I don't need this procedure since I will only use diagonal matrices and inverse of such are trivial.<br><br>It will come in handy someday though, I am sure.<br>Thanks again.<br><br>--- <b>30.3.11 (Śr), Hong Zhang <i><hzhang@mcs.anl.gov></i></b> napisał(a):<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>Od: Hong Zhang <hzhang@mcs.anl.gov><br>Temat: Re: [petsc-users] Matrix inverse and LU decomposition<br>Do: "PETSc users list" <petsc-users@mcs.anl.gov><br>Data: 30 Marzec 2011 (Środa), 15:07<br><br><div id="yiv274543480">You need call<div><br><div>MatSetType(I,MATDENSE);</div><div>MatSetType(Dinv,MATDENSE);</div><div><br></div><div>See petsc-dev/src/mat/examples/tests/ex1.c (attached) on how to
use</div><div>MatMatSolve().</div><div>Can you send me your complete code so I can check why Dinv is empty?</div>
<div><br></div><div>Hong<br><br><div class="yiv274543480gmail_quote">On Wed, Mar 30, 2011 at 8:31 AM, Bartłomiej W <span dir="ltr"><<a rel="nofollow" ymailto="mailto:bartlomiej.wach@yahoo.pl" target="_blank" href="/mc/compose?to=bartlomiej.wach@yahoo.pl">bartlomiej.wach@yahoo.pl</a>></span> wrote:<br><blockquote class="yiv274543480gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font: inherit;" valign="top">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></tbody></table></blockquote></div><br></div></div>
</div></blockquote></td></tr></table>