Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Stokhos_MPBlockDiagonalPreconditioner.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 
47  const Teuchos::RCP<const EpetraExt::MultiComm>& mp_comm_,
48  int num_mp_blocks_,
49  const Teuchos::RCP<const Epetra_Map>& base_map_,
50  const Teuchos::RCP<const Epetra_Map>& mp_map_,
51  const Teuchos::RCP<Stokhos::AbstractPreconditionerFactory>& prec_factory_,
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  block_precs(num_mp_blocks),
60  useTranspose(false)
61 {
62 }
63 
66 {
67 }
68 
69 void
71 setupPreconditioner(const Teuchos::RCP<Stokhos::BlockDiagonalOperator>& mp_op,
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 
78  Teuchos::RCP<Stokhos::ProductContainer<Epetra_Operator> > mp_ops =
79  mp_op->getMPOps();
80  for (int i=0; i<num_mp_blocks; i++)
81  block_precs[i] = prec_factory->compute(mp_ops->getCoeffPtr(i));
82  if (num_mp_blocks > 0) {
83  label = std::string("Stokhos MP Block Diagonal Preconditioner:\n") +
84  std::string(" ***** ") +
85  std::string(block_precs[0]->Label());
86  }
87 }
88 
89 int
91 SetUseTranspose(bool UseTheTranspose)
92 {
93  useTranspose = UseTheTranspose;
94  for (int i=0; i<num_mp_blocks; i++)
95  block_precs[i]->SetUseTranspose(useTranspose);
96 
97  return 0;
98 }
99 
100 int
102 Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
103 {
104  EpetraExt::BlockMultiVector mp_input(View, *base_map, Input);
105  EpetraExt::BlockMultiVector mp_result(View, *base_map, Result);
106  for (int i=0; i<num_mp_blocks; i++) {
107  block_precs[i]->Apply(*(mp_input.GetBlock(i)), *(mp_result.GetBlock(i)));
108  }
109 
110  return 0;
111 }
112 
113 int
115 ApplyInverse(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
116 {
117  EpetraExt::BlockMultiVector mp_input(View, *base_map, Input);
118  EpetraExt::BlockMultiVector mp_result(View, *base_map, Result);
119  for (int i=0; i<num_mp_blocks; i++) {
120  block_precs[i]->ApplyInverse(*(mp_input.GetBlock(i)),
121  *(mp_result.GetBlock(i)));
122  }
123 
124  return 0;
125 }
126 
127 double
129 NormInf() const
130 {
131  double product_nrm = 0.0;
132  for (int i=0; i<num_mp_blocks; i++) {
133  double nrm = block_precs[i]->NormInf();
134  if (nrm > product_nrm)
135  product_nrm = nrm;
136  }
137 
138  return product_nrm;
139 }
140 
141 
142 const char*
144 Label () const
145 {
146  return const_cast<char*>(label.c_str());
147 }
148 
149 bool
152 {
153  return useTranspose;
154 }
155 
156 bool
158 HasNormInf() const
159 {
160  if (num_mp_blocks == 0)
161  return false;
162  return block_precs[0]->HasNormInf();
163 }
164 
165 const Epetra_Comm &
167 Comm() const
168 {
169  return *mp_comm;
170 }
171 const Epetra_Map&
174 {
175  return *mp_map;
176 }
177 
178 const Epetra_Map&
181 {
182  return *mp_map;
183 }
virtual void setupPreconditioner(const Teuchos::RCP< Stokhos::BlockDiagonalOperator > &mp_op, const Epetra_Vector &x)
Setup preconditioner.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
virtual const char * Label() const
Returns a character string describing the operator.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
const IndexType const IndexType const IndexType const IndexType const ValueType const ValueType * x
Definition: csr_vector.h:260
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 ...
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator. ...
MPBlockDiagonalPreconditioner(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 const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
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 ...