landlab.grid.divergence¶
Calculate vector divergence and related quantities at nodes or cells.
- calc_flux_div_at_cell(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:
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.
- Returns:
Flux divergence at cells.
- Return type:
ndarray (x number of cells)
Examples
>>> from landlab import RasterModelGrid >>> from landlab.grid.divergence import calc_flux_div_at_cell >>> rg = RasterModelGrid((3, 4), xy_spacing=10.0) >>> import numpy as np >>> z = rg.add_zeros("topographic__elevation", at="node") >>> z[5] = 50.0 >>> z[6] = 36.0 >>> lg = rg.calc_grad_at_link(z) # there are 17 links >>> 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=rg.BC_NODE_IS_CLOSED) >>> rg.set_status_at_node_on_edges(top=rg.BC_NODE_IS_CLOSED) >>> 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]) >>> _ = rg.add_field("neg_grad_at_link", -lg, at="link") >>> calc_flux_div_at_cell(rg, "neg_grad_at_link") array([1.64, 0.94])
Notes
Performs a numerical flux divergence operation at cells.
- calc_flux_div_at_node(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:
unit_flux (ndarray or field name) – Flux per unit width along links (x number of links).
- Returns:
Flux divergence at nodes.
- Return type:
ndarray (x number of nodes)
Examples
>>> from landlab import RasterModelGrid >>> from landlab.grid.divergence import calc_flux_div_at_node >>> rg = RasterModelGrid((3, 4), xy_spacing=10.0) >>> z = rg.add_zeros("topographic__elevation", at="node") >>> z[5] = 50.0 >>> z[6] = 36.0 >>> lg = rg.calc_grad_at_link(z) # there are 17 links >>> 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=rg.BC_NODE_IS_CLOSED) >>> rg.set_status_at_node_on_edges(top=rg.BC_NODE_IS_CLOSED) >>> unit_flux_at_links = np.zeros(rg.number_of_links) >>> unit_flux_at_links[rg.active_links] = -lg[rg.active_links] >>> calc_flux_div_at_node(rg, unit_flux_at_links) array([0. , 0. , 0. , 0. , 0. , 1.14, 0.22, 0. , 0. , 0. , 0. , 0. ]) >>> _ = rg.add_field("neg_grad_at_link", -lg, at="link") >>> calc_flux_div_at_node(rg, "neg_grad_at_link") array([0. , 0. , 0. , 0. , 0. , 1.64, 0.94, 0. , 0. , 0. , 0. , 0. ])
Notes
Performs a numerical flux divergence operation on nodes.
- calc_net_flux_at_node(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:
unit_flux_at_links (ndarray or field name) – Flux per unit width associated with links.
out (ndarray, optional) – Buffer to hold the result.
- Returns:
Net flux at nodes.
- Return type:
ndarray (x number of cells)
Examples
>>> from landlab import RasterModelGrid >>> rg = RasterModelGrid((3, 4), xy_spacing=10.0) >>> z = rg.add_zeros("topographic__elevation", at="node") >>> z[5] = 50.0 >>> z[6] = 36.0 >>> lg = rg.calc_grad_at_link(z) # there are 17 links >>> 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=rg.BC_NODE_IS_CLOSED) >>> rg.set_status_at_node_on_edges(top=rg.BC_NODE_IS_CLOSED) >>> unit_flux_at_links = np.zeros(rg.number_of_links) >>> unit_flux_at_links[rg.active_links] = -lg[rg.active_links] >>> nlfn = calc_net_flux_at_node(rg, unit_flux_at_links) >>> np.round(nlfn) array([ 0., 0., 0., 0., 0., 114., 22., 0., 0., 0., 0., 0.])
>>> from landlab import HexModelGrid >>> hg = HexModelGrid((3, 3), spacing=10.0) >>> z = hg.add_zeros("topographic__elevation", at="node", clobber=True) >>> z[4] = 50.0 >>> z[5] = 36.0 >>> lg = hg.calc_grad_at_link(z) # there are ? links >>> lg array([ 0. , 0. , 0. , 5. , 5. , 3.6, 3.6, 0. , 5. , -1.4, -3.6, 0. , -5. , -5. , -3.6, -3.6, 0. , 0. , 0. ]) >>> nlfn = calc_net_flux_at_node(hg, -lg) >>> np.round(nlfn) array([ 0., 0., 0., 0., 152., 96., 0., 0., 0., 0.])
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.