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