File: Bratu3D.pyx

package info (click to toggle)
petsc4py 3.23.1-1exp2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 3,448 kB
  • sloc: python: 12,503; ansic: 1,697; makefile: 343; f90: 313; sh: 14
file content (36 lines) | stat: -rw-r--r-- 1,200 bytes parent folder | download | duplicates (2)
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
34
35
36
from petsc4py.PETSc cimport Vec,  PetscVec
from petsc4py.PETSc cimport Mat,  PetscMat
from petsc4py.PETSc cimport DM,   PetscDM
from petsc4py.PETSc cimport SNES

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, DM 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, DM 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, DM 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