Loading...
Searching...
No Matches
system_matrix.hpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#ifndef __BITPIT_SYSTEM_MATRIX_HPP__
26#define __BITPIT_SYSTEM_MATRIX_HPP__
27
28#include <vector>
29
30#if BITPIT_ENABLE_MPI==1
31# include <mpi.h>
32#endif
33
34#include "bitpit_containers.hpp"
35
36namespace bitpit {
37
39
40public:
42 SparseMatrix(long nRows, long nCols, long nNZ);
43 SparseMatrix(int blockSize, long nRows, long nCols, long nNZ);
44#if BITPIT_ENABLE_MPI==1
45 SparseMatrix(MPI_Comm communicator);
46 SparseMatrix(MPI_Comm communicator, bool partitioned, long nRows, long nCols, long nNZ);
47 SparseMatrix(MPI_Comm communicator, bool partitioned, int blockSize, long nRows, long nCols, long nNZ);
48#endif
49
50#if BITPIT_ENABLE_MPI==1
51 SparseMatrix(const SparseMatrix &other);
52 SparseMatrix(SparseMatrix &&other) = default;
53#endif
54
56
57 void initialize(long nRows, long nCols, long nNZ);
58 void initialize(int blockSize, long nRows, long nCols, long nNZ);
59#if BITPIT_ENABLE_MPI==1
60 void initialize(bool partitioned, long nRows, long nCols, long nNZ);
61 void initialize(bool partitioned, int blockSize, long nRows, long nCols, long nNZ);
62#endif
63 void clear(bool release = false);
64 void squeeze();
65
66 virtual void display(std::ostream &stream, double negligiblity, int indent = 0) const;
67
68 void assembly();
69 bool isAssembled() const;
70
71 long countMissingRows() const;
72 long countAddedRows() const;
73
74 int getBlockSize() const;
75
76 long getRowCount() const;
77 long getColCount() const;
78
79 long getRowElementCount() const;
80 long getColElementCount() const;
81
82 long getNZCount() const;
83 long getRowNZCount(long row) const;
84 long getMaxRowNZCount() const;
85
86 long getNZElementCount() const;
87 long getRowNZElementCount(long row) const;
88 long getMaxRowNZElementCount() const;
89
90#if BITPIT_ENABLE_MPI==1
91 bool isPartitioned() const;
92
93 const MPI_Comm & getCommunicator() const;
94
95 long getRowGlobalCount() const;
96 long getRowGlobalOffset() const;
97
98 long getRowGlobalElementCount() const;
99 long getRowGlobalElementOffset() const;
100
101 long getColGlobalCount() const;
102 long getColGlobalOffset() const;
103
104 long getColGlobalElementCount() const;
105 long getColGlobalElementOffset() const;
106
107 long getNZGlobalCount() const;
108 long getMaxRowNZGlobalCount() const;
109
110 long getNZGlobalElementCount() const;
112
113 std::vector<long> extractLocalGlobalRows() const;
114 std::vector<long> extractGhostGlobalRows() const;
115
116 std::vector<long> extractLocalGlobalCols() const;
117 std::vector<long> extractGhostGlobalCols() const;
118#endif
119
120 void addRow(const std::vector<long> &rowPattern, const std::vector<double> &rowValues);
121 void addRow(long nRowNZ, const long *rowPattern, const double *rowValues);
122
124 void getRowPattern(long row, ConstProxyVector<long> *pattern) const;
125
127 void getRowValues(long row, ConstProxyVector<double> *values) const;
128
129 std::unique_ptr<SparseMatrix> computeTranspose() const;
130
131protected:
132 int m_blockSize;
133
134 long m_nRows;
135 long m_nCols;
136 long m_nNZ;
137 long m_maxRowNZ;
138
139 long m_lastRow;
140
141 bool m_assembled;
142
143#if BITPIT_ENABLE_MPI==1
144 bool m_partitioned;
145 MPI_Comm m_communicator;
146
147 long m_global_nRows;
148 long m_global_nCols;
149 long m_global_nNZ;
150 long m_global_maxRowNZ;
151 long m_global_rowOffset;
152 long m_global_colOffset;
153#endif
154
155 FlatVector2D<long> m_pattern;
156 std::vector<double> m_values;
157
158 long * getRowPatternData(long row);
159 const long * getRowPatternData(long row) const;
160
161 double * getRowValuesData(long row);
162 const double * getRowValuesData(long row) const;
163
166 void clearPatternStorage(bool release);
167
169 void squeezeValueStorage();
170 void clearValueStorage(bool release);
171
172private:
173 void _initialize(int blockSize, long nRows, long nCols, long nNZ);
174#if BITPIT_ENABLE_MPI==1
175 void _initialize(bool partitioned, int bBlocks, long nRows, long nCols, long nNZ);
176#endif
177
178#if BITPIT_ENABLE_MPI==1
179 void setCommunicator(MPI_Comm communicator);
180 void freeCommunicator();
181#endif
182
183 void initializePatternStorage(long capacity);
184 void initializeValueStorage(long capacity);
185
186 long getNZElementCount(long nNZ) const;
187
188};
189
190}
191
192#endif
Metafunction for generation of a flattened vector of vectors.
Metafunction for generating a list of elements that can be either stored in an external vectror or,...
long countMissingRows() const
const MPI_Comm & getCommunicator() const
long getColElementCount() const
void initialize(long nRows, long nCols, long nNZ)
long getColGlobalCount() const
ConstProxyVector< double > getRowValues(long row) const
long getColGlobalOffset() const
long getNZGlobalElementCount() const
long getNZElementCount() const
void clear(bool release=false)
long getMaxRowNZCount() const
long getRowNZElementCount(long row) const
virtual void display(std::ostream &stream, double negligiblity, int indent=0) const
long getRowGlobalCount() const
std::unique_ptr< SparseMatrix > computeTranspose() const
long getRowElementCount() const
std::vector< long > extractLocalGlobalRows() const
long getRowGlobalElementCount() const
long getMaxRowNZGlobalElementCount() const
std::vector< long > extractGhostGlobalRows() const
ConstProxyVector< long > getRowPattern(long row) const
long getMaxRowNZElementCount() const
long getNZGlobalCount() const
long getRowGlobalElementOffset() const
void addRow(const std::vector< long > &rowPattern, const std::vector< double > &rowValues)
long * getRowPatternData(long row)
long getColGlobalElementCount() const
long getColGlobalElementOffset() const
std::vector< long > extractLocalGlobalCols() const
long getRowNZCount(long row) const
void clearValueStorage(bool release)
std::vector< long > extractGhostGlobalCols() const
void clearPatternStorage(bool release)
double * getRowValuesData(long row)
long getRowGlobalOffset() const
long getMaxRowNZGlobalCount() const
long countAddedRows() const
--- layout: doxygen_footer ---