def __init__(self, layers): self.__comm = Epetra.PyComm() self.__layers = layers self.__single_proc_map, self.__multiple_proc_map = self.generate_maps() self.__importer = Epetra.Import(self.__multiple_proc_map, self.__single_proc_map) self.__exporter = Epetra.Export(self.__multiple_proc_map, self.__single_proc_map)
def __init__(self, graph, layers): self.__comm = Epetra.PyComm() self.__layers = layers self.__single_proc_map, self.__multiple_proc_map = self.generate_maps() self.__importer = Epetra.Import(self.__multiple_proc_map, self.__single_proc_map) self.__exporter = Epetra.Export(self.__multiple_proc_map, self.__single_proc_map) self.__nproc = self.__comm.NumProc() self.__block_matrix_layout = procmap(blockmap(graph), self.__nproc) self.__scheduler = partition(self.__block_matrix_layout)
def __init_overlap_import_export(self): """ Initialize Jacobian based on the row and column maps of the balanced neighborhood graph. """ balanced_map = self.get_balanced_map() field_balanced_map = self.get_balanced_field_map() overlap_map = self.get_overlap_map() field_overlap_map = self.get_field_overlap_map() self.overlap_importer = Epetra.Import(balanced_map, overlap_map) self.overlap_exporter = Epetra.Export(overlap_map, balanced_map) self.field_overlap_importer = Epetra.Import(field_balanced_map, field_overlap_map) self.field_overlap_exporter = Epetra.Export(field_overlap_map, field_balanced_map) return
parameter_list.set("Partitioning Method","RCB") if not VERBOSE: parameter_sublist = parameter_list.sublist("ZOLTAN") parameter_sublist.set("DEBUG_LEVEL", "0") #Create a partitioner to load balance the grid partitioner = Isorropia.Epetra.Partitioner(my_nodes, parameter_list) #And a redistributer redistributer = Isorropia.Epetra.Redistributor(partitioner) #Redistribute nodes my_nodes_balanced = redistributer.redistribute(my_nodes) #The new load balanced map balanced_map = my_nodes_balanced.Map() #Create importer and exporters to move data between banlanced and #unbalanced maps importer = Epetra.Import(balanced_map, unbalanced_map) exporter = Epetra.Export(balanced_map, unbalanced_map) #Create distributed vectors to store the balanced node positions my_x = Epetra.Vector(balanced_map) my_y = Epetra.Vector(balanced_map) my_families_balanced = Epetra.MultiVector(balanced_map, max_family_length) #Import the balanced node positions and family information my_x.Import(my_nodes[0],importer, Epetra.Insert) my_y.Import(my_nodes[1],importer, Epetra.Insert) my_families_balanced.Import(my_families,importer, Epetra.Insert) #Convert to integer data type for indexing purposes later my_families = np.array(my_families_balanced.T, dtype=np.int32) #Create a flattened list of all family global indices (locally owned #+ ghosts) my_global_ids_required = np.unique(my_families[my_families != -1]) #Create a list of locally owned global ids my_owned_ids = np.array(balanced_map.MyGlobalElements())
def T(self): """Transpose matrix After https://github.com/trilinos/Trilinos_tutorial/wiki/Tpetra_Exercises_Advanced_CrsMatrix_ExplicitTranspose#how-to-compute-the-transpose-of-a-crsmatrix Sadly, `EpetraExt.RowMatrix_Transpose` isn't exposed in PyTrilinos. Returns ------- ~fipy.matrices.trilinosMatrix._TrilinosMatrix Examples -------- >>> import fipy as fp >>> mesh = fp.Grid1D(nx=10) >>> ids = fp.CellVariable(mesh=mesh, value=mesh._globalOverlappingCellIDs) >>> mat = _TrilinosColMeshMatrix(mesh=mesh, rows=1) >>> mat.put(vector=ids.value, ... id1=[fp.parallelComm.procID] * mesh.numberOfCells, ... id2=mesh._localOverlappingCellIDs, ... overlapping=True) >>> print(mat.T.numpyArray) # doctest: +SERIAL [[ 0.] [ 1.] [ 2.] [ 3.] [ 4.] [ 5.] [ 6.] [ 7.] [ 8.] [ 9.]] >>> print(mat.T.numpyArray) # doctest: +PARALLEL_2 [[ 0. 0.] [ 1. 0.] [ 2. 0.] [ 3. 3.] [ 4. 4.] [ 5. 5.] [ 6. 6.] [ 0. 7.] [ 0. 8.] [ 0. 9.]] """ self.finalize() # transpose the maps rowMap = self.matrix.ColMap() colMap = self.matrix.RowMap() domainMap = self.matrix.RangeMap() rangeMap = self.matrix.DomainMap() # 2. Create a new CrsMatrix AT, with A's column Map as AT's row Map. numEntriesPerRow = self.matrix.NumGlobalNonzeros( ) // self.matrix.NumGlobalCols() A_T = Epetra.CrsMatrix( Epetra.Copy, rowMap, # RuntimeError: InsertMyValues cannot be # called on Epetra_CrsMatrix that does not # have a column map colMap, numEntriesPerRow) # 1. On each process, extract and transpose the local data. for irow in range(self.matrix.NumMyRows()): # "Returns a two-tuple of numpy arrays of the same size; the first is # an array of integers that represent the nonzero columns on the # matrix" # # No, it's not. Returns values *then* indices val, jcol = self.matrix.ExtractMyRowCopy(irow) # 3. Insert the transposed local data into AT. # Note that the column Map owns all of AT's local data. This # means that Step 3 can use local indices. A_T.InsertMyValues(jcol, [irow] * len(jcol), val) # 4. Fill complete AT (you'll need to supply the domain and range # Map, because the row Map of AT is not one to one in general). A_T.FillComplete(domainMap, rangeMap) # 5. If desired, redistribute AT (using an Export) to have a # one-to-one row Map. exporter = Epetra.Export(rowMap, rangeMap) A_T_bis = Epetra.CrsMatrix(Epetra.Copy, rangeMap, numEntriesPerRow) A_T_bis.Export(A_T, exporter, Epetra.Insert) A_T_bis.FillComplete(domainMap, rangeMap) return _TrilinosMatrix(matrix=A_T_bis)