Teko Version of the Day
Teko_LU2x2InverseOp.cpp
00001 /*
00002 // @HEADER
00003 // 
00004 // ***********************************************************************
00005 // 
00006 //      Teko: A package for block and physics based preconditioning
00007 //                  Copyright 2010 Sandia Corporation 
00008 //  
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 //  
00012 // Redistribution and use in source and binary forms, with or without
00013 // modification, are permitted provided that the following conditions are
00014 // met:
00015 //  
00016 // 1. Redistributions of source code must retain the above copyright
00017 // notice, this list of conditions and the following disclaimer.
00018 //  
00019 // 2. Redistributions in binary form must reproduce the above copyright
00020 // notice, this list of conditions and the following disclaimer in the
00021 // documentation and/or other materials provided with the distribution.
00022 //  
00023 // 3. Neither the name of the Corporation nor the names of the
00024 // contributors may be used to endorse or promote products derived from
00025 // this software without specific prior written permission. 
00026 //  
00027 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00028 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00030 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00031 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00032 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00033 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00034 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00035 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
00036 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00037 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 //  
00039 // Questions? Contact Eric C. Cyr (eccyr@sandia.gov)
00040 // 
00041 // ***********************************************************************
00042 // 
00043 // @HEADER
00044 
00045 */
00046 
00047 #include "Teko_LU2x2InverseOp.hpp"
00048 
00049 #include "Thyra_DefaultProductVectorSpace.hpp"
00050 #include "Thyra_ProductMultiVectorBase.hpp"
00051 #include "Thyra_DefaultMultipliedLinearOp.hpp"
00052 #include "Thyra_MultiVectorStdOps.hpp"
00053 
00054 using namespace Thyra;
00055 using Teuchos::RCP;
00056 using Teuchos::ArrayRCP;
00057 using Teuchos::dyn_cast;
00058 
00059 namespace Teko {
00060 
00061 // Thyra::LinearOpBase requirements
00063 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp & A,
00064                                const LinearOp & invA00,
00065                                const LinearOp & invS)
00066    : A_(A), hatInvA00_(invA00), tildeInvA00_(invA00), invS_(invS), 
00067      A10_(A->getBlock(1,0)), A01_(A->getBlock(0,1))
00068 {
00069    using Teuchos::tuple;
00070    using Thyra::productVectorSpace;
00071  
00072    // create and store range space
00073    productRange_   = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
00074 
00075    // create and store domain space
00076    productDomain_  = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain())());
00077 }
00078 
00090 LU2x2InverseOp::LU2x2InverseOp(const BlockedLinearOp & A,
00091                                const LinearOp & hatInvA00,
00092                                const LinearOp & tildeInvA00,
00093                                const LinearOp & invS)
00094    : A_(A), hatInvA00_(hatInvA00), tildeInvA00_(tildeInvA00), invS_(invS), 
00095      A10_(A->getBlock(1,0)), A01_(A->getBlock(0,1))
00096 {
00097    using Teuchos::tuple;
00098    using Thyra::productVectorSpace;
00099  
00100    // create and store range space
00101    productRange_  = productVectorSpace<double>(tuple(hatInvA00_->range(), invS_->range())());
00102 
00103    // create and store domain space
00104    productDomain_ = productVectorSpace<double>(tuple(hatInvA00_->domain(), invS_->domain()));
00105 }
00106 
00107 void LU2x2InverseOp::implicitApply(const BlockedMultiVector & x, BlockedMultiVector & y,
00108                                 const double alpha, const double beta) const
00109 {
00110    // get src blocks
00111    MultiVector f = getBlock(0,x); // f
00112    MultiVector g = getBlock(1,x); // g
00113   
00114    // get extra storage
00115    MultiVector ps = deepcopy(g); // this is need b/c of p = -inv(S)*p
00116    
00117    // get destination blocks
00118    MultiVector u = getBlock(0,y); // u (u^)
00119    MultiVector p = getBlock(1,y); // p (p^)
00120 
00121    // for efficiency make copies of u and p
00122    MultiVector uc,pc; // copies of u and p
00123    if(beta!=0) {
00124       // perform a deep copy
00125       uc = deepcopy(u);
00126       pc = deepcopy(p);
00127    } else {
00128       // perform a shallow copy
00129 
00130       // uc and pc point 
00131       // to the data of u and p
00132       uc = u;
00133       pc = p;
00134    }
00135 
00136    // set temporary operator for performing inv(A_00)*A_01
00137    LinearOp invA00_A01 = Thyra::multiply(tildeInvA00_,A01_);
00138 
00139    // compute actual product
00140    applyOp(hatInvA00_,  f,  uc);            // u   = inv(A_00) * f
00141    applyOp(A10_,       uc,  ps, -1.0, 1.0); // ps += -A_10*u
00142    applyOp(invS_,      ps,  pc, -1.0);      // p   = -inv(S)*ps
00143    applyOp(invA00_A01, pc,  uc, -1.0, 1.0); // u  += -inv(A_00)*A_01*p
00144 
00145    // scale result by alpha
00146    if(beta!=0) {
00147       update(alpha,uc,beta,u); // u = alpha * uc + beta * u
00148       update(alpha,pc,beta,p); // p = alpha * pc + beta * p
00149    } 
00150    else if(alpha!=1.0) {  
00151       scale(alpha,u); // u = alpha * u
00152       scale(alpha,p); // p = alpha * p
00153    }
00154 }
00155 
00156 void LU2x2InverseOp::describe(Teuchos::FancyOStream & out_arg,
00157                                       const Teuchos::EVerbosityLevel verbLevel) const
00158 {
00159   using Teuchos::OSTab;
00160 
00161   RCP<Teuchos::FancyOStream> out = rcp(&out_arg,false);
00162   OSTab tab(out);
00163   switch(verbLevel) {
00164      case Teuchos::VERB_DEFAULT:
00165      case Teuchos::VERB_LOW:
00166         *out << this->description() << std::endl;
00167         break;
00168      case Teuchos::VERB_MEDIUM:
00169      case Teuchos::VERB_HIGH:
00170      case Teuchos::VERB_EXTREME:
00171         {
00172            *out << Teuchos::Describable::description() << "{"
00173                 << "rangeDim=" << this->range()->dim()
00174                 << ",domainDim=" << this->domain()->dim()
00175                 << "}\n";
00176            {
00177               OSTab tab(out);
00178               *out << "[invS]:\n";
00179               *out << Teuchos::describe(*invS_,verbLevel);
00180 
00181               *out << "[hatInvA00]:\n";
00182               *out << Teuchos::describe(*hatInvA00_,verbLevel);
00183 
00184               *out << "[tildeInvA00]:\n";
00185               *out << Teuchos::describe(*tildeInvA00_,verbLevel);
00186 
00187               *out << "[A_10]:\n";
00188               *out << Teuchos::describe(*A10_,verbLevel);
00189 
00190               *out << "[A_01]:\n";
00191               *out << Teuchos::describe(*A01_,verbLevel);
00192            }
00193            break;
00194         }
00195      default:
00196         TEUCHOS_TEST_FOR_EXCEPT(true); // Should never get here!
00197   }
00198 }
00199 
00200 } // end namespace Teko
 All Classes Files Functions Variables