![]() |
GemaCoreLib
The GeMA Core library
|
This class manages a group of ValueSets that have all the same size and must grow (or shrink) together. It also manages the memory used by each value set, allowing for "packed" layouts where data from different value sets are interleaved in memory for better cache access. As a bonus, it keeps track of a map from data id to their value sets. More...
#include <gmValueSetGroup.h>


Public Member Functions | |
| GmValueSetGroup (GmSimulationData *simData, GmMesh *mesh) | |
| Constructor. Creates an empty group. Value sets should be added by calls to addValueSet() After all adds are done, call init() to prepare the value sets for usage. The simulation data and mesh parameters are needed for instancing value sets that can store function references (as indicated by the info metadata). The simulation data is also needed for access to the autoPackAttributes configuration parameter. If simData is NULL, the parameter will be considered as false (in addition to the no support for functions in the value sets). The mesh can be set to NULL if the stored value sest are not directly bound to a mesh (bound to a property set, for example). In that case, a GmSingleVector storage will be used (since we can not base the decision on the GmMesh::useDualVectors() result for NULL meshes). | |
| virtual | ~GmValueSetGroup () |
| Destructor. | |
| virtual bool | addValueSet (QString id, GmValueInfo *info) |
| Adds a new value set to the group. If the group has not been initialized yet, an empty value set will be added. Otherwise, after adding, it will be automatically initialised with the same size as the existing sets. Notice that adding a set to a pack after initialization might lead to a complete restructuring of the pack. Returns false on errors. | |
| virtual bool | removeValueSet (QString id, bool releaseInfo=false) |
| Removes a value set from the group. If that value set belongs to a pack and the group has already been initialized, this will lead to a pack restructuring. Returns false for an invalid id or if there was an error restructuring a pack. | |
| bool | isEmpty () const |
| Returns true if this group is empty (does not include any value set). | |
| int | numSets () const |
| Returns the number of sets stored in this group. | |
| void | addValueSetBegin () |
| Starts the addition of value sets to a new / existing pack after the group has been initialized. Pack reestructuring will be delayed until a call to addValueSetEnd(). If called before group initialization, does nothing. | |
| bool | addValueSetEnd () |
| Ends the addition of value sets to a new / existing pack after the group has been initialized. Pack reestructuring will be executed. If called before group initialization, does nothing. If there was no call to addValueSet() in the begin / end block, dos nothing. On error, will try to leave the group in the state prior to the begin call, removing the added value sets, INCLUDING those that do not belong to a pack. That can go wrong if we are unable to revert used pack buffers to the previous state (the only other possible side effect is the addition of new, empty, packs). | |
| bool | insideAddBlock () const |
| Returns true if addValueSetBegin() has been called without a matching addValueSetEnd() call. | |
| int | nextNewPack () const |
| Returns the number of the next unused pack id. | |
| virtual bool | init (int numValues) |
| Initializes all the ValueSets, being responsible for allocating memory and initializing data. Either all sets are allocated or none are. | |
| bool | initialized () const |
| Returns true if the group has been initialized with a call to init() | |
| int | numValues () const |
| Returns the size (number of "entries") of the stored value sets. | |
| virtual bool | addValues (int numAddedValues) |
| Adds the given number of values to the sets, initializing them to the default value. Returns false on errors. On errors previous values are kept. Keep in mind that either all sets are resized or none are. | |
| virtual void | removeValues (int index, int numValues) |
| Removes numValues from the set, starting from (and including) index. Can not fail (but might not release memory). | |
| virtual void | restoreSize (int oldSize) |
| Restores the size of the sets to the previous size before addValues. | |
| virtual void | clear () |
| Removes all value sets from the group. | |
| virtual void | clearData () |
| Clears all value sets, returning their size to 0. The value sets themselves remain on the group. | |
| virtual bool | saveState (GmValueSet::SaveStateMode mode, const GmLogCategory &logger) |
| Saves the state for all sets in the group. | |
| const QMap< QString, int > & | dataMap () const |
| Returns a map indexed by value set data id, storing the id position in the value set list. | |
| bool | contains (QString id) const |
| Returns true if the group contains a value set for an attribute named id. | |
| const QVector< GmValueSet * > & | valueSets () const |
| Returns a list with the stored value sets. The map returned by dataMap() is an index onto this list. Can contain NULL values if addValueSet() was called with a NULL info pointer (although strange, this is useful for handling node attributes for meshes with ghost nodes). | |
| GmValueSet * | valueSet (QString id) const |
| Returns the value set associated with the given data id. Returns NULL if not found. | |
| virtual size_t | printMemoryStatistics (const GmLogCategory &logger, GmLogLevel level) const |
| Prints memory usage for this value set to the given logger. Returns the used memory as reported by usedMemory() | |
| virtual size_t | usedMemory () const |
| Returns an estimative of the memory used by the set group in bytes. | |
Protected Member Functions | |
| virtual GmValueSet * | createValueSet (GmValueInfo *info, GmPackedBuffer *pack) |
| Virtual function used to create the stored value set. Can be overwritten by descendant classes. | |
| GmPackedBuffer * | getPack (int packId) |
| Returns, crating if necessary, the pack associated with the given id. Returns NULL if no pack is needed. | |
Protected Attributes | |
| GmSimulationData * | _simData |
| The simulation data object. Needed for value sets accepting function values. Might be NULL. | |
| GmMesh * | _mesh |
| The associated mesh object. Needed for most value sets accepting function values (except property sets). Might be NULL. | |
| bool | _init |
| Have we been initialized yet? | |
| int | _insideBlock |
| Are we inside an addValueSetBegin / End block? If inside, stores the index in _valueSets of the first vs added after the begin. Stores -1 if outside a block. | |
| int | _numValues |
| The size of the stored value sets. | |
| QMap< QString, int > | _idMap |
| Maps stored value set ids to their position in _valueSets. | |
| QVector< GmValueSet * > | _valueSets |
| The list of stored value sets. | |
| QMap< int, GmPackedBuffer * > | _packs |
| A map indexing packed buffers by their id. | |
This class manages a group of ValueSets that have all the same size and must grow (or shrink) together. It also manages the memory used by each value set, allowing for "packed" layouts where data from different value sets are interleaved in memory for better cache access. As a bonus, it keeps track of a map from data id to their value sets.
When first created, empty value sets are added to the group by calls to addValueSet(). Memory is allocated for them on the call to init(). This delayed allocation, after all value sets are added, is required to manage "packed" layouts.
Also notice that for Gauss attributes, every value set in the group MUST be tied to the same rule set in order to make sure that they have (and will always have) the same size.
Each value set data can be either stand alone or belong to a value set pack where data is interleaved in memory. A group can manage several packs. Inserting a value set into a pack is controlled by the pack id found on the value set info. A value > 0 means that that pack will be used. A value of -1 means that this value set will NEVER be added to a pack. A value of 0 (the default) means that this value set can be included on a global group pack depending on the global configuration parameter "autoPackAttributes" (with an exception, see below).
Packing is incompatible with allocMode = auto. If packing is given explicitely for a value set (pack > 0) and it has allocMode set to auto (the default), the allocMode will be ignored. If pack is 0 and it would be added to the global group pack due to the global options, an exception is made for value sets that have allocMode = auto, functions enabled and a function as default value. Those value sets will not be added to the global pack, behaving as if they have pack equal to -1.
Value sets inside a packed group have a shared buffer, each one with its own offset. The internal order of the value sets in the buffer follows the order in which value sets where added to the group, unless we have value sets storing non double values. In that case, value sets are ordered by decreasing size of their data "sizeof" (keeping the add order inside each size) and padded at the end to guarantee proper alignment for the greatest size. If a value set has a fixed number of states, they are kept side by side at the buffer. Value sets with an unlimited number of states can not belong to a pack.
Adding and removing value sets from the group after initialization can be a costly operation if the added / removed sets belong to an existing pack. If you want to avoid those costs, set the pack value for the added data to -1 or, if adding several value sets, add them to a new pack while surrounding the add call inside an addValueSetBegin() / addValueSetEnd() block.
The shared buffer used to store packed value set data, in the same way as the standard buffers for a standard value set, can be based on either the GmSingleVector or GmDualVector classes. The first one is a plain old data vector, while the second one separates the data into a initial set and a "growing" set for later added values. This can be interesting for dynamic meshes where new nodes / cells are added ofently during the simulation, but still representing a small fraction of the mesh size. With the Dual vector policy, only the "growing" part is resized. The choice of which vector to use is based on the result returned by GmMesh::useDualVectors().
The createValueSet() virtual function is used for instancing the child value sets. The default implementation creates instances of the GmValueSet / GmGaussValueSet classes. This function can be overridden for situations where a derived classs from GmValueSet / GmGaussValueSet is needed (XFem implementation, for example)
|
virtual |
Adds the given number of values to the sets, initializing them to the default value. Returns false on errors. On errors previous values are kept. Keep in mind that either all sets are resized or none are.
Reimplemented in GmGaussValueSetGroup.
|
virtual |
Adds a new value set to the group. If the group has not been initialized yet, an empty value set will be added. Otherwise, after adding, it will be automatically initialised with the same size as the existing sets. Notice that adding a set to a pack after initialization might lead to a complete restructuring of the pack. Returns false on errors.
The new value set will be created with a call to createValueSet(). To help on the management of ghost nodes data by the mesh class, it is possible to call this function with an id but an empty info pointer. In that case, the id will be added to the map and a NULL pointer will be added to the value set list.
The info pointer ownership will be transfered to the created value set. On error, it remains with the caller.
Reimplemented in GmGaussValueSetGroup.
|
inlineprotectedvirtual |
Virtual function used to create the stored value set. Can be overwritten by descendant classes.
Reimplemented in GmGaussValueSetGroup.
|
virtual |
Initializes all the ValueSets, being responsible for allocating memory and initializing data. Either all sets are allocated or none are.
Returns false if it was not possible to allocate memory.
Reimplemented in GmGaussValueSetGroup.
|
virtual |
Removes numValues from the set, starting from (and including) index. Can not fail (but might not release memory).
Reimplemented in GmGaussValueSetGroup.
|
virtual |
Removes a value set from the group. If that value set belongs to a pack and the group has already been initialized, this will lead to a pack restructuring. Returns false for an invalid id or if there was an error restructuring a pack.
If the releaseInfo flag is set to true, the info object associated with the removed value set is taken from the set and is NOT released with it.
|
virtual |
Restores the size of the sets to the previous size before addValues.
Reimplemented in GmGaussValueSetGroup.
|
virtual |
Returns an estimative of the memory used by the set group in bytes.
It returns in general the variable memory that depends on the number of set entries but does not include constant overheads used by the class for control