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::RCP;
56 using Teuchos::ArrayRCP;
57 using Teuchos::dyn_cast;
58 
59 namespace Teko {
60 
61 // Thyra::LinearOpBase requirements
63 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp & A,
64  const LinearOp & invA00,
65  const LinearOp & invS)
66  : A_(A), hatInvA00_(invA00), tildeInvA00_(invA00), invS_(invS),
67  A10_(A->getBlock(1,0)), A01_(A->getBlock(0,1))
68 {
69  using Teuchos::tuple;
70  using Thyra::productVectorSpace;
71 
72  // create and store range space
73  productRange_ = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
74 
75  // create and store domain space
76  productDomain_ = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain())());
77 }
78 
90 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp & A,
91  const LinearOp & hatInvA00,
92  const LinearOp & tildeInvA00,
93  const LinearOp & invS)
94  : A_(A), hatInvA00_(hatInvA00), tildeInvA00_(tildeInvA00), invS_(invS),
95  A10_(A->getBlock(1,0)), A01_(A->getBlock(0,1))
96 {
97  using Teuchos::tuple;
98  using Thyra::productVectorSpace;
99 
100  // create and store range space
101  productRange_ = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
102 
103  // create and store domain space
104  productDomain_ = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain()));
105 }
106 
107 void LU2x2InverseOp::implicitApply(const BlockedMultiVector & x, BlockedMultiVector & y,
108  const double alpha, const double beta) const
109 {
110  // get src blocks
111  MultiVector f = getBlock(0,x); // f
112  MultiVector g = getBlock(1,x); // g
113 
114  // get extra storage
115  MultiVector ps = deepcopy(g); // this is need b/c of p = -inv(S)*p
116 
117  // get destination blocks
118  MultiVector u = getBlock(0,y); // u (u^)
119  MultiVector p = getBlock(1,y); // p (p^)
120 
121  // for efficiency make copies of u and p
122  MultiVector uc,pc; // copies of u and p
123  if(beta!=0) {
124  // perform a deep copy
125  uc = deepcopy(u);
126  pc = deepcopy(p);
127  } else {
128  // perform a shallow copy
129 
130  // uc and pc point
131  // to the data of u and p
132  uc = u;
133  pc = p;
134  }
135 
136  // set temporary operator for performing inv(A_00)*A_01
137  LinearOp invA00_A01 = Thyra::multiply(tildeInvA00_,A01_);
138 
139  // compute actual product
140  applyOp(hatInvA00_, f, uc); // u = inv(A_00) * f
141  applyOp(A10_, uc, ps, -1.0, 1.0); // ps += -A_10*u
142  applyOp(invS_, ps, pc, -1.0); // p = -inv(S)*ps
143  applyOp(invA00_A01, pc, uc, -1.0, 1.0); // u += -inv(A_00)*A_01*p
144 
145  // scale result by alpha
146  if(beta!=0) {
147  update(alpha,uc,beta,u); // u = alpha * uc + beta * u
148  update(alpha,pc,beta,p); // p = alpha * pc + beta * p
149  }
150  else if(alpha!=1.0) {
151  scale(alpha,u); // u = alpha * u
152  scale(alpha,p); // p = alpha * p
153  }
154 }
155 
156 void LU2x2InverseOp::describe(Teuchos::FancyOStream & out_arg,
157  const Teuchos::EVerbosityLevel verbLevel) const
158 {
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:
166  *out << this->description() << std::endl;
167  break;
168  case Teuchos::VERB_MEDIUM:
169  case Teuchos::VERB_HIGH:
170  case Teuchos::VERB_EXTREME:
171  {
172  *out << Teuchos::Describable::description() << "{"
173  << "rangeDim=" << this->range()->dim()
174  << ",domainDim=" << this->domain()->dim()
175  << "}\n";
176  {
177  OSTab tab(out);
178  *out << "[invS]:\n";
179  *out << Teuchos::describe(*invS_,verbLevel);
180 
181  *out << "[hatInvA00]:\n";
182  *out << Teuchos::describe(*hatInvA00_,verbLevel);
183 
184  *out << "[tildeInvA00]:\n";
185  *out << Teuchos::describe(*tildeInvA00_,verbLevel);
186 
187  *out << "[A_10]:\n";
188  *out << Teuchos::describe(*A10_,verbLevel);
189 
190  *out << "[A_01]:\n";
191  *out << Teuchos::describe(*A01_,verbLevel);
192  }
193  break;
194  }
195  default:
196  TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
197  }
198 }
199 
200 } // 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