def _calcValue(self): l = len(self.distribution) bins = self.mesh.cellCenters[0] n = numerix.searchsorted(numerix.sort(self.distribution), bins) n = numerix.concatenate([n, [l]]) dx = bins[1:] - bins[:-1] return (n[1:] - n[:-1]) / numerix.concatenate([dx, [dx[-1]]]) / float(l)
def _ijv2csr(self, i, j, v): """Convert arrays of matrix indices and values into CSR format see: http://netlib.org/linalg/html_templates/node91.html#SECTION00931100000000000000 .. note:: petsc4py only understands CSR formatted matrices (setValuesCSR and setValuesIJV both inexplicably call the same underlying routine). Parameters ---------- i : array_like column indices j : array_like row indices v : array_like non-zero values Returns ------- ptrs : array_like locations in the val vector that start a row, terminated with len(val) + 1 cols : array_like column indices data : array_like non-zero values """ i = numerix.asarray(i) j = numerix.asarray(j) v = numerix.asarray(v) start_row, end_row = self.matrix.getOwnershipRange() ix = numerix.lexsort([i, j]) ix = ix[(j[ix] >= start_row) & (j[ix] < end_row)] cols = i[ix] row_ptr = numerix.searchsorted(j[ix], numerix.arange(start_row, end_row + 1)) vals = v[ix] # note: PETSc (at least via pip) only seems to handle 32 bit addressing return row_ptr.astype('int32'), cols.astype('int32'), vals
def _ijv2csr(self, i, j, v): """Convert arrays of matrix indices and values into CSR format see: http://netlib.org/linalg/html_templates/node91.html#SECTION00931100000000000000 .. note:: petsc4py only understands CSR formatted matrices (setValuesCSR and setValuesIJV both inexplicably call the same underlying routine). Parameters ---------- i : array_like column indices j : array_like row indices v : array_like non-zero values Returns ------- row_ptr : array_like locations in the val vector that start a row, terminated with len(val) + 1 cols : array_like column indices val : array_like non-zero values """ # from fipy.tools.debug import PRINT # PRINT("i:", i) # PRINT("j:", j) # PRINT("v:", v) i = numerix.asarray(i) j = numerix.asarray(j) v = numerix.asarray(v) start_row, end_row = self.matrix.getOwnershipRange() # PRINT("start_row:", start_row) # PRINT("end_row:", end_row) ix = numerix.lexsort([i, j]) ix = ix[(j[ix] >= start_row) & (j[ix] < end_row)] cols = i[ix] row_ptr = numerix.searchsorted( j[ix], # numerix.arange(0, self._shape[1]+1)) numerix.arange(start_row, end_row + 1)) vals = v[ix] # PRINT("i[ix]:", i[ix]) # PRINT("j[ix]:", j[ix]) # PRINT("v[ix]:", v[ix]) # PRINT("size:", self._shape) # PRINT("shape:", self._shape[0]) # # PRINT("row_ptr:", row_ptr) # PRINT("cols:", cols) # PRINT("vals:", vals) # # PRINT("size:", self.matrix.sizes) # PRINT("owns-rows:", self.matrix.getOwnershipRange()) # PRINT("owns-cols:", self.matrix.getOwnershipRangesColumn()) # note: PETSc (at least via pip) only seems to handle 32 bit addressing return row_ptr.astype('int32'), cols.astype('int32'), vals