43 #include "Teuchos_TimeMonitor.hpp" 48 const Teuchos::RCP<const EpetraExt::MultiComm>& sg_comm_,
50 const Teuchos::RCP<const Stokhos::EpetraSparse3Tensor>& epetraCijk_,
51 const Teuchos::RCP<const Epetra_Map>& base_map_,
52 const Teuchos::RCP<const Epetra_Map>& sg_map_,
53 const Teuchos::RCP<Stokhos::AbstractPreconditionerFactory>& prec_factory_,
54 const Teuchos::RCP<Teuchos::ParameterList>& params_) :
55 label(
"Stokhos Approximate Jacobi Preconditioner"),
58 epetraCijk(epetraCijk_),
61 prec_factory(prec_factory_),
69 num_iter = params_->get(
"Number of Jacobi Iterations", 2);
71 Teuchos::RCP<Teuchos::ParameterList> sgOpParams =
72 Teuchos::rcp(&(params_->sublist(
"Jacobi SG Operator")),
false);
73 sgOpParams->set(
"Include Mean",
false);
74 if (!sgOpParams->isParameter(
"Only Use Linear Terms"))
75 sgOpParams->set(
"Only Use Linear Terms",
true);
81 if (sgOpParams->get<
bool>(
"Only Use Linear Terms") &&
105 sg_poly = sg_op->getSGPolynomial();
106 mean_prec = prec_factory->compute(sg_poly->getCoeffPtr(0));
107 label = std::string(
"Stokhos Approximate Jacobi Preconditioner:\n") +
108 std::string(
" ***** ") +
109 std::string(mean_prec->Label());
110 mat_free_op->setupOperator(sg_poly);
117 useTranspose = UseTranspose;
118 sg_op->SetUseTranspose(UseTranspose);
119 mat_free_op->SetUseTranspose(UseTranspose);
120 mean_prec->SetUseTranspose(UseTranspose);
129 return sg_op->Apply(Input, Result);
136 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR 137 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Total Approximate Jacobi Time");
143 bool made_copy =
false;
150 if (rhs_block == Teuchos::null || rhs_block->NumVectors() != m)
152 Teuchos::rcp(
new EpetraExt::BlockMultiVector(*base_map, *sg_map, m));
155 EpetraExt::BlockMultiVector input_block(
View, *base_map, *input);
156 EpetraExt::BlockMultiVector result_block(
View, *base_map, Result);
158 int myBlockRows = epetraCijk->numMyRows();
159 result_block.PutScalar(0.0);
160 for (
int iter=0; iter<num_iter; iter++) {
164 rhs_block->Update(1.0, input_block, 0.0);
166 mat_free_op->Apply(result_block, *rhs_block);
167 rhs_block->Update(1.0, input_block, -1.0);
171 for(
int i=0; i<myBlockRows; i++) {
172 #ifdef STOKHOS_TEUCHOS_TIME_MONITOR 173 TEUCHOS_FUNC_TIME_MONITOR(
"Stokhos: Total AJ Deterministic Preconditioner Time");
175 mean_prec->ApplyInverse(*(rhs_block->GetBlock(i)),
176 *(result_block.GetBlock(i)));
191 return sg_op->NormInf();
199 return const_cast<char*
>(label.c_str());
213 return sg_op->HasNormInf();
Teuchos::RCP< const EpetraExt::MultiComm > sg_comm
Stores SG parallel communicator.
Teuchos::RCP< const Epetra_Map > sg_map
Stores SG map.
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 ~ApproxJacobiPreconditioner()
Destructor.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Teuchos::RCP< const Stokhos::EpetraSparse3Tensor > epetraCijk
Stores Epetra Cijk tensor.
Teuchos::RCP< const Epetra_Map > base_map
Stores base map.
Teuchos::RCP< Stokhos::SGOperator > mat_free_op
SG operator to implement SG mat-vec.
int num_iter
Number of Jacobi iterations.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
virtual const char * Label() const
Returns a character string describing the operator.
virtual Teuchos::RCP< Stokhos::SGOperator > build(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 > &domain_base_map, const Teuchos::RCP< const Epetra_Map > &range_base_map, const Teuchos::RCP< const Epetra_Map > &domain_sg_map, const Teuchos::RCP< const Epetra_Map > &range_sg_map)
Build preconditioner operator.
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 bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::SGOperator > &sg_op, const Epetra_Vector &x)
Setup preconditioner.
Teuchos::RCP< const Stokhos::OrthogPolyBasis< int, double > > sg_basis
Stochastic Galerking basis.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
ApproxJacobiPreconditioner(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 > &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.
Factory for generating stochastic Galerkin preconditioners.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.