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

Public Member Functions

 GmVectorSet (int maxVectorTypes, 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...
 
 ~GmVectorSet ()
 Destructor.
 
bool init (int maxNodes, int numVectors,...)
 Allocates memory for the vector set, returning false on errors. More...
 
bool adjustSizes (int maxNodes)
 Adjusts the maximum sizes of local vectors according to the given maximum number of dofs. Can be called more than once to update vector sizes on model changes. More...
 
void clear ()
 Clears the set, restoring it to the state after construction.
 
void prepareSet (int nnodes)
 Prepares the vector set, for the current thread, to hold vectors 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 vectors as unfilled. If nnodes is equal to -1, prepares a common GmVector object that can be resized freely (does not use external memory).
 
bool containsType (int type) const
 Returns true if the vector set contains a vector 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 vectors in calls to vector() or useVector()
 
int numEnabledTypes () const
 Returns the number of enabled types in the vector set.
 
GmVectorvector (int type)
 Returns a vector for the current thread, identified by its type. More...
 
GmVectoruseVector (int type)
 Returns a vector for the current thread, identified by its type, and marks it as filled. More...
 
GmVectoruseVector (int type, bool fill)
 Returns a vector for the current thread, identified by its type. If the fill parameter is true, also marks the vector as filled AND zeroes its contents. More...
 
void setFilled (int type, bool filled)
 Marks a vector, identified by its type in the set, as filled or unfilled. IMPORTANT: The supplied type MUST belong to the set IMPORTANT 2: Only the vector associated with the CURRENT thread is marked.
 
bool filled (int type) const
 Returns true if the vector 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 vector 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 numVectors () const
 Return the number of vectors stored in this set.
 
const GmVectorvectorFromIndex (int index) const
 Returns a vector, tied to the current thread, identified by its index in the set.
 
bool filledFromIndex (int index) const
 Returns true if the vector tied to the current thread, indentified by its index, was marked as filled (default when set prepared = false)
 

Protected Member Functions

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

Protected Attributes

int _nTypes
 The number of existing vector types.
 
int * _typeIndex
 An index mapping vector types to its position within the set.
 
int * _indexType
 Reverse index for finding the type from the vector index.
 
bool * _typeEnabled
 A vector stating if the type is enabled or not.
 
int _nEnabled
 The number of enabled vectors in _typeEnabled.
 
QStringList _typeNames
 Optional names for vector types.
 
int _nVectors
 The number of vectors stored in this set.
 
int _maxNodes
 The maximum dimension of a vector (maximum number of element nodes)
 
GmTLBuffer< double, true > _vectorMemory
 Memory used to hold data for the set vectors.
 
GmTLBuffer< GmVector, true > _vectors
 Vector with vectors prepared by prepareSet()
 
GmTLBuffer< bool, true > _filled
 Vector stating, for each vector, 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 vector set on several threads is possible and each thread has its OWN set of vectors / control info.

The stored vectors 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 vector types. Vector types are numeric values that identify a vector semantics. Inside a vector set, there should be only one vector of each type.

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

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

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

Constructor & Destructor Documentation

◆ GmVectorSet()

GmVectorSet::GmVectorSet ( int  maxVectorTypes,
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 VectorSet. It's on the init call that the required memory is allocated.

Member Function Documentation

◆ adjustSizes()

bool GmVectorSet::adjustSizes ( int  maxNodes)

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

If the given maxNodes is less than the current size, the vectors will not be shrinked, but left untouched. If a particular vector is, at the moment, a resizable vector, it will be changed to a vector 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 vector set will become unusable.

◆ init()

bool GmVectorSet::init ( int  maxNodes,
int  numVectors,
  ... 
)

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

This function should be probably called only once. If you ever need to change the maximum size of set vectors, 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 vectors can have. In general it should be equal to the maximum number of nodes in the element types present in a mesh.
numVectorsThe number of vectors stored in the set
...The variable list of parameters should contain the types of the stored vectors. The number of parameters should be equal to numVectors. 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 GmVectorSet::initTypes ( int  numVectors,
va_list  typeList 
)
protected

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

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

Parameters
numVectorsThe number of local vectors stored in the set
...The variable list of parameters should contain the types of the stored vectors. The number of parameters should be equal to numVectors. 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.

◆ useVector() [1/2]

GmVector & GmVectorSet::useVector ( int  type)

Returns a vector 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 vector (which should NOT be changed in any way).

◆ useVector() [2/2]

GmVector & GmVectorSet::useVector ( int  type,
bool  fill 
)

Returns a vector for the current thread, identified by its type. If the fill parameter is true, also marks the vector as filled AND zeroes its contents.

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

◆ vector()

GmVector & GmVectorSet::vector ( int  type)

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

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


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