GeMA
The GeMA main application
Cell mesh object methods

Most used:

Index:

Cell geometry methods

mesh:numCells()
Description: Returns the number of cells in this mesh (elements for an element mesh).
Parameters: None.
Returns: Returns the number of cells in the mesh.

Example:

local ncells = m:numCells()


mesh:numActiveCells()
Description: Returns the number of active cells in this mesh. Inactive cells do not take part in analysis processes. A cell can be marked as active or inactive by calling the cell:setActive() method over a cell object returned by mesh:cell().
Parameters: None.
Returns: Returns the number of active cells in the mesh.

Example:

local nactive = m:numActiveCells()


mesh:cell(index)
Description: Returns a cell object given its id in the mesh.
Parameters: index - The cell id number (an index between 1 and mesh:numCells()).
Returns: Returns the cell object.

Example:

local c = m:cell(1) -- Returns the first cell mesh object


mesh:numCellTypes()
Description: Returns a table specifying the number of cells in the mesh for each cell type.
Parameters: None.
Returns: Returns a table indexed by cell type name (see Element types), with the number of cells in the mesh for each type. Entries for cell types that are not present in the mesh are not filled (value equals nil).

Example:

-- Print the number of "quad4" and "tri3" elements in th mesh
local types = m:numCellTypes()
print('quad4', types.quad4)
print('tri3', types.tri3)


mesh:numActiveCellTypes()
Description: Returns a table specifying the number of active cells in the mesh for each cell type.
Parameters: None.
Returns: Returns a table indexed by cell type name (see Element types), with the number of active cells in the mesh for each type. Entries for cell types that do not have active cells in the mesh are not filled (value equals nil).

Example:

-- Print the number of active "quad4" and "tri3" elements in th mesh
local types = m:numActiveCellTypes()
print('quad4', types.quad4)
print('tri3', types.tri3)


mesh:maxNumCellNodes()
Description: Returns the maximum number of nodes in a mesh cell (equivalent to calculating the maximum of the number of nodes of each type that has a non nil entry in the table returned by mesh:numCellTypes()).
Parameters: None.
Returns: Returns the maximum number of nodes among types present in the mesh.

Example:

local maxNodes = m:maxNumCellNodes()


mesh:maxNumCellGhostNodes()
Description: Returns the maximum number of ghost nodes in a mesh cell. Depending on the mesh implementation, this number might be an upper limit, meaning that no cell has more than the returned number of ghost nodes, but without implying that there is a cell with that number.
Parameters: None.
Returns: Returns the maximum number of ghost nodes among cells present in the mesh.

Example:

local maxGhostNodes = m:maxNumCellGhostNodes()


mesh:maxTotalNumCellNodes()
Description: Returns the maximum number of regular + ghost nodes in a mesh cell. Depending on the mesh implementation, this number might be an upper limit, meaning that no cell has more than the returned number of nodes, but without implying that there is a cell with that number.
Parameters: None.
Returns: Returns the maximum number of regular + ghost nodes among cells present in the mesh.

Example:

local maxNodes = m:maxTotalNumCellNodes()


mesh:addCells(numCells)
Description: Adds the specified number of cells to the mesh, whithout initializing their nodes or properties. After calling this function, make sure to initialize cell node lists and properties by calling cell:setNodes() and cell:setProperties() for each added cell. Attribute values for the new cells are initialized with their respective default values.
IMPORTANT: When adding cells to the mesh, if at all possible, avoid calling this function several times in a sequence. Calling it once with the total number of cells is much more efficent than calling it repeatedlly with just a few cells. If cells are added during the simulation loop, please remember to call mesh:emitMeshChanged(). This function can only be called if mesh:hasCapability("addCells") returns true.
Parameters: numCells - A table defining the number of cells to add, grouped by cell type. The given table should be keyed by the cell type name (see Element types) and have as values the number of added cells for each type. Notice that cells are added to the mesh in the order defined by the GmCellType enumeration, i.e., if the numCells list defines that we want 10 new "quad4" elements and 20 new "tri3" elements, all the "quad4" elements will be added before the "tri3" elements since "quad4" appears before "tri3" in that enumeration. For a finer control of the cell creation order, consider calling this function multiple times, each one with a single type entry in the numCells table.
Returns: Returns the index of the first new included cell.

