# sl.findneighbours: Find Node Neighbours Based on Triangular Elements In helgegoessling/spheRlab: Spherical Geometry, Analysis, and Plotting of Geoscientific Data on Arbitrary Grids

## Description

Given the triangular elements (node triplets) of a regular mesh, find all neighbour nodes for each node.

## Usage

 `1` ```sl.findneighbours(elem, maxmaxneigh = 12, reverse = TRUE, verbose = FALSE, max.iter = 10) ```

## Arguments

 `elem` an `Ne`x`3` matrix with the node indices of the triangular elements in rows. `maxmaxneigh` an integer specifying an upper limit for the expected maximum number of neighbours for a node. For a typical (close to orthogonal) triangular mesh, there are 6 neighbours per node on average; the default value `maxmaxneigh=12` is relatively safe. A too small value results in an error. A larger value implies more memory usage. `reverse` a logical value indicating whether the order of the node neighbours shall be reversed (clockwise/counterclockwise). `verbose` a logical value indicating whether print statements shall report on the function progess. `max.iter` an integer specifying the maximum number of iterations used to order the neighbours of each node. The default `max.iter=10` should be on the safe side.

## Details

It may happen that, despite a sufficiently high value of `max.iter`, node neighbours can't be arranged in order and a corresponding warning is printed. In this case the affected nodes might be 'bad' nodes connecting two or more separate regions of the mesh domain, for example two ocean basins (as well as two pieces of land); such a connection should be represented either by multiple nodes, or closed completely. If 'bad' nodes exists, only one contiguous part of the mesh (wrt neighbour nodes and adjacent elements) will be returned for those nodes.

## Value

 `neighbour.nodes` an `N`x`M` matrix with each row containing all neighbours of one node. The neighbours are arranged in clockwise or counterclockwise order, depending on the direction of rotation provided in `elem` (can be reversed by the argument `reverse`). `M` is the maximum number of neighbours actually found for a node (`M<=maxmaxneigh`). `neighbour.elems` an `N`x`M` matrix with each row containing all triangular elements (identified by the row indices in `elem`) adjacent to one node. The elements are arranged in clockwise or counterclockwise order, depending on the direction of rotation provided in `elem` (can be reversed by the argument `reverse`). `M` is the maximum number of neighbours actually found for a node (`M<=maxmaxneigh`). `internal.nodes` a vector of length `N` with logical values indicating which nodes are internal, that is, non-coastal. `N.neighbour.nodes` a vector of length `N` with the number of neighbours for each node. `all.elements.arranged` a logical value indicating whether all neighbours and elements have been ordered successfully. `elems.completed` `NULL` if `all.elements.arranged=TRUE`, otherwise a vector of length `N` with logical values indicating which nodes were successfully arranged in order.

## Note

This function is used by `sl.grid.readFESOM`.

## Author(s)

Helge Goessling

`sl.grid.readFESOM`
 `1` ```## To be provided ... ```