33 #include <boost/core/ignore_unused.hpp> 41 template<
typename DataType,
typename InnerMatrixType>
48 m_numberOfBlockRows(0),
49 m_numberOfBlockColumns(0)
53 template<
typename DataType,
typename InnerMatrixType>
55 unsigned int rowsPerBlock,
unsigned int columnsPerBlock,
57 BaseType(numberOfBlockRows*rowsPerBlock, numberOfBlockColumns*columnsPerBlock,type),
59 m_rowSizes(numberOfBlockRows),
60 m_columnSizes(numberOfBlockColumns),
62 m_numberOfBlockRows(numberOfBlockRows),
63 m_numberOfBlockColumns(numberOfBlockColumns)
65 m_storageSize = GetRequiredStorageSize();
67 for(
unsigned int i = 1; i <= numberOfBlockRows; ++i)
69 m_rowSizes[i-1] = i*rowsPerBlock-1;
72 for(
unsigned int i = 1; i <= numberOfBlockColumns; ++i)
74 m_columnSizes[i-1] = i*columnsPerBlock-1;
78 template<
typename DataType,
typename InnerMatrixType>
80 const unsigned int* rowsPerBlock,
const unsigned int* columnsPerBlock,
82 BaseType(
std::accumulate(rowsPerBlock, rowsPerBlock + numberOfBlockRows, 0),
83 std::accumulate(columnsPerBlock, columnsPerBlock + numberOfBlockColumns, 0),
86 m_rowSizes(numberOfBlockRows),
87 m_columnSizes(numberOfBlockColumns),
89 m_numberOfBlockRows(numberOfBlockRows),
90 m_numberOfBlockColumns(numberOfBlockColumns)
92 m_storageSize = GetRequiredStorageSize();
94 Initialize(rowsPerBlock, columnsPerBlock);
97 template<
typename DataType,
typename InnerMatrixType>
101 BaseType(
std::accumulate(rowsPerBlock.data(), rowsPerBlock.data() + numberOfBlockRows, 0),
102 std::accumulate(columnsPerBlock.data(), columnsPerBlock.data() + numberOfBlockColumns, 0),
105 m_rowSizes(numberOfBlockRows),
106 m_columnSizes(numberOfBlockColumns),
108 m_numberOfBlockRows(numberOfBlockRows),
109 m_numberOfBlockColumns(numberOfBlockColumns)
111 m_storageSize = GetRequiredStorageSize();
113 Initialize(rowsPerBlock.data(), columnsPerBlock.data());
116 template<
typename DataType,
typename InnerMatrixType>
120 BaseType(
std::accumulate(rowsPerBlock.begin(), rowsPerBlock.end(), 0),
121 std::accumulate(columnsPerBlock.begin(), columnsPerBlock.end(), 0),
124 m_rowSizes(rowsPerBlock.num_elements()),
125 m_columnSizes(columnsPerBlock.num_elements()),
127 m_numberOfBlockRows(rowsPerBlock.num_elements()),
128 m_numberOfBlockColumns(columnsPerBlock.num_elements())
130 m_storageSize = GetRequiredStorageSize();
132 Initialize(rowsPerBlock.data(), columnsPerBlock.data());
135 template<
typename DataType,
typename InnerMatrixType>
138 m_data(
rhs.m_data.num_elements()),
139 m_rowSizes(
rhs.m_rowSizes),
140 m_columnSizes(
rhs.m_columnSizes),
141 m_storageSize(
rhs.m_storageSize),
142 m_numberOfBlockRows(
rhs.m_numberOfBlockRows),
143 m_numberOfBlockColumns(
rhs.m_numberOfBlockColumns)
145 for(
unsigned int i = 0; i <
rhs.m_data.num_elements(); ++i)
147 m_data[i] = InnerType::CreateWrapper(
rhs.m_data[i]);
151 template<
typename DataType,
typename InnerMatrixType>
152 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetRequiredStorageSize()
const 154 return BaseType::GetRequiredStorageSize(this->GetStorageType(), this->GetNumberOfBlockRows(),
155 this->GetNumberOfBlockColumns());
158 template<
typename DataType,
typename InnerMatrixType>
159 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::CalculateBlockIndex(
unsigned int row,
unsigned int column)
const 161 return BaseType::CalculateIndex(this->GetStorageType(),
162 row, column, m_numberOfBlockRows, m_numberOfBlockColumns, this->GetTransposeFlag());
165 template<
typename DataType,
typename InnerMatrixType>
166 const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::InnerType*
167 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlockPtr(
unsigned int row,
unsigned int column)
const 169 ASSERTL2(this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows : row < m_numberOfBlockColumns,
170 std::string(
"Row ") + std::to_string(row) +
171 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockRows) +
172 std::string(
" rows"));
173 ASSERTL2(this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns : column < m_numberOfBlockColumns,
174 std::string(
"Column ") + std::to_string(column) +
175 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockColumns) +
176 std::string(
" columns"));
177 int x = CalculateBlockIndex(row,column);
184 return m_data[x].get();
188 template<
typename DataType,
typename InnerMatrixType>
189 std::shared_ptr<const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::InnerType>
190 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlock(
unsigned int row,
unsigned int column)
const 192 ASSERTL2(this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows : row < m_numberOfBlockColumns,
193 std::string(
"Row ") + std::to_string(row) +
194 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockRows) +
195 std::string(
" rows"));
196 ASSERTL2(this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns : column < m_numberOfBlockRows,
197 std::string(
"Column ") + std::to_string(column) +
198 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockColumns) +
199 std::string(
" columns"));
200 int x = CalculateBlockIndex(row,column);
203 return std::shared_ptr<const InnerType>();
211 template<
typename DataType,
typename InnerMatrixType>
212 std::shared_ptr<typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::InnerType>&
213 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlock(
unsigned int row,
unsigned int column)
215 ASSERTL2(this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows : row < m_numberOfBlockColumns,
216 std::string(
"Row ") + std::to_string(row) +
217 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockRows) +
218 std::string(
" rows"));
219 ASSERTL2(this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns : column < m_numberOfBlockRows,
220 std::string(
"Column ") + std::to_string(column) +
221 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockColumns) +
222 std::string(
" columns"));
223 int x = CalculateBlockIndex(row,column);
226 return m_nullBlockPtr;
234 template<
typename DataType,
typename InnerMatrixType>
235 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::SetBlock(
unsigned int row,
unsigned int column, std::shared_ptr<InnerType>& m)
237 ASSERTL2(this->GetTransposeFlag() ==
'N' ? row < m_numberOfBlockRows : row < m_numberOfBlockColumns,
238 std::string(
"Row ") + std::to_string(row) +
239 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockRows) +
240 std::string(
" rows"));
241 ASSERTL2(this->GetTransposeFlag() ==
'N' ? column < m_numberOfBlockColumns : column < m_numberOfBlockRows,
242 std::string(
"Column ") + std::to_string(column) +
243 std::string(
" requested in a block matrix with a maximum of ") + std::to_string(m_numberOfBlockColumns) +
244 std::string(
" columns"));
245 m_data[CalculateBlockIndex(row, column)] = InnerType::CreateWrapper(m);
250 template<
typename DataType,
typename InnerMatrixType>
251 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::ConstGetValueType 252 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::operator()(
unsigned int row,
unsigned int col)
const 254 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + std::to_string(row) +
255 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
256 std::string(
" rows"));
257 ASSERTL2(col < this->GetColumns(), std::string(
"Column ") + std::to_string(col) +
258 std::string(
" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
259 std::string(
" columns"));
265 if( this->GetTransposeFlag() ==
'T' )
267 std::swap(rowSizes, columnSizes);
270 unsigned int blockRow = std::lower_bound(rowSizes->begin(), rowSizes->end(), row) - rowSizes->begin();
271 unsigned int blockColumn = std::lower_bound(columnSizes->begin(), columnSizes->end(), col) - columnSizes->begin();
272 const std::shared_ptr<const InnerType> block = GetBlock(blockRow, blockColumn);
274 unsigned int actualRow = row;
277 actualRow = row-((*rowSizes)[blockRow-1])-1;
280 unsigned int actualCol = col;
281 if( blockColumn > 0 )
283 actualCol = col-((*columnSizes)[blockColumn-1])-1;
289 return (*block)(actualRow, actualCol);
293 return m_zeroElement;
297 template<
typename DataType,
typename InnerMatrixType>
298 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetStorageSize()
const 300 return m_storageSize;
303 template<
typename DataType,
typename InnerMatrixType>
304 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfBlockRows()
const 306 if( this->GetTransposeFlag() ==
'N' )
308 return m_numberOfBlockRows;
312 return m_numberOfBlockColumns;
316 template<
typename DataType,
typename InnerMatrixType>
317 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfBlockColumns()
const 319 if( this->GetTransposeFlag() ==
'N' )
321 return m_numberOfBlockColumns;
325 return m_numberOfBlockRows;
329 template<
typename DataType,
typename InnerMatrixType>
330 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfRowsInBlockRow(
unsigned int blockRow)
const 332 if( this->GetTransposeFlag() ==
'N' )
334 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockRows, m_rowSizes);
338 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockColumns, m_columnSizes);
342 template<
typename DataType,
typename InnerMatrixType>
343 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfColumnsInBlockColumn(
unsigned int blockCol)
const 345 if( this->GetTransposeFlag() ==
'T' )
347 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockRows, m_rowSizes);
351 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockColumns, m_columnSizes);
355 template<
typename DataType,
typename InnerMatrixType>
356 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlockSizes(
360 if( this->GetTransposeFlag() ==
'T' )
362 rowSizes = m_columnSizes;
363 colSizes = m_rowSizes;
367 rowSizes = m_rowSizes;
368 colSizes = m_columnSizes;
372 template<
typename DataType,
typename InnerMatrixType>
373 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::begin() {
return iterator(*
this, 0, 0); }
375 template<
typename DataType,
typename InnerMatrixType>
376 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::end() {
return iterator(*
this); }
378 template<
typename DataType,
typename InnerMatrixType>
379 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::const_iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::begin()
const {
return const_iterator(*
this, 0, 0); }
381 template<
typename DataType,
typename InnerMatrixType>
382 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::const_iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::end()
const {
return const_iterator(*
this); }
385 template<
typename DataType,
typename InnerMatrixType>
391 template<
typename DataType,
typename InnerMatrixType>
392 std::shared_ptr<NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag> > NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::CreateWrapper(
const std::shared_ptr<
NekMatrix<
NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag> >&
rhs)
394 return std::shared_ptr<ThisType>(
new ThisType(*
rhs));
398 template<
typename DataType,
typename InnerMatrixType>
399 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfElementsInBlock(
unsigned int block,
unsigned int totalBlocks,
const Array<OneD, unsigned int>& sizes)
401 boost::ignore_unused(totalBlocks);
402 ASSERTL2(block < totalBlocks, std::string(
"Block Element ") + std::to_string(block) +
403 std::string(
" requested in a matrix with a maximum of ") + std::to_string(totalBlocks) +
404 std::string(
" blocks."));
407 return sizes[block]+1;
411 return sizes[block] - sizes[block-1];
415 template<
typename DataType,
typename InnerMatrixType>
416 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::Initialize(
const unsigned int* rowsPerBlock,
const unsigned int* columnsPerBlock)
418 m_storageSize = this->GetRows()*this->GetColumns();
419 if (this->GetRows() > 0)
421 m_rowSizes[0] = rowsPerBlock[0] - 1;
422 for(
unsigned int i = 1; i < m_numberOfBlockRows; ++i)
424 m_rowSizes[i] = rowsPerBlock[i] + m_rowSizes[i-1];
427 if (this->GetColumns() > 0)
429 m_columnSizes[0] = columnsPerBlock[0] - 1;
430 for(
unsigned int i = 1; i < m_numberOfBlockColumns; ++i)
432 m_columnSizes[i] = columnsPerBlock[i] + m_columnSizes[i-1];
437 template<
typename DataType,
typename InnerMatrixType>
438 typename boost::call_traits<typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::NumberType>::value_type
439 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_GetValue(
unsigned int row,
unsigned int column)
const 441 return (*
this)(row, column);
444 template<
typename DataType,
typename InnerMatrixType>
445 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_GetStorageSize()
const 447 return this->GetStorageSize();
450 template<
typename DataType,
typename InnerMatrixType>
451 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_Transpose()
453 for (
auto &ptr : m_data)
526 template LIB_UTILITIES_EXPORT class NekMatrix<NekMatrix< NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>, BlockMatrixTag>;
InnerType::NumberType NumberType
iterator_base< ThisType > iterator
#define LIB_UTILITIES_EXPORT
InnerType::ConstGetValueType ConstGetValueType
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed t...
iterator_base< const ThisType > const_iterator
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs