findiff_sparse_elements: Get sparse matrix elements for 1st or 2nd order...

View source: R/flownet_finitedifferences.R

findiff_sparse_elementsR Documentation

Get sparse matrix elements for 1st or 2nd order differentiation

Description

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)

Usage

findiff_sparse_elements(nx, ny, direction, i0 = 0, multiplier = 1, ...)

Arguments

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 real_only == TRUE

direction

direction of differentiation

  • direction = "x": 1st order in x-direction (d/dx)

  • direction = "y": 1st order in y-direction (d/dy)

  • direction = "xx": 2nd order in x-direction (d^2/dx^2)

  • direction = "xy": 2nd order in y-direction (d^2/dy^2)

  • direction = "xy": 1st order in x and y-direction (d^2/dxdy)

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

Value

a tibble with node indices for row (row), column (col) and value (val) columns of non-zero entries in the matrix

Examples

nx <- 4
ny <- 3
findiff_sparse_elements(nx, ny, "x")
findiff_sparse_elements(nx, ny, "yy")
findiff_sparse_elements(nx, ny, "xy")

GJMeijer/soilmech documentation built on May 22, 2022, 10:39 a.m.