[petsc-users] petsc4py - Convert c example code to Python

Matthew Knepley knepley at gmail.com
Mon Apr 1 08:17:38 CDT 2019


On Mon, Apr 1, 2019 at 9:08 AM Nicola Creati via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Hello,
>
> thanks Barry. I cannot test both codes, C and Python, since the filling
> of the Jacobian matrix  get the following Error:
>
> Traceback (most recent call last):
>    File "PETSc/petscts.pxi", line 382, in petsc4py.PETSc.TS_IJacobian
>    File "ex13.py", line 61, in Jacobian_func
>      B.setValueStencil(row, col, value)
>    File "PETSc/Mat.pyx", line 948, in petsc4py.PETSc.Mat.setValueStencil
>    File "PETSc/petscmat.pxi", line 1100, in
> petsc4py.PETSc.matsetvaluestencil
> petsc4py.PETSc.Error: error code 63
> [0] TSComputeIJacobian() line 912 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ts/interface/ts.c
> [0] MatSetValuesStencil() line 1576 in
> /home/ncreati/Downloads/petsc-3.10.3/src/mat/interface/matrix.c
> [0] MatSetValuesLocal() line 2152 in
> /home/ncreati/Downloads/petsc-3.10.3/src/mat/interface/matrix.c
> [0] MatSetValues() line 1349 in
> /home/ncreati/Downloads/petsc-3.10.3/src/mat/interface/matrix.c
> [0] MatSetValues_SeqAIJ() line 477 in
> /home/ncreati/Downloads/petsc-3.10.3/src/mat/impls/aij/seq/aij.c
> [0] Argument out of range
> [0] Inserting a new nonzero at (9,8) in the matrix
>

This comes from improper preallocation of the matrix. You can call

  J.setOption(MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE)

to turn it off I believe. If you created this matrix yourself, then its
probably
just a logic error in preallocation. If you got it from a DM, then you a
trying to insert outside the stencil you told the DM about.

  Thanks,

    Matt


> The above exception was the direct cause of the following exception:
>
> SystemError: <built-in method insert of list object at 0x7fa47b53c0c8>
> returned a result with an error set
> Exception ignored in: 'petsc4py.PETSc.traceback'
> SystemError: <built-in method insert of list object at 0x7fa47b53c0c8>
> returned a result with an error set
> Traceback (most recent call last):
>    File "ex13.py", line 121, in <module>
>      ts.solve(u)
>    File "PETSc/TS.pyx", line 657, in petsc4py.PETSc.TS.solve
> petsc4py.PETSc.Error: error code 73
> [0] TSSolve() line 3775 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ts/interface/ts.c
> [0] TSStep() line 3592 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ts/interface/ts.c
> [0] TSStep_Theta() line 216 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ts/impls/implicit/theta/theta.c
> [0] TSTheta_SNESSolve() line 176 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ts/impls/implicit/theta/theta.c
> [0] SNESSolve() line 4397 in
> /home/ncreati/Downloads/petsc-3.10.3/src/snes/interface/snes.c
> [0] SNESSolve_NEWTONLS() line 224 in
> /home/ncreati/Downloads/petsc-3.10.3/src/snes/impls/ls/ls.c
> [0] KSPSolve() line 723 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ksp/ksp/interface/itfunc.c
> [0] KSPSetUp() line 391 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ksp/ksp/interface/itfunc.c
> [0] PCSetUp() line 932 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ksp/pc/interface/precon.c
> [0] PCSetUp_ILU() line 134 in
> /home/ncreati/Downloads/petsc-3.10.3/src/ksp/pc/impls/factor/ilu/ilu.c
> [0] MatGetOrdering() line 180 in
> /home/ncreati/Downloads/petsc-3.10.3/src/mat/order/sorder.c
> [0] Object is in wrong state
> [0] Not for unassembled matrix
>
> I believe that my Python conversion is wrong but I cannot figure it out.
>
> Nicola
>
>
> --
>
> Nicola Creati
> Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS
> www.inogs.it
> Dipartimento di Geofisica della Litosfera Geophysics of Lithosphere
> Department
> CARS (Cartography and Remote Sensing) Research Group
> http://www.inogs.it/Cars/
> Borgo Grotta Gigante 42/c 34010 Sgonico - Trieste - ITALY
> ncreati at ogs.trieste.it
> off.   +39 040 2140 213
> fax.   +39 040 327307
>
> _____________________________________________________________________
> This communication, that may contain confidential and/or legally
> privileged information, is intended solely for the use of the intended
> addressees. Opinions, conclusions and other information contained in this
> message, that do not relate to the official business of OGS, shall be
> considered as not given or endorsed by it. Every opinion or advice
> contained in this communication is subject to the terms and conditions
> provided by the agreement governing the engagement with such a client. Any
> use, disclosure, copying or distribution of the contents of this
> communication by a not-intended recipient or in violation of the purposes
> of this communication is strictly prohibited and may be unlawful. For Italy
> only: Ai sensi del D.Lgs.196/2003 - "T.U. sulla Privacy" si precisa che le
> informazioni contenute in questo messaggio sono riservate ed a uso
> esclusivo del destinatario.
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190401/6b306fce/attachment.html>


More information about the petsc-users mailing list