42 #include "AbstractLinAlgPack_BasisSystemPermDirectSparse.hpp"
43 #include "AbstractLinAlgPack_MatrixOp.hpp"
44 #include "AbstractLinAlgPack_MatrixOpNonsingAggr.hpp"
45 #include "AbstractLinAlgPack_MatrixPermAggr.hpp"
46 #include "AbstractLinAlgPack_MatrixConvertToSparseEncap.hpp"
47 #include "AbstractLinAlgPack_MatrixExtractSparseElements.hpp"
48 #include "AbstractLinAlgPack_MultiVectorMutableDense.hpp"
49 #include "AbstractLinAlgPack_PermutationSerial.hpp"
50 #include "AbstractLinAlgPack_MatrixSymPosDefCholFactor.hpp"
51 #include "Teuchos_AbstractFactoryStd.hpp"
52 #include "Teuchos_Assert.hpp"
53 #include "Teuchos_dyn_cast.hpp"
55 namespace AbstractLinAlgPack {
62 new Teuchos::AbstractFactoryStd<
MatrixSymOp,MatrixSymPosDefCholFactor>())
74 direct_solver_ = direct_solver;
75 n_ = m_ = r_ = Gc_nz_ = 0;
76 init_var_inv_perm_.resize(0);
77 init_equ_inv_perm_.resize(0);
129 return equ_undecomp_;
143 *out <<
"\nUsing a direct sparse solver to update basis ...\n";
148 const size_type Gc_rows = n, Gc_cols = m, Gc_nz = Gc.
nz();
150 Gc_rows != n_ || Gc_cols != m_ || Gc_nz != Gc_nz_, std::invalid_argument
151 ,
"BasisSystemPermDirectSparse::set_basis(...) : Error, "
152 "This matrix object is not compatible with last call to set_basis() or select_basis()!" );
154 C == NULL, std::invalid_argument
155 ,
"BasisSystemPermDirectSparse::set_basis(...) : Error!" );
164 C_bm = get_basis_matrix(C_aggr);
167 set_A_mctse( n, m, Gc_pa, &A_mctse );
170 direct_solver_->factor(
179 *out <<
"\nCurrent basis is singular : " << excpt.what() << std::endl
180 <<
"Throwing SingularBasis exception to client ...\n";
183 ,
"BasisSystemPermDirectSparse::update_basis(...) : Error, the current basis "
184 "is singular : " << excpt.what() );
187 update_basis_and_auxiliary_matrices( Gc, C_bm, &C_aggr, D, GcUP );
196 return Teuchos::null;
203 return Teuchos::null;
210 return Teuchos::null;
228 *out <<
"\nUsing a direct sparse solver to set a new basis ...\n";
233 const size_type Gc_rows = n, Gc_cols = m, Gc_nz = Gc.
nz();
235 P_equ == NULL || equ_decomp == NULL, std::invalid_argument
236 ,
"BasisSystemPermDirectSparse::set_basis(...) : Error!" );
238 C == NULL, std::invalid_argument
239 ,
"BasisSystemPermDirectSparse::set_basis(...) : Error!" );
248 C_bm = get_basis_matrix(C_aggr);
250 const PermutationSerial
251 &P_var_s =
dyn_cast<
const PermutationSerial>(P_var),
252 &P_equ_s = dyn_cast<const PermutationSerial>(*P_equ);
254 init_var_inv_perm_ = *P_var_s.inv_perm();
256 init_equ_inv_perm_ = *P_equ_s.inv_perm();
259 set_A_mctse( n, m, Gc_pa, &A_mctse );
261 IVector row_perm_ds, col_perm_ds;
263 direct_solver_->analyze_and_factor(
271 if( rank < var_dep.
size() ) {
275 do_some_basis_stuff(Gc,var_dep,*equ_decomp,C_bm,&C_aggr,D,GcUP);
294 *out <<
"\nUsing a direct sparse solver to select a new basis ...\n";
297 const char msg_err_head[] =
"BasisSystemPermDirectSparse::set_basis(...) : Error!";
299 Gc == NULL, std::invalid_argument
300 ,msg_err_head <<
" Must have equality constriants in this current implementation! " );
307 const size_type Gc_rows = Gc->
rows(), Gc_cols = Gc->
cols(), Gc_nz = Gc->
nz();
309 P_var == NULL || var_dep == NULL, std::invalid_argument, msg_err_head );
311 P_equ == NULL || equ_decomp == NULL, std::invalid_argument, msg_err_head );
313 C == NULL, std::invalid_argument, msg_err_head );
322 C_bm = get_basis_matrix(C_aggr);
326 init_var_inv_perm_.resize(0);
328 init_equ_inv_perm_.resize(0);
330 set_A_mctse( n, m, Gc_pa, &A_mctse );
336 direct_solver_->analyze_and_factor(
351 &P_var_s =
dyn_cast<PermutationSerial>(*P_var),
352 &P_equ_s =
dyn_cast<PermutationSerial>(*P_equ);
355 P_var_s.initialize( var_perm_ds, Teuchos::null );
357 P_equ_s.initialize( equ_perm_ds, Teuchos::null );
359 const int num_row_part = 2;
360 const int num_col_part = 2;
361 const index_type row_part[3] = { 1, rank, n+1 };
362 const index_type col_part[3] = { 1, rank, m+1 };
365 ,
Teuchos::rcp(
new PermutationSerial(var_perm_ds,Teuchos::null))
366 ,
Teuchos::rcp(
new PermutationSerial(equ_perm_ds,Teuchos::null))
368 P_var,row_part,num_row_part
369 ,P_equ,col_part,num_col_part
373 do_some_basis_stuff(*Gc,*var_dep,*equ_decomp,C_bm,&C_aggr,D,GcUP);
383 if( C_aggr.mns().get() ) {
386 if(C_bm.
get() == NULL)
387 dyn_cast<const DirectSparseSolver::BasisMatrix>(*C_aggr.mns());
390 C_bm = direct_solver_->basis_matrix_factory()->create();
395 void BasisSystemPermDirectSparse::set_A_mctse(
398 ,
const MatrixPermAggr &Gc_pa
399 ,MatrixConvertToSparseEncap *A_mctse
403 Teuchos::rcp_dynamic_cast<const MatrixExtractSparseElements>(Gc_pa.mat_orig())
404 ,
Teuchos::rcp( init_var_rng_.
size() < n ? &init_var_inv_perm_ : NULL, false )
406 ,
Teuchos::rcp( init_equ_rng_.
size() < m ? &init_equ_inv_perm_ : NULL, false )
412 void BasisSystemPermDirectSparse::update_basis_and_auxiliary_matrices(
415 ,MatrixOpNonsingAggr *C_aggr
416 ,MatrixOp* D, MatrixOp* GcUP
422 Gc.sub_view(var_dep_,equ_decomp_)
430 MultiVectorMutableDense *D_mvd = &
dyn_cast<MultiVectorMutableDense>(*D);
433 D_mvd->initialize(var_dep_.
size(),var_indep_.
size());
444 void BasisSystemPermDirectSparse::do_some_basis_stuff(
446 ,
const Range1D& var_dep,
const Range1D& equ_decomp
448 ,MatrixOpNonsingAggr *C_aggr
449 ,MatrixOp* D, MatrixOp* GcUP
457 var_indep_ = ( var_dep.size() == n
459 : ( var_dep.lbound() == 1
460 ? Range1D(var_dep.size()+1,n)
461 : Range1D(1,n-var_dep.size()) ) );
463 equ_undecomp_ = ( equ_decomp.size() == m
465 : ( equ_decomp.lbound() == 1
466 ? Range1D(equ_decomp.size()+1,m)
467 : Range1D(1,m-equ_decomp.size()) ) );
474 update_basis_and_auxiliary_matrices( Gc, C_bm, C_aggr, D, GcUP );
virtual size_type nz() const
Return the number of nonzero elements in the matrix.
Range1D equ_undecomp() const
const perm_fcty_ptr_t factory_P_inequ() const
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
Abstract base class for all polymorphic symmetrix nonsingular matrices that can be used to compute ma...
BasisSystemPermDirectSparse(const direct_solver_ptr_t &direct_solver=Teuchos::null)
Calls this->initialize()
void initialize(const direct_solver_ptr_t &direct_solver)
Initialize given a direct sparse solver object.
Abstract class for objects that represent the factorized matrix and can be used to solve for differen...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Aggregate matrix class for a matrix and its permuted view.
T_To & dyn_cast(T_From &from)
const perm_fcty_ptr_t factory_P_var() const
Range1D var_indep() const
virtual mat_ptr_t perm_view(const Permutation *P_row, const index_type row_part[], int num_row_part, const Permutation *P_col, const index_type col_part[], int num_col_part) const
Create a permuted view: M_perm = P_row' * M * P_col.
Interface adding operations specific for a symmetric matrix {abstract}.
const mat_fcty_ptr_t factory_D() const
const perm_fcty_ptr_t factory_P_equ() const
void initialize(const mat_ptr_t &mat_orig, const perm_ptr_t &row_perm, const perm_ptr_t &col_perm, const mat_ptr_t &mat_perm)
Initialize.
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)
Base class for all matrices that support basic matrix operations.
const mat_nonsing_fcty_ptr_t factory_C() const
const mat_fcty_ptr_t factory_GcUP() const
static const Range1D Invalid
Abstract interface to permutation matrices.
void set_basis(const Permutation &P_var, const Range1D &var_dep, const Permutation *P_equ, const Range1D *equ_decomp, const MatrixOp &Gc, MatrixOpNonsing *C, MatrixOp *D, MatrixOp *GcUP, EMatRelations mat_rel, std::ostream *out)
Interface for setting and selecting a basis from the Jacobian from a set of equations.
Abstract base class for all nonsingular polymorphic matrices that can be used to compute matrix-vecto...
void M_StInvMtM(MatrixOp *m_lhs, value_type alpha, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2)
m_lhs = alpha * inv(op(mwo_rhs1)) * op(mwo_rhs2) (right)
virtual size_type rows() const
Return the number of rows in the matrix.
void select_basis(const Vector *nu, MatrixOp *Gc, Permutation *P_var, Range1D *var_dep, Permutation *P_equ, Range1D *equ_decomp, MatrixOpNonsing *C, MatrixOp *D, MatrixOp *GcUP, EMatRelations mat_rel, std::ostream *out)
Abstract base class for all nonsingular polymorphic matrices that can solve for linear system with bu...
Sparse conversion subclass based on views of a MatrixExtractSparseElements object.
void update_basis(const MatrixOp &Gc, MatrixOpNonsing *C, MatrixOp *D, MatrixOp *GcUP, EMatRelations mat_rel, std::ostream *out) const
Aggregate matrix class pulling together a MatrixOp object and a MatrixNonsing object into a unified m...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Range1D equ_decomp() const