Skip to main content
`Ctrl`+`K`

# PetscSFSetGraphFromCoordinates

Create SF by fuzzy matching leaf coordinates to root coordinates

## Synopsis

    #include "petscsf.h"
    PetscErrorCode PetscSFSetGraphFromCoordinates(PetscSF sf, PetscInt nroots, PetscInt nleaves, PetscInt dim, PetscReal tol, const PetscReal rootcoords[], const PetscReal leafcoords[])

Collective

## Input Parameters

- sf - PetscSF to set graph on

- nroots - number of root coordinates

- nleaves - number of leaf coordinates

- dim - spatial dimension of coordinates

- tol - positive tolerance for matching

- rootcoords - array of root coordinates in which root i component d is [i*dim+d]

- leafcoords - array of root coordinates in which leaf i component d is [i*dim+d]

## Notes

The tolerance typically represents the rounding error incurred by numerically computing coordinates via possibly-different procedures. Passing anything from `PETSC_SMALL` to `100 * PETSC_MACHINE_EPSILON` is appropriate for most use cases.

## Example

As a motivating example, consider fluid flow in the x direction with y (distance from a wall). The spanwise direction, z, has periodic boundary conditions and needs some spanwise length to allow turbulent structures to develop. The distribution is stationary with respect to z, so you want to average turbulence variables (like Reynolds stress) over the z direction. It is complicated in a 3D simulation with arbitrary partitioner to uniquely number the nodes or quadrature point coordinates to average these quantities into a 2D plane where they will be visualized, but it’s easy to compute the projection of each 3D point into the 2D plane.

Suppose a 2D target mesh and 3D source mesh (logically an extrusion of the 2D, though perhaps not created in that way) are distributed independently on a communicator. Each rank passes its 2D target points as root coordinates and the 2D projection of its 3D source points as leaf coordinates. Calling `PetscSFReduceBegin()`/`PetscSFReduceEnd()` on the result will sum data from the 3D sources to the 2D targets.

As a concrete example, consider three MPI ranks with targets (roots)

    Rank 0: (0, 0), (0, 1)
    Rank 1: (0.1, 0), (0.1, 1)
    Rank 2: (0.2, 0), (0.2, 1)

Note that targets must be uniquely owned. Suppose also that we identify the following leaf coordinates (perhaps via projection from a 3D space).

    Rank 0: (0, 0), (0.1, 0), (0, 1), (0.1, 1)
    Rank 1: (0, 0), (0.1, 0), (0.2, 0), (0, 1), (0.1, 1)
    Rank 2: (0.1, 0), (0.2, 0), (0.1, 1), (0.2, 1)

Leaf coordinates may be repeated, both on a rank and between ranks. This example yields the following `PetscSF` capable of reducing from sources to targets.

    Roots by rank
    [0]  0:   0.0000e+00   0.0000e+00   0.0000e+00   1.0000e+00
    [1]  0:   1.0000e-01   0.0000e+00   1.0000e-01   1.0000e+00
    [2]  0:   2.0000e-01   0.0000e+00   2.0000e-01   1.0000e+00
    Leaves by rank
    [0]  0:   0.0000e+00   0.0000e+00   1.0000e-01   0.0000e+00   0.0000e+00
    [0]  5:   1.0000e+00   1.0000e-01   1.0000e+00
    [1]  0:   0.0000e+00   0.0000e+00   1.0000e-01   0.0000e+00   2.0000e-01
    [1]  5:   0.0000e+00   0.0000e+00   1.0000e+00   1.0000e-01   1.0000e+00
    [1] 10:   2.0000e-01   1.0000e+00
    [2]  0:   1.0000e-01   0.0000e+00   2.0000e-01   0.0000e+00   1.0000e-01
    [2]  5:   1.0000e+00   2.0000e-01   1.0000e+00
    PetscSF Object: 3 MPI processes
      type: basic
      [0] Number of roots=2, leaves=4, remote ranks=2
      [0] 0 <- (0,0)
      [0] 1 <- (1,0)
      [0] 2 <- (0,1)
      [0] 3 <- (1,1)
      [1] Number of roots=2, leaves=6, remote ranks=3
      [1] 0 <- (0,0)
      [1] 1 <- (1,0)
      [1] 2 <- (2,0)
      [1] 3 <- (0,1)
      [1] 4 <- (1,1)
      [1] 5 <- (2,1)
      [2] Number of roots=2, leaves=4, remote ranks=2
      [2] 0 <- (1,0)
      [2] 1 <- (2,0)
      [2] 2 <- (1,1)
      [2] 3 <- (2,1)

## See Also

`PetscSFCreate()`, `PetscSFSetGraph()`, `PetscSFCreateByMatchingIndices()`

## Level

advanced

## Location

src/vec/is/sf/utils/sfcoord.c

## Examples

src/dm/impls/plex/tutorials/ex15.c

Index of all PetscSF routines
Table of Contents for all manual pages
Index of all manual pages