void assign (const Teuchos::RCP<Thyra_LinearOp>& lop, const ST value) { // Allow failure, since we don't know what the underlying linear algebra is auto tmat = getTpetraMatrix(lop,false); if (!tmat.is_null()) { // Tpetra throws when trying to set scalars in an already filled matrix bool callFillComplete = false; if(!tmat->isFillActive()){ tmat->resumeFill(); callFillComplete = true; } tmat->setAllToScalar(value); if(callFillComplete){ tmat->fillComplete(); } return; } // TODO: add epetra // If all the tries above are not successful, throw an error. TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error, "Error! Could not cast Thyra_LinearOp to any of the supported concrete types.\n"); }
void CrsMatrixWrapper<ST>::resetValues(bool preserveSolverData) { resumeFill(); mat.setAllToScalar(static_cast<ST>(0.)); fillComplete(true); if (!preserveSolverData) { m_solver.reset(); m_preconditioner.reset(); } m_resetCalled = true; }
void resumeFill (const Teuchos::RCP<Thyra_LinearOp>& lop) { // Allow failure, since we don't know what the underlying linear algebra is auto tmat = getTpetraMatrix(lop,false); if (!tmat.is_null()) { tmat->resumeFill(); return; } // TODO: add epetra // If all the tries above are not successful, throw an error. TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error, "Error! Could not cast Thyra_LinearOp to any of the supported concrete types.\n"); }
void CrsMatrixWrapper<ST>::nullifyRowsAndCols( const Teuchos::ArrayView<const real_t>& rowMask, const Teuchos::ArrayView<const real_t>& colView, ST mdv) { const_TrilinosMap_ptr rowMap(mat.getRowMap()); RCP<VectorType<real_t> > lclCol = rcp(new VectorType<real_t>(rowMap, colView, colView.size(), 1)); RCP<VectorType<real_t> > gblCol = rcp(new VectorType<real_t>( mat.getColMap(), 1)); const ImportType importer(rowMap, mat.getColMap()); gblCol->doImport(*lclCol, importer, Tpetra::INSERT); Teuchos::ArrayRCP<const real_t> colMask(gblCol->getData(0)); const ST zero = Teuchos::ScalarTraits<ST>::zero(); resumeFill(); // Can't use OpenMP here as replaceLocalValues() is not thread-safe. //#pragma omp parallel for for (LO lclrow = 0; lclrow < mat.getNodeNumRows(); lclrow++) { Teuchos::ArrayView<const LO> indices; Teuchos::ArrayView<const ST> values; std::vector<GO> cols; std::vector<ST> vals; mat.getLocalRowView(lclrow, indices, values); GO row = rowMap->getGlobalElement(lclrow); for (size_t c = 0; c < indices.size(); c++) { const LO lclcol = indices[c]; const GO col = mat.getColMap()->getGlobalElement(lclcol); if (rowMask[lclrow] > 0. || colMask[lclcol] > 0.) { cols.push_back(lclcol); vals.push_back(row==col ? mdv : zero); } } if (cols.size() > 0) mat.replaceLocalValues(lclrow, cols, vals); } fillComplete(true); }