1# -------------------------------------------------------------------- 2 3class DSType(object): 4 BASIC = S_(PETSCDSBASIC) 5 6# -------------------------------------------------------------------- 7 8cdef class DS(Object): 9 10 Type = DSType 11 12 # 13 14 def __cinit__(self): 15 self.obj = <PetscObject*> &self.ds 16 self.ds = NULL 17 18 def view(self, Viewer viewer=None): 19 cdef PetscViewer vwr = NULL 20 if viewer is not None: vwr = viewer.vwr 21 CHKERR( PetscDSView(self.ds, vwr) ) 22 23 def destroy(self): 24 CHKERR( PetscDSDestroy(&self.ds) ) 25 return self 26 27 def create(self, comm=None): 28 cdef MPI_Comm ccomm = def_Comm(comm, PETSC_COMM_DEFAULT) 29 cdef PetscDS newds = NULL 30 CHKERR( PetscDSCreate(ccomm, &newds) ) 31 PetscCLEAR(self.obj); self.ds = newds 32 return self 33 34 def setType(self, ds_type): 35 cdef PetscDSType cval = NULL 36 ds_type = str2bytes(ds_type, &cval) 37 CHKERR( PetscDSSetType(self.ds, cval) ) 38 39 def getType(self): 40 cdef PetscDSType cval = NULL 41 CHKERR( PetscDSGetType(self.ds, &cval) ) 42 return bytes2str(cval) 43 44 def setFromOptions(self): 45 CHKERR( PetscDSSetFromOptions(self.ds) ) 46 47 def setUp(self): 48 CHKERR( PetscDSSetUp(self.ds) ) 49 return self 50 51 # 52 53 def getSpatialDimension(self): 54 cdef PetscInt dim = 0 55 CHKERR( PetscDSGetSpatialDimension(self.ds, &dim) ) 56 return toInt(dim) 57 58 def getCoordinateDimension(self): 59 cdef PetscInt dim = 0 60 CHKERR( PetscDSGetCoordinateDimension(self.ds, &dim) ) 61 return toInt(dim) 62 63 def getNumFields(self): 64 cdef PetscInt nf = 0 65 CHKERR( PetscDSGetNumFields(self.ds, &nf) ) 66 return toInt(nf) 67 68 def getFieldIndex(self, Object disc): 69 cdef PetscInt field = 0 70 CHKERR( PetscDSGetFieldIndex(self.ds, disc.obj[0], &field) ) 71 return toInt(field) 72 73 def getTotalDimensions(self): 74 cdef PetscInt tdim = 0 75 CHKERR( PetscDSGetTotalDimension(self.ds, &tdim) ) 76 return toInt(tdim) 77 78 def getTotalComponents(self): 79 cdef PetscInt tcmp = 0 80 CHKERR( PetscDSGetTotalComponents(self.ds, &tcmp) ) 81 return toInt(tcmp) 82 83 def getDimensions(self): 84 cdef PetscInt nf = 0, *dims = NULL 85 CHKERR( PetscDSGetNumFields(self.ds, &nf) ) 86 CHKERR( PetscDSGetDimensions(self.ds, &dims) ) 87 return array_i(nf, dims) 88 89 def getComponents(self): 90 cdef PetscInt nf = 0, *cmps = NULL 91 CHKERR( PetscDSGetNumFields(self.ds, &nf) ) 92 CHKERR( PetscDSGetComponents(self.ds, &cmps) ) 93 return array_i(nf, cmps) 94 95 def setDiscretisation(self, f, disc): 96 cdef PetscInt cf = asInt(f) 97 cdef FE fe = disc 98 CHKERR( PetscDSSetDiscretization(self.ds, cf, <PetscObject> fe.fe) ) 99 100 101 102# -------------------------------------------------------------------- 103 104del DSType 105 106# -------------------------------------------------------------------- 107