Example:

-- Add 10 quad4 and 20 tri3 elements to the mesh
local ntypes = {quad4 = 10, tri3 = 20}
local pos = m:addCells(ntypes)
-- Init quad4 cells
for i = 1, 10 do
local c = m:cell(pos)
pos = pos + 1
... -- Fill lists with cell nodes and properties
c:setNodes(elementNodesList, m)
c:setProperties(elementPropertiesList, m)
end
-- Init tri3 cells
for i = 1, 10 do
local c = m:cell(pos)
pos = pos + 1
... -- Fill lists with cell nodes and properties
c:setNodes(elementNodesList, m)
c:setProperties(elementPropertiesList, m)
end
m:emitMeshChanged()


Cell topology methods

mesh:adjacentCell(cellIndex, edgeSide)
mesh:adjacentCell(cell, edgeSide)
Description: Given a cell (defined either by its index or by a cell object) and a cell side index (edge index for surface elements or face index for solid elements, undefined for line elements), returns the adjacent cell by that side or nil if that side is at the mesh border. Also returns the index of the neighbor side in the adjacent cell.
IMPORTANT: This function should only be called if mesh:hasCapability("topology") returns true.
Parameters: cellIndex The cell id number (an index between 1 and mesh:numCells()).
cell The cell object.
sideIndex The index of the side whose adjacent neighbor will be queried. It should be an edge local index (a value between 1 and geometry:numEdges()) for surface elements and a face local index (a value between 1 and geometry:numFaces()) for solid elements. See the Element types page for the edge and face organization for each cell type.
Returns: Returns the adjacent cell object or nil if the edge or face is on the mesh border. If there is an adjacent side, also returns the index of the neighbor side at the adjacent cell.

Example:

-- Get the adjacent cell to the second edge of the first mesh cell
local adjCell, adjCellSide = m:adjacentCell(1, 2)


mesh:nodeAdjacentNodes(nodeIndex, options)
Description: Returns a list with the set of nodes that are adjacent to the given node. Nodes are considered adjacent if they are connected by an edge. Each list entry is a node index (a value between 1 and mesh:numNodes()).
IMPORTANT: This function should only be called if mesh:hasCapability("topology") returns true.
Parameters: nodeIndex The node index (a value from 1 to mesh:numNodes() - the given node can not be a ghost node).
options An optional string parameter defining the behaviour of the function when applied over a node from a quadratic element. If equal to "star" (the default if the parameter is ommited) and nodeIndex is a cell vertex, the adjacent nodes will be other cell vertices, ignoring any quadratic nodes between them. If equal to "qstar", the quadratic nodes on the edges leaving nodeIndexwill be returned instead. If nodeIndex is itself a quadratic node in the middle of an edge, the edge endpoints will be returned independently of the selecetd option. For quadratic mid surface or mid volume nodes, an empty list will be returned.
Returns: Returns a list (table) with the set of adjacent nodes. Will return an empty list if the node does not belong to any element or if it belongs only to a bar on a surface mesh, or to a bar or surface element on a solid mesh.

Example:

-- Print the set of nodes adjacent to node 5
local adjacentNodes = m:nodeAdjacentNodes(5)
for i = 1, #adjacentNodes do
print(adjacentNodes[i])
end


mesh:nodeAdjacentCells(nodeIndex)
Description: Returns a list with the set of cells sharing the given node. Each list entry is a cell object.
IMPORTANT: This function should only be called if mesh:hasCapability("topology") returns true.
Parameters: nodeIndex - The node index (a value from 1 to mesh:numNodes() - the given node can not be a ghost node).
Returns: Returns a list (table) with the set of cell objects including the given node on their definition. Will return an empty list if the node does not belong to any element or if it belongs only to a bar on a surface mesh, or to a bar or surface element on a solid mesh.

Example:

-- Print the set of cells adjacent to node 5
local adjacentCells = m:nodeAdjacentCells(5)
for i = 1, #adjacentCells do
print(adjacentCells[i]:id())
end


