|
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_LU2x2PreconditionerFactory.hpp" 00048 00049 // Teko includes 00050 #include "Teko_LU2x2InverseOp.hpp" 00051 #include "Teko_BlockUpperTriInverseOp.hpp" 00052 00053 // default strategies 00054 #include "Teko_LU2x2DiagonalStrategy.hpp" 00055 #include "NS/Teko_PCDStrategy.hpp" 00056 00057 using Teuchos::rcp; 00058 using Teuchos::RCP; 00059 00060 namespace Teko { 00061 00062 // construct a PreconditionerFactory 00063 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(LinearOp & invA00, LinearOp & invS) 00064 : invOpsStrategy_(rcp(new StaticLU2x2Strategy(invA00,invA00,invS))), useFullLDU_(true) 00065 { } 00066 00068 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(LinearOp & hatInvA00,LinearOp & tildeInvA00,LinearOp & invS) 00069 : invOpsStrategy_(rcp(new StaticLU2x2Strategy(hatInvA00,tildeInvA00,invS))), useFullLDU_(true) 00070 { } 00071 00072 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory(const RCP<LU2x2Strategy> & strategy) 00073 : invOpsStrategy_(strategy), useFullLDU_(true) 00074 { } 00075 00076 LU2x2PreconditionerFactory::LU2x2PreconditionerFactory() 00077 : invOpsStrategy_(Teuchos::null), useFullLDU_(true) 00078 { } 00079 00080 // for PreconditionerFactoryBase 00082 00083 // initialize a newly created preconditioner object 00084 LinearOp LU2x2PreconditionerFactory::buildPreconditionerOperator(BlockedLinearOp & A,BlockPreconditionerState & state) const 00085 { 00086 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildPreconditionerOperator",10); 00087 LinearOp hatInvA00 = invOpsStrategy_->getHatInvA00(A,state); 00088 LinearOp tildeInvA00 = invOpsStrategy_->getTildeInvA00(A,state); 00089 LinearOp invS = invOpsStrategy_->getInvS(A,state); 00090 00091 // build the SchurSolve LinearOp 00092 if(useFullLDU()) 00093 return createLU2x2InverseOp(A,hatInvA00,tildeInvA00,invS,"LU2x2-Full"); 00094 else { 00095 std::vector<LinearOp> invDiag(2); 00096 invDiag[0] = hatInvA00; 00097 invDiag[1] = scale(-1.0,invS); 00098 return createBlockUpperTriInverseOp(A,invDiag,"LU2x2-Upper"); 00099 } 00100 } 00101 00114 void LU2x2PreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList & settings) 00115 { 00116 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeFromParameterList",10); 00117 00118 // use Golub & Wathen type or full LDU decomposition for inverse solve? 00119 bool useLDU = true; 00120 if(settings.isParameter("Use LDU")) 00121 useLDU = settings.get<bool>("Use LDU"); 00122 setFullLDU(useLDU); 00123 00124 // build strategy object 00125 std::string stratName = settings.get<std::string>("Strategy Name"); 00126 const Teuchos::ParameterList & pl = settings.sublist("Strategy Settings"); 00127 invOpsStrategy_ = buildStrategy(stratName,pl,getInverseLibrary(),getRequestHandler()); 00128 } 00129 00144 Teuchos::RCP<Teuchos::ParameterList> LU2x2PreconditionerFactory::getRequestedParameters() const 00145 { 00146 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::getRequestedParameters",0); 00147 return invOpsStrategy_->getRequestedParameters(); 00148 } 00149 00163 bool LU2x2PreconditionerFactory::updateRequestedParameters(const Teuchos::ParameterList & pl) 00164 { 00165 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::updateRequestedParameters",0); 00166 return invOpsStrategy_->updateRequestedParameters(pl); 00167 } 00168 00170 // Static members and methods 00172 00174 CloneFactory<LU2x2Strategy> LU2x2PreconditionerFactory::strategyBuilder_; 00175 00188 RCP<LU2x2Strategy> LU2x2PreconditionerFactory::buildStrategy(const std::string & name, 00189 const Teuchos::ParameterList & settings, 00190 const RCP<const InverseLibrary> & invLib, 00191 const RCP<RequestHandler> & rh) 00192 { 00193 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::buildStrategy",0); 00194 00195 // initialize the defaults if necessary 00196 if(strategyBuilder_.cloneCount()==0) initializeStrategyBuilder(); 00197 00198 Teko_DEBUG_MSG_BEGIN(1) 00199 std::vector<std::string> names; 00200 strategyBuilder_.getCloneNames(names); 00201 DEBUG_STREAM << "Strategy names = "; 00202 for(std::size_t i=0;i<names.size();i++) 00203 DEBUG_STREAM << names[i] << ", "; 00204 DEBUG_STREAM << std::endl; 00205 Teko_DEBUG_MSG_END() 00206 00207 // request the preconditioner factory from the CloneFactory 00208 RCP<LU2x2Strategy> strategy = strategyBuilder_.build(name); 00209 00210 if(strategy==Teuchos::null) { 00211 Teko_DEBUG_MSG("Warning: Could not build LU2x2Strategy named \"" 00212 << name << "\"...pressing on, failure expected",0) 00213 return Teuchos::null; 00214 } 00215 00216 // now that inverse library has been set, 00217 // pass in the parameter list 00218 strategy->setRequestHandler(rh); 00219 strategy->initializeFromParameterList(settings,*invLib); 00220 00221 return strategy; 00222 } 00223 00237 void LU2x2PreconditionerFactory::addStrategy(const std::string & name,const RCP<Cloneable> & clone) 00238 { 00239 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::addStrategy",10); 00240 00241 // initialize the defaults if necessary 00242 if(strategyBuilder_.cloneCount()==0) initializeStrategyBuilder(); 00243 00244 // add clone to builder 00245 strategyBuilder_.addClone(name,clone); 00246 } 00247 00249 void LU2x2PreconditionerFactory::initializeStrategyBuilder() 00250 { 00251 Teko_DEBUG_SCOPE("LU2x2PreconditionerFactory::initializeStrategyBuilder",10); 00252 00253 RCP<Cloneable> clone; 00254 00255 // add various strategies to the factory 00256 clone = rcp(new AutoClone<LU2x2DiagonalStrategy>()); 00257 strategyBuilder_.addClone("Diagonal Strategy",clone); 00258 00259 // add various strategies to the factory 00260 clone = rcp(new AutoClone<NS::PCDStrategy>()); 00261 strategyBuilder_.addClone("NS PCD Strategy",clone); 00262 } 00263 00264 } // end namespace Teko
1.7.4