Exemple #1
0
def create_identity(vec, val=1):
    raise NotImplementedError()
    """Create an identity matrix with the layout given by the supplied
    GenericVector. The values of the vector are NOT used."""
    import numpy
    from PyTrilinos import Epetra
    from dolfin import EpetraMatrix
    rowmap = vec.down_cast().vec().Map()
    graph = Epetra.CrsGraph(Epetra.Copy, rowmap, 1, True)
    indices = numpy.array([0], dtype=numpy.intc)
    for row in rowmap.MyGlobalElements():
        indices[0] = row
        graph.InsertGlobalIndices(row, indices)
    graph.FillComplete()

    matrix = EpetraMatrix(graph)
    indices = numpy.array(rowmap.MyGlobalElements())
    if val == 0:
        matrix.zero(indices)
    else:
        matrix.ident(indices)
        if val != 1:
            matrix *= val

    return matrix
Exemple #2
0
def scipy_csr_matrix2CrsMatrix(sp, comm):
    Ap = sp.indptr
    Aj = sp.indices
    Ax = sp.data
    m = Ap.shape[0]-1
    aMap = Epetra.Map(m, 0, comm)
    # range Map
    arMap=Epetra.Map(sp.shape[0], 0, comm)
    # domain Map
    adMap=Epetra.Map(sp.shape[1], 0, comm)
    aGraph = Epetra.CrsGraph( Epetra.Copy, aMap, 0)
    for ii in range(aMap.NumGlobalElements()):
          i = aMap.GID(ii)
          indy = range(Ap[i],Ap[i+1])
          if (indy != []): 
              aGraph.InsertGlobalIndices(i, Aj[indy])
    aGraph.FillComplete(adMap, arMap)
    A = Epetra.CrsMatrix(Epetra.Copy, aGraph)
    for ii in range(aMap.NumGlobalElements()):
          i = aMap.GID(ii)
          indy = range(Ap[i],Ap[i+1])
	  if (indy != []): 
	      A.SumIntoGlobalValues(i, Ax[indy], Aj[indy])
    A.FillComplete(adMap, arMap)
    return A	      
Exemple #3
0
    def __init_field_graph(self):

        # Assign velocity_x (ux) and velocity_y (uy) indices for each node
        ##Rambod change removed *2 ( added it back)
        self.number_of_field_variables = 2 * self.__global_number_of_nodes
        global_indices = self.balanced_map.MyGlobalElements()
        Global_Indices = global_indices  #self.balanced_map.MyGlobalElements()

        XY_Global_Indices = np.zeros(2 * len(Global_Indices), dtype=np.int32)

        for index in range(len(Global_Indices)):
            XY_Global_Indices[2 * index] = 2 * Global_Indices[index]
            XY_Global_Indices[2 * index + 1] = 2 * Global_Indices[index] + 1

        XY_list = XY_Global_Indices.tolist()

        field_global_indices = np.empty(2 * global_indices.shape[0],
                                        dtype=np.int32)

        field_global_indices[0:-1:2] = 2 * global_indices
        field_global_indices[1::2] = 2 * global_indices + 1

        ### removed multiply by two here rambod Rambod
        Number_of_Global_Variables = 2 * self.__global_number_of_nodes

        # create Epetra Map based on node degrees of Freedom
        #self.field_balanced_map = Epetra.Map(self.number_of_field_variables,field_global_indices.tolist(),0, self.comm)
        self.field_balanced_map = Epetra.Map(Number_of_Global_Variables,
                                             XY_list, 0, self.comm)

        # Instantiate the corresponding graph
        self.balanced_field_graph = Epetra.CrsGraph(Epetra.Copy,
                                                    self.field_balanced_map,
                                                    True)
        # fill the field graph
        for i in global_indices:
            # array of global indices in neighborhood of each node
            global_index_array = (
                self.balanced_neighborhood_graph.ExtractGlobalRowCopy(i))
            # convert global node indices to appropriate field indices
            field_index_array = (np.sort(
                np.r_[2 * global_index_array,
                      2 * global_index_array + 1]).astype(np.int32))

            # insert rows into balanced graph per appropriate rows
            self.balanced_field_graph.InsertGlobalIndices(
                2 * i, field_index_array)
            self.balanced_field_graph.InsertGlobalIndices(
                2 * i + 1, field_index_array)

        # complete fill of balanced graph
        self.balanced_field_graph.FillComplete()
        # create balanced field map from balanced field neighborhood graph
        self.balanced_field_map = self.balanced_field_graph.Map()

        return
Exemple #4
0
    def create_graph(self):

        standard_map = Epetra.Map(self.nx, 0, self.comm)
        self.graph = Epetra.CrsGraph(Epetra.Copy, standard_map, 3)
        for gid in standard_map.MyGlobalElements():
            # Boundaries: Dirichlet boundary conditions
            if gid in (0, self.nx - 1):
                self.graph.InsertGlobalIndices(gid, [gid])
            else:
                self.graph.InsertGlobalIndices(gid, [gid - 1, gid, gid + 1])
        self.graph.FillComplete()
Exemple #5
0
    def __init_neighborhood_graph(self):
        """
           Creates the neighborhood ``connectivity'' graph.  This is used to
           load balanced the problem and initialize Jacobian data.
        """

        #Create the standard unbalanced map to instantiate the Epetra.CrsGraph
        #This map has all nodes on the 0 rank processor.
        standard_map = Epetra.Map(self.__global_number_of_nodes,
                                  len(self.nodes), 0, self.comm)
        #Compute a list of the lengths of each neighborhood list
        num_indices_per_row = np.array(
            [len(item) for item in self.neighborhoods], dtype=np.int32)
        #Instantiate the graph
        self.neighborhood_graph = Epetra.CrsGraph(Epetra.Copy, standard_map,
                                                  num_indices_per_row, True)

        #Fill the graph
        for rid, row in enumerate(self.neighborhoods):
            self.neighborhood_graph.InsertGlobalIndices(rid, row)
        #Complete fill of graph
        self.neighborhood_graph.FillComplete()

        return