Stokhos Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Stokhos_MeanBasedPreconditioner.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>& sg_comm_,
48 const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& sg_basis_,
49 const Teuchos::RCP<const Stokhos::EpetraSparse3Tensor>& epetraCijk_,
50 const Teuchos::RCP<const Epetra_Map>& base_map_,
51 const Teuchos::RCP<const Epetra_Map>& sg_map_,
52 const Teuchos::RCP<Stokhos::AbstractPreconditionerFactory>& prec_factory_,
53 const Teuchos::RCP<Teuchos::ParameterList>& params_) :
54 label("Stokhos Mean-Based Preconditioner"),
55 sg_comm(sg_comm_),
56 sg_basis(sg_basis_),
57 epetraCijk(epetraCijk_),
58 base_map(base_map_),
59 sg_map(sg_map_),
60 num_blocks(0),
61 prec_factory(prec_factory_),
62 mean_prec(),
63 useTranspose(false),
64 use_block_apply(true)
65{
66 use_block_apply = params_->get("Use Block Apply", true);
67}
68
73
74void
76setupPreconditioner(const Teuchos::RCP<Stokhos::SGOperator>& sg_op,
77 const Epetra_Vector& x)
78{
79 TEUCHOS_TEST_FOR_EXCEPTION(prec_factory == Teuchos::null, std::logic_error,
80 "Error! setupPreconditioner() cannot be called when " <<
81 "prec_factory is null!" << std::endl);
82
83 Teuchos::RCP<Stokhos::EpetraOperatorOrthogPoly > sg_poly =
84 sg_op->getSGPolynomial();
85 mean_prec = prec_factory->compute(sg_poly->getCoeffPtr(0));
86 label = std::string("Stokhos Mean-Based Preconditioner:\n") +
87 std::string(" ***** ") +
88 std::string(mean_prec->Label());
89 num_blocks = sg_basis()->size();
90}
91
92int
94SetUseTranspose(bool UseTheTranspose)
95{
96 useTranspose = UseTheTranspose;
97 mean_prec->SetUseTranspose(useTranspose);
98
99 return 0;
100}
101
102int
104Apply(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
105{
106 int myBlockRows = epetraCijk->numMyRows();
107
108 if (!use_block_apply) {
109 EpetraExt::BlockMultiVector sg_input(View, *base_map, Input);
110 EpetraExt::BlockMultiVector sg_result(View, *base_map, Result);
111 for (int i=0; i<myBlockRows; i++) {
112 mean_prec->Apply(*(sg_input.GetBlock(i)), *(sg_result.GetBlock(i)));
113 }
114 }
115
116 else {
117 int m = Input.NumVectors();
118 Epetra_MultiVector input_block(
119 View, *base_map, Input.Values(), base_map->NumMyElements(),
120 m*myBlockRows);
121 Epetra_MultiVector result_block(
122 View, *base_map, Result.Values(), base_map->NumMyElements(),
123 m*myBlockRows);
124 mean_prec->Apply(input_block, result_block);
125 }
126
127 return 0;
128}
129
130int
132ApplyInverse(const Epetra_MultiVector& Input, Epetra_MultiVector& Result) const
133{
134 int myBlockRows = epetraCijk->numMyRows();
135
136 if (!use_block_apply) {
137 EpetraExt::BlockMultiVector sg_input(View, *base_map, Input);
138 EpetraExt::BlockMultiVector sg_result(View, *base_map, Result);
139 for (int i=0; i<myBlockRows; i++) {
140 mean_prec->ApplyInverse(*(sg_input.GetBlock(i)),
141 *(sg_result.GetBlock(i)));
142 }
143 }
144
145 else {
146 int m = Input.NumVectors();
147 Epetra_MultiVector input_block(
148 View, *base_map, Input.Values(), base_map->NumMyElements(),
149 m*myBlockRows);
150 Epetra_MultiVector result_block(
151 View, *base_map, Result.Values(), base_map->NumMyElements(),
152 m*myBlockRows);
153 mean_prec->ApplyInverse(input_block, result_block);
154 }
155
156 return 0;
157}
158
159double
161NormInf() const
162{
163 return mean_prec->NormInf();
164}
165
166
167const char*
169Label () const
170{
171 return const_cast<char*>(label.c_str());
172}
173
174bool
176UseTranspose() const
177{
178 return useTranspose;
179}
180
181bool
183HasNormInf() const
184{
185 return true;
186}
187
188const Epetra_Comm &
190Comm() const
191{
192 return *sg_comm;
193}
194const Epetra_Map&
196OperatorDomainMap() const
197{
198 return *sg_map;
199}
200
201const Epetra_Map&
203OperatorRangeMap() const
204{
205 return *sg_map;
206}
virtual const Epetra_Map & OperatorRangeMap() const
Returns the Epetra_Map object associated with the range of this matrix operator.
virtual bool HasNormInf() const
Returns true if the this object can provide an approximate Inf-norm, false otherwise.
virtual const Epetra_Comm & Comm() const
Returns a reference to the Epetra_Comm communicator associated with this operator.
virtual const char * Label() const
Returns a character string describing the operator.
bool use_block_apply
Flag indicating whether to use apply all vectors simultaneously.
virtual const Epetra_Map & OperatorDomainMap() const
Returns the Epetra_Map object associated with the domain of this matrix operator.
virtual double NormInf() const
Returns an approximate infinity norm of the operator matrix.
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 void setupPreconditioner(const Teuchos::RCP< Stokhos::SGOperator > &sg_op, const Epetra_Vector &x)
Setup preconditioner.
virtual int SetUseTranspose(bool UseTranspose)
Set to true if the transpose of the operator is requested.
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 ...
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.
virtual bool UseTranspose() const
Returns the current UseTranspose setting.
Abstract base class for multivariate orthogonal polynomials.