mesh:edgeAdjacentCells(cellIndex, edgeIndex)
mesh:edgeAdjacentCells(cell, edgeIndex)
Description: Given a cell (defined either by its index or by a cell object) and a cell edge index, returns the list of cells including that edge. The original input cell is added to the list. For surface meshes, this is simmilar to calling mesh:adjacentCell().
IMPORTANT: This function should only be called if mesh:hasCapability("topology") returns true.
Parameters: cellIndex The cell id number (an index between 1 and mesh:numCells()).
cell The cell object.
edgeIndex The index of the edge whose adjacent cells will be queried. It should be an edge local index (a value between 1 and geometry:numEdges()). See the Element types page for the edge organization for each cell type.
Returns: Returns a list (table) filled with the set of adjacent cell objects.

Example:

-- Get the adjacents cell to the second edge of the first mesh cell
local adjCells = m:edgeAdjacentCells(1, 2)


mesh:isBorderNode(nodeIndex)
Description: Returns true if this node belongs to any edge or face that does not have an adjacent cell. Returns false otherwise (this includes nodes that do not belong to any cell or belonging only to non manifold cells - bars or surface cells in a solid mesh).
IMPORTANT: This function should only be called if mesh:hasCapability("topology") returns true.
Parameters: nodeIndex - The node index (a value from 1 to mesh:numNodes() - the given node can not be a ghost node).
Returns: Returns true or false defining whether the node is on the mesh border or not.

Example:

-- Is node 5 on the mesh border?
local inBorder = m:isBorderNode(5)


mesh:clearTopology()
Description: If the mesh has an associated topology structure, gives a hint to the mesh that the topology information will not be needed anymore and can be removed, if at all possible.
Parameters: None.
Returns: None.

Example:

m:clearTopology()


Cell data methods

mesh:cellAttributeIds()
Description: Returns a list with the name (id) of every cell attribute associated with the mesh.
Parameters: None.
Returns: Returns a table with cell attribute ids (strings).

Example:

local cellAttrIds = m:cellAttributeIds()


mesh:cellAttributeInfo(name)
Description: Returns an object with metadata information about the named mesh cell attribute.
Parameters: name - The cell attribute name (id).
Returns: Returns a value info object or nil if the requested name was not found in the mesh.

Example:

local rhoInfo = m:cellAttributeInfo('rho')


mesh:cellAttributeAccessor(name, unit)
mesh:cellAttributeAccessor(name, state, locked, unit)
Description: Returns a Cell accessor object that can be used to retrieve and update data for cell attributes. Can be called with two different signatures. The first, receiving only the attribute name and an optional unit, always retrieves data from the current state and is the most used. The second, allows for defining the desired state from which data will be recovered / written. As a matter of fact, the first format is equivalent to calling the second one as mesh:cellAttributeAccessor(name, 0, true, unit).
Parameters: name The name (id) of the cell attribute.
state An optional state number referencing the history state that the accessor will operate on. A value of zero means the most recent state, 1 the previous one, 2 the one before that and so on. Valid values range from zero to the oldest state for the requested variable, which can be queried with a call to mesh:numCellAttributeStates(). Remember that for a cell accessor to support states, the history parameter must be set on its value info object.
locked The locked parameter controls the behaviour of the accessor once a new state is created for the value. The 'lock' refers to the state number, so if locked is false and a new state is created, the accessor doesn't change and continues to point to the same data. If locked is true, the accessor will be locked to that state number, so when a new state is created, the accessor changes the data its looking upon to reflect the new state. For example, an accessor locked on state 0 will always point to the current state, and one locked to state 1 will always point to the previous saved value.
unit An optional string with the desired unit for returned values. If different from the data unit, the accessor will automatically convert values.
Returns: A Cell accessor object or nil on errors (the requested name is unknown, or the requested unit is incompatible with the data unit, for example).

Example:

local rhoAc = m:cellAttributeAccessor('rho') -- Get an accessor to the 'rho' cell attribute
local rhoAc2 = m:cellAttributeAccessor('rho', 'g/cm3') -- Get an accessor to the 'rho' cell attribute with values converted to g/cm3
local rhoAc3 = m:cellAttributeAccessor('rho', 1, true) -- Get an accessor locked on the previous saved value of attribute 'rho'


