|
Teko Version of the Day
|
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_BlockUpperTriInverseOp.hpp" 00048 00049 #include "Teuchos_Utils.hpp" 00050 00051 namespace Teko { 00052 00053 using Teuchos::RCP; 00054 00065 BlockUpperTriInverseOp::BlockUpperTriInverseOp(BlockedLinearOp & U,const std::vector<LinearOp> & invDiag) 00066 : U_(U) 00067 { 00068 invDiag_ = invDiag; 00069 00070 // sanity check 00071 int blocks = blockRowCount(U_); 00072 TEUCHOS_ASSERT(blocks>0); 00073 TEUCHOS_ASSERT(blocks==blockColCount(U_)); 00074 TEUCHOS_ASSERT(blocks==(int) invDiag_.size()); 00075 00076 // create the range and product space 00078 00079 // just flip flop them! 00080 productRange_ = U->productDomain(); 00081 productDomain_ = U->productRange(); 00082 } 00083 00096 void BlockUpperTriInverseOp::implicitApply(const BlockedMultiVector & src, BlockedMultiVector & dst, 00097 const double alpha, const double beta) const 00098 { 00099 int blocks = blockCount(src); 00100 00101 TEUCHOS_ASSERT(blocks==blockRowCount(U_)); 00102 TEUCHOS_ASSERT(blocks==blockCount(dst)); 00103 00104 // build a scrap vector for storing work 00105 srcScrap_ = datacopy(src,srcScrap_); 00106 BlockedMultiVector dstCopy; 00107 if(beta!=0.0) { 00108 dstScrap_ = datacopy(dst,dstScrap_); 00109 dstCopy = dstScrap_; 00110 } 00111 else 00112 dstCopy = dst; // shallow copy 00113 00114 // extract the blocks components from 00115 // the source and destination vectors 00116 std::vector<MultiVector> dstVec; 00117 std::vector<MultiVector> scrapVec; 00118 for(int b=0;b<blocks;b++) { 00119 dstVec.push_back(getBlock(b,dstCopy)); 00120 scrapVec.push_back(getBlock(b,srcScrap_)); 00121 } 00122 00123 // run back-substituion: run over each column 00124 // From Heath pg. 66 00125 for(int b=blocks-1;b>=0;b--) { 00126 applyOp(invDiag_[b], scrapVec[b], dstVec[b]); 00127 00128 // loop over each row 00129 for(int i=0;i<b;i++) { 00130 LinearOp u_ib = getBlock(i,b,U_); 00131 if(u_ib!=Teuchos::null) { 00132 applyOp(u_ib,dstVec[b],scrapVec[i],-1.0,1.0); 00133 } 00134 } 00135 } 00136 00137 // scale result by alpha 00138 if(beta!=0) 00139 update(alpha,dstCopy,beta,dst); // dst = alpha * dstCopy + beta * dst 00140 else if(alpha!=1.0) 00141 scale(alpha,dst); // dst = alpha * dst 00142 } 00143 00144 void BlockUpperTriInverseOp::describe(Teuchos::FancyOStream & out_arg, 00145 const Teuchos::EVerbosityLevel verbLevel) const 00146 { 00147 using Teuchos::OSTab; 00148 00149 RCP<Teuchos::FancyOStream> out = rcp(&out_arg,false); 00150 OSTab tab(out); 00151 switch(verbLevel) { 00152 case Teuchos::VERB_DEFAULT: 00153 case Teuchos::VERB_LOW: 00154 *out << this->description() << std::endl; 00155 break; 00156 case Teuchos::VERB_MEDIUM: 00157 case Teuchos::VERB_HIGH: 00158 case Teuchos::VERB_EXTREME: 00159 { 00160 *out << Teuchos::Describable::description() << "{" 00161 << "rangeDim=" << this->range()->dim() 00162 << ",domainDim=" << this->domain()->dim() 00163 << ",rows=" << blockRowCount(U_) 00164 << ",cols=" << blockColCount(U_) 00165 << "}\n"; 00166 { 00167 OSTab tab(out); 00168 *out << "[U Operator] = "; 00169 *out << Teuchos::describe(*U_,verbLevel); 00170 } 00171 { 00172 OSTab tab(out); 00173 *out << "[invDiag Operators]:\n"; 00174 tab.incrTab(); 00175 for(int i=0;i<blockRowCount(U_);i++) { 00176 *out << "[invD(" << i << ")] = "; 00177 *out << Teuchos::describe(*invDiag_[i],verbLevel); 00178 } 00179 } 00180 break; 00181 } 00182 default: 00183 TEST_FOR_EXCEPT(true); // Should never get here! 00184 } 00185 } 00186 00187 } // end namespace Teko
1.7.4