GeMA
The GeMA main application
Regular mesh object methods

Index:

Regular grid mesh methods

mesh:nodeSpacing(dim)
Description: Returns the spacing, in the given direction, for a regular grid mesh.
Parameters: dim - The queried dimension (from 1 to the mesh coordinate dimension). A value of 1 means x, 2 means y and 3 means z.
Returns: Returns the mesh regular spacing in the given direction.

Example:

local dx = m:nodeSpacing(1)
local dy = m:nodeSpacing(2)


mesh:nodeCount(dim)
Description: Returns the node count, in the given direction, for a regular grid mesh.
Parameters: dim - The queried dimension (from 1 to the mesh coordinate dimension). A value of 1 means x, 2 means y and 3 means z.
Returns: Returns the number of nodes in the given direction.

Example:

local nx = m:nodeCount(1)
local ny = m:nodeCount(2)


mesh:nodeWrap(dim)
Description: Returns true if the mesh 'wraps around', in the given direction, for a regular grid mesh. Wrapping around means that the last and first nodes in that direction are conceptually neighbors.
Parameters: dim - The queried dimension (from 1 to the mesh coordinate dimension). A value of 1 means x, 2 means y and 3 means z.
Returns: Returns the mesh wrap mode in the given direction.

Example:

if m:nodeWrap(1) then
...
end


mesh:nodeFromIndex(i, j, k)
Description: Given a set of node column, line and depth indices, returns the correspondent node index. The number of parameters sent to the function should be equal to the mesh coordinate dimension.
Parameters: i The node position (index) in the x dimension (from 1 to mesh:nodeCount(1)). Corresponds to the grid column index.
j The node position (index) in the y dimension (from 1 to mesh:nodeCount(2)). Corresponds to the grid line index.
k The node position (index) in the z dimension (from 1 to mesh:nodeCount(3)). Corresponds to the grid depth index.
Returns: Returns the mesh node index.

Example:

-- Get the x, y coordinate for the node at the 4th column and 5th line in a regular 2D grid
local ac = m:nodeCoordAccessor()
local nodeindex = m:nodeFromIndex(4, 5)
local coord = ac:value(nodeIndex)
local x, y = coord(1), coord(2)


mesh:indexFromNode(nodeIndex)
Description: Given a node index, returns its (i, j, k) coordinates, corresponding to the node's column, line and/or depth in the grid mesh. The number of returned coordinates depends on the mesh dimension.
Parameters: nodeIndex - The mesh node index (from 1 to mesh:numNodes()).
Returns: Returns the grid indices corresponding to the given node. The number of returned values is equal to the mesh dimension.

Example:

local i, j = m:indexFromNode(nodeIndex)
-- Show that nodeFromIndex() and indexFromNode() are opposite operations.
for n = 1, m:numNodes() do
local i, j, k = m:indexFromNode(n)
assert(m:nodeFromIndex(i, j, k) == n)
end


mesh:neighbor(node, di, dj, dk)
Description: Given a node index and a set of offsets in each direction, returns the mesh index of the correspondent neighbor index. If the mesh wraps around in a given dimension, the last and first nodes in that dimension will be neighbors. The number of offset parameters sent to the function should be equal to the mesh coordinate dimension.
Parameters: node The base node index (from 1 to mesh:numNodes()).
di The desired integer offset from node in the x direction. Can be a positive, negative or zero value.
dj The desired integer offset from node in the y direction. Can be a positive, negative or zero value.
dk The desired integer offset from node in the z direction. Can be a positive, negative or zero value.
Returns: Returns the mesh index of the specified neighbor node or nil if out of bounds (there is no neighbor in the given direction).

Example:

local nextX = m:neighbor(node, 1, 0)
local prevX = m:neighbor(node, -1, 0)
local nextY = m:neighbor(node, 0, 1)
local prevY = m:neighbor(node, 0, -1)
loca next2X = m:neighbor(node, 2, 0) -- The node two steps ahead in the x direction