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>
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(row < m_numberOfBlockRows, std::string(
"Row ") + boost::lexical_cast<std::string>(row) +
170 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockRows) +
171 std::string(
" rows"));
172 ASSERTL2(column < m_numberOfBlockColumns, std::string(
"Column ") + boost::lexical_cast<std::string>(column) +
173 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockColumns) +
174 std::string(
" columns"));
175 int x = CalculateBlockIndex(row,column);
182 return m_data[x].get();
186 template<
typename DataType,
typename InnerMatrixType>
187 boost::shared_ptr<const typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::InnerType>
188 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlock(
unsigned int row,
unsigned int column)
const
190 ASSERTL2(row < m_numberOfBlockRows, std::string(
"Row ") + boost::lexical_cast<std::string>(row) +
191 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockRows) +
192 std::string(
" rows"));
193 ASSERTL2(column < m_numberOfBlockColumns, std::string(
"Column ") + boost::lexical_cast<std::string>(column) +
194 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockColumns) +
195 std::string(
" columns"));
196 int x = CalculateBlockIndex(row,column);
199 return boost::shared_ptr<const InnerType>();
207 template<
typename DataType,
typename InnerMatrixType>
208 boost::shared_ptr<typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::InnerType>&
209 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlock(
unsigned int row,
unsigned int column)
211 ASSERTL2(row < m_numberOfBlockRows, std::string(
"Row ") + boost::lexical_cast<std::string>(row) +
212 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockRows) +
213 std::string(
" rows"));
214 ASSERTL2(column < m_numberOfBlockColumns, std::string(
"Column ") + boost::lexical_cast<std::string>(column) +
215 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockColumns) +
216 std::string(
" columns"));
217 int x = CalculateBlockIndex(row,column);
220 return m_nullBlockPtr;
228 template<
typename DataType,
typename InnerMatrixType>
229 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::SetBlock(
unsigned int row,
unsigned int column, boost::shared_ptr<InnerType>& m)
231 ASSERTL2(row < m_numberOfBlockRows, std::string(
"Row ") + boost::lexical_cast<std::string>(row) +
232 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockRows) +
233 std::string(
" rows"));
234 ASSERTL2(column < m_numberOfBlockColumns, std::string(
"Column ") + boost::lexical_cast<std::string>(column) +
235 std::string(
" requested in a block matrix with a maximum of ") + boost::lexical_cast<std::string>(m_numberOfBlockColumns) +
236 std::string(
" columns"));
237 m_data[CalculateBlockIndex(row, column)] = InnerType::CreateWrapper(m);
242 template<
typename DataType,
typename InnerMatrixType>
243 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::ConstGetValueType
244 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::operator()(
unsigned int row,
unsigned int col)
const
246 ASSERTL2(row < this->GetRows(), std::string(
"Row ") + boost::lexical_cast<std::string>(row) +
247 std::string(
" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(this->GetRows()) +
248 std::string(
" rows"));
249 ASSERTL2(col < this->GetColumns(), std::string(
"Column ") + boost::lexical_cast<std::string>(col) +
250 std::string(
" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(this->GetColumns()) +
251 std::string(
" columns"));
257 if( this->GetTransposeFlag() ==
'T' )
259 std::swap(rowSizes, columnSizes);
262 unsigned int blockRow = std::lower_bound(rowSizes->begin(), rowSizes->end(), row) - rowSizes->begin();
263 unsigned int blockColumn = std::lower_bound(columnSizes->begin(), columnSizes->end(), col) - columnSizes->begin();
264 const boost::shared_ptr<const InnerType> block = GetBlock(blockRow, blockColumn);
266 unsigned int actualRow = row;
269 actualRow = row-((*rowSizes)[blockRow-1])-1;
272 unsigned int actualCol = col;
273 if( blockColumn > 0 )
275 actualCol = col-((*columnSizes)[blockColumn-1])-1;
281 return (*block)(actualRow, actualCol);
285 return m_zeroElement;
289 template<
typename DataType,
typename InnerMatrixType>
290 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetStorageSize()
const
292 return m_storageSize;
295 template<
typename DataType,
typename InnerMatrixType>
296 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfBlockRows()
const
298 if( this->GetTransposeFlag() ==
'N' )
300 return m_numberOfBlockRows;
304 return m_numberOfBlockColumns;
308 template<
typename DataType,
typename InnerMatrixType>
309 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfBlockColumns()
const
311 if( this->GetTransposeFlag() ==
'N' )
313 return m_numberOfBlockColumns;
317 return m_numberOfBlockRows;
321 template<
typename DataType,
typename InnerMatrixType>
322 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfRowsInBlockRow(
unsigned int blockRow)
const
324 if( this->GetTransposeFlag() ==
'N' )
326 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockRows, m_rowSizes);
330 return GetNumberOfElementsInBlock(blockRow, m_numberOfBlockColumns, m_columnSizes);
334 template<
typename DataType,
typename InnerMatrixType>
335 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfColumnsInBlockColumn(
unsigned int blockCol)
const
337 if( this->GetTransposeFlag() ==
'T' )
339 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockRows, m_rowSizes);
343 return GetNumberOfElementsInBlock(blockCol, m_numberOfBlockColumns, m_columnSizes);
347 template<
typename DataType,
typename InnerMatrixType>
348 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetBlockSizes(
352 if( this->GetTransposeFlag() ==
'T' )
354 rowSizes = m_columnSizes;
355 colSizes = m_rowSizes;
359 rowSizes = m_rowSizes;
360 colSizes = m_columnSizes;
364 template<
typename DataType,
typename InnerMatrixType>
365 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::begin() {
return iterator(*
this, 0, 0); }
367 template<
typename DataType,
typename InnerMatrixType>
368 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::end() {
return iterator(*
this); }
370 template<
typename DataType,
typename InnerMatrixType>
371 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::const_iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::begin()
const {
return const_iterator(*
this, 0, 0); }
373 template<
typename DataType,
typename InnerMatrixType>
374 typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>
::const_iterator NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::end()
const {
return const_iterator(*
this); }
377 template<
typename DataType,
typename InnerMatrixType>
380 return ThisType(rhs);
383 template<
typename DataType,
typename InnerMatrixType>
384 boost::shared_ptr<NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag> > NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::CreateWrapper(
const boost::shared_ptr<NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag> >& rhs)
386 return boost::shared_ptr<ThisType>(
new ThisType(*rhs));
390 template<
typename DataType,
typename InnerMatrixType>
391 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::GetNumberOfElementsInBlock(
unsigned int block,
unsigned int totalBlocks,
const Array<OneD, unsigned int>& sizes)
393 ASSERTL2(block < totalBlocks, std::string(
"Block Element ") + boost::lexical_cast<std::string>(block) +
394 std::string(
" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(totalBlocks) +
395 std::string(
" blocks."));
398 return sizes[block]+1;
402 return sizes[block] - sizes[block-1];
406 template<
typename DataType,
typename InnerMatrixType>
407 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::Initialize(
const unsigned int* rowsPerBlock,
const unsigned int* columnsPerBlock)
409 m_storageSize = this->GetRows()*this->GetColumns();
410 if (this->GetRows() > 0)
412 m_rowSizes[0] = rowsPerBlock[0] - 1;
413 for(
unsigned int i = 1; i < m_numberOfBlockRows; ++i)
415 m_rowSizes[i] = rowsPerBlock[i] + m_rowSizes[i-1];
418 if (this->GetColumns() > 0)
420 m_columnSizes[0] = columnsPerBlock[0] - 1;
421 for(
unsigned int i = 1; i < m_numberOfBlockColumns; ++i)
423 m_columnSizes[i] = columnsPerBlock[i] + m_columnSizes[i-1];
428 template<
typename DataType,
typename InnerMatrixType>
429 typename boost::call_traits<typename NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::NumberType>::value_type
430 NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_GetValue(
unsigned int row,
unsigned int column)
const
432 return (*
this)(row, column);
435 template<
typename DataType,
typename InnerMatrixType>
436 unsigned int NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_GetStorageSize()
const
438 return this->GetStorageSize();
441 template<
typename DataType,
typename InnerMatrixType>
442 void NekMatrix<NekMatrix<DataType, InnerMatrixType>, BlockMatrixTag>::v_Transpose()
444 BOOST_FOREACH(boost::shared_ptr<InnerType> ptr, m_data)
517 template LIB_UTILITIES_EXPORT class NekMatrix<NekMatrix< NekMatrix<NekDouble, StandardMatrixTag>, ScaledMatrixTag>, BlockMatrixTag>;
iterator_base< ThisType > iterator
#define LIB_UTILITIES_EXPORT
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
#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