GemaCoreLib
The GeMA Core library
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
GmMatrixSet Class Reference
Collaboration diagram for GmMatrixSet:
Collaboration graph
[legend]

Public Member Functions

 GmMatrixSet (int maxMatrixTypes, const QStringList &typeNames)
 Constructor. Receives as parameters the maximum number of existing types and, optionally, their names (which are then available to use in error messages) More...
 
 ~GmMatrixSet ()
 Destructor.
 
bool init (int maxNodes, int numMatrices,...)
 Allocates memory for the matrix set, returning false on errors. More...
 
bool adjustSizes (int maxNodes)
 Adjusts the maximum sizes of local matrices according to the given maximum number of dofs. Can be called more than once to update matrix sizes on model changes. More...
 
void clear ()
 Clears the set, restoring it to the state after construction.
 
void prepareSet (int nnodes)
 Prepares the matrix set, for the current thread, to hold matrices with sizes equal to nnodes (which should be less or equal to the maximum number of nodes given in the call to init() or in the last call to adjustSizes()), marks all matrices as unsymmetric and unfilled. If nnodes is equal to -1, prepares a common GmMatrix object that can be resized freely (does not use external memory).
 
bool containsType (int type) const
 Returns true if the matrix set contains a matrix of the requested type AND the type is enabled.
 
void setTypeEnabled (int type, bool enabled)
 Enables or disables a type in the set. Disabled types do NOT return matrices in calls to matrix() or useMatrix()
 
int numEnabledTypes () const
 Returns the number of enabled types in the matrix set.
 
GmMatrixmatrix (int type)
 Returns a matrix for the current thread, identified by its type. More...
 
GmMatrixuseMatrix (int type)
 Returns a matrix for the current thread, identified by its type, and marks it as filled. More...
 
GmMatrixuseMatrix (int type, bool fill, bool sym)
 Returns a matrix for the current thread, identified by its type. If the fill parameter is true, also marks the matrix as filled, zeroes its contents and sets the matrix as symmetric or not according to the sym parameter. More...
 
void setSymmetric (int type, bool symmetric)
 Marks a matrix, identified by its type in the set, as symmetric or unsymmetric. IMPORTANT: The supplied type MUST belong to the set. IMPORTANT 2: Only the matrix associated with the CURRENT thread is marked.
 
void setFilled (int type, bool filled)
 Marks a matrix, identified by its type in the set, as filled or unfilled. IMPORTANT: The supplied type MUST belong to the set IMPORTANT 2: Only the matrix associated with the CURRENT thread is marked.
 
bool symmetric (int type) const
 Returns true if the matrix from the current thread, identified by its type, was marked symmetric (default when set prepared = false). IMPORTANT: The supplied type MUST belong to the set.
 
bool filledSymmetric () const
 Returns true if ALL the filled matrices in the set, for the current thread, are marked as symmetric. More...
 
bool filled (int type) const
 Returns true if the matrix from the current thread, identified by its type, was marked as filled (default when set prepared = false). IMPORTANT: The supplied type MUST belong to the set.
 
