# Divergence calculation functions¶

Calculate vector divergence and related quantities at nodes or cells.

calc_flux_div_at_cell(grid, unit_flux, out=None)[source]

Calculate divergence of link-based fluxes at cells.

This function is very similar to the function calc_flux_div_at_node.

Given a flux per unit width across each cell face in the grid, calculate the net outflux (or influx, if negative) divided by cell area, at each cell.

Parameters: grid : ModelGrid A ModelGrid. unit_flux_at_links_across_faces : ndarray or field name Flux per unit width along links at faces (x number of faces) or link field. ndarray (x number of cells) Flux divergence at cells.

Notes

Performs a numerical flux divergence operation at cells.

Examples

>>> from landlab import RasterModelGrid, CLOSED_BOUNDARY
>>> from landlab.grid.divergence import calc_flux_div_at_cell
>>> rg = RasterModelGrid(3, 4, 10.0)
>>> import numpy as np
>>> z[5] = 50.0
>>> z[6] = 36.0
>>> lg
array([ 0. ,  0. ,  0. ,  0. ,  5. ,  3.6,  0. ,  5. , -1.4, -3.6,  0. ,
-5. , -3.6,  0. ,  0. ,  0. ,  0. ])
>>> fg = lg[rg.link_at_face]  # there are 7 faces
>>> fg
array([ 5. ,  3.6,  5. , -1.4, -3.6, -5. , -3.6])
>>> calc_flux_div_at_cell(rg, -fg)
array([ 1.64,  0.94])
>>> rg.set_status_at_node_on_edges(right=CLOSED_BOUNDARY)
>>> rg.set_status_at_node_on_edges(top=CLOSED_BOUNDARY)
>>> unit_flux_at_faces = np.zeros(rg.number_of_faces)
>>> unit_flux_at_faces[rg.active_faces] = -fg[rg.active_faces]
>>> calc_flux_div_at_cell(rg, unit_flux_at_faces)
array([ 1.14,  0.22])
array([ 1.64,  0.94])

calc_flux_div_at_node(grid, unit_flux, out=None)[source]

Calculate divergence of link-based fluxes at nodes.

Given a flux per unit width across each face in the grid, calculate the net outflux (or influx, if negative) divided by cell area, at each node (zero or “out” value for nodes without cells).

Parameters: grid : ModelGrid A ModelGrid. unit_flux : ndarray or field name Flux per unit width along links (x number of links). ndarray (x number of nodes) Flux divergence at nodes.

Notes

Performs a numerical flux divergence operation on nodes.

Examples

>>> from landlab import RasterModelGrid, CLOSED_BOUNDARY
>>> from landlab.grid.divergence import calc_flux_div_at_node
>>> rg = RasterModelGrid(3, 4, 10.0)
>>> z[5] = 50.0
>>> z[6] = 36.0
>>> lg
array([ 0. ,  0. ,  0. ,  0. ,  5. ,  3.6,  0. ,  5. , -1.4, -3.6,  0. ,
-5. , -3.6,  0. ,  0. ,  0. ,  0. ])
>>> calc_flux_div_at_node(rg, -lg)
array([ 0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.64,  0.94,  0.  ,  0.  ,
0.  ,  0.  ,  0.  ])
>>> rg.set_status_at_node_on_edges(right=CLOSED_BOUNDARY)
>>> rg.set_status_at_node_on_edges(top=CLOSED_BOUNDARY)
array([ 0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.14,  0.22,  0.  ,  0.  ,
0.  ,  0.  ,  0.  ])
array([ 0.  ,  0.  ,  0.  ,  0.  ,  0.  ,  1.64,  0.94,  0.  ,  0.  ,
0.  ,  0.  ,  0.  ])

calc_net_flux_at_node(grid, unit_flux_at_links, out=None)[source]

Calculate net link fluxes at nodes.

Given a flux per unit width along each link in the grid, calculate the net outflux (or influx, if negative) at each node. Fluxes are treated as zero for links that have no faces, and net fluxes are treated as zero for nodes that have no cell.

Parameters: grid : ModelGrid A ModelGrid. unit_flux_at_links : ndarray or field name Flux per unit width associated with links. out : ndarray, optional Buffer to hold the result. ndarray (x number of cells) Net flux at nodes.

Notes

This is essentially a line integral for the fluxes along the boundaries of each cell. Hence, the resulting output has dimensions of total flux (so, if the unit flux happens to be mass per time per face width, the output will be in mass per unit time). Because a line integral is undefined where there are no cells (i.e., perimeter nodes), the result is given as zeros for these nodes. The current algorithm uses fancy indexing (calling _calc_net_face_flux_at_cells) and could probably be made faster.

Examples

>>> from landlab import RasterModelGrid, CLOSED_BOUNDARY
>>> rg = RasterModelGrid(3, 4, 10.0)
>>> z[5] = 50.0
>>> z[6] = 36.0
>>> lg
array([ 0. ,  0. ,  0. ,  0. ,  5. ,  3.6,  0. ,  5. , -1.4, -3.6,  0. ,
-5. , -3.6,  0. ,  0. ,  0. ,  0. ])
>>> calc_net_flux_at_node(rg, -lg)
array([   0.,    0.,    0.,    0.,    0.,  164.,   94.,    0.,    0.,
0.,    0.,    0.])
>>> rg.set_status_at_node_on_edges(right=CLOSED_BOUNDARY)
>>> rg.set_status_at_node_on_edges(top=CLOSED_BOUNDARY)
>>> np.round(nlfn)
array([   0.,    0.,    0.,    0.,    0.,  114.,   22.,    0.,    0.,
0.,    0.,    0.])

>>> from landlab import HexModelGrid
>>> hg = HexModelGrid(3, 3, 10.0)
>>> z = hg.add_zeros('node', 'topographic__elevation', noclobber=False)
>>> z[4] = 50.0
>>> z[5] = 36.0