Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MeanBasedPreconditioner.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "EpetraExt_BlockMultiVector.h"
12 
16  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis_,
18  const Teuchos::RCP<const Epetra_Map>& base_map_,
19  const Teuchos::RCP<const Epetra_Map>& sg_map_,
21  const Teuchos::RCP<Teuchos::ParameterList>& params_) :
22  label("Stokhos Mean-Based Preconditioner"),
23  sg_comm(sg_comm_),
24  sg_basis(sg_basis_),
25  epetraCijk(epetraCijk_),
26  base_map(base_map_),
27  sg_map(sg_map_),
28  num_blocks(0),
29  prec_factory(prec_factory_),
30  mean_prec(),
31  useTranspose(false),
32  use_block_apply(true)
33 {
34  use_block_apply = params_->get("Use Block Apply", true);
35 }
36 
39 {
40 }
41 
42 void
45  const Epetra_Vector& x)
46 {
47  TEUCHOS_TEST_FOR_EXCEPTION(prec_factory == Teuchos::null, std::logic_error,
48  "Error! setupPreconditioner() cannot be called when " <<
49  "prec_factory is null!" << std::endl);
50 
52  sg_op->getSGPolynomial();
53  mean_prec = prec_factory->compute(sg_poly->getCoeffPtr(0));
54  label = std::string("Stokhos Mean-Based Preconditioner:\n") +
55  std::string(" ***** ") +
56  std::string(mean_prec->Label());
57  num_blocks = sg_basis()->size();
58 }
59 
60 int
62 SetUseTranspose(bool UseTheTranspose)
63 {
64  useTranspose = UseTheTranspose;
65  mean_prec->SetUseTranspose(useTranspose);
66 
67  return 0;
68 }
69 
70 int
72 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
73 {
74  int myBlockRows = epetraCijk->numMyRows();
75 
76  if (!use_block_apply) {
77  EpetraExt::BlockMultiVector sg_input(View, *base_map, Input);
78  EpetraExt::BlockMultiVector sg_result(View, *base_map, Result);
79  for (int i=0; i<myBlockRows; i++) {
80  mean_prec->Apply(*(sg_input.GetBlock(i)), *(sg_result.GetBlock(i)));
81  }
82  }
83 
84  else {
85  int m = Input.NumVectors();
86  Epetra_MultiVector input_block(
87  View, *base_map, Input.Values(), base_map->NumMyElements(),
88  m*myBlockRows);
89  Epetra_MultiVector result_block(
90  View, *base_map, Result.Values(), base_map->NumMyElements(),
91  m*myBlockRows);
92  mean_prec->Apply(input_block, result_block);
93  }
94 
95  return 0;
96 }
97 
98 int
101 {
102  int myBlockRows = epetraCijk->numMyRows();
103 
104  if (!use_block_apply) {
105  EpetraExt::BlockMultiVector sg_input(View, *base_map, Input);
106  EpetraExt::BlockMultiVector sg_result(View, *base_map, Result);
107  for (int i=0; i<myBlockRows; i++) {
108  mean_prec->ApplyInverse(*(sg_input.GetBlock(i)),
109  *(sg_result.GetBlock(i)));
110  }
111  }
112 
113  else {
114  int m = Input.NumVectors();
115  Epetra_MultiVector input_block(
116  View, *base_map, Input.Values(), base_map->NumMyElements(),
117  m*myBlockRows);
118  Epetra_MultiVector result_block(
119  View, *base_map, Result.Values(), base_map->NumMyElements(),
120  m*myBlockRows);
121  mean_prec->ApplyInverse(input_block, result_block);
122  }
123 
124  return 0;
125 }
126 
127 double
129 NormInf() const
130 {
131  return mean_prec->NormInf();
132 }
133 
134 
135 const char*
137 Label () const
138 {
139  return const_cast<char*>(label.c_str());
140 }
141 
142 bool
145 {
146  return useTranspose;
147 }
148 
149 bool
151 HasNormInf() const
152 {
153  return true;
154 }
155 
156 const Epetra_Comm &
158 Comm() const
159 {
160  return *sg_comm;
161 }
162 const Epetra_Map&
165 {
166  return *sg_map;
167 }
168 
169 const Epetra_Map&
172 {
173  return *sg_map;
174 }
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
MeanBasedPreconditioner(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 > &params)
Constructor.
T & get(ParameterList &l, const std::string &name)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::SGOperator > &sg_op, const Epetra_Vector &x)
Setup preconditioner.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
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 ...
bool use_block_apply
Flag indicating whether to use apply all vectors simultaneously.
virtual Teuchos::RCP< Stokhos::EpetraOperatorOrthogPoly > getSGPolynomial()=0
Get SG polynomial.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this 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 ...
Teuchos::RCP< coeff_type > getCoeffPtr(ordinal_type i)
Return ref-count pointer to coefficient i.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
virtual const char * Label() const
Returns a character string describing the operator.