GemaCoreLib
The GeMA Core library
gmSparseMatrixLayoutBuilder.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 
25 #ifndef _GEMA_SPARSE_MATRIX_LAYOUT_BUILDER_H_
26 #define _GEMA_SPARSE_MATRIX_LAYOUT_BUILDER_H_
27 
28 #include "gmCoreConfig.h"
29 
30 #include "gmSparseMatrixLayout.h"
31 
32 #include <QSet>
33 #include <QPair>
34 
35 class GmElementMesh;
36 
40 {
41 public:
44 
51  virtual bool begin(int n, int expectedNnz) = 0;
52 
57  virtual bool addEntry(int row, int col) = 0;
58 
62  virtual bool end() = 0;
63 
64  static int nnzEstimative(const GmElementMesh* mesh, int maxDofsPerNode);
65 };
66 
70 template <class IndexType, GmSparseMatrixLayoutTypes T> class GmHashCSxSparseMatrixLayoutBuilder: public GmSparseMatrixLayoutBuilder
71 {
72 public:
74 
75  virtual bool begin(int n, int expectedNnz);
76  virtual bool addEntry(int row, int col);
77  virtual bool end();
78 
79 private:
80  Q_DISABLE_COPY(GmHashCSxSparseMatrixLayoutBuilder);
81 
85 };
86 
90 template <class IndexType, GmSparseMatrixLayoutTypes T> class GmVectorCSxSparseMatrixLayoutBuilder: public GmSparseMatrixLayoutBuilder
91 {
92 public:
94 
96 
97  virtual bool begin(int n, int expectedNnz);
98  virtual bool addEntry(int row, int col);
99  virtual bool end();
100 
101 private:
102  Q_DISABLE_COPY(GmVectorCSxSparseMatrixLayoutBuilder);
103 
104  void clear();
105  bool insertIfNew(int* p, int size, int value, int ptrIndex);
106 
107  struct ExtData
108  {
109  int _nalloc;
110  int* _data;
111 
112  bool allocData(int size, int* initData, int initSize);
113  };
114 
116  int _nnz;
117  int _n;
118  bool _hasExtData;
119  const int _extDataSize;
120 
126  int* _dataVec;
127 
128 #ifdef ENABLE_SPARSE_MEMORY_DEBUG
129  void entryAdded(int addedSize);
130 
131  int _memAloc;
132  int _numEntries;
133 #endif
134 };
135 
136 
137 #endif
138 
virtual bool addEntry(int row, int col)
Informs the builder that the entry in the given row/column is not 0.0. Keep in mind that this functio...
Definition: gmSparseMatrixLayoutBuilder.cpp:134
virtual bool begin(int n, int expectedNnz)
Informs the builder that the process of calling addEntry() is about to begin. Paremeter n is the numb...
Definition: gmSparseMatrixLayoutBuilder.cpp:281
int * _dataVec
The prealocated memory for colum(CSR)/row(CSC) data. Size equal to (_n*_nnz). Row/column indices are ...
Definition: gmSparseMatrixLayoutBuilder.h:126
Declaration of usefull configuration definitions for the Core library.
int _expectedNnz
The initial guess for the number of non zeros (stored for statistic only)
Definition: gmSparseMatrixLayoutBuilder.h:84
An interface for building the layout structure of a sparse matrix.
Definition: gmSparseMatrixLayoutBuilder.h:39
GmCSxSparseMatrixLayout< IndexType, T > * _layout
The layout object being filled.
Definition: gmSparseMatrixLayoutBuilder.h:82
const int _extDataSize
The number of _dataVec entries needed to hold an ExtData structure.
Definition: gmSparseMatrixLayoutBuilder.h:119
virtual bool end()
Finishes the building process completing the creation of the associate layout structure....
Definition: gmSparseMatrixLayoutBuilder.cpp:399
GmCSxSparseMatrixLayout< IndexType, T > * _layout
The layout object being filled.
Definition: gmSparseMatrixLayoutBuilder.h:115
int * _data
A pointer to the extra buffer.
Definition: gmSparseMatrixLayoutBuilder.h:110
bool allocData(int size, int *initData, int initSize)
An auxiliar function that just allocates a vector of the given size, initializes its first entries wi...
Definition: gmSparseMatrixLayoutBuilder.cpp:631
A class for creating a CSR/CSC matrix layout by using an intermediary vector based structure to conso...
Definition: gmSparseMatrixLayoutBuilder.h:90
int _nnz
The pre-allocated initial guess for the number of non zeros per row/column.
Definition: gmSparseMatrixLayoutBuilder.h:116
virtual bool end()
Finishes the building process completing the creation of the associate layout structure....
Definition: gmSparseMatrixLayoutBuilder.cpp:165
void clear()
Clears the internal _dataVec structure.
Definition: gmSparseMatrixLayoutBuilder.cpp:256
virtual ~GmSparseMatrixLayoutBuilder()
Virtual destructor.
Definition: gmSparseMatrixLayoutBuilder.h:43
int _n
The number of matrix rows (CSR) / columns (CSC)
Definition: gmSparseMatrixLayoutBuilder.h:117
virtual bool begin(int n, int expectedNnz)
Informs the builder that the process of calling addEntry() is about to begin. Paremeter n is the numb...
Definition: gmSparseMatrixLayoutBuilder.cpp:94
bool _hasExtData
Did we needed any ExtData vector?
Definition: gmSparseMatrixLayoutBuilder.h:118
virtual bool addEntry(int row, int col)
Informs the builder that the entry in the given row/column is not 0.0. Keep in mind that this functio...
Definition: gmSparseMatrixLayoutBuilder.cpp:327
A structure for storing a matrix layout in either CSR or CSC format. The template type defines the ty...
Definition: gmSparseMatrixLayout.h:123
#define GMC_API_EXPORT
Macro for controling if the class is being exported (GEMA_CORE_LIB defined) or imported (GEMA_CORE_LI...
Definition: gmCoreConfig.h:35
QSet< QPair< int, int > > _nodeNodeMap
The hash table used to collect used matrix entry coordinates.
Definition: gmSparseMatrixLayoutBuilder.h:83
bool insertIfNew(int *p, int size, int value, int ptrIndex)
Searches for value in the array pointed by p, with the given size. If the value is not found in p,...
Definition: gmSparseMatrixLayoutBuilder.cpp:592
Definition: gmSparseMatrixLayoutBuilder.h:107
virtual ~GmVectorCSxSparseMatrixLayoutBuilder()
Destructor.
Definition: gmSparseMatrixLayoutBuilder.cpp:248
Base interface for FEM (finite element) meshes.
Definition: gmElementMesh.h:40
Declaration of the GmSparseMatrixLayout structure and its derived types.
A class for creating a CSR/CSC matrix layout by using an intermediary hash table to consolidate the (...
Definition: gmSparseMatrixLayoutBuilder.h:70
int _nalloc
The number of allocated entries in the extension vector WITH negative sign. Always less than -1.
Definition: gmSparseMatrixLayoutBuilder.h:109