41template <
typename DataType,
typename InnerMatrixType>
44 :
BaseType(0, 0, type), m_data(), m_rowSizes(), m_columnSizes(),
45 m_storageSize(), m_numberOfBlockRows(0), m_numberOfBlockColumns(0)
49template <
typename DataType,
typename InnerMatrixType>
51 unsigned int numberOfBlockRows,
unsigned int numberOfBlockColumns,
52 unsigned int rowsPerBlock,
unsigned int columnsPerBlock,
MatrixStorage type)
53 :
BaseType(numberOfBlockRows * rowsPerBlock,
54 numberOfBlockColumns * columnsPerBlock, type),
55 m_data(), m_rowSizes(numberOfBlockRows),
56 m_columnSizes(numberOfBlockColumns), m_storageSize(0),
57 m_numberOfBlockRows(numberOfBlockRows),
58 m_numberOfBlockColumns(numberOfBlockColumns)
60 m_storageSize = GetRequiredStorageSize();
62 m_storageSize, std::shared_ptr<InnerType>());
63 for (
unsigned int i = 1; i <= numberOfBlockRows; ++i)
65 m_rowSizes[i - 1] = i * rowsPerBlock - 1;
68 for (
unsigned int i = 1; i <= numberOfBlockColumns; ++i)
70 m_columnSizes[i - 1] = i * columnsPerBlock - 1;
74template <
typename DataType,
typename InnerMatrixType>
76 unsigned int numberOfBlockRows,
unsigned int numberOfBlockColumns,
77 const unsigned int *rowsPerBlock,
const unsigned int *columnsPerBlock,
80 std::accumulate(rowsPerBlock, rowsPerBlock + numberOfBlockRows, 0),
81 std::accumulate(columnsPerBlock,
82 columnsPerBlock + numberOfBlockColumns, 0),
84 m_data(), m_rowSizes(numberOfBlockRows),
85 m_columnSizes(numberOfBlockColumns), m_storageSize(0),
86 m_numberOfBlockRows(numberOfBlockRows),
87 m_numberOfBlockColumns(numberOfBlockColumns)
89 m_storageSize = GetRequiredStorageSize();
91 m_storageSize, std::shared_ptr<InnerType>());
92 Initialize(rowsPerBlock, columnsPerBlock);
95template <
typename DataType,
typename InnerMatrixType>
97 unsigned int numberOfBlockRows,
unsigned int numberOfBlockColumns,
101 rowsPerBlock.data() + numberOfBlockRows, 0),
102 std::accumulate(columnsPerBlock.data(),
103 columnsPerBlock.data() + numberOfBlockColumns,
106 m_data(), m_rowSizes(numberOfBlockRows),
107 m_columnSizes(numberOfBlockColumns), m_storageSize(0),
108 m_numberOfBlockRows(numberOfBlockRows),
109 m_numberOfBlockColumns(numberOfBlockColumns)
111 m_storageSize = GetRequiredStorageSize();
113 m_storageSize, std::shared_ptr<InnerType>());
114 Initialize(rowsPerBlock.data(), columnsPerBlock.data());
117template <
typename DataType,
typename InnerMatrixType>
122 std::accumulate(rowsPerBlock.begin(), rowsPerBlock.end(), 0),
123 std::accumulate(columnsPerBlock.begin(), columnsPerBlock.end(), 0),
125 m_data(), m_rowSizes(rowsPerBlock.size()),
126 m_columnSizes(columnsPerBlock.size()), m_storageSize(0),
127 m_numberOfBlockRows(rowsPerBlock.size()),
128 m_numberOfBlockColumns(columnsPerBlock.size())
130 m_storageSize = GetRequiredStorageSize();
132 m_storageSize, std::shared_ptr<InnerType>());
133 Initialize(rowsPerBlock.data(), columnsPerBlock.data());
136template <
typename DataType,
typename InnerMatrixType>
139 : BaseType(rhs), m_data(rhs.m_data.size()), m_rowSizes(rhs.m_rowSizes),
140 m_columnSizes(rhs.m_columnSizes), m_storageSize(rhs.m_storageSize),
141 m_numberOfBlockRows(rhs.m_numberOfBlockRows),
142 m_numberOfBlockColumns(rhs.m_numberOfBlockColumns)
144 for (
unsigned int i = 0; i < rhs.m_data.size(); ++i)
146 m_data[i] = InnerType::CreateWrapper(rhs.m_data[i]);
150template <
typename DataType,
typename InnerMatrixType>
151unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>,
152 BlockMatrixTag>::GetRequiredStorageSize()
const
154 return BaseType::GetRequiredStorageSize(this->GetStorageType(),
155 this->GetNumberOfBlockRows(),
156 this->GetNumberOfBlockColumns());
159template <
typename DataType,
typename InnerMatrixType>
161 BlockMatrixTag>::CalculateBlockIndex(
unsigned int row,
165 return BaseType::CalculateIndex(this->GetStorageType(), row, column,
166 m_numberOfBlockRows, m_numberOfBlockColumns,
167 this->GetTransposeFlag());
170template <
typename DataType,
typename InnerMatrixType>
172 BlockMatrixTag>::InnerType *
174 unsigned int row,
unsigned int column)
const
177 this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows
178 : row < m_numberOfBlockColumns,
179 std::string(
"Row ") + std::to_string(row) +
180 std::string(
" requested in a block matrix with a maximum of ") +
181 std::to_string(m_numberOfBlockRows) + std::string(
" rows"));
183 this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns
184 : column < m_numberOfBlockColumns,
185 std::string(
"Column ") + std::to_string(column) +
186 std::string(
" requested in a block matrix with a maximum of ") +
187 std::to_string(m_numberOfBlockColumns) + std::string(
" columns"));
188 int x = CalculateBlockIndex(row, column);
195 return m_data[x].get();
199template <
typename DataType,
typename InnerMatrixType>
200std::shared_ptr<const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
201 BlockMatrixTag>::InnerType>
203 unsigned int row,
unsigned int column)
const
206 this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows
207 : row < m_numberOfBlockColumns,
208 std::string(
"Row ") + std::to_string(row) +
209 std::string(
" requested in a block matrix with a maximum of ") +
210 std::to_string(m_numberOfBlockRows) + std::string(
" rows"));
212 this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns
213 : column < m_numberOfBlockRows,
214 std::string(
"Column ") + std::to_string(column) +
215 std::string(
" requested in a block matrix with a maximum of ") +
216 std::to_string(m_numberOfBlockColumns) + std::string(
" columns"));
217 int x = CalculateBlockIndex(row, column);
220 return std::shared_ptr<const InnerType>();
228template <
typename DataType,
typename InnerMatrixType>
229std::shared_ptr<typename NekMatrix<NekMatrix<DataType, InnerMatrixType>,
230 BlockMatrixTag>::InnerType> &
232 unsigned int row,
unsigned int column)
235 this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows
236 : row < m_numberOfBlockColumns,
237 std::string(
"Row ") + std::to_string(row) +
238 std::string(
" requested in a block matrix with a maximum of ") +
239 std::to_string(m_numberOfBlockRows) + std::string(
" rows"));
241 this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns
242 : column < m_numberOfBlockRows,
243 std::string(
"Column ") + std::to_string(column) +
244 std::string(
" requested in a block matrix with a maximum of ") +
245 std::to_string(m_numberOfBlockColumns) + std::string(
" columns"));
246 int x = CalculateBlockIndex(row, column);
249 return m_nullBlockPtr;
257template <
typename DataType,
typename InnerMatrixType>
259 unsigned int row,
unsigned int column, std::shared_ptr<InnerType> &m)
262 this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows
263 : row < m_numberOfBlockColumns,
264 std::string(
"Row ") + std::to_string(row) +
265 std::string(
" requested in a block matrix with a maximum of ") +
266 std::to_string(m_numberOfBlockRows) + std::string(
" rows"));
268 this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns
269 : column < m_numberOfBlockRows,
270 std::string(
"Column ") + std::to_string(column) +
271 std::string(
" requested in a block matrix with a maximum of ") +
272 std::to_string(m_numberOfBlockColumns) + std::string(
" columns"));
273 m_data[CalculateBlockIndex(row, column)] = InnerType::CreateWrapper(m);
276template <
typename DataType,
typename InnerMatrixType>
278 BlockMatrixTag>::ConstGetValueType
280 unsigned int row,
unsigned int col)
const
283 std::string(
"Row ") + std::to_string(row) +
284 std::string(
" requested in a matrix with a maximum of ") +
285 std::to_string(this->GetRows()) + std::string(
" rows"));
287 std::string(
"Column ") + std::to_string(col) +
288 std::string(
" requested in a matrix with a maximum of ") +
289 std::to_string(this->GetColumns()) + std::string(
" columns"));
294 if (this->GetTransposeFlag() ==
'T')
296 std::swap(rowSizes, columnSizes);
299 unsigned int blockRow =
300 std::lower_bound(rowSizes->begin(), rowSizes->end(), row) -
302 unsigned int blockColumn =
303 std::lower_bound(columnSizes->begin(), columnSizes->end(), col) -
304 columnSizes->begin();
305 const std::shared_ptr<const InnerType> block =
306 GetBlock(blockRow, blockColumn);
308 unsigned int actualRow = row;
311 actualRow = row - ((*rowSizes)[blockRow - 1]) - 1;
314 unsigned int actualCol = col;
317 actualCol = col - ((*columnSizes)[blockColumn - 1]) - 1;
322 return (*block)(actualRow, actualCol);
326 return m_zeroElement;
330template <
typename DataType,
typename InnerMatrixType>
332 BlockMatrixTag>::GetStorageSize()
const
334 return m_storageSize;
337template <
typename DataType,
typename InnerMatrixType>
339 BlockMatrixTag>::GetNumberOfBlockRows()
const
341 if (this->GetTransposeFlag() ==
'N')
343 return m_numberOfBlockRows;
347 return m_numberOfBlockColumns;
351template <
typename DataType,
typename InnerMatrixType>
353 BlockMatrixTag>::GetNumberOfBlockColumns()
const
355 if (this->GetTransposeFlag() ==
'N')
357 return m_numberOfBlockColumns;
361 return m_numberOfBlockRows;
365template <
typename DataType,
typename InnerMatrixType>
367 GetNumberOfRowsInBlockRow(
unsigned int blockRow)
const
369 if (this->GetTransposeFlag() ==
'N')
371 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockRows,
376 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockColumns,
381template <
typename DataType,
typename InnerMatrixType>
383 GetNumberOfColumnsInBlockColumn(
unsigned int blockCol)
const
385 if (this->GetTransposeFlag() ==
'T')
387 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockRows,
392 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockColumns,
397template <
typename DataType,
typename InnerMatrixType>
402 if (this->GetTransposeFlag() ==
'T')
404 rowSizes = m_columnSizes;
405 colSizes = m_rowSizes;
409 rowSizes = m_rowSizes;
410 colSizes = m_columnSizes;
414template <
typename DataType,
typename InnerMatrixType>
416 BlockMatrixTag>::iterator
422template <
typename DataType,
typename InnerMatrixType>
424 BlockMatrixTag>::iterator
430template <
typename DataType,
typename InnerMatrixType>
432 BlockMatrixTag>::const_iterator
438template <
typename DataType,
typename InnerMatrixType>
440 BlockMatrixTag>::const_iterator
446template <
typename DataType,
typename InnerMatrixType>
450 BlockMatrixTag> &rhs)
452 return ThisType(rhs);
455template <
typename DataType,
typename InnerMatrixType>
456std::shared_ptr<NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>>
457NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::CreateWrapper(
458 const std::shared_ptr<
459 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>> &rhs)
461 return std::shared_ptr<ThisType>(
new ThisType(*rhs));
464template <
typename DataType,
typename InnerMatrixType>
466 GetNumberOfElementsInBlock(
unsigned int block,
467 [[maybe_unused]]
unsigned int totalBlocks,
471 std::string(
"Block Element ") + std::to_string(block) +
472 std::string(
" requested in a matrix with a maximum of ") +
473 std::to_string(totalBlocks) + std::string(
" blocks."));
476 return sizes[block] + 1;
480 return sizes[block] - sizes[block - 1];
484template <
typename DataType,
typename InnerMatrixType>
486 BlockMatrixTag>::Initialize(
const unsigned int *rowsPerBlock,
487 const unsigned int *columnsPerBlock)
489 m_storageSize = this->GetRows() * this->GetColumns();
490 if (this->GetRows() > 0)
492 m_rowSizes[0] = rowsPerBlock[0] - 1;
493 for (
unsigned int i = 1; i < m_numberOfBlockRows; ++i)
495 m_rowSizes[i] = rowsPerBlock[i] + m_rowSizes[i - 1];
498 if (this->GetColumns() > 0)
500 m_columnSizes[0] = columnsPerBlock[0] - 1;
501 for (
unsigned int i = 1; i < m_numberOfBlockColumns; ++i)
503 m_columnSizes[i] = columnsPerBlock[i] + m_columnSizes[i - 1];
508template <
typename DataType,
typename InnerMatrixType>
509typename boost::call_traits<
511 BlockMatrixTag>::NumberType>::value_type
513 unsigned int row,
unsigned int column)
const
515 return (*
this)(row, column);
518template <
typename DataType,
typename InnerMatrixType>
520 BlockMatrixTag>::v_GetStorageSize()
const
522 return this->GetStorageSize();
525template <
typename DataType,
typename InnerMatrixType>
527 BlockMatrixTag>::v_Transpose()
529 for (
auto &ptr : m_data)
531 if (ptr.get() !=
nullptr)
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
#define LIB_UTILITIES_EXPORT
iterator_base< const ThisType > const_iterator
iterator_base< ThisType > iterator