mesh:addCellAttributeSet(valInfo)
Description: Creates a new value set for storing data for a new cell attribute and associates this new attribute with the mesh.
Parameters: valInfo - A new value info object created by a call to ValueInfo(), with valueKind equal to "cell attribute".
Returns: Returns true on success, false on error.

Example:

local newInfo = ValueInfo('cell attribute', {id = 'new1', unit = 's'})
assert(m:addCellAttributeSet(newInfo) == true)


mesh:removeCellAttributeSet(name)
Description: Removes the named cell attribute from the mesh. Use carefully.
Parameters: name - The name (id) of the cell attribute.
Returns: Nothing.

Example:

m:removeCellAttributeSet('rho')


mesh:clearCellAttributeSets()
Description: Removes all cell attributes from the mesh. Use carefully.
Parameters: None.
Returns: Nothing.

Example:

m:clearCellAttributeSets()


Cell property methods

mesh:cellPropertyInfo(name)
Description: Returns an object with metadata information about the named cell property.
Parameters: name - The property name (id).
Returns: Returns a value info object or nil if the requested name was not found in the mesh.

Example:

local rhoInfo = m:cellPropertyInfo('rho')


mesh:cellPropertyAccessor(name, unit)
Description: Returns a Cell accessor object that can be used to retrieve data for cell properties. Unlike other accessor types, a property accessor always retrieves data from the current state.
Parameters: name The name (id) of the cell property.
unit An optional string with the desired unit for returned values. If different from the data unit, the accessor will automatically convert values.
Returns: A Cell accessor object or nil on errors (the requested name is unknown, or the requested unit is incompatible with the data unit, for example).

Example:

local rhoAc = m:cellPropertyAccessor('rho') -- Get an accessor to the 'rho' cell property
local rhoAc2 = m:cellPropertyAccessor('rho', 'g/cm3') -- Get an accessor to the 'rho' cell property with values converted to g/cm3


mesh:numPropertySets()
Description: Returns the number of property sets attached to this mesh.
Parameters: None.
Returns: Returns the number of property sets.

Example:

local npsets = m:numPropertySets()


mesh:propertySets()
Description: Returns a list with the property set objects attached to this mesh.
Parameters: None.
Returns: Returns a list of property set objects.

Example:

-- Prints the name of the property sets attached to this mesh
local psets = m:propertySets()
for i = 1, #psets do
print(psets[i]:id())
end


mesh:propertySetIndex(name)
Description: Returns the index of the property set that includes the given property name.
Parameters: name - The property name.
Returns: Returns the index inside the list returned by mesh:propertySets() of the property set object that contains 'name' among its properties. Returns nil for unknown names.

Example:

local psetIndex = m:propertySetIndex('rho')


Cell quality methods

mesh:isValid()
Description: Checks the mesh cells validity. The mesh is considered valid if all of its cells are valid according to cell:isValid().
Parameters: None.
Returns: Returns true if all the mesh cells are valid, false otherwise.

Example:

if m:isValid() then
...
end


mesh:edgeMinLength()
Description: Returns the minimum edge length for all edges in the mesh. The returned value is expressed in the mesh coordinates unit and might be an approximation for quadratic elements. The returned statistics are calculated on first usage (of any of the edge or bounding box min/max length functions) and are not updated automatically when cell nodes change or have their coordinates updated. Use mesh:clearCellStatistics() to force an update.
Parameters: None.
Returns: Returns the minimum mesh edge length.

Example:

local minLen = m:edgeMinLength()


mesh:edgeMaxLength()
Description: Returns the maximum edge length for all edges in the mesh. The returned value is expressed in the mesh coordinates unit and might be an approximation for quadratic elements. The returned statistics are calculated on first usage (of any of the edge or bounding box min/max length functions) and are not updated automatically when cell nodes change or have their coordinates updated. Use mesh:clearCellStatistics() to force an update.i
Parameters: None.
Returns: Returns the maximum mesh edge length.

Example:

local maxLen = m:edgeMaxLength()


mesh:cellBboxMinLength()
Description: Among all the cells in the mesh, returns the minimum length of a mesh cell bounding box diagonal. The returned value is expressed in the mesh coordinates unit. The returned statistics are calculated on first usage (of any of the edge or bounding box min/max length functions) and are not updated automatically when cell nodes change or have their coordinates updated. Use mesh:clearCellStatistics() to force an update.
Parameters: None.
Returns: Returns the minimum length of a mesh cell bounding box diagonal.

