GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
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
31
32#include <QSet>
33#include <QPair>
34
35class GmElementMesh;
36
40{
41public:
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
70template <class IndexType, GmSparseMatrixLayoutTypes T> class GmHashCSxSparseMatrixLayoutBuilder: public GmSparseMatrixLayoutBuilder
71{
72public:
74
75 virtual bool begin(int n, int expectedNnz);
76 virtual bool addEntry(int row, int col);
77 virtual bool end();
78
79private:
81
85};
86
90template <class IndexType, GmSparseMatrixLayoutTypes T> class GmVectorCSxSparseMatrixLayoutBuilder: public GmSparseMatrixLayoutBuilder
91{
92public:
94
96
97 virtual bool begin(int n, int expectedNnz);
98 virtual bool addEntry(int row, int col);
99 virtual bool end();
100
101private:
103
104 void clear();
105 bool insertIfNew(int* p, int size, int value, int ptrIndex);
106
107 struct ExtData
108 {
110 int* _data;
111
112 bool allocData(int size, int* initData, int initSize);
113 };
114
116 int _nnz;
117 int _n;
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
Base interface for FEM (finite element) meshes.
Definition gmElementMesh.h:42
A class for creating a CSR/CSC matrix layout by using an intermediary hash table to consolidate the (...
Definition gmSparseMatrixLayoutBuilder.h:71
QSet< QPair< int, int > > _nodeNodeMap
The hash table used to collect used matrix entry coordinates.
Definition gmSparseMatrixLayoutBuilder.h:83
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
GmCSxSparseMatrixLayout< IndexType, T > * _layout
The layout object being filled.
Definition gmSparseMatrixLayoutBuilder.h:82
int _expectedNnz
The initial guess for the number of non zeros (stored for statistic only)
Definition gmSparseMatrixLayoutBuilder.h:84
virtual bool end()
Finishes the building process completing the creation of the associate layout structure....
Definition gmSparseMatrixLayoutBuilder.cpp:165
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
An interface for building the layout structure of a sparse matrix.
Definition gmSparseMatrixLayoutBuilder.h:40
virtual ~GmSparseMatrixLayoutBuilder()
Virtual destructor.
Definition gmSparseMatrixLayoutBuilder.h:43
virtual bool begin(int n, int expectedNnz)=0
Informs the builder that the process of calling addEntry() is about to begin. Paremeter n is the numb...
virtual bool end()=0
Finishes the building process completing the creation of the associate layout structure....
virtual bool addEntry(int row, int col)=0
Informs the builder that the entry in the given row/column is not 0.0. Keep in mind that this functio...
A class for creating a CSR/CSC matrix layout by using an intermediary vector based structure to conso...
Definition gmSparseMatrixLayoutBuilder.h:91
int _nnz
The pre-allocated initial guess for the number of non zeros per row/column.
Definition gmSparseMatrixLayoutBuilder.h:116
GmCSxSparseMatrixLayout< IndexType, T > * _layout
The layout object being filled.
Definition gmSparseMatrixLayoutBuilder.h:115
int _n
The number of matrix rows (CSR) / columns (CSC)
Definition gmSparseMatrixLayoutBuilder.h:117
const int _extDataSize
The number of _dataVec entries needed to hold an ExtData structure.
Definition gmSparseMatrixLayoutBuilder.h:119
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
int * _dataVec
The prealocated memory for colum(CSR)/row(CSC) data. Size equal to (_n*_nnz). Row/column indices are ...
Definition gmSparseMatrixLayoutBuilder.h:126
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
virtual ~GmVectorCSxSparseMatrixLayoutBuilder()
Destructor.
Definition gmSparseMatrixLayoutBuilder.cpp:248
virtual bool end()
Finishes the building process completing the creation of the associate layout structure....
Definition gmSparseMatrixLayoutBuilder.cpp:399
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:589
void clear()
Clears the internal _dataVec structure.
Definition gmSparseMatrixLayoutBuilder.cpp:256
bool _hasExtData
Did we needed any ExtData vector?
Definition gmSparseMatrixLayoutBuilder.h:118
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
Declaration of the GmSparseMatrixLayout structure and its derived types.
A structure for storing a matrix layout in either CSR or CSC format. The template type defines the ty...
Definition gmSparseMatrixLayout.h:124
Definition gmSparseMatrixLayoutBuilder.h:108
int _nalloc
The number of allocated entries in the extension vector WITH negative sign. Always less than -1.
Definition gmSparseMatrixLayoutBuilder.h:109
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:628