47 #include "AbstractLinAlgPack_DirectSparseSolverDense.hpp"
48 #include "AbstractLinAlgPack_VectorDenseEncap.hpp"
49 #include "DenseLinAlgLAPack.hpp"
50 #include "DenseLinAlgPack_PermVecMat.hpp"
51 #include "Teuchos_AbstractFactoryStd.hpp"
52 #include "Teuchos_Assert.hpp"
53 #include "Teuchos_Workspace.hpp"
54 #include "Teuchos_dyn_cast.hpp"
61 void my_swap( T* v1, T* v2 )
71 std::valarray<T>& cva(
const std::valarray<T>& va )
73 return const_cast<std::valarray<T>&
>(va);
78 namespace AbstractLinAlgPack {
114 yd().dim() != xd().dim(), std::invalid_argument
115 ,
"DirectSparseSolverDense::BasisMatrixDense::V_InvMtV(...) : Error, "
116 " y.dim() = " << yd().dim() <<
" != x.dim() = " << xd().dim() <<
"!"
120 Workspace<value_type> B_store(wss,xd().dim());
121 DMatrixSlice B(&B_store[0],B_store.size(),B_store.size(),B_store.size(),1);
156 DenseLinAlgPack::perm_ele(xd(),fn.basis_perm_,&b);
163 DenseLinAlgLAPack::getrs(
173 DenseLinAlgPack::inv_perm_ele(b,fn.basis_perm_,&yd());
184 DirectSparseSolverDense::FactorizationStructureDense::FactorizationStructureDense()
200 namespace mmp = MemMngPack;
235 namespace mmp = MemMngPack;
242 *out <<
"\nUsing LAPACK xGETRF to analyze and factor a new matrix ...\n";
254 nz = A.
num_nonzeros( MCTS::EXTRACT_FULL_MATRIX ,MCTS::ELEMENTS_ALLOW_DUPLICATES_SUM );
258 n <= 0 || m <= 0 || m > n, std::invalid_argument
259 ,
"DirectSparseSolverDense::imp_analyze_and_factor(...) : Error!" );
262 Workspace<value_type> a_val(wss,nz);
263 Workspace<index_type> a_row_i(wss,nz);
264 Workspace<index_type> a_col_j(wss,nz);
266 MCTS::EXTRACT_FULL_MATRIX
267 ,MCTS::ELEMENTS_ALLOW_DUPLICATES_SUM
294 for( size_type k = 0; k < nz; ++k )
295 fn.LU_(a_col_j[k],a_row_i[k]) += a_val[k];
301 DenseLinAlgLAPack::getrf( &fn.LU_(), &fn.ipiv_[0], &fs.rank_ );
318 fs.col_perm_.resize(n);
319 DenseLinAlgPack::identity_perm(&fs.col_perm_);
320 Workspace<index_type> col_perm_unsorted(wss,fs.rank_);
321 if( m == n && n == fs.rank_ ) {
323 fn.rect_analyze_and_factor_ =
false;
326 fn.rect_analyze_and_factor_ =
true;
328 for( index_type k = 1; k <= fs.rank_; ++k ) {
329 my_swap( &fs.col_perm_(k), &fs.col_perm_(fn.ipiv_[k-1]) );
330 col_perm_unsorted[k-1] = fs.col_perm_(k);
333 std::sort(&(fs.col_perm_)[0] , &(fs.col_perm_)[0] + fs.rank_ );
334 std::sort(&(fs.col_perm_)[0] + fs.rank_, &(fs.col_perm_)[0] + n );
338 fs.inv_col_perm_.resize(n);
339 DenseLinAlgPack::inv_perm( fs.col_perm_, &fs.inv_col_perm_ );
341 if( !(m == n && n == fs.rank_) ) {
343 fn.basis_perm_.resize(fs.rank_);
344 for( size_type k = 1; k <= fs.rank_; ++k ) {
345 fn.basis_perm_(k) = fs.inv_col_perm_(col_perm_unsorted[k-1]);
354 DenseLinAlgPack::identity_perm(row_perm);
355 *col_perm = fs.col_perm_;
366 namespace mmp = MemMngPack;
373 *out <<
"\nUsing LAPACK xGETRF to refactor the basis matrix ...\n";
385 nz = A.
num_nonzeros( MCTS::EXTRACT_FULL_MATRIX ,MCTS::ELEMENTS_ALLOW_DUPLICATES_SUM );
389 (m != fs.m_ || n != fs.n_ || nz != fs.nz_), std::invalid_argument
390 ,
"DirectSparseSolverDense::imp_factor(...): Error!"
394 Workspace<value_type> a_val(wss,nz);
395 Workspace<index_type> a_row_i(wss,nz);
396 Workspace<index_type> a_col_j(wss,nz);
398 MCTS::EXTRACT_FULL_MATRIX
399 ,MCTS::ELEMENTS_ALLOW_DUPLICATES_SUM
416 fn.rect_analyze_and_factor_ =
false;
417 fn.LU_.resize(fs.rank_,fs.rank_);
418 fn.ipiv_.resize(fs.rank_);
422 for( size_type k = 0; k < nz; ++k ) {
423 const index_type B_i = fs.inv_col_perm_(a_col_j[k]);
424 const index_type B_j = a_row_i[k];
425 if( B_i <= fs.rank_ && B_j <= fs.rank_ )
426 fn.LU_(B_i,B_j) = a_val[k];
433 FortranTypes::f_int B_rank = 0;
434 DenseLinAlgLAPack::getrf( &fn.LU_(), &fn.ipiv_[0], &B_rank );
438 ,
"DirectSparseSolverDense::imp_factor(...): Error, the basis matrix is no "
439 "longer full rank with B_rank = " << B_rank <<
" != fs.rank = " << fs.rank_ <<
"!"
void imp_factor(const AbstractLinAlgPack::MatrixConvertToSparse &A, const FactorizationStructure &fact_struc, FactorizationNonzeros *fact_nonzeros, std::ostream *out)
virtual void coor_extract_nonzeros(EExtractRegion extract_region, EElementUniqueness element_uniqueness, const index_type len_Aval, value_type Aval[], const index_type len_Aij, index_type Arow[], index_type Acol[], const index_type row_offset=0, const index_type col_offset=0) const =0
Extract sparse elements in a coordinate data structure.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
void V_InvMtV(VectorMutable *v_lhs, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2) const
const BasisMatrix::fact_struc_ptr_t & get_fact_struc() const
virtual index_type num_nonzeros(EExtractRegion extract_region, EElementUniqueness element_uniqueness) const =0
Returns the number of nonzeros in the matrix.
Stores the factorization structure for Dense.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void estimated_fillin_ratio(value_type estimated_fillin_ratio)
T_To & dyn_cast(T_From &from)
Stores the factorization nonzeros for Dense.
void imp_analyze_and_factor(const AbstractLinAlgPack::MatrixConvertToSparse &A, FactorizationStructure *fact_struc, FactorizationNonzeros *fact_nonzeros, DenseLinAlgPack::IVector *row_perm, DenseLinAlgPack::IVector *col_perm, size_type *rank, std::ostream *out)
virtual size_type cols() const
Return the number of columns in the matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Mix-in interface for extracing explicit elements from a sparse matrix in one of several Fortran compa...
const Teuchos::RCP< FactorizationStructure > create_fact_struc() const
Extract a constant DenseLinAlgPack::DVectorSlice view of a Vector object.
const Teuchos::RCP< FactorizationNonzeros > create_fact_nonzeros() const
const basis_matrix_factory_ptr_t basis_matrix_factory() const
void resize(size_type rows, size_type cols, value_type val=value_type())
Abstract class for objects that represent the factorization structure of a particular matrix...
Transp trans_not(Transp _trans)
DirectSparseSolverDense()
Default constructor.
Abstract interface for mutable coordinate vectors {abstract}.
Implements the BasisMatrix object for Dense.
Teuchos::RCP< BasisMatrixImp > create_matrix() const
Extract a non-const DenseLinAlgPack::DVectorSlice view of a VectorMutable object. ...
Abstract class for objects that represent the factorization nonzeros of a particular matrix...
virtual size_type rows() const
Return the number of rows in the matrix.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()