Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Stokhos_MPMeanBasedPreconditioner.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
43 #include "EpetraExt_BlockMultiVector.h"
44 
48  int num_mp_blocks_,
49  const Teuchos::RCP<const Epetra_Map>& base_map_,
50  const Teuchos::RCP<const Epetra_Map>& mp_map_,
52  const Teuchos::RCP<Teuchos::ParameterList>& params_) :
53  label("Stokhos MP Block Diagonal Preconditioner"),
54  mp_comm(mp_comm_),
55  num_mp_blocks(num_mp_blocks_),
56  base_map(base_map_),
57  mp_map(mp_map_),
58  prec_factory(prec_factory_),
59  mean_prec(),
60  useTranspose(false)
61 {
62 }
63 
66 {
67 }
68 
69 void
72  const Epetra_Vector& x)
73 {
74  TEUCHOS_TEST_FOR_EXCEPTION(prec_factory == Teuchos::null, std::logic_error,
75  "Error! setupPreconditioner() cannot be called when " <<
76  "prec_factory is null!" << std::endl);
77 
79  mp_op->getMPOps();
80  mean_prec = prec_factory->compute(mp_ops->getCoeffPtr(0));
81  if (num_mp_blocks > 0) {
82  label = std::string("Stokhos MP Mean Preconditioner:\n") +
83  std::string(" ***** ") +
84  std::string(mean_prec->Label());
85  }
86 }
87 
88 int
90 SetUseTranspose(bool UseTheTranspose)
91 {
92  useTranspose = UseTheTranspose;
93  mean_prec->SetUseTranspose(useTranspose);
94 
95  return 0;
96 }
97 
98 int
100 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
101 {
102  EpetraExt::BlockMultiVector mp_input(View, *base_map, Input);
103  EpetraExt::BlockMultiVector mp_result(View, *base_map, Result);
104  for (int i=0; i<num_mp_blocks; i++) {
105  mean_prec->Apply(*(mp_input.GetBlock(i)), *(mp_result.GetBlock(i)));
106  }
107 
108  return 0;
109 }
110 
111 int
114 {
115  EpetraExt::BlockMultiVector mp_input(View, *base_map, Input);
116  EpetraExt::BlockMultiVector mp_result(View, *base_map, Result);
117  for (int i=0; i<num_mp_blocks; i++) {
118  mean_prec->ApplyInverse(*(mp_input.GetBlock(i)), *(mp_result.GetBlock(i)));
119  }
120 
121  return 0;
122 }
123 
124 double
126 NormInf() const
127 {
128  return mean_prec->NormInf();
129 }
130 
131 
132 const char*
134 Label () const
135 {
136  return const_cast<char*>(label.c_str());
137 }
138 
139 bool
142 {
143  return useTranspose;
144 }
145 
146 bool
148 HasNormInf() const
149 {
150  return mean_prec->HasNormInf();
151 }
152 
153 const Epetra_Comm &
155 Comm() const
156 {
157  return *mp_comm;
158 }
159 const Epetra_Map&
162 {
163  return *mp_map;
164 }
165 
166 const Epetra_Map&
169 {
170  return *mp_map;
171 }
virtual const char * Label() const
Returns a character string describing the 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 ...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::BlockDiagonalOperator > &mp_op, const Epetra_Vector &x)
Setup preconditioner.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
MPMeanBasedPreconditioner(const Teuchos::RCP< const EpetraExt::MultiComm > &mp_comm, int num_mp_blocks, const Teuchos::RCP< const Epetra_Map > &base_map, const Teuchos::RCP< const Epetra_Map > &mp_map, const Teuchos::RCP< Stokhos::AbstractPreconditionerFactory > &prec_factory, const Teuchos::RCP< Teuchos::ParameterList > &params)
Constructor.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual Teuchos::RCP< Stokhos::ProductEpetraOperator > getMPOps()
Get multi-point ops.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain 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 ...