Change storage in BlockRandomAccessSparseMatrix

- TripletSparseMatrix in BlockRandomAccessSparseMatrix is replaced with
   BlockSparseMatrix
 - BlockSparseMatrix::ToCompressedRowSparseMatrix is performed in a
   direct sort-less way

Change-Id: Ib951fda1b9394050e2c47a9721172c5e3c674801
This commit is contained in:
Dmitriy Korchemkin
2023-04-08 14:12:25 +03:00
parent d340f81bd0
commit 77ad8bb4e5
14 changed files with 361 additions and 207 deletions
+17 -13
View File
@@ -299,32 +299,36 @@ LinearSolver::Summary SparseSchurComplementSolver::SolveReducedLinearSystem(
summary.termination_type = LinearSolverTerminationType::SUCCESS;
summary.message = "Success.";
const TripletSparseMatrix* tsm =
const BlockSparseMatrix* bsm =
down_cast<const BlockRandomAccessSparseMatrix*>(lhs())->matrix();
if (tsm->num_rows() == 0) {
if (bsm->num_rows() == 0) {
return summary;
}
std::unique_ptr<CompressedRowSparseMatrix> lhs;
const CompressedRowSparseMatrix::StorageType storage_type =
sparse_cholesky_->StorageType();
if (storage_type ==
CompressedRowSparseMatrix::StorageType::UPPER_TRIANGULAR) {
lhs = CompressedRowSparseMatrix::FromTripletSparseMatrix(*tsm);
lhs->set_storage_type(
CompressedRowSparseMatrix::StorageType::UPPER_TRIANGULAR);
if (!crs_lhs_) {
crs_lhs_ = bsm->ToCompressedRowSparseMatrix();
crs_lhs_->set_storage_type(
CompressedRowSparseMatrix::StorageType::UPPER_TRIANGULAR);
} else {
bsm->UpdateCompressedRowSparseMatrix(crs_lhs_.get());
}
} else {
lhs = CompressedRowSparseMatrix::FromTripletSparseMatrixTransposed(*tsm);
lhs->set_storage_type(
CompressedRowSparseMatrix::StorageType::LOWER_TRIANGULAR);
if (!crs_lhs_) {
crs_lhs_ = bsm->ToCompressedRowSparseMatrixTranspose();
crs_lhs_->set_storage_type(
CompressedRowSparseMatrix::StorageType::LOWER_TRIANGULAR);
} else {
bsm->UpdateCompressedRowSparseMatrixTranspose(crs_lhs_.get());
}
}
*lhs->mutable_col_blocks() = blocks_;
*lhs->mutable_row_blocks() = blocks_;
summary.num_iterations = 1;
summary.termination_type = sparse_cholesky_->FactorAndSolve(
lhs.get(), rhs().data(), solution, &summary.message);
crs_lhs_.get(), rhs().data(), solution, &summary.message);
return summary;
}