Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
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 }
Stokhos::MPMeanBasedPreconditioner::ApplyInverse
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 ...
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:113
Stokhos::MPMeanBasedPreconditioner::Apply
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 ...
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:100
Stokhos::MPMeanBasedPreconditioner::Label
virtual const char * Label() const
Returns a character string describing the operator.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:134
Stokhos::MPMeanBasedPreconditioner::SetUseTranspose
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:90
Stokhos::MPMeanBasedPreconditioner::UseTranspose
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:141
Stokhos::MPMeanBasedPreconditioner::OperatorDomainMap
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:161
Epetra_Comm
Teuchos::RCP< const EpetraExt::MultiComm >
Stokhos::MPMeanBasedPreconditioner::setupPreconditioner
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::BlockDiagonalOperator > &mp_op, const Epetra_Vector &x)
Setup preconditioner.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:71
Stokhos::MPMeanBasedPreconditioner::HasNormInf
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:148
Epetra_Vector
Stokhos::MPMeanBasedPreconditioner::Comm
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:155
Stokhos::MPMeanBasedPreconditioner::MPMeanBasedPreconditioner
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.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:46
cusp::detail::device::x
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
Stokhos::MPMeanBasedPreconditioner::NormInf
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:126
Epetra_MultiVector
Stokhos_MPMeanBasedPreconditioner.hpp
Stokhos::BlockDiagonalOperator::getMPOps
virtual Teuchos::RCP< Stokhos::ProductEpetraOperator > getMPOps()
Get multi-point ops.
Definition: Stokhos_BlockDiagonalOperator.cpp:81
Stokhos::MPMeanBasedPreconditioner::OperatorRangeMap
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:168
Epetra_Map
TEUCHOS_TEST_FOR_EXCEPTION
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
View
View
Definition: Kokkos_View_MP_Vector_Interlaced.hpp:180
Stokhos::MPMeanBasedPreconditioner::~MPMeanBasedPreconditioner
virtual ~MPMeanBasedPreconditioner()
Destructor.
Definition: Stokhos_MPMeanBasedPreconditioner.cpp:65