Example:

local minLen = m:cellBboxMinLength()


mesh:cellBboxMaxLength()
Description: Among all the cells in the mesh, returns the maximum length of a mesh cell bounding box diagonal. The returned value is expressed in the mesh coordinates unit. The returned statistics are calculated on first usage (of any of the edge or bounding box min/max length functions) and are not updated automatically when cell nodes change or have their coordinates updated. Use mesh:clearCellStatistics() to force an update.
Parameters: None.
Returns: Returns the maximum length of a mesh cell bounding box diagonal.

Example:

local maxLen = m:cellBboxMaxLength()


mesh:clearCellStatistics()
Description: Clears the internal statistics returned by the edge and bounding box min/max length functions. This function should be called after mesh geometry changes, if those statistics are being used.
Parameters: None.
Returns: Nothing.

Example:

m:clearCellStatistics()


mesh:printQualityHistogram(activeOnly)
Description: Prints cells quality histogram.
Parameters: activeOnly - If true, only the active cells will be scanned, all of them otherwise. Default = true.
Returns: Nothing.

Example:

m:printQualityHistogram() -- default mode, only considers active cells
m:printQualityHistogram(false) -- quality is evaluated for every cell in the mesh


Cell group methods

mesh:cellGroupIds()
Description: Returns a list with the names of the configured mesh cell groups.
Parameters: None.
Returns: Returns a table with cell group names (can be empty).

Example:

-- Prints cell group names
local gids = m:cellGroupIds()
for i = 1, #gids do
print(gids[i])
end


mesh:cellGroupIndex(name)
Description: Returns the index of the given group in the group names list returned by mesh:cellGroupIds().
Parameters: name - The cell group name (id).
Returns: Returns the group index or nil if the given name does not correspond to any mesh cell group.

Example:

local gindex = m:cellGroupIndex('group_name')


mesh:numCellsInGroup(groupIndex)
Description: Given a group index, returns the number of cells in this group.
Parameters: groupIndex - The cell group index (a value between 1 and the number of entries in the list returned by mesh:cellGroupIds()).
Returns: Returns the number of cells in the given group.

Example:

-- Get the number of cells in the group named 'myGroup'
local ncells = m:numCellsInGroup(m:cellGroupIndex('myGroup'))


mesh:cellInGroup(groupIndex, cellIndex)
Description: Returns the cell object given its position inside a cell group.
Parameters: groupIndex The cell group index (a value between 1 and the number of entries in the list returned by mesh:cellGroupIds()).
cellIndex The cell index inside the group (a value between 1 and mesh:numCellsInGroup()).
Returns: Returns the cell object.

Example:

-- Print the id of every cell inside the cell group named 'myGroup'
local gindex = m:cellGroupIndex('myGroup')
for i = 1, m:numCellsInGroup(gindex) do
local c = m:cellInGroup(gindex, i)
print(c:id())
end


mesh:addCellGroup(groupName)
Description: Adds a new (empty) cell group to the mesh. This function can only be called if mesh:hasCapability("editGroups") returns true.
Parameters: groupName The name of the cell group that will be added to the mesh. Must be a new group name.
Returns: Returns the added cell group index (its index in the list returned by mesh:cellGroupIds()) or nil if the group could not be added.

Example:

-- Adds a new cell group called 'new group' to the mesh
m:addCellgroup('new group')


mesh:addCellsToGroup(groupIndex, cellIdList)
mesh:addCellsToGroup(groupIndex, cellRangeList)
Description: Adds a list of cells to the given cell group. Added cells can be given either as a table with cell ids or as a table with sub-tables containing id ranges. This function can only be called if mesh:hasCapability("editGroups") returns true.
Parameters: groupIndex The cell group index (a value between 1 and the number of entries in the list returned by mesh:cellGroupIds()).
cellIdList A table with the cell ids for the cells to be added to the group.
cellRangeList A table with cell id ranges for the cells to be added to the group. Each range is given as a sub-table storing the first and last cell indices in the range.
Returns: Returns true on success, false if it was not possible to add cells to the group.

Example:

