GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmGaussIndex.h
Go to the documentation of this file.
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
23#ifndef _GEMA_GAUSSINDEX_H_
24#define _GEMA_GAUSSINDEX_H_
25
26#include "gmCoreConfig.h"
27
28#include <QVarLengthArray>
29
30class GmElementMesh;
31class GmCellGroupSet;
32
42{
43public:
45 virtual ~GmGaussIndex() {}
46
48 virtual int numPoints() const = 0;
49
51 virtual int numCells() const = 0;
52
54 virtual int numPoints(int cellId) const = 0;
55
61 virtual int pointIndex(int cellId, int ip) const = 0;
62
66 virtual int cellIp(int gpIndex, int* ip) const = 0;
67};
68
73template <class T>
75{
76public:
78 GmGaussIndexProxy(T* proxy, bool ownership) : _proxy(proxy), _ownsProxy(ownership) {}
79
81 virtual ~GmGaussIndexProxy() { if(_ownsProxy) delete _proxy; }
82
83 // Comments on the base class
84 virtual int numPoints() const { return _proxy->numPoints(); }
85 virtual int numCells() const { return _proxy->numCells(); }
86 virtual int numPoints(int cellId) const { return _proxy->numPoints(cellId); }
87 virtual int pointIndex(int cellId, int ip) const { return _proxy->pointIndex(cellId, ip); }
88 virtual int cellIp(int gpIndex, int* ip) const { return _proxy->cellIp(gpIndex, ip); }
89
90private:
91 T* _proxy;
93};
94
107{
108public:
110 int numPoints() const { return _numIp ? _numCells * _numIp : _cellOffset.last(); }
111
113 int numCells() const { return _numCells; }
114
116 int numPoints(int cellId) const
117 {
118 assert(cellId >= 0 && cellId < _numCells);
119 return _numIp ? _numIp : _cellOffset[cellId + 1] - _cellOffset[cellId];
120 }
121
125 int pointIndex(int cellId, int ip) const
126 {
127 assert(cellId >= 0 && cellId < _numCells);
128 assert(ip >= 0 && ip < numPoints(cellId));
129 return ip + (_numIp ? cellId * _numIp : _cellOffset[cellId]);
130 }
131
135 int cellIp(int gpIndex, int* ip) const
136 {
137 assert(gpIndex >= 0 && gpIndex < numPoints());
138 assert(ip);
139
140 if(_numIp)
141 {
142 *ip = gpIndex % _numIp;
143 return gpIndex / _numIp;
144 }
145
146 int pos = qUpperBound(_cellOffset, gpIndex) - _cellOffset.data();
147 assert(pos >= 0 && pos < _cellOffset.size()); // The last sentinel guarantees that searched value is less than the last vector value
148
149 if(gpIndex < _cellOffset[pos])
150 pos--; // if gpIndex < _cellOffset[pos], pos must be > 0
151
152 *ip = gpIndex - _cellOffset[pos];
153 return pos;
154 }
155
157 void clear() { _numIp = _numCells = 0; _cellOffset.clear(); _cellOffset.append(0); }
158
160 size_t usedMemory() const { return _numIp ? 0 : _cellOffset.capacity() * sizeof(int); }
161
162#if defined ENABLE_TESTS || defined ENABLE_VALUESET_TESTS
163 void validateInternalStructure() const;
164#endif
165
166protected:
168 GmUnfilteredGaussIndexBase() : _numIp(0), _numCells(0) { _cellOffset.append(0); }
169
170 int _numIp;
172
178
179private:
180 Q_DISABLE_COPY(GmUnfilteredGaussIndexBase);
181};
182
193{
194public:
196 virtual int numPoints() const { return _cellOffset.last(); }
197
199 virtual int numCells() const { return _numCells; }
200
202 virtual int numPoints(int cellId) const
203 {
204 assert(cellId >= 0 && cellId < _cellOffset.size()-1);
205 return _cellOffset[cellId + 1] - _cellOffset[cellId];
206 }
207
213 virtual int pointIndex(int cellId, int ip) const
214 {
215 assert(cellId >= 0 && cellId < _cellOffset.size()-1);
216 assert((ip >= 0 && ip < numPoints(cellId)) || (_cellOffset[cellId + 1] == _cellOffset[cellId]));
217 return (_cellOffset[cellId + 1] != _cellOffset[cellId]) ? ip + _cellOffset[cellId] : -1;
218 }
219
220
224 virtual int cellIp(int gpIndex, int* ip) const
225 {
226 assert(gpIndex >= 0 && gpIndex < numPoints());
227 assert(ip);
228
229 int pos = qUpperBound(_cellOffset, gpIndex) - _cellOffset.data();
230 assert(pos >= 0 && pos < _cellOffset.size()); // The last sentinel guarantees that searched value is less than the last vector value
231
232 if(gpIndex < _cellOffset[pos])
233 pos--; // if gpIndex < _cellOffset[pos], pos must be > 0
234
235 *ip = gpIndex - _cellOffset[pos];
236 return pos;
237 }
238
240 void clear() { _numCells = 0; _cellOffset.clear(); _cellOffset.append(0); }
241
243 size_t usedMemory() const { return _cellOffset.capacity() * sizeof(int); }
244
245#if defined ENABLE_TESTS || defined ENABLE_VALUESET_TESTS
246 void validateInternalStructure() const;
247#endif
248
249protected:
251 GmFilteredGaussIndexBase() : _numCells(0) { _cellOffset.append(0); }
252
253
255
267
268private:
269 Q_DISABLE_COPY(GmFilteredGaussIndexBase);
270};
271
272
275{
276public:
277 GmMeshGaussIndex(const GmElementMesh* mesh, int ruleSet);
278
279 bool init();
280
281 bool addValues(const int* numAddedValues);
282 bool addValues(int firstAddedElement);
283
284 void restoreSize(int oldNumCells);
285
287 const GmElementMesh* mesh() const { return _mesh; }
288
289private:
290 bool addValuesWorker(const int* numAddedValues, int firstAddedElement);
291
292 int numAddedGaussPoints(const int* numTypes, int* pointsPerCell, int* numElem);
293 int numAddedGaussPoints(int firstElement, int* pointsPerCell, int* numElem);
294
295 int fixedAddedElements(const int* numTypes, int firstElement, int* numElem) const;
296
297 void fillOffsetVectorFromMesh (int firstCell = 0);
298 void fillOffsetVectorFromTypes(int firstCell, const int* numTypes, int newFixed);
299
301 int _rule;
302};
303
312{
313public:
314 GmFixedMeshSetGaussIndex(const GmElementMesh* mesh, const int* cellSet, int numCells, int ruleSet);
315
316 bool init();
317
318private:
320 const int* _cells;
321 int _rule;
322};
323
326{
327public:
328 GmFilteredCellSetGaussIndex(const GmCellGroupSet* group, bool activeOnly, int ruleSet);
329
330 bool init();
331
332private:
335 int _rule;
336};
337
338
339#endif
340
341
Interface for helping managing mesh cell groups and returning the elements in their union.
Definition gmCellGroupSet.h:35
Base interface for FEM (finite element) meshes.
Definition gmElementMesh.h:42
A Gauss index interface indexing a filtered set of mesh elements.
Definition gmGaussIndex.h:326
int _rule
The indexed rule set.
Definition gmGaussIndex.h:335
bool _activeOnly
Should we index active cells only?
Definition gmGaussIndex.h:334
const GmCellGroupSet * _group
The group set object listing the set of mesh cells.
Definition gmGaussIndex.h:333
A helper class that implements a GaussIndex like interface for the case where the index can filter ce...
Definition gmGaussIndex.h:193
void clear()
Clears the index.
Definition gmGaussIndex.h:240
virtual int numPoints(int cellId) const
Returns the number of Gauss points for the given Cell. Returns 0 if the cell does not belongs to the ...
Definition gmGaussIndex.h:202
virtual int cellIp(int gpIndex, int *ip) const
Given a Gauss point "linear" index (a value from 0 to numPoints()-1), returns the mesh cell index + i...
Definition gmGaussIndex.h:224
virtual int numCells() const
Returns the number of cells in the index.
Definition gmGaussIndex.h:199
int _numCells
The number of cells in the index set (might be less than the number of cells in the offset vector)
Definition gmGaussIndex.h:254
size_t usedMemory() const
Returns the size of the used memory.
Definition gmGaussIndex.h:243
QVarLengthArray< int, 2 > _cellOffset
Definition gmGaussIndex.h:266
virtual int numPoints() const
Returns the number of Gauss points in the index.
Definition gmGaussIndex.h:196
GmFilteredGaussIndexBase()
Default empty index constructor.
Definition gmGaussIndex.h:251
virtual int pointIndex(int cellId, int ip) const
Given a mesh cell index and an integration point index, returns the Gauss point "linear" index,...
Definition gmGaussIndex.h:213
A Gauss index interface always indexing ALL the elements in either the full mesh or in the given mesh...
Definition gmGaussIndex.h:312
const GmElementMesh * _mesh
The mesh object to which this index is tied to.
Definition gmGaussIndex.h:319
const int * _cells
The cell subset. If NULL the whole mesh will be used.
Definition gmGaussIndex.h:320
int _rule
The indexed rule set.
Definition gmGaussIndex.h:321
A class storing an index capable of determining the number of integration points belonging to a mesh,...
Definition gmGaussIndex.h:42
virtual int pointIndex(int cellId, int ip) const =0
Given a mesh cell index and an integration point index, returns the Gauss point "linear" index,...
virtual int cellIp(int gpIndex, int *ip) const =0
Given a Gauss point "linear" index (a value from 0 to numPoints()-1), returns the mesh cell index + i...
virtual ~GmGaussIndex()
Virtual destructor.
Definition gmGaussIndex.h:45
virtual int numPoints(int cellId) const =0
Returns the number of Gauss points for the given Cell. Returns 0 if the cell does not belongs to the ...
virtual int numPoints() const =0
Returns the number of Gauss points in the index.
virtual int numCells() const =0
Returns the number of cells in the index.
A helper class that implements a GmGaussIndex interface from a proxy object that includes all the nee...
Definition gmGaussIndex.h:75
virtual int cellIp(int gpIndex, int *ip) const
Given a Gauss point "linear" index (a value from 0 to numPoints()-1), returns the mesh cell index + i...
Definition gmGaussIndex.h:88
virtual int numPoints(int cellId) const
Returns the number of Gauss points for the given Cell. Returns 0 if the cell does not belongs to the ...
Definition gmGaussIndex.h:86
GmGaussIndexProxy(T *proxy, bool ownership)
Constructor. Takes ownership of the received object if ownership is true.
Definition gmGaussIndex.h:78
virtual int numPoints() const
Returns the number of Gauss points in the index.
Definition gmGaussIndex.h:84
bool _ownsProxy
Do we own the proxy object?
Definition gmGaussIndex.h:92
virtual ~GmGaussIndexProxy()
Destructor. Deletes the proxy if we have its ownership.
Definition gmGaussIndex.h:81
T * _proxy
The proxy object.
Definition gmGaussIndex.h:91
virtual int numCells() const
Returns the number of cells in the index.
Definition gmGaussIndex.h:85
virtual int pointIndex(int cellId, int ip) const
Given a mesh cell index and an integration point index, returns the Gauss point "linear" index,...
Definition gmGaussIndex.h:87
A Gauss index interface always indexing ALL the elements of a mesh, with support for mesh growing.
Definition gmGaussIndex.h:275
const GmElementMesh * mesh() const
Returns the associated mesh.
Definition gmGaussIndex.h:287
const GmElementMesh * _mesh
The mesh object to which this index is tied to.
Definition gmGaussIndex.h:300
int _rule
The indexed rule set.
Definition gmGaussIndex.h:301
A helper class that implements a GaussIndex like interface for the basic case where the ENTIRE mesh i...
Definition gmGaussIndex.h:107
int pointIndex(int cellId, int ip) const
Given a mesh cell index and an integration point index, returns the Gauss point "linear" index,...
Definition gmGaussIndex.h:125
int numCells() const
Returns the number of cells in the index.
Definition gmGaussIndex.h:113
QVarLengthArray< int, 2 > _cellOffset
Definition gmGaussIndex.h:177
int numPoints(int cellId) const
Returns the number of Gauss points for the given Cell.
Definition gmGaussIndex.h:116
GmUnfilteredGaussIndexBase()
Default empty index constructor.
Definition gmGaussIndex.h:168
int _numCells
The number of cells in the index set.
Definition gmGaussIndex.h:171
int _numIp
The fixed number of integration points per cell or 0 if index based.
Definition gmGaussIndex.h:170
int cellIp(int gpIndex, int *ip) const
Given a Gauss point "linear" index (a value from 0 to numPoints()-1), returns the mesh cell index + i...
Definition gmGaussIndex.h:135
int numPoints() const
Returns the number of Gauss points in the index.
Definition gmGaussIndex.h:110
void clear()
Clears the index.
Definition gmGaussIndex.h:157
size_t usedMemory() const
Returns the size of the used memory.
Definition gmGaussIndex.h:160
Declaration of useful configuration definitions for the Core library.
#define GMC_API_EXPORT
Macro for controlling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_L...
Definition gmCoreConfig.h:35