int index (int type) const
 Returns the index inside the set of the supplied type (-1 if the type doesn't belong to the set).
 
int typeFromIndex (int index) const
 Given a matrix index, returns its type.
 
QString typeName (int type) const
 Returns a name associated to the given type from the list supplied in the constructor.
 
int numMatrices () const
 Return the number of matrices stored in this set.
 
const GmMatrixmatrixFromIndex (int index) const
 Returns a matrix, tied to the current thread, identified by its index in the set.
 
bool symmetricFromIndex (int index) const
 Returns true if the matrix tied to the current thread, and indentified by its index, was marked symmetric (default when set prepared = false)
 
bool filledFromIndex (int index) const
 Returns true if the matrix tied to the current thread, indentified by its index, was marked as filled (default when set prepared = false)
 

Protected Member Functions

bool initTypes (int numMatrices, va_list typeList)
 Informs the matrix set about the local matrix types that will be stored on it. More...
 

Protected Attributes

int _nTypes
 The number of existing matrix types.
 
int * _typeIndex
 An index mapping matrix types to its position within the set.
 
int * _indexType
 Reverse index for finding the type from the matrix index.
 
bool * _typeEnabled
 A vector stating if the type is enabled or not.
 
int _nEnabled
 The number of enabled matrices in _typeEnabled.
 
QStringList _typeNames
 Optional names for matrix types.
 
int _nMatrices
 The number of matrices stored in this set.
 
int _maxNodes
 The maximum dimension of a matrix (maximum number of element nodes)
 
GmTLBuffer< double, true > _matrixMemory
 Memory used to hold data for the set matrices.
 
GmTLBuffer< GmMatrix, true > _matrices
 Vector with matrices prepared by prepareSet()
 
GmTLBuffer< bool, true > _symmetric
 Vector stating, for each matrix, if it is symmetric or not.
 
GmTLBuffer< bool, true > _filled
 Vector stating, for each matrix, if it was filled by the user or not.
 

Detailed Description

One set is created for each possible thread configured on the thread manager, so concurrent access to a matrix set on several threads is possible and each thread has its OWN set of matrices / control info.

The stored matrices can be accessed through their index in the set or through an integer type. When a set is created, it's given the maximum number of possible matrix types. Matrix types are numeric values that identify a matrix semantics. Inside a matrix set, there should be only one matrix of each type.

When the matrix set is initialized, the types of the matrices bound to that set are given and the set stores matrices for those matrix types only. The maximum number of rows and columns of a matrix is also given. Stored matrices can have sizes up to the maximum given size.

The set is particularly appropriate to hold matrices that will have their sizes changed accordingly to element sizes. The memory used by the matrices is pre-allocated and the process of "resizing" the matrices for the appropriate element size (by a call to prepareSet()) is very fast since no memory allocations are needed.

To enable using the matrix set for handling local matrices that are not tied to an element size, and so with unbounded sizes, it is possible to request that the returned matrices to be common GmMatrix objects whose size can be set dynamically. This is done by calling prepaperSet() with a size equal to -1.

Constructor & Destructor Documentation

◆ GmMatrixSet()

GmMatrixSet::GmMatrixSet ( int  maxMatrixTypes,
const QStringList typeNames 
)

Constructor. Receives as parameters the maximum number of existing types and, optionally, their names (which are then available to use in error messages)

Keep in mind that a successfull call to init() must be made prior to using a matrixSet. It's on the init call that the required memory is allocated.

Member Function Documentation

◆ adjustSizes()

bool GmMatrixSet::adjustSizes ( int  maxNodes)

Adjusts the maximum sizes of local matrices according to the given maximum number of dofs. Can be called more than once to update matrix sizes on model changes.

If the given maxNodes is less than the current size, the matrices will not be shrinked, but left untouched. If a particular matrix is, at the moment, a resizable matrix, it will be changed to a matrix pointing to the allocated memory.

Parameters
maxElemDofsThe maximum number of dofs needed by a model element.
Returns
Returns true when successfull, false on errors. In that case, the matrix set will become unusable.

◆ filledSymmetric()

bool GmMatrixSet::filledSymmetric ( ) const

Returns true if ALL the filled matrices in the set, for the current thread, are marked as symmetric.

Obs: Assumes that all filled matrices are enabled... Returns false if there is no filled matrix on the set

◆ init()

bool GmMatrixSet::init ( int  maxNodes,
int  numMatrices,
  ... 
)

Allocates memory for the matrix set, returning false on errors.

This function should be probably called only once. If you ever need to change the maximum size of set matrices, please call adjustSizes() instead. If the number of types needs to be changed, call clear() before calling init() again.

Parameters
maxNodesThe maximum number of rows that the stored (square) matrices can have. In general it should be equal to the maximum number of nodes in the element types present in a mesh.
numMatricesThe number of matrices stored in the set
...The variable list of parameters should contain the types of the stored matrices. The number of parameters should be equal to numMatrices. Each value should be a unique type number (between 0 and the maximum number of types given in the constructor)
Returns
Returns true when successfull, false on errors.

◆ initTypes()

bool GmMatrixSet::initTypes ( int  numMatrices,
va_list  typeList 
)
protected

Informs the matrix set about the local matrix types that will be stored on it.

This function does NOT allocate memory for the matrices. It only prepares the global used structure. Memory allocation is deferred to the adjustSizes() call. Returns false on errors.

Parameters
numMatricesThe number of local matrices stored in the set
...The variable list of parameters should contain the types of the stored matrices. The number of parameters should be equal to numMatrices. Each value should be a unique type number (between 0 and the maximum number of types given in the constructor)
Returns
Returns true when successfull, false on errors.

◆ matrix()

GmMatrix & GmMatrixSet::matrix ( int  type)

Returns a matrix for the current thread, identified by its type.

If the requested type is missing from the set or is disabled, returns an empty matrix (which should NOT be changed in any way).

◆ useMatrix() [1/2]

GmMatrix & GmMatrixSet::useMatrix ( int  type)

Returns a matrix for the current thread, identified by its type, and marks it as filled.

If the requested type is missing from the set or is disabled, returns an empty matrix (which should NOT be changed in any way).

◆ useMatrix() [2/2]

GmMatrix & GmMatrixSet::useMatrix ( int  type,
bool  fill,
bool  sym 
)

Returns a matrix for the current thread, identified by its type. If the fill parameter is true, also marks the matrix as filled, zeroes its contents and sets the matrix as symmetric or not according to the sym parameter.

If the requested type is missing from the set or is disabled, returns an empty matrix (which should NOT be changed in any way).


The documentation for this class was generated from the following files: