-
Notifications
You must be signed in to change notification settings - Fork 11
/
Scatter.pyx
99 lines (80 loc) · 3.47 KB
/
Scatter.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# --------------------------------------------------------------------
cdef class Scatter(Object):
Mode = ScatterMode
#
def __cinit__(self):
self.obj = <PetscObject*> &self.sct
self.sct = NULL
def __call__(self, x, y, addv=None, mode=None):
self.scatter(x, y, addv, mode)
#
def view(self, Viewer viewer=None):
cdef PetscViewer vwr = NULL
if viewer is not None: vwr = viewer.vwr
CHKERR( VecScatterView(self.sct, vwr) )
def destroy(self):
CHKERR( VecScatterDestroy(&self.sct) )
return self
def create(self, Vec vec_from not None, IS is_from,
Vec vec_to not None, IS is_to):
cdef PetscIS cisfrom = NULL, cisto = NULL
if is_from is not None: cisfrom = is_from.iset
if is_to is not None: cisto = is_to.iset
cdef PetscScatter newsct = NULL
CHKERR( VecScatterCreate(
vec_from.vec, cisfrom, vec_to.vec, cisto, &newsct) )
PetscCLEAR(self.obj); self.sct = newsct
return self
def copy(self):
cdef Scatter scatter = Scatter()
CHKERR( VecScatterCopy(self.sct, &scatter.sct) )
return scatter
@classmethod
def toAll(cls, Vec vec not None):
cdef Scatter scatter = Scatter()
cdef Vec ovec = Vec()
CHKERR( VecScatterCreateToAll(
vec.vec, &scatter.sct, &ovec.vec) )
return (scatter, ovec)
@classmethod
def toZero(cls, Vec vec not None):
cdef Scatter scatter = Scatter()
cdef Vec ovec = Vec()
CHKERR( VecScatterCreateToZero(
vec.vec, &scatter.sct, &ovec.vec) )
return (scatter, ovec)
#
def begin(self, Vec vec_from not None, Vec vec_to not None,
addv=None, mode=None):
cdef PetscInsertMode caddv = insertmode(addv)
cdef PetscScatterMode csctm = scattermode(mode)
CHKERR( VecScatterBegin(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
def end(self, Vec vec_from not None, Vec vec_to not None,
addv=None, mode=None):
cdef PetscInsertMode caddv = insertmode(addv)
cdef PetscScatterMode csctm = scattermode(mode)
CHKERR( VecScatterEnd(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
#
def scatterBegin(self, Vec vec_from not None, Vec vec_to not None,
addv=None, mode=None):
cdef PetscInsertMode caddv = insertmode(addv)
cdef PetscScatterMode csctm = scattermode(mode)
CHKERR( VecScatterBegin(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
def scatterEnd(self, Vec vec_from not None, Vec vec_to not None,
addv=None, mode=None):
cdef PetscInsertMode caddv = insertmode(addv)
cdef PetscScatterMode csctm = scattermode(mode)
CHKERR( VecScatterEnd(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
def scatter(self, Vec vec_from not None, Vec vec_to not None,
addv=None, mode=None):
cdef PetscInsertMode caddv = insertmode(addv)
cdef PetscScatterMode csctm = scattermode(mode)
CHKERR( VecScatterBegin(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
CHKERR( VecScatterEnd(self.sct, vec_from.vec, vec_to.vec,
caddv, csctm) )
# --------------------------------------------------------------------