petsc-3.12.0 2019-09-29
Report Typos and Errors

PetscSFGetSubSF

Returns an SF for a specific subset of points. Leaves are re-numbered to reflect the new ordering.

Synopsis

#include "petscdmnetwork.h"  
PetscErrorCode DMNetworkGetSupportingEdges(DM dm,PetscInt vertex,PetscInt *nedges,const PetscInt *edges[])

Input Parameters

masterSF - the original SF structure
map - a ISLocalToGlobal mapping that contains the subset of points

Output Parameters

subSF -a subset of the masterSF for the desired subset. */

PetscErrorCode PetscSFGetSubSF(PetscSF mastersf, ISLocalToGlobalMapping map, PetscSF *subSF) {

PetscErrorCode ierr; PetscInt nroots, nleaves, *ilocal_sub; PetscInt i, *ilocal_map, nroots_sub, nleaves_sub = 0; PetscInt *local_points, *remote_points; PetscSFNode *iremote_sub; const PetscInt *ilocal; const PetscSFNode *iremote;

PetscFunctionBegin; ierr = PetscSFGetGraph(mastersf,&nroots,&nleaves,&ilocal,&iremote);CHKERRQ(ierr);

/* Look for leaves that pertain to the subset of points. Get the local ordering */ ierr = PetscMalloc1(nleaves,&ilocal_map);CHKERRQ(ierr); ierr = ISGlobalToLocalMappingApply(map,IS_GTOLM_MASK,nleaves,ilocal,NULL,ilocal_map);CHKERRQ(ierr); for (i = 0; i < nleaves; i++) { if (ilocal_map[i] != -1) nleaves_sub += 1; } /* Re-number ilocal with subset numbering. Need information from roots */ ierr = PetscMalloc2(nroots,&local_points,nroots,&remote_points);CHKERRQ(ierr); for (i = 0; i < nroots; i++) local_points[i] = i; ierr = ISGlobalToLocalMappingApply(map,IS_GTOLM_MASK,nroots,local_points,NULL,local_points);CHKERRQ(ierr); ierr = PetscSFBcastBegin(mastersf, MPIU_INT, local_points, remote_points);CHKERRQ(ierr); ierr = PetscSFBcastEnd(mastersf, MPIU_INT, local_points, remote_points);CHKERRQ(ierr); /* Fill up graph using local (that is, local to the subset) numbering. */ ierr = PetscMalloc1(nleaves_sub,&ilocal_sub);CHKERRQ(ierr); ierr = PetscMalloc1(nleaves_sub,&iremote_sub);CHKERRQ(ierr); nleaves_sub = 0; for (i = 0; i < nleaves; i++) { if (ilocal_map[i] != -1) { ilocal_sub[nleaves_sub] = ilocal_map[i]; iremote_sub[nleaves_sub].rank = iremote[i].rank; iremote_sub[nleaves_sub].index = remote_points[ilocal[i]]; nleaves_sub += 1; } } ierr = PetscFree2(local_points,remote_points);CHKERRQ(ierr); ierr = ISLocalToGlobalMappingGetSize(map,&nroots_sub);CHKERRQ(ierr);

/* Create new subSF */ ierr = PetscSFCreate(PETSC_COMM_WORLD,subSF);CHKERRQ(ierr); ierr = PetscSFSetFromOptions(*subSF);CHKERRQ(ierr); ierr = PetscSFSetGraph(*subSF,nroots_sub,nleaves_sub,ilocal_sub,PETSC_OWN_POINTER,iremote_sub,PETSC_COPY_VALUES);CHKERRQ(ierr); ierr = PetscFree(ilocal_map);CHKERRQ(ierr); ierr = PetscFree(iremote_sub);CHKERRQ(ierr); PetscFunctionReturn(0); }

/*@C DMNetworkGetSupportingEdges - Return the supporting edges for this vertex point

Not Collective

Input Parameters

dm - The DMNetwork object
p - the vertex point

Output Paramters

nedges - number of edges connected to this vertex point
edges - List of edge points

Fortran Notes

Since it returns an array, this routine is only available in Fortran 90, and you must include petsc.h90 in your code.

See Also

DMNetworkCreate, DMNetworkGetConnectedVertices

Level

intermediate

Location

src/dm/impls/network/network.c
Index of all DMNetwork routines
Table of Contents for all manual pages
Index of all manual pages