Teko Version of the Day
Loading...
Searching...
No Matches
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
48
49#include "Thyra_DefaultProductVectorSpace.hpp"
50#include "Thyra_ProductMultiVectorBase.hpp"
51#include "Thyra_DefaultMultipliedLinearOp.hpp"
52#include "Thyra_MultiVectorStdOps.hpp"
53
54using namespace Thyra;
55using Teuchos::RCP;
56using Teuchos::ArrayRCP;
57using Teuchos::dyn_cast;
58
59namespace Teko {
60
61// Thyra::LinearOpBase requirements
63LU2x2InverseOp::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
90LU2x2InverseOp::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
107void 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
156void 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 *out << "[invS]:\n";
178 *out << Teuchos::describe(*invS_,verbLevel);
179
180 *out << "[hatInvA00]:\n";
181 *out << Teuchos::describe(*hatInvA00_,verbLevel);
182
183 *out << "[tildeInvA00]:\n";
184 *out << Teuchos::describe(*tildeInvA00_,verbLevel);
185
186 *out << "[A_10]:\n";
187 *out << Teuchos::describe(*A10_,verbLevel);
188
189 *out << "[A_01]:\n";
190 *out << Teuchos::describe(*A01_,verbLevel);
191 }
192 break;
193 }
194 default:
195 TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
196 }
197}
198
199} // end namespace Teko
void scale(const double alpha, MultiVector &x)
Scale a multivector by a constant.
MultiVector getBlock(int i, const BlockedMultiVector &bmv)
Get the ith block from a BlockedMultiVector object.
MultiVector deepcopy(const MultiVector &v)
Perform a deep copy of the vector.
const LinearOp hatInvA00_
inverse of
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 tildeInvA00_
inverse of
Teuchos::RCP< const Thyra::ProductVectorSpaceBase< double > > productDomain_
Domain vector space.
virtual VectorSpace domain() const
Domain space of this operator.
Teuchos::RCP< const Thyra::ProductVectorSpaceBase< double > > productRange_
Range vector space.
const LinearOp invS_
inverse of
virtual VectorSpace range() const
Range space of this operator.
const LinearOp A01_
operator
const LinearOp A10_
operator