<div dir="ltr">Chris,<div><br></div><div>I believe Lisandro does have an example that can help you here. Take a look at his demo here (petsc4py/demo/wrap-cython/):</div><div><br></div><div><a href="https://bitbucket.org/petsc/petsc4py/src/2c8d5dcc0a7fb9519e68d3caba5a0501f4bb6143/demo/wrap-cython/?at=master">https://bitbucket.org/petsc/petsc4py/src/2c8d5dcc0a7fb9519e68d3caba5a0501f4bb6143/demo/wrap-cython/?at=master</a><br></div><div><br></div><div>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?</div><div><br></div><div>Nate</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Nov 19, 2015 at 3:41 AM Chris Eldred <<a href="mailto:chris.eldred@gmail.com">chris.eldred@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hey Jed,<br>
<br>
I will give that a look today and see what I can do.<br>
<br>
On a more general note, what I would really like to be able to do is<br>
use petsc4py as a driver script that just calls PETSc functions, and<br>
do the computationally expensive parts such as stiffness matrix<br>
assembly and load vector assembly in C.<br>
<br>
To this end, is it possible to create a PETSc matrix or vector in<br>
Python, and then pass them to a C function that modifies them? Then<br>
MatSetValues would be called in C, but the AssemblyBegin/AssemblyEnd<br>
pairs (and Matrix creation, etc) could be called in Python.<br>
<br>
-Chris<br>
<br>
On Wed, Nov 18, 2015 at 8:27 PM, Jed Brown <<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>> wrote:<br>
> Nathan Collier <<a href="mailto:nathaniel.collier@gmail.com" target="_blank">nathaniel.collier@gmail.com</a>> writes:<br>
>> ack MatSetValuesStencil<br>
>><br>
>> returns<br>
>><br>
>> src/PETSc/petscmat.pxi<br>
>> 222:    int<br>
>> MatSetValuesStencil(PetscMat,PetscInt,PetscMatStencil[],PetscInt,PetscMatStencil[],PetscScalar[],PetscInsertMode)<br>
>> 1027:        CHKERR( MatSetValuesStencil(A,<br>
>><br>
>> but 'ack MatSetValueStencil' returns nothing. Hope it helps,<br>
><br>
> Mat.pyx defines Mat.setValueStencil which calls petscmat.pxi's<br>
> matsetvaluestencil which calls PETSc's MatSetValuesStencil with an array<br>
> of length 1.  I can't think of any reason not to generalize this to set<br>
> many values at once.  Chris, would you like to take a pass at adding<br>
> this?<br>
<br>
<br>
<br>
--<br>
Chris Eldred<br>
Postdoctoral Fellow, LAGA, University of Paris 13<br>
PhD, Atmospheric Science, Colorado State University, 2015<br>
DOE Computational Science Graduate Fellow (Alumni)<br>
B.S. Applied Computational Physics, Carnegie Mellon University, 2009<br>
<a href="mailto:chris.eldred@gmail.com" target="_blank">chris.eldred@gmail.com</a><br>
</blockquote></div>