find_xy: Find the coordinates of specified mesh cells

View source: R/find_xy.R

find_xyR Documentation

Find the coordinates of specified mesh cells

Description

This function finds the coordinates of specified mesh cells. For nodes, these can be extracted from the nodexy dataframe or from the mesh. The latter method is not quite as accurate and is slower; this difference may become noticeable for large meshes. However, for elements, the extraction of coordinates from the mesh is the only implemented method.

Usage

find_xy(mesh_ID, mesh, nodexy = NULL)

Arguments

mesh_ID

A vector of integers which define the mesh IDs for which coordinates are desired.

mesh

A mesh, created by build_mesh, around nodes or elements.

nodexy

(optional) A dataframe with columns which specify the coordinates and IDs of each cell in the mesh around nodes in columns named 'node_id', 'x' and 'y' (see dat_nodexy). If provided, coordinates are extracted from nodexy rather than mesh. This is recommended.

Value

The function returns a dataframe with mesh IDs ('mesh_ID') and corresponding coordinates ('x' and 'y').

Author(s)

Edward Lavender

Examples


#### Define mesh cells for which we want to extract coordinates
# In this hypothetical situation, we'll use mesh IDs for which we know their coordinates
# ... so that we can compare the two approaches:
set.seed(1)
select <- sample(1:nrow(dat_nodexy), 10)
dat <- dat_nodexy[select, ]

#### Examples: find_xy using nodexy and mesh options respectively
dat_xy1 <- find_xy(dat$node_id, nodexy = dat_nodexy)
dat_xy2 <- find_xy(dat$node_id, mesh = dat_mesh_around_nodes)

#### Coordinates from the nodexy method are exactly correct but coordinates from the mesh
# ... are not as accurate:
identical(dat, dat_xy1)
identical(dat, dat_xy2)
cbind(dat, dat_xy1, dat_xy2)

#### The nodexy approach is also considerably faster. For these reasons, the nodexy
# ... approach is recommended for node cells where possible.
microbenchmark::microbenchmark(find_xy(dat$node_id, nodexy = dat_nodexy),
                               find_xy(dat$node_id, mesh = dat_mesh_around_nodes)
)


edwardlavender/fvcom.tbx documentation built on Nov. 26, 2022, 10:28 p.m.