-
Notifications
You must be signed in to change notification settings - Fork 23
/
Bratu3D.pyx
33 lines (28 loc) · 1.18 KB
/
Bratu3D.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from petsc4py.PETSc cimport Vec, PetscVec
from petsc4py.PETSc cimport Mat, PetscMat
from petsc4py.PETSc cimport DMDA, PetscDM
from petsc4py.PETSc cimport SNES, PetscSNES
from petsc4py.PETSc import Error
cdef extern from "Bratu3Dimpl.h":
ctypedef struct Params:
double lambda_
int FormInitGuess(PetscDM da, PetscVec x, Params *p)
int FormFunction (PetscDM da, PetscVec x, PetscVec F, Params *p)
int FormJacobian (PetscDM da, PetscVec x, PetscMat J, Params *p)
def formInitGuess(Vec x, DA da, double lambda_):
cdef int ierr
cdef Params p = {"lambda_" : lambda_}
ierr = FormInitGuess(da.dm, x.vec, &p)
if ierr != 0: raise Error(ierr)
def formFunction(SNES snes, Vec x, Vec f, DA da, double lambda_):
cdef int ierr
cdef Params p = {"lambda_" : lambda_}
ierr = FormFunction(da.dm, x.vec, f.vec, &p)
if ierr != 0: raise Error(ierr)
def formJacobian(SNES snes, Vec x, Mat J, Mat P, DA da, double lambda_):
cdef int ierr
cdef Params p = {"lambda_" : lambda_}
ierr = FormJacobian(da.dm, x.vec, P.mat, &p)
if ierr != 0: raise Error(ierr)
if J != P: J.assemble() # for matrix-free operator
return Mat.Structure.SAME_NONZERO_PATTERN