-- Adds cells 10, 15 and 18 to the third cell group
m:addCellsToGroup(3, {10, 15, 18})
-- Adds cells 10 to 15 and 18 to 25 to the third cell group
m:addCellsToGroup(3, {{10, 15}, {18, 25}})


mesh:cellBoundaryGroups()
Description: Returns a map storing the configured set of cell boundary objects.
Parameters: None.
Returns: Returns a table indexed by cell boundary group names, with each entry storing a reference to a cell boundary object.

Example:

-- Prints the name and number of cells for each boundary group in the mesh
local boundaries = m:cellBoundaryGroups()
for name, boundary in pairs(boundaries) do
print(name, boundary:numCells())
end


History methods

mesh:saveCellAttributeState(name, mode)
Description: Saves the current state for the given cell attribute, creating a new current state. The time associated with the new current state is initialized to the value of the current simulation time (set either explicitly by a call to setCurrentTime() or implicitly by some process functions). This can later be changed by a call to mesh:setCellAttributeStateTime().
Parameters: name The name (id) of the cell attribute.
mode The requested save mode, defining how the new state will be initialized. Can be one of the following strings: "init" (new state is initialized with the data default value), "noinit" (new state is not initialized at all) or "copy" (new state is initialized with a copy of the current state).
Returns: Returns true if successful, false otherwise. In particular, this function returns false if the given attribute does not have history values enabled.

Example:

m:saveCellAttributeState('rho', 'noinit')


mesh:numCellAttributeStates(name)
Description: Returns the number of existing history states for the given cell attribute.
Parameters: name - The name (id) of the cell attribute.
Returns: Returns the number of existing states or -1 for unknown names.

Example:

local nstates = m:numCellAttributeStates('rho')


mesh:cellAttributeStateTag(name, state)
Description: Returns the tag attached to the requested state, for the given cell attribute.
Parameters: name The name (id) of the cell attribute.
state The state number, referencing the history state to be queried. A value of zero means the most recent state, 1 the previous one, 2 the one before that and so on. Valid values range from zero to the oldest state for the requested attribute, which can be obtained with a call to mesh:numCellAttributeStates().
Returns: The state tag attached to the requested state or "" if the name doesn't exists.

Example:

local tag = n:cellAttributeStateTag('rho', 0) -- Tag from the current state
local oldTag = n:cellAttributeStateTag('rho', 1) -- Tag from the previous state


mesh:cellAttributeStateTime(name, state)
Description: Returns the time attached to the requested state, for the given cell attribute.
Parameters: name The name (id) of the cell attribute.
state The state number, referencing the history state to be queried. A value of zero means the most recent state, 1 the previous one, 2 the one before that and so on. Valid values range from zero to the oldest state for the requested attribute, which can be obtained with a call to mesh:numCellAttributeStates().
Returns: The time attached to the requested state or -1 if the name doesn't exists.

Example:

local t = n:cellAttributeStateTime('rho', 0) -- Time from the current state
local oldt = n:cellAttributeStateTime('rho', 1) -- Time from the previous state


mesh:setCellAttributeStateTag(name, state, tag)
Description: Updates the tag attached to the requested state, for the given cell attribute.
Parameters: name The name (id) of the cell attribute.
state The state number, referencing the history state to be queried. A value of zero means the most recent state, 1 the previous one, 2 the one before that and so on. Valid values range from zero to the oldest state for the requested attribute, which can be obtained with a call to mesh:numCellAttributeStates().
tag The new state tag.
Returns: Nothing.

Example:

m:setCellAttributeStateTag('rho', 1, 'myTag') -- Updates the tag from the previous state for cell attribute 'rho'


mesh:setCellAttributeStateTime(name, state, time)
Description: Updates the time attached to the requested state, for the given cell attribute.
Parameters: name The name (id) of the cell attribute.
state The state number, referencing the history state to be queried. A value of zero means the most recent state, 1 the previous one, 2 the one before that and so on. Valid values range from zero to the oldest state for the requested attribute, which can be obtained with a call to mesh:numCellAttributeStates().
time The new state time, expressed in the same unit as the current simulation time unit.
Returns: Nothing.

Example:

m:setCellAttributeStateTime('rho', 1, 12.5) -- Updates the time from the previous state for cell attribute 'rho'