43#include "Teuchos_TimeMonitor.hpp"
45#include "EpetraExt_BlockMultiVector.h"
46#include "Teuchos_Assert.hpp"
50 const Teuchos::RCP<const EpetraExt::MultiComm>& sg_comm_,
52 const Teuchos::RCP<const Stokhos::EpetraSparse3Tensor>& epetraCijk_,
53 const Teuchos::RCP<const Epetra_Map>& base_map_,
54 const Teuchos::RCP<const Epetra_Map>& sg_map_,
55 const Teuchos::RCP<Stokhos::AbstractPreconditionerFactory>& mean_prec_factory_,
56 const Teuchos::RCP<Stokhos::AbstractPreconditionerFactory>& G_prec_factory_,
57 const Teuchos::RCP<Teuchos::ParameterList>& params_) :
58 label(
"Stokhos Kronecker Product Preconditioner"),
75 scale_op =
params->get(
"Scale Operator by Inverse Basis Norms",
true);
82 int dim = sg_basis->dimension();
83 if (epetraCijk->getKEnd() > dim+1)
85 Teuchos::rcp(new EpetraSparse3Tensor(*epetraCijk, 1, dim+1));
103 label = std::string(
"Stokhos Kronecker Product Preconditioner:\n") +
104 std::string(
" ***** ") +
108 Teuchos::RCP<const Epetra_CrsGraph> graph =
epetraCijk->getStochasticGraph();
111 const Teuchos::Array<double>& norms =
sg_basis->norm_squared();
113 Teuchos::RCP<Epetra_CrsMatrix> A0 =
114 Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
sg_poly->getCoeffPtr(0),
true);
120 k_end =
Cijk->find_k(dim+1);
124 Teuchos::RCP<Epetra_CrsMatrix> A_k =
125 Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(
sg_poly->getCoeffPtr(k),
129 j_it !=
Cijk->j_end(k_it); ++j_it) {
132 i_it !=
Cijk->i_end(j_it); ++i_it) {
134 double c =
value(i_it)*traceAB/traceAB0;
137 G->SumIntoGlobalValues(i, 1, &c, &
j);
146 label = std::string(
"Stokhos Kronecker Product Preconditioner:\n") +
147 std::string(
" ***** ") +
148 std::string(
mean_prec->Label()) + std::string(
"\n") +
149 std::string(
" ***** ") +
150 std::string(
G_prec->Label());
159 TEUCHOS_TEST_FOR_EXCEPTION(
161 "Stokhos::KroneckerProductPreconditioner::SetUseTranspose(): " <<
162 "Preconditioner does not support transpose!" << std::endl);
171 EpetraExt::BlockMultiVector sg_input(
View, *
base_map, Input);
172 EpetraExt::BlockMultiVector sg_result(
View, *
base_map, Result);
176 int vecLen = sg_input.GetBlock(0)->MyLength();
177 int m = sg_input.NumVectors();
186 for (
int i=0; i<NumMyElements; i++) {
187 mean_prec->Apply(*(sg_input.GetBlock(i)), *(sg_result.GetBlock(i)));
190 Teuchos::RCP<Epetra_MultiVector> x;
191 for (
int irow=0 ; irow<NumMyElements; irow++) {
192 x = sg_result.GetBlock(irow);
193 for (
int vcol=0; vcol<m; vcol++) {
194 for (
int icol=0; icol<vecLen; icol++) {
195 (*result_MVT)[m*vcol+icol][irow] = (*x)[vcol][icol];
203 for (
int irow=0; irow<NumMyElements; irow++) {
204 x = sg_result.GetBlock(irow);
205 for (
int vcol=0; vcol<m; vcol++) {
206 for (
int icol=0; icol<vecLen; icol++) {
207 (*x)[vcol][icol] = (*result_MVT)[m*vcol+icol][irow];
219#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
220 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Total Kronecker Product Prec Time");
223 EpetraExt::BlockMultiVector sg_input(
View, *
base_map, Input);
224 EpetraExt::BlockMultiVector sg_result(
View, *
base_map, Result);
228 int vecLen = sg_input.GetBlock(0)->MyLength();
229 int m = sg_input.NumVectors();
238 Teuchos::RCP<Epetra_MultiVector> x;
239 for (
int irow=0 ; irow<NumMyElements; irow++) {
240 x = sg_input.GetBlock(irow);
241 for (
int vcol=0; vcol<m; vcol++) {
242 for (
int icol=0; icol<vecLen; icol++) {
243 (*result_MVT)[m*vcol+icol][irow] = (*x)[vcol][icol];
250#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
251 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: G Preconditioner Apply Inverse");
256 for (
int irow=0; irow<NumMyElements; irow++) {
257 x = sg_result.GetBlock(irow);
258 for (
int vcol=0; vcol<m; vcol++) {
259 for (
int icol=0; icol<vecLen; icol++) {
260 (*x)[vcol][icol] = (*result_MVT)[m*vcol+icol][irow];
267#ifdef STOKHOS_TEUCHOS_TIME_MONITOR
268 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Mean Preconditioner Apply Inverse");
270 for (
int i=0; i<NumMyElements; i++) {
271 mean_prec->ApplyInverse(*(sg_result.GetBlock(i)),
272 *(sg_result.GetBlock(i)));
292 return const_cast<char*
>(
label.c_str());
333 double traceAB = 0.0;
334 for (
int i=0; i<n; i++) {
336 for (
int j=0;
j<m;
j++) {
337 traceAB += A[i][
j]*B[i][
j];
int NumMyElements() const
int NumMyEntries(int Row) const
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 ...
Teuchos::RCP< Epetra_Operator > mean_prec
Stores mean preconditioner.
std::string label
Label for operator.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
Teuchos::RCP< const EpetraExt::MultiComm > sg_comm
Stores SG parallel communicator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
bool useTranspose
Flag indicating whether transpose was selected.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
bool only_use_linear
Limit construction of G to linear terms.
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::SGOperator > &sg_op, const Epetra_Vector &x)
Setup preconditioner.
Teuchos::RCP< const Epetra_Map > base_map
Stores base map.
virtual ~KroneckerProductPreconditioner()
Destructor.
Teuchos::RCP< Teuchos::ParameterList > params
Preconditioner parameters.
Teuchos::RCP< const Cijk_type > Cijk
Stores triple product tensor.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
bool scale_op
Flag indicating whether operator be scaled with <\psi_i^2>.
Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > mean_prec_factory
Stores factory for building mean preconditioner.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Stores Epetra Cijk tensor.
Teuchos::RCP< Epetra_MultiVector > result_MVT
Teuchos::RCP< Epetra_Operator > G_prec
Stores G preconditioner.
double MatrixTrace(const Epetra_CrsMatrix &A, const Epetra_CrsMatrix &B) const
Compute trace of matrix A'B.
Teuchos::RCP< Epetra_CrsMatrix > G
Pointer to CrsMatrix G.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator.
Teuchos::RCP< Stokhos::SGOperator > sg_op
Pointer to the SG operator.
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.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerking basis.
Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > G_prec_factory
Stores factory for building G preconditioner.
Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > sg_poly
Pointer to the PCE expansion of Jacobian.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
Teuchos::RCP< const Epetra_Map > sg_map
Stores SG map.
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.
Abstract base class for multivariate orthogonal polynomials.
kji_sparse_array::const_iterator k_iterator
SparseArrayIterator< index_iterator, value_iterator >::value_reference value(const SparseArrayIterator< index_iterator, value_iterator > &it)
SparseArrayIterator< index_iterator, value_iterator >::value_type index(const SparseArrayIterator< index_iterator, value_iterator > &it)
j_sparse_array::const_iterator kji_iterator
ji_sparse_array::const_iterator kj_iterator