How to use the petsc4py.PETSc.InsertMode function in petsc4py

To help you get started, we’ve selected a few petsc4py examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github OP2 / PyOP2 / pyop2 / petsc_base.py View on Github external
def set_local_diagonal_entries(self, rows, diag_val=1.0, idx=None):
        rows = np.asarray(rows, dtype=IntType)
        rbs, _ = self.dims[0][0]
        if rbs > 1:
            if idx is not None:
                rows = rbs * rows + idx
            else:
                rows = np.dstack([rbs*rows + i for i in range(rbs)]).flatten()
        rows = rows.reshape(-1, 1)
        self.change_assembly_state(Mat.INSERT_VALUES)
        if len(rows) > 0:
            values = np.full(rows.shape, diag_val, dtype=ScalarType)
            self.handle.setValuesLocalRCV(rows, rows, values,
                                          addv=PETSc.InsertMode.INSERT_VALUES)
github erdc / proteus / src / LinearAlgebraTools.py View on Github external
def scatter_reverse_add(self):
        self.ghostUpdateBegin(p4pyPETSc.InsertMode.ADD_VALUES,p4pyPETSc.ScatterMode.REVERSE)
        self.ghostUpdateEnd(p4pyPETSc.InsertMode.ADD_VALUES,p4pyPETSc.ScatterMode.REVERSE)
github erdc / proteus / proteus / LinearAlgebraTools.py View on Github external
def scatter_reverse_add(self):
        if self.proteus2petsc_subdomain is not None:
            self.proteus_array[:] = self.proteus_array[self.petsc2proteus_subdomain]
        self.ghostUpdateBegin(p4pyPETSc.InsertMode.ADD_VALUES,p4pyPETSc.ScatterMode.REVERSE)
        self.ghostUpdateEnd(p4pyPETSc.InsertMode.ADD_VALUES,p4pyPETSc.ScatterMode.REVERSE)
        if self.proteus2petsc_subdomain is not None:
            self.proteus_array[:] = self.proteus_array[self.proteus2petsc_subdomain]
github mathLab / RBniCS / rbnics / backends / dolfin / wrapping / evaluate_sparse_function_at_dofs.py View on Github external
out_index = vec.getValue(i)
            vec_i_processor = mpi_comm.rank
        vec_i_processor = mpi_comm.allreduce(vec_i_processor, op=MAX)
        assert vec_i_processor >= 0
        out_reduced_i_processor = -1
        if reduced_i >= out_row_start and reduced_i < out_row_end:
            out_reduced_i_processor = mpi_comm.rank
        out_reduced_i_processor = mpi_comm.allreduce(vec_i_processor, op=MAX)
        assert out_reduced_i_processor >= 0
        if vec_i_processor != out_reduced_i_processor:
            if mpi_comm.rank == vec_i_processor:
                mpi_comm.send(out_index, dest=out_reduced_i_processor)
            if mpi_comm.rank == out_reduced_i_processor:
                out_index = mpi_comm.recv(source=vec_i_processor)
        if mpi_comm.rank == out_reduced_i_processor:
            out.setValues(reduced_i, out_index, addv=PETSc.InsertMode.INSERT)
    out.assemble()
    out.ghostUpdate()
github sfepy / sfepy / sfepy / parallel / parallel.py View on Github external
def gather_to_zero(pvec):
        """
        Return the global PETSc vector, corresponding to `pvec`, on the task of
        rank zero. The vector is reused between calls!
        """
        g20.scatter(pvec, pvec_full, PETSc.InsertMode.INSERT,
                    PETSc.ScatterMode.FORWARD)

        return pvec_full
github MiroK / fenics_ii / xii / assembler / trace_matrix.py View on Github external
visited_dofs[dof_T] = True

                # Define trace dof
                TV_dof.dof = local_T
                
                # Eval at V basis functions
                for local, dof in enumerate(dofs):
                    # Set which basis foo
                    V_basis_f.dof = local
                    
                    dof_values[local] = TV_dof.eval(V_basis_f)

                # Can fill the matrix now
                col_indices = np.array(dofs, dtype='int32')
                # Insert
                mat.setValues([dof_T], col_indices, dof_values, PETSc.InsertMode.INSERT_VALUES)
    return mat
github MiroK / fenics_ii / fenics_ii / reduced_eig / reduced_op.py View on Github external
m = len(I)

    I_perp = set(map(long, range(0, n))).difference(set(I))
    k = len(I_perp)
    assert m + k == n

    E_perp = PETSc.Mat()
    E_perp.createAIJ(size=(n, k), nnz=1)
    E_perp.setUp()

    for col, row in enumerate(I_perp):
        rows = [row]
        cols = [col]
        values = [1.] 

        E_perp.setValues(rows, cols, values, PETSc.InsertMode.INSERT_VALUES)
    E_perp.assemble()

    # Reduce as Ep.T.(A.Ep)
    R0, RA = PETSc.Mat(), PETSc.Mat()
    A.matMult(E_perp, R0)
    E_perp.transposeMatMult(R0, RA)
    RA = PETScMatrix(RA)

    if M is not None:
        RM = PETSc.Mat()
        M.matMult(E_perp, R0)
        E_perp.transposeMatMult(R0, RM)
        RM = PETScMatrix(RM)

    # Solve the reduced eigenvalue problem
    info('Solving reduced GEVP of size %d' % RA.size(0))
github MiroK / fenics_ii / xii / assembler / injection_matrix.py View on Github external
fine_dofs = fdmap.cell_dofs(f_cell)

            for local, dof in enumerate(fine_dofs):
                if visited_rows[dof]:
                    continue
                else:
                    visited_rows[dof] = True
                            
                Vf_dof.dof = local
                # Evaluete coarse basis foos here
                for local_c, dof_c in enumerate(coarse_dofs):
                    Vc_basis_f.dof = local_c
                    row_values[local_c] = Vf_dof.eval(Vc_basis_f)
                # Insert
                mat.setValues([dof], coarse_dofs, row_values, PETSc.InsertMode.INSERT_VALUES)

    return PETScMatrix(mat)