build_mesh | R Documentation |
This function is used to build an unstructured mesh (around nodes or elements) from node coordinates and connections as a SpatialPolygonsDataFrame. This function was designed with the WeStCOMS unstructured mesh in mind.
build_mesh( nodexy, trinodes, mesh_type = "element", proj4string = sp::CRS(as.character("+init=epsg:4326")), cl = NULL, pass2varlist = NULL )
nodexy |
A dataframe containing node IDs and coordinates. The dataframe should have three columns: 'node_id', 'x' and 'y'. See |
trinodes |
A dataframe containing element IDs and the surrounding nodes (i.e. which nodes are linked to which other nodes). The dataframe should have four columns: 'element_id', 'node1', 'node2' and 'node3'. See |
mesh_type |
A character specifying the mesh type to be built. There are two options: |
proj4string |
A projection string of class |
cl |
A cluster object created by |
pass2varlist |
A list containing the names of exported objects. This may be required if |
An SpatialPolygonsDataFrame (see SpatialPolygonsDataFrame-class
). Each polygon has an ID corresponding to the ID of the node or element which is surrounds, as supplied by the nodexy or trinodes dataframe respectively.
Edward Lavender
SpatialPolygonsDataFrame-class
for the output class;
dat_nodexy
for an example nodexy dataframe;
dat_trinodes
for an example trinodes dataframe;
makeCluster
and clusterExport
for more information on parallelisation.
# 1) Build a mesh around elements (based on nodes) on a single processor # You will receive a warning when you run this: # ...'In sp::Polygon(coords, hole) : less than 4 coordinates in polygon'. # This can be safely ignored. This is because each polygon is a prism; # ... i.e., only comprised of three coordinates. mesh_around_elements <- build_mesh(nodexy = dat_nodexy, trinodes = dat_trinodes, mesh_type = "node", cl = NULL, pass2varlist = NULL) # 2) Build a mesh around nodes (based on elements) on a single processor mesh_around_nodes <- build_mesh(nodexy = dat_nodexy, trinodes = dat_trinodes, mesh_type = "element", cl = NULL, pass2varlist = NULL) # 3) Build a mesh around elements (based on nodes) using parallel processing # Define cluster object: cl <- parallel::makeCluster(2L) # Run the build_mesh algorithm in parallel by supplying a cluster: mesh_around_elements <- build_mesh(nodexy = dat_nodexy, trinodes = dat_trinodes, mesh_type = "node", cl = cl, pass2varlist = c("dat_nodexy", "dat_trinodes")) # Note that the connection with the cluster is closed within the function.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.