landlab.grid.hex_mappers¶
Grid element mappers that are specific to hex grids.
Mapping functions unique to hex grids¶
|
Map (x,y) components of link data data_at_link onto nodes of hex grid. |
- class LinkAtNode[source]¶
Bases:
IntEnum
- EAST = 0¶
- ENE = 0¶
- ESE = 5¶
- NNE = 1¶
- NNW = 2¶
- NORTH = 1¶
- SOUTH = 4¶
- SSE = 5¶
- SSW = 4¶
- WEST = 3¶
- WNW = 2¶
- WSW = 3¶
- classmethod __contains__(value)¶
Return True if value is in cls.
value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members.
- __dir__()¶
Returns public methods and other interesting attributes.
- classmethod __getitem__(name)¶
Return the member matching name.
- classmethod __iter__()¶
Return members in definition order.
- classmethod __len__()¶
Return the number of members (no aliases)
- __new__(value)¶
- map_link_vector_components_to_node_hex(grid, data_at_link)[source]¶
Map (x,y) components of link data data_at_link onto nodes of hex grid.
- Parameters:
grid (HexModelGrid) – Landlab HexModelGrid object
data_at_links (ndarray of float x number of links) – Data to be mapped
- Returns:
(x_component, y_component) – The x and y components of the field at each node. Both x and y components for non-core nodes are set to zero.
- Return type:
tuple of ndarray
Examples
>>> import numpy as np >>> from landlab import HexModelGrid >>> from landlab.grid.mappers import map_link_vector_components_to_node
>>> grid = HexModelGrid((3, 3)) >>> link_data = np.full(grid.number_of_links, 0.5 * 3.0**0.5) >>> link_data[np.isclose(grid.angle_of_link, 0.0)] = 0.0
>>> vx, vy = map_link_vector_components_to_node(grid, link_data) >>> vx array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]) >>> vy array([0., 0., 0., 0., 1., 1., 0., 0., 0., 0.])
>>> link_data = np.arange(grid.number_of_links) >>> vx, vy = map_link_vector_components_to_node(grid, link_data) >>> vx array([0. , 0. , 0. , 0. , 8.5, 9.5, 0. , 0. , 0. , 0. ])
>>> link_data = np.full(grid.number_of_links, 0.5 * 3.0**0.5) >>> link_data[np.isclose(grid.angle_of_link, 2.0 / 3.0 * np.pi)] = 0.0
>>> vx, vy = map_link_vector_components_to_node(grid, link_data) >>> np.round(vx, 3) array([0. , 0. , 0. , 0. , 0.866, 0.866, 0. , 0. , 0. , 0. ]) >>> vy array([0. , 0. , 0. , 0. , 0.5, 0.5, 0. , 0. , 0. , 0. ])
>>> grid = HexModelGrid((3, 3), orientation="vertical") >>> link_data = np.arange(grid.number_of_links)
>>> vx, vy = map_link_vector_components_to_node(grid, link_data) >>> vy array([ 0. , 0. , 0. , 5.5, 0. , 0. , 12.5, 0. , 0. , 0. ])
>>> link_data = np.full(grid.number_of_links, 0.5 * 3.0**0.5) >>> link_data[np.isclose(grid.angle_of_link, np.pi / 2.0)] = 0.0
>>> vx, vy = map_link_vector_components_to_node(grid, link_data) >>> vx array([0., 0., 0., 1., 0., 0., 1., 0., 0., 0.]) >>> vy array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])
Notes
Calculation is only made for core nodes; boundary nodes receive zeros.
For a grid with orientation=’horizontal’, one of the 3 link orientations is horizontal. The x component is therefore taken as the average value of the links to the east (right) and west (left). For a grid with orientation=’vertical’, the same principle applies for the y component: it is the average of the link values to the north/top and south/bottom.
In general, the theory behind the approach is that there exists a “true” vector field that has been projected onto the links. Let $V = (v_x, v_y)$ be the true vector. The projection of $V$ onto two links with unit vectors $l_1 = (l_{1x}, l_{1y})$ and $l_2 = (l_{2x}, l_{2y})$ yields the following formula for the scalar magnitude, or component, of the two link vectors:
L_1 = V dot l_1 L_2 = V dot l_2
We know $L_1$ and $L_2$: they are the values associated with two adjacent links, and here we’re interested either in the nne and nnw oriented links (in a horizontally oriented grid) or the ene and ese oriented links (on a vertically oriented grid). We also know the unit vectors $l_1$ and $l_2$, which derive from the link orientations (they involve sin 60 and cos 60). So we have two equations with two unknowns: the vector components $v_x$ and $v_y$.
In practice, we use this math to obtain the $y$ component for a horizontal grid, and the $x$ component for a vertical grid. The opposite component is found directly from the horizontal or vertical links, respectively.
Note that in the above doc tests, we take advantage of the fact that sin 60 deg = half the square root of 3 (no need to import math or numpy).