View source: R/flownet_finitedifferences.R
findiff_sparse_elements | R Documentation |
Function generates rows, column and values for sparse matrix to get a first order approximation of values for all real nodes in a regularly spaced, rectangular grid in either the x or y direction.
The function assumes a regular, square grid where nodes are numbered row-first. The grid contains ghost nodes, and has a size 1*1.
The grid contains 'ghost' nodes on the side of all edges. For a 4*3 grid, the numbering is ('g' indicates a ghost node):
ix=0 | ix=1 | ix=2 | ix=3 | ix=4 | ix=5 | |
iy=4 | 23 (g) | 24 (g) | 25 (g) | 26 (g) | ||
iy=3 | 17 (g) | 18 | 19 | 20 | 21 | 22 (g) |
iy=2 | 11 (g) | 12 | 13 | 14 | 15 | 16 (g) |
iy=1 | 5 (g) | 6 | 7 | 8 | 9 | 10 (g) |
iy=0 | 1 (g) | 2 (g) | 3 (g) | 4 (g) | ||
The finite difference approximation is of the second order (central differences). When only real nodes are used and the node lies on an edge, a second order approximation is used (forwards or backwards, depending on the position)
findiff_sparse_elements(nx, ny, direction, i0 = 0, multiplier = 1, ...)
nx, ny |
number of real nodes in x and y-directions. There need to be
at least 3 (real or ghost) nodes in the direction of differentiation,
or 4 in case 2nd order differentiation is requested with
|
direction |
direction of differentiation
|
i0 |
optional index offset for node offset |
multiplier |
optional multipliers for all values in the finite difference matrix to differentiate real nodes |
... |
potential extra arguments |
a tibble with node indices for row (row
), column (col
) and
value (val
) columns of non-zero entries in the matrix
nx <- 4 ny <- 3 findiff_sparse_elements(nx, ny, "x") findiff_sparse_elements(nx, ny, "yy") findiff_sparse_elements(nx, ny, "xy")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.