10 #ifndef _TEUCHOS_SERIALQRDENSESOLVER_UQ_PCE_HPP_
11 #define _TEUCHOS_SERIALQRDENSESOLVER_UQ_PCE_HPP_
27 template<
typename OrdinalType,
typename Storage>
70 base_QR_.factorWithEquilibration(flag);
75 base_QR_.solveWithTranspose(flag);
80 base_QR_.solveWithTranspose(trans);
92 int factor() {
return base_QR_.factor(); }
98 int solve() {
return base_QR_.solve(); }
105 return base_QR_.computeEquilibrateScaling();
173 bool solved() {
return base_QR_.solved(); }
211 std::vector<ScalarType>
tau()
const {
return base_QR_.tau(); }
220 void Print(std::ostream& os)
const;
268 template <
typename Ordinal,
typename Value,
typename Device>
288 new (v_pce+i)
pce_type(cijk, vector_size, v+i*vector_size,
false);
297 using namespace details;
301 template<
typename OrdinalType,
typename Storage>
302 SerialQRDenseSolver<OrdinalType,Sacado::UQ::PCE<Storage> >::
303 SerialQRDenseSolver()
305 Object(
"Teuchos::SerialQRDenseSolver"),
314 template<
typename OrdinalType,
typename Storage>
323 template<
typename OrdinalType,
typename Storage>
333 template<
typename OrdinalType,
typename Storage>
341 mat->values(), mat->stride()*mat->numCols());
345 mat->stride()*SacadoSize_,
346 mat->numRows()*SacadoSize_,
352 template<
typename OrdinalType,
typename Storage>
360 base_mat->values(), base_mat->stride()*base_mat->numCols(), SacadoSize_);
364 base_mat->stride()/SacadoSize_,
365 base_mat->numRows()/SacadoSize_,
366 base_mat->numCols()));
371 template<
typename OrdinalType,
typename Storage>
376 A->numRows() <
A->numCols(), std::invalid_argument,
377 "SerialQRDenseSolver<T>::setMatrix: the matrix A must have A.numRows() >= A.numCols()!");
386 if (Storage::is_static)
387 SacadoSize_ = Storage::static_size;
388 else if (M_ > 0 && N_ > 0)
389 SacadoSize_ = (*A)(0,0).size();
393 return base_QR_.setMatrix( createBaseMatrix(
A) );
397 template<
typename OrdinalType,
typename Storage>
405 B->numCols() != X->numCols(), std::invalid_argument,
406 "SerialQRDenseSolver<T>::setVectors: X and B have different numbers of columns!");
408 B->values()==0, std::invalid_argument,
409 "SerialQRDenseSolver<T>::setVectors: B is an empty SerialDenseMatrix<T>!");
411 X->values()==0, std::invalid_argument,
412 "SerialQRDenseSolver<T>::setVectors: X is an empty SerialDenseMatrix<T>!");
414 B->stride()<1, std::invalid_argument,
415 "SerialQRDenseSolver<T>::setVectors: B has an invalid stride!");
417 X->stride()<1, std::invalid_argument,
418 "SerialQRDenseSolver<T>::setVectors: X has an invalid stride!");
424 return base_QR_.setVectors( createBaseMatrix(X), createBaseMatrix(
B) );
429 template<
typename OrdinalType,
typename Storage>
432 int ret = base_QR_.
formQ();
433 FactorQ_ = createMatrix( base_QR_.getQ() );
439 template<
typename OrdinalType,
typename Storage>
442 int ret = base_QR_.
formR();
443 FactorR_ = createMatrix( base_QR_.getR() );
444 Factor_ = createMatrix( base_QR_.getFactoredMatrix() );
450 template<
typename OrdinalType,
typename Storage>
454 return base_QR_.
multiplyQ(transq, createBaseMatrix(C));
459 template<
typename OrdinalType,
typename Storage>
463 return base_QR_.
solveR(transr, createBaseMatrix(C));
468 template<
typename OrdinalType,
typename Storage>
470 Print(std::ostream& os)
const {
472 if (Matrix_!=
Teuchos::null) os <<
"Solver Matrix" << std::endl << *Matrix_ << std::endl;
473 if (Factor_!=
Teuchos::null) os <<
"Solver Factored Matrix" << std::endl << *Factor_ << std::endl;
474 if (LHS_ !=
Teuchos::null) os <<
"Solver LHS" << std::endl << *LHS_ << std::endl;
475 if (RHS_ !=
Teuchos::null) os <<
"Solver RHS" << std::endl << *RHS_ << std::endl;
static Value * getValueArray(pce_type *v, Ordinal len)
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > FactorR_
RCP< BaseMatrixType > Base_Matrix_
Stokhos::DynamicStorage< Ordinal, Value, Device > Storage
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getLHS() const
Returns pointer to current LHS.
int setMatrix(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &A)
pce_type::cijk_type cijk_type
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getR() const
Returns pointer to R (assuming factorization has been performed).
bool equilibratedA()
Returns true if factor is equilibrated (factor available via getFactoredMatrix()).
Sacado::ETPCE::OrthogPoly< double, Stokhos::StandardStorage< int, double > > pce_type
int multiplyQ(ETransp transq, SerialDenseMatrix< OrdinalType, ScalarType > &C)
int solveR(ETransp transr, SerialDenseMatrix< OrdinalType, ScalarType > &C)
OrdinalType numRows() const
Returns row dimension of system.
ScalarType::value_type BaseScalarType
static pce_type * getPCEArray(Value *v, Ordinal len, Ordinal vector_size)
RCP< MatrixType > FactorQ_
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int factor()
Computes the in-place QR factorization of the matrix using the LAPACK routine _GETRF or the Eigen cla...
std::vector< ScalarType > tau() const
Returns pointer to pivot vector (if factorization has been computed), zero otherwise.
RCP< MatrixType > Matrix_
OrdinalType numCols() const
Returns column dimension of system.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > LHS_
virtual ~SerialQRDenseSolver()
SerialQRDenseSolver destructor.
RCP< MatrixType > Factor_
bool transpose()
Returns true if adjoint of this matrix has and will be used.
SerialQRDenseSolver & operator=(const SerialQRDenseSolver< OrdinalType, ScalarType > &Source)
int equilibrateRHS()
Equilibrates the current RHS.
ScalarTraits< ScalarType >::magnitudeType MagnitudeType
Templated class for solving dense linear problems.
SerialDenseMatrix< OrdinalType, BaseScalarType > BaseMatrixType
RCP< MatrixType > FactorR_
bool solved()
Returns true if the current set of vectors has been solved.
bool factored()
Returns true if matrix is factored (factor available via getFactoredMatrix()).
bool formedR()
Returns true if R has been formed explicitly.
MagnitudeType ANORM() const
Returns the absolute value of the largest element of this matrix (returns -1 if not yet computed)...
RCP< BaseMatrixType > Base_LHS_
Specialization for Sacado::UQ::PCE< Storage<...> >
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > Matrix_
int unequilibrateLHS()
Unscales the solution vectors if equilibration was used to solve the system.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getRHS() const
Returns pointer to current RHS.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< BaseMatrixType > Base_Factor_
bool equilibratedB()
Returns true if RHS is equilibrated (RHS available via getRHS()).
void factorWithEquilibration(bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to factor...
Sacado::UQ::PCE< Storage > pce_type
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > FactorQ_
bool formedQ()
Returns true if Q has been formed explicitly.
void Print(std::ostream &os) const
int computeEquilibrateScaling()
Determines if this matrix should be scaled.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > Factor_
RCP< BaseMatrixType > Base_FactorQ_
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getMatrix() const
Returns pointer to current matrix.
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > RHS_
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getQ() const
Returns pointer to Q (assuming factorization has been performed).
KOKKOS_INLINE_FUNCTION constexpr std::enable_if< is_view_uq_pce< view_type >::value, typename CijkType< view_type >::type >::type cijk(const view_type &view)
Sacado::UQ::PCE< Storage > ScalarType
int solve()
Computes the solution X to AX = B for the this matrix and the B provided to SetVectors()..
int equilibrateMatrix()
Equilibrates the this matrix.
SerialQRDenseSolver< OrdinalType, BaseScalarType > BaseQRType
void solveWithTranspose(bool flag)
If flag is true, causes all subsequent function calls to work with the adjoint of this matrix...
SerialDenseMatrix< OrdinalType, ScalarType > MatrixType
RCP< BaseMatrixType > Base_FactorR_
RCP< BaseMatrixType > Base_RHS_
int setVectors(const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &X, const RCP< SerialDenseMatrix< OrdinalType, ScalarType > > &B)
bool shouldEquilibrate()
Returns true if the LAPACK general rules for equilibration suggest you should equilibrate the system...
RCP< SerialDenseMatrix< OrdinalType, ScalarType > > getFactoredMatrix() const
Returns pointer to factored matrix (assuming factorization has been performed).
void solveWithTransposeFlag(Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (Teuchos::NO_TRANS...