formalize new fromMatrix

This commit is contained in:
Tobias Meyer Andersen 2024-06-26 15:41:42 +02:00
parent 605e32c54b
commit 65aa334313

View File

@ -98,22 +98,21 @@ CuSparseMatrix<T>::fromMatrix(const MatrixType& matrix, bool copyNonZeroElements
rowIndices.push_back(0);
// This line assumes that the index (0, 0) has a nonzero element, this is not true for lower
// triangular matrices for instance that I need in new DILU version
// const size_t blockSize = matrix[0][0].N();
// We must find the pointer to the first element in the matrix
// Iterate until we find an element, we can get the blocksize from the element
size_t blockSizeTmp;
// TODO: Can this be done more cleanly in the DUNE api to access the raw data more directly?
constexpr size_t blockSizeTmp = MatrixType::block_type::rows;
T* nonZeroElementsTmp = nullptr;
for (auto rowIt = matrix.begin(); rowIt != matrix.end(); ++rowIt){
auto colIt = rowIt->begin();
if (colIt != rowIt->end()){
blockSizeTmp = colIt->N();
nonZeroElementsTmp = const_cast<T*>(&((*colIt)[0][0]));
break;
}
}
OPM_ERROR_IF(nonZeroElementsTmp == nullptr, "error converting DUNE matrix to CuSparse matrix");
const size_t blockSize = blockSizeTmp;
const size_t numberOfRows = matrix.N();
const size_t numberOfNonzeroBlocks = matrix.nonzeroes();
@ -136,8 +135,7 @@ CuSparseMatrix<T>::fromMatrix(const MatrixType& matrix, bool copyNonZeroElements
if (copyNonZeroElementsDirectly) {
// const T* nonZeroElements = static_cast<const T*>(&((matrix[0][0][0][0])));
const T* nonZeroElements = static_cast<const T*>(nonZeroElementsTmp);
const T* nonZeroElements = nonZeroElementsTmp;
return CuSparseMatrix<T>(
nonZeroElements, rowIndices.data(), columnIndices.data(), numberOfNonzeroBlocks, blockSize, numberOfRows);
} else {