[petsc-users] Diagnosing Poisson Solver Behavior

K. N. Ramachandran knram06 at gmail.com
Wed Oct 14 23:44:31 CDT 2015


Hello all,

@Matt: Actually I can't fully adopt the SNES ex5 since I think I am much
closer to getting the DMDA stuff to work, even if it is just serial. So I
am currently focussing on that.

@Barry: The matrix is coming from the Finite difference discretization of a
3D regular grid. I had a look at KSP ex45.c and I am struggling with what
looks to be a simple problem.

I currently supply the matrix to PETSc in a CSR form. I have specified
ComputeRHS and ComputeMatrix functions, analogous to ex45.c.

If my 3D grid is regular cube with 5 nodes on each side, I create DMDA
using DMDACreate3d((comm world), boundary types, STAR_STENCIL, etc., M = 5,
N = 5, P = 5, dof=1, s=1, PETSC_NULL on remaining).

In the ComputeMatrix function, I try to reuse my CSR form by doing:

#undef __FUNCT__
#define __FUNCT__ "ComputeMatrix"
PetscErrorCode ComputeMatrix(KSP ksp, Mat J, Mat A, void* ctx)
{
    PetscFunctionBeginUser;

    Mat temp;
    // build up the matrix
    MatCreateSeqAIJWithArrays(PETSC_COMM_WORLD, numRows, numRows, rows,
cols, values, &temp);

    MatCopy(temp, A, DIFFERENT_NONZERO_PATTERN);

    MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
    MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);

    PetscFunctionReturn(0);

} // end of ComputeMatrix

Where rows, cols, values are stored globally, for now. Also I am keeping
the code serial, so I am just trying to use DMDA as a convenient way to
take care of interpolation between MG levels, if my understanding is
correct.

But on the MatCopy line, I get an error

DM Object: 1 MPI processes
  type: da
Processor [0] M 5 N 5 P 5 m 1 n 1 p 1 w 1 s 1
X range of indices: 0 5, Y range of indices: 0 5, Z range of indices: 0 5
[0]PETSC ERROR: --------------------- Error Message
--------------------------------------------------------------
[0]PETSC ERROR: Argument out of range
[0]PETSC ERROR: Inserting a new nonzero at (25,27) in the matrix
[0]PETSC ERROR: See http://www.mcs.anl.gov/petsc/documentation/faq.html for
trouble shooting.
[0]PETSC ERROR: Petsc Release Version 3.6.2, Oct, 02, 2015

I have been trying but I have not been able to resolve this quickly. I feel
like I am creating the DMDA correctly. Is there a better way of reusing a
CSR form to setup a DM Matrix? Should I be doing DMCreateMatrix?

Thanks a lot for your help.


Regards,
K.N.Ramachandran
Ph: 814-441-4279
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20151015/052f3732/attachment.html>


More information about the petsc-users mailing list