[petsc-dev] MatSetValuesStencil analogue in petsc4py

Nathan Collier nathaniel.collier at gmail.com
Thu Nov 19 06:46:53 CST 2015


Chris,

I believe Lisandro does have an example that can help you here. Take a look
at his demo here (petsc4py/demo/wrap-cython/):

https://bitbucket.org/petsc/petsc4py/src/2c8d5dcc0a7fb9519e68d3caba5a0501f4bb6143/demo/wrap-cython/?at=master

He implements a FormFunction and FormInitialGuess in pure C, wraps them
with cython and then calls them from python. Is this what you had in mind?

Nate



On Thu, Nov 19, 2015 at 3:41 AM Chris Eldred <chris.eldred at gmail.com> wrote:

> Hey Jed,
>
> I will give that a look today and see what I can do.
>
> On a more general note, what I would really like to be able to do is
> use petsc4py as a driver script that just calls PETSc functions, and
> do the computationally expensive parts such as stiffness matrix
> assembly and load vector assembly in C.
>
> To this end, is it possible to create a PETSc matrix or vector in
> Python, and then pass them to a C function that modifies them? Then
> MatSetValues would be called in C, but the AssemblyBegin/AssemblyEnd
> pairs (and Matrix creation, etc) could be called in Python.
>
> -Chris
>
> On Wed, Nov 18, 2015 at 8:27 PM, Jed Brown <jed at jedbrown.org> wrote:
> > Nathan Collier <nathaniel.collier at gmail.com> writes:
> >> ack MatSetValuesStencil
> >>
> >> returns
> >>
> >> src/PETSc/petscmat.pxi
> >> 222:    int
> >>
> MatSetValuesStencil(PetscMat,PetscInt,PetscMatStencil[],PetscInt,PetscMatStencil[],PetscScalar[],PetscInsertMode)
> >> 1027:        CHKERR( MatSetValuesStencil(A,
> >>
> >> but 'ack MatSetValueStencil' returns nothing. Hope it helps,
> >
> > Mat.pyx defines Mat.setValueStencil which calls petscmat.pxi's
> > matsetvaluestencil which calls PETSc's MatSetValuesStencil with an array
> > of length 1.  I can't think of any reason not to generalize this to set
> > many values at once.  Chris, would you like to take a pass at adding
> > this?
>
>
>
> --
> Chris Eldred
> Postdoctoral Fellow, LAGA, University of Paris 13
> PhD, Atmospheric Science, Colorado State University, 2015
> DOE Computational Science Graduate Fellow (Alumni)
> B.S. Applied Computational Physics, Carnegie Mellon University, 2009
> chris.eldred at gmail.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20151119/9725b703/attachment.html>


More information about the petsc-dev mailing list