Teko  Version of the Day
 All Classes Files Functions Variables Pages
Teko_LU2x2InverseOp.cpp
1 /*
2 // @HEADER
3 //
4 // ***********************************************************************
5 //
6 // Teko: A package for block and physics based preconditioning
7 // Copyright 2010 Sandia Corporation
8 //
9 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
10 // the U.S. Government retains certain rights in this software.
11 //
12 // Redistribution and use in source and binary forms, with or without
13 // modification, are permitted provided that the following conditions are
14 // met:
15 //
16 // 1. Redistributions of source code must retain the above copyright
17 // notice, this list of conditions and the following disclaimer.
18 //
19 // 2. Redistributions in binary form must reproduce the above copyright
20 // notice, this list of conditions and the following disclaimer in the
21 // documentation and/or other materials provided with the distribution.
22 //
23 // 3. Neither the name of the Corporation nor the names of the
24 // contributors may be used to endorse or promote products derived from
25 // this software without specific prior written permission.
26 //
27 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
28 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
31 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 //
39 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
40 //
41 // ***********************************************************************
42 //
43 // @HEADER
44 
45 */
46 
47 #include "Teko_LU2x2InverseOp.hpp"
48 
49 #include "Thyra_DefaultProductVectorSpace.hpp"
50 #include "Thyra_ProductMultiVectorBase.hpp"
51 #include "Thyra_DefaultMultipliedLinearOp.hpp"
52 #include "Thyra_MultiVectorStdOps.hpp"
53 
54 using namespace Thyra;
55 using Teuchos::ArrayRCP;
56 using Teuchos::dyn_cast;
57 using Teuchos::RCP;
58 
59 namespace Teko {
60 
61 // Thyra::LinearOpBase requirements
63 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp& A, const LinearOp& invA00,
64  const LinearOp& invS)
65  : A_(A),
66  hatInvA00_(invA00),
67  tildeInvA00_(invA00),
68  invS_(invS),
69  A10_(A->getBlock(1, 0)),
70  A01_(A->getBlock(0, 1)) {
71  using Teuchos::tuple;
72  using Thyra::productVectorSpace;
73 
74  // create and store range space
75  productRange_ = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
76 
77  // create and store domain space
78  productDomain_ = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain())());
79 }
80 
92 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp& A, const LinearOp& hatInvA00,
93  const LinearOp& tildeInvA00, const LinearOp& invS)
94  : A_(A),
95  hatInvA00_(hatInvA00),
96  tildeInvA00_(tildeInvA00),
97  invS_(invS),
98  A10_(A->getBlock(1, 0)),
99  A01_(A->getBlock(0, 1)) {
100  using Teuchos::tuple;
101  using Thyra::productVectorSpace;
102 
103  // create and store range space
104  productRange_ = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
105 
106  // create and store domain space
107  productDomain_ = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain()));
108 }
109 
110 void LU2x2InverseOp::implicitApply(const BlockedMultiVector& x, BlockedMultiVector& y,
111  const double alpha, const double beta) const {
112  // get src blocks
113  MultiVector f = getBlock(0, x); // f
114  MultiVector g = getBlock(1, x); // g
115 
116  // get extra storage
117  MultiVector ps = deepcopy(g); // this is need b/c of p = -inv(S)*p
118 
119  // get destination blocks
120  MultiVector u = getBlock(0, y); // u (u^)
121  MultiVector p = getBlock(1, y); // p (p^)
122 
123  // for efficiency make copies of u and p
124  MultiVector uc, pc; // copies of u and p
125  if (beta != 0) {
126  // perform a deep copy
127  uc = deepcopy(u);
128  pc = deepcopy(p);
129  } else {
130  // perform a shallow copy
131 
132  // uc and pc point
133  // to the data of u and p
134  uc = u;
135  pc = p;
136  }
137 
138  // set temporary operator for performing inv(A_00)*A_01
139  LinearOp invA00_A01 = Thyra::multiply(tildeInvA00_, A01_);
140 
141  // compute actual product
142  applyOp(hatInvA00_, f, uc); // u = inv(A_00) * f
143  applyOp(A10_, uc, ps, -1.0, 1.0); // ps += -A_10*u
144  applyOp(invS_, ps, pc, -1.0); // p = -inv(S)*ps
145  applyOp(invA00_A01, pc, uc, -1.0, 1.0); // u += -inv(A_00)*A_01*p
146 
147  // scale result by alpha
148  if (beta != 0) {
149  update(alpha, uc, beta, u); // u = alpha * uc + beta * u
150  update(alpha, pc, beta, p); // p = alpha * pc + beta * p
151  } else if (alpha != 1.0) {
152  scale(alpha, u); // u = alpha * u
153  scale(alpha, p); // p = alpha * p
154  }
155 }
156 
157 void LU2x2InverseOp::describe(Teuchos::FancyOStream& out_arg,
158  const Teuchos::EVerbosityLevel verbLevel) const {
159  using Teuchos::OSTab;
160 
161  RCP<Teuchos::FancyOStream> out = rcp(&out_arg, false);
162  OSTab tab(out);
163  switch (verbLevel) {
164  case Teuchos::VERB_DEFAULT:
165  case Teuchos::VERB_LOW: *out << this->description() << std::endl; break;
166  case Teuchos::VERB_MEDIUM:
167  case Teuchos::VERB_HIGH:
168  case Teuchos::VERB_EXTREME: {
169  *out << Teuchos::Describable::description() << "{"
170  << "rangeDim=" << this->range()->dim() << ",domainDim=" << this->domain()->dim()
171  << "}\n";
172  {
173  *out << "[invS]:\n";
174  *out << Teuchos::describe(*invS_, verbLevel);
175 
176  *out << "[hatInvA00]:\n";
177  *out << Teuchos::describe(*hatInvA00_, verbLevel);
178 
179  *out << "[tildeInvA00]:\n";
180  *out << Teuchos::describe(*tildeInvA00_, verbLevel);
181 
182  *out << "[A_10]:\n";
183  *out << Teuchos::describe(*A10_, verbLevel);
184 
185  *out << "[A_01]:\n";
186  *out << Teuchos::describe(*A01_, verbLevel);
187  }
188  break;
189  }
190  default: TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
191  }
192 }
193 
194 } // end namespace Teko
const LinearOp hatInvA00_
inverse of
Teuchos::RCP< const Thyra::ProductVectorSpaceBase< double > > productRange_
Range vector space.
const LinearOp A01_
operator
Teuchos::RCP< const Thyra::ProductVectorSpaceBase< double > > productDomain_
Domain vector space.
virtual VectorSpace domain() const
Domain space of this operator.
virtual void implicitApply(const BlockedMultiVector &x, BlockedMultiVector &y, const double alpha=1.0, const double beta=0.0) const
Perform a matrix vector multiply with this operator.
const LinearOp invS_
inverse of
virtual VectorSpace range() const
Range space of this operator.
const LinearOp A10_
operator
const LinearOp tildeInvA00_
inverse of