13 #include "EpetraExt_BlockMultiVector.h"
26 label(
"Stokhos Kronecker Product Preconditioner"),
29 epetraCijk(epetraCijk_),
32 mean_prec_factory(mean_prec_factory_),
33 G_prec_factory(G_prec_factory_),
39 Cijk(epetraCijk->getParallelCijk()),
41 only_use_linear(false)
70 mean_prec = mean_prec_factory->compute(sg_poly->getCoeffPtr(0));
71 label = std::string(
"Stokhos Kronecker Product Preconditioner:\n") +
72 std::string(
" ***** ") +
73 std::string(mean_prec->Label());
83 double traceAB0 = MatrixTrace(*A0, *A0);
86 if (only_use_linear) {
87 int dim = sg_basis->dimension();
88 k_end = Cijk->find_k(dim+1);
95 double traceAB = MatrixTrace(*A_k, *A0);
97 j_it != Cijk->j_end(k_it); ++j_it) {
98 int j = epetraCijk->GCID(index(j_it));
100 i_it != Cijk->i_end(j_it); ++i_it) {
101 int i = epetraCijk->GRID(index(i_it));
102 double c = value(i_it)*traceAB/traceAB0;
105 G->SumIntoGlobalValues(i, 1, &c, &j);
112 G_prec = G_prec_factory->compute(G);
114 label = std::string(
"Stokhos Kronecker Product Preconditioner:\n") +
115 std::string(
" ***** ") +
116 std::string(mean_prec->Label()) + std::string(
"\n") +
117 std::string(
" ***** ") +
118 std::string(G_prec->Label());
125 useTranspose = UseTranspose;
126 mean_prec->SetUseTranspose(useTranspose);
128 UseTranspose ==
true, std::logic_error,
129 "Stokhos::KroneckerProductPreconditioner::SetUseTranspose(): " <<
130 "Preconditioner does not support transpose!" << std::endl);
139 EpetraExt::BlockMultiVector sg_input(
View, *base_map, Input);
140 EpetraExt::BlockMultiVector sg_result(
View, *base_map, Result);
144 int vecLen = sg_input.GetBlock(0)->MyLength();
145 int m = sg_input.NumVectors();
147 if (result_MVT ==
Teuchos::null || result_MVT->NumVectors() != vecLen*m) {
154 for (
int i=0; i<NumMyElements; i++) {
155 mean_prec->Apply(*(sg_input.GetBlock(i)), *(sg_result.GetBlock(i)));
159 for (
int irow=0 ; irow<NumMyElements; irow++) {
160 x = sg_result.GetBlock(irow);
161 for (
int vcol=0; vcol<m; vcol++) {
162 for (
int icol=0; icol<vecLen; icol++) {
163 (*result_MVT)[m*vcol+icol][irow] = (*x)[vcol][icol];
169 G_prec->Apply(*result_MVT, *result_MVT);
171 for (
int irow=0; irow<NumMyElements; irow++) {
172 x = sg_result.GetBlock(irow);
173 for (
int vcol=0; vcol<m; vcol++) {
174 for (
int icol=0; icol<vecLen; icol++) {
175 (*x)[vcol][icol] = (*result_MVT)[m*vcol+icol][irow];
187 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
191 EpetraExt::BlockMultiVector sg_input(
View, *base_map, Input);
192 EpetraExt::BlockMultiVector sg_result(
View, *base_map, Result);
196 int vecLen = sg_input.GetBlock(0)->MyLength();
197 int m = sg_input.NumVectors();
199 if (result_MVT ==
Teuchos::null || result_MVT->NumVectors() != vecLen*m) {
207 for (
int irow=0 ; irow<NumMyElements; irow++) {
208 x = sg_input.GetBlock(irow);
209 for (
int vcol=0; vcol<m; vcol++) {
210 for (
int icol=0; icol<vecLen; icol++) {
211 (*result_MVT)[m*vcol+icol][irow] = (*x)[vcol][icol];
218 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
221 G_prec->ApplyInverse(*result_MVT, *result_MVT);
224 for (
int irow=0; irow<NumMyElements; irow++) {
225 x = sg_result.GetBlock(irow);
226 for (
int vcol=0; vcol<m; vcol++) {
227 for (
int icol=0; icol<vecLen; icol++) {
228 (*x)[vcol][icol] = (*result_MVT)[m*vcol+icol][irow];
235 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR
238 for (
int i=0; i<NumMyElements; i++) {
239 mean_prec->ApplyInverse(*(sg_result.GetBlock(i)),
240 *(sg_result.GetBlock(i)));
252 return mean_prec->NormInf() * G_prec->NormInf();
260 return const_cast<char*
>(label.c_str());
274 return mean_prec->NormInf() && G_prec->NormInf();
301 double traceAB = 0.0;
302 for (
int i=0; i<n; i++) {
304 for (
int j=0;
j<m;
j++) {
305 traceAB += A[i][
j]*B[i][
j];
#define TEUCHOS_FUNC_TIME_MONITOR(FUNCNAME)
double MatrixTrace(const Epetra_CrsMatrix &A, const Epetra_CrsMatrix &B) const
Compute trace of matrix A'B.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Stores Epetra Cijk tensor.
int NumMyEntries(int Row) const
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
T & get(ParameterList &l, const std::string &name)
bool only_use_linear
Limit construction of G to linear terms.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual ~KroneckerProductPreconditioner()
Destructor.
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::SGOperator > &sg_op, const Epetra_Vector &x)
Setup preconditioner.
virtual ordinal_type dimension() const =0
Return dimension of basis.
KroneckerProductPreconditioner(const Teuchos::RCP< const EpetraExt::MultiComm > &sg_comm, const Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > &sg_basis, const Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > &epetraCijk, const Teuchos::RCP< const Epetra_Map > &base_map, const Teuchos::RCP< const Epetra_Map > &sg_map, const Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > &mean_prec_factory, const Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > &G_prec_factory, const Teuchos::RCP< Teuchos::ParameterList > ¶ms)
Constructor.
Bi-directional iterator for traversing a sparse array.
virtual int ApplyInverse(const Epetra_MultiVector &X, Epetra_MultiVector &Y) const
Returns the result of the inverse of the operator applied to a Epetra_MultiVector Input in Result as ...
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
int NumMyElements() const
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
bool scale_op
Flag indicating whether operator be scaled with <^2>
Teuchos::RCP< Teuchos::ParameterList > params
Preconditioner parameters.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerking basis.
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()=0
Get SG polynomial.
virtual int Apply(const Epetra_MultiVector &Input, Epetra_MultiVector &Result) const
Returns the result of a Epetra_Operator applied to a Epetra_MultiVector Input in Result as described ...
virtual const char * Label() const
Returns a character string describing the operator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.