44 #include "AbstractLinAlgPack_BasisSystemComposite.hpp" 45 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp" 46 #include "AbstractLinAlgPack_MatrixComposite.hpp" 47 #include "AbstractLinAlgPack_MultiVectorMutable.hpp" 48 #include "AbstractLinAlgPack_VectorSpaceBlocked.hpp" 49 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 50 #include "ReleaseResource_ref_count_ptr.hpp" 51 #include "Teuchos_AbstractFactoryStd.hpp" 52 #include "Teuchos_dyn_cast.hpp" 53 #include "Teuchos_Assert.hpp" 60 class AllocatorMultiVectorMutable {
62 AllocatorMultiVectorMutable(
64 ,AbstractLinAlgPack::size_type num_vecs
66 :vec_space_(vec_space)
71 ptr_t allocate()
const 73 return vec_space_->create_members(num_vecs_);
77 AbstractLinAlgPack::size_type num_vecs_;
86 void BasisSystemComposite::initialize_space_x(
96 TEUCHOS_TEST_FOR_EXCEPTION(
97 space_xD.get() == NULL, std::invalid_argument
98 ,
"BasisSystemComposite::initialize_space_x(...): Error!" );
99 TEUCHOS_TEST_FOR_EXCEPTION(
100 var_dep == NULL, std::invalid_argument
101 ,
"BasisSystemComposite::initialize_space_x(...): Error!" );
102 TEUCHOS_TEST_FOR_EXCEPTION(
103 space_xI.get() != NULL && var_indep == NULL, std::invalid_argument
104 ,
"BasisSystemComposite::initialize_space_x(...): Error!" );
105 TEUCHOS_TEST_FOR_EXCEPTION(
106 space_x == NULL, std::invalid_argument
107 ,
"BasisSystemComposite::initialize_space_x(...): Error!" );
109 *var_dep =
Range1D(1,space_xD->dim());
110 if(space_xI.get()) *var_indep =
Range1D(var_dep->
ubound()+1,var_dep->
ubound()+space_xI->dim());
111 else *var_indep = Range1D::Invalid;
114 vec_spaces[2] = { space_xD, space_xI };
123 BasisSystemComposite::factory_Gc()
126 return Teuchos::rcp(
new Teuchos::AbstractFactoryStd<MatrixOp,MatrixComposite>() );
129 void BasisSystemComposite::initialize_Gc(
140 using Teuchos::dyn_cast;
142 TEUCHOS_TEST_FOR_EXCEPTION(
143 space_x.get() == NULL, std::invalid_argument
144 ,
"BasisSystemComposite::initialize_Gc(...): Error!" );
145 TEUCHOS_TEST_FOR_EXCEPTION(
146 space_c.get() == NULL, std::invalid_argument
147 ,
"BasisSystemComposite::initialize_Gc(...): Error!" );
152 var_dep_size = var_dep.
size();
154 TEUCHOS_TEST_FOR_EXCEPTION(
155 C.get() == NULL, std::invalid_argument
156 ,
"BasisSystemComposite::initialize_Gc(...): Error!" );
157 TEUCHOS_TEST_FOR_EXCEPTION(
158 var_dep_size < n && N.get() == NULL, std::invalid_argument
159 ,
"BasisSystemComposite::initialize_Gc(...): Error!" );
160 TEUCHOS_TEST_FOR_EXCEPTION(
161 Gc == NULL, std::invalid_argument
162 ,
"BasisSystemComposite::initialize_Gc(...): Error!" );
174 typedef Teuchos::RCP<mmp::ReleaseResource_ref_count_ptr<MatrixOpNonsing> > C_rr_ptr_ptr_t;
176 C_rr_ptr_ptr = Teuchos::rcp(
new mmp::ReleaseResource_ref_count_ptr<MatrixOpNonsing>(C));
180 ,C_rr_ptr_ptr->ptr.get()
186 typedef Teuchos::RCP<mmp::ReleaseResource_ref_count_ptr<MatrixOp> > N_rr_ptr_ptr_t;
188 N_rr_ptr_ptr = Teuchos::rcp(
new mmp::ReleaseResource_ref_count_ptr<MatrixOp>(N));
192 ,N_rr_ptr_ptr->ptr.get()
201 void BasisSystemComposite::get_C_N(
207 using Teuchos::dyn_cast;
209 TEUCHOS_TEST_FOR_EXCEPTION(
210 Gc == NULL, std::invalid_argument
211 ,
"BasisSystemComposite::get_C_N(...): Error!" );
217 TEUCHOS_TEST_FOR_EXCEPTION(
218 C == NULL, std::invalid_argument
219 ,
"BasisSystemComposite::get_C_N(...): Error!" );
220 TEUCHOS_TEST_FOR_EXCEPTION(
221 n > m && N == NULL, std::invalid_argument
222 ,
"BasisSystemComposite::get_C_N(...): Error!" );
228 MatrixComposite::matrix_list_t::const_iterator
231 if( mat_itr != mat_end ) {
232 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr != mat_end ) );
234 const_cast<MatrixOp&
>(*(mat_itr++)->A_) );
236 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr != mat_end ) );
237 *N = &
const_cast<MatrixOp&
>(*(mat_itr++)->A_);
239 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr == mat_end ) );
247 void BasisSystemComposite::get_C_N(
253 using Teuchos::dyn_cast;
258 TEUCHOS_TEST_FOR_EXCEPTION(
259 C == NULL, std::invalid_argument
260 ,
"BasisSystemComposite::get_C_N(...): Error!" );
261 TEUCHOS_TEST_FOR_EXCEPTION(
262 n > m && N == NULL, std::invalid_argument
263 ,
"BasisSystemComposite::get_C_N(...): Error!" );
269 MatrixComposite::matrix_list_t::const_iterator
272 if( mat_itr != mat_end ) {
273 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr != mat_end ) );
276 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr != mat_end ) );
277 *N = &dyn_cast<
const MatrixOp>(*(mat_itr++)->A_);
279 TEUCHOS_TEST_FOR_EXCEPT( !( mat_itr == mat_end ) );
282 TEUCHOS_TEST_FOR_EXCEPTION(
283 true, std::invalid_argument
284 ,
"BasisSystemComposite::get_C_N(...): Error, " 285 "The Gc matrix object has not been initialized with C and N!" );
291 BasisSystemComposite::BasisSystemComposite()
305 const size_type n = space_x->dim(), m = space_c->dim();
325 space_x,var_dep,var_indep,space_c,factory_C,factory_transDtD,factory_S
343 TEUCHOS_TEST_FOR_EXCEPTION(
344 space_x.get() == NULL, std::invalid_argument
345 ,
"BasisSystemComposite::initialize(...): Error!" );
346 TEUCHOS_TEST_FOR_EXCEPTION(
347 space_c.get() == NULL, std::invalid_argument
348 ,
"BasisSystemComposite::initialize(...): Error!" );
350 const size_type n = space_x->dim(), m = space_c->dim();
352 TEUCHOS_TEST_FOR_EXCEPTION(
353 var_dep.
size() + var_indep.
size() != space_x->dim(), std::invalid_argument
354 ,
"BasisSystemComposite::initialize(...): Error!" );
355 TEUCHOS_TEST_FOR_EXCEPTION(
357 , std::invalid_argument
358 ,
"BasisSystemComposite::initialize(...): Error!" );
359 TEUCHOS_TEST_FOR_EXCEPTION(
361 , std::invalid_argument
362 ,
"BasisSystemComposite::initialize(...): Error!" );
363 TEUCHOS_TEST_FOR_EXCEPTION(
364 factory_C.get() == NULL, std::invalid_argument
365 ,
"BasisSystemComposite::initialize(...): Error!" );
374 if( factory_D_.get() == NULL ) {
375 factory_D_ = Teuchos::abstractFactoryStd<MatrixOp,MultiVectorMutable>(
376 AllocatorMultiVectorMutable(space_x_->sub_space(var_dep),var_indep.
size() ) );
385 space_x_ = Teuchos::null;
388 factory_C_ = Teuchos::null;
389 factory_D_ = Teuchos::null;
450 using Teuchos::dyn_cast;
452 n = var_dep_.size() + var_indep_.size(),
454 TEUCHOS_TEST_FOR_EXCEPTION(
455 n == 0, std::logic_error
456 ,
"BasisSystemComposite::update_basis(...): Error, this must be initialized first!" );
457 TEUCHOS_TEST_FOR_EXCEPTION(
458 C == NULL && ( n > m ? D == NULL :
false ), std::logic_error
459 ,
"BasisSystemComposite::update_basis(...): Error, C or D must be non-NULL!" );
465 get_C_N( Gc, &C_aggr, &N_aggr );
472 update_D(*C_aggr,*N_aggr,D,mat_rel);
const mat_fcty_ptr_t factory_D() const
static void get_C_N(MatrixOp *Gc, MatrixOpNonsing **C, MatrixOp **N)
Get the non-const aggregate matrices C and N (or NULL pointers if not initialized).
Interface for the creation and maintainance of a basis matrix for a decomposition of linearlized cons...
matrix_list_t::iterator matrices_begin()
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixOp > > mat_fcty_ptr_t
const VectorSpace::space_ptr_t & space_x() const
void add_matrix(size_type row_offset, size_type col_offset, value_type alpha, const GenPermMatrixSlice *P, const release_resource_ptr_t &P_release, BLAS_Cpp::Transp P_trans, const MatrixOp *A, const release_resource_ptr_t &A_release, BLAS_Cpp::Transp A_trans, const GenPermMatrixSlice *Q, const release_resource_ptr_t &Q_release, BLAS_Cpp::Transp Q_trans)
Add a sub-matrix alpha*op(P)*op(A)*op(Q).
virtual void update_D(const MatrixOpNonsing &C, const MatrixOp &N, MatrixOp *D, EMatRelations mat_rel) const
Overridden by subclasses to update D if a specialized implementation is needed.
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixOpNonsing > > mat_nonsing_fcty_ptr_t
Teuchos::RCP< MatrixOp > N_ptr_t
void update_basis(const MatrixOp &Gc, MatrixOpNonsing *C, MatrixOp *D, MatrixOp *GcUP, EMatRelations mat_rel, std::ostream *out) const
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixOp > > fcty_Gc_ptr_t
virtual void finish_construction(const VectorSpace::space_ptr_t &space_cols, const VectorSpace::space_ptr_t &space_rows)
Call to finish the construction process.
const VectorSpace::space_ptr_t & space_c() const
virtual size_type cols() const
Return the number of columns in the matrix.
virtual void initialize(const mat_sym_fcty_ptr_t &factory_transDtD, const mat_sym_nonsing_fcty_ptr_t &factory_S)
Initialize the factory objects for the special matrices for D'*D and S = I + D'*D.
Teuchos::RCP< const VectorSpace > space_ptr_t
matrix_list_t::iterator matrices_end()
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixSymOp > > mat_sym_fcty_ptr_t
const mat_nonsing_fcty_ptr_t factory_C() const
VectorSpace subclass for the composite of one or more VectorSpace objects.
Base class for all matrices that support basic matrix operations.
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixSymOpNonsing > > mat_sym_nonsing_fcty_ptr_t
Teuchos::RCP< MatrixOpNonsing > C_ptr_t
static const Range1D Invalid
void reinitialize(size_type rows=0, size_type cols=0)
Initialize a sized (on unsized) zero matrix to start with.
Interface for a collection of mutable vectors (multi-vector, matrix).
virtual void set_uninitialized()
Set uninitialized.
virtual const mat_sym_nonsing_fcty_ptr_t factory_S() const
Returns a matrix factory for the result of S = I + D'*D
void initialize(const VectorSpace::space_ptr_t &space_x, const Range1D &var_dep, const Range1D &var_indep, const VectorSpace::space_ptr_t &space_c, const mat_nonsing_fcty_ptr_t &factory_C, const mat_sym_fcty_ptr_t &factory_transDtD, const mat_sym_nonsing_fcty_ptr_t &factory_S, const mat_fcty_ptr_t &factory_D=Teuchos::null)
Initialize.
virtual const mat_sym_fcty_ptr_t factory_transDtD() const
Returns a matrix factory for the result of J = D'*D
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.
Range1D var_indep() const
Matrix class for matrices composed out of a set of other matrices and vectors.