|
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 // Teko includes 00048 #include "Teko_IterativePreconditionerFactory.hpp" 00049 00050 #include "Teko_PreconditionerInverseFactory.hpp" 00051 00052 namespace Teko { 00053 00055 IterativePreconditionerFactory::IterativePreconditionerFactory() 00056 : correctionNum_(0), precFactory_(Teuchos::null) 00057 { } 00058 00062 IterativePreconditionerFactory::IterativePreconditionerFactory(unsigned int correctionNum, 00063 const Teuchos::RCP<Teko::InverseFactory> & precFactory) 00064 : correctionNum_(correctionNum), precFactory_(precFactory) 00065 { } 00066 00070 IterativePreconditionerFactory::IterativePreconditionerFactory(unsigned int correctionNum, 00071 const Teuchos::RCP<Teko::PreconditionerFactory> & precFactory) 00072 : correctionNum_(correctionNum) 00073 { 00074 precFactory_ = Teuchos::rcp(new Teko::PreconditionerInverseFactory(precFactory,precFactory->getRequestHandler())); 00075 } 00076 00077 00081 LinearOp IterativePreconditionerFactory::buildPreconditionerOperator(LinearOp & lo,PreconditionerState & state) const 00082 { 00083 TEST_FOR_EXCEPTION(precFactory_==Teuchos::null,std::runtime_error, 00084 "ERROR: Teko::IterativePreconditionerFactory::buildPreconditionerOperator requires that a " 00085 << "preconditioner factory has been set. Currently it is null!"); 00086 00087 // build user specified preconditioner 00088 ModifiableLinearOp & invP = state.getModifiableOp("prec"); 00089 if(invP==Teuchos::null) 00090 invP = Teko::buildInverse(*precFactory_,lo,state); 00091 else 00092 Teko::rebuildInverse(*precFactory_,lo,invP); 00093 00094 // // no repititions are required 00095 // if(correctionNum_==0) return invP; 00096 00097 // now build correction operator 00098 LinearOp I = Thyra::identity(lo->range(),"I"); 00099 LinearOp AiP = multiply(lo,invP.getConst(),"AiP"); 00100 LinearOp correction = add(I,scale(-1.0,AiP)); // I - A * iPA 00101 00102 LinearOp resMap = I; // will map r_n to r_{n+1} 00103 for(unsigned int i=0;i<correctionNum_;i++) 00104 resMap = add(I,multiply(resMap,correction)); // resMap = I + resMap*(I-A*iP) 00105 00106 // iP = (I-A*iP)^{correctionNum} 00107 return multiply(invP.getConst(),resMap); 00108 } 00109 00113 void IterativePreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList & settings) 00114 { 00115 00116 correctionNum_ = 1; 00117 if(settings.isParameter("Iteration Count")) 00118 correctionNum_ = settings.get<int>("Iteration Count"); 00119 00120 TEST_FOR_EXCEPTION(not settings.isParameter("Preconditioner Type"),std::runtime_error, 00121 "Parameter \"Preconditioner Type\" is required by a Teko::IterativePreconditionerFactory"); 00122 00123 // grab library and preconditioner name 00124 Teuchos::RCP<const InverseLibrary> il = getInverseLibrary(); 00125 std::string precName = settings.get<std::string>("Preconditioner Type"); 00126 00127 // build preconditioner factory 00128 precFactory_ = il->getInverseFactory(precName); 00129 TEST_FOR_EXCEPTION(precFactory_==Teuchos::null,std::runtime_error, 00130 "ERROR: \"Preconditioner Type\" = " << precName 00131 << " could not be found"); 00132 } 00133 00137 Teuchos::RCP<Teuchos::ParameterList> IterativePreconditionerFactory::getRequestedParameters() const 00138 { 00139 TEST_FOR_EXCEPTION(precFactory_==Teuchos::null,std::runtime_error, 00140 "ERROR: Teko::IterativePreconditionerFactory::getRequestedParameters requires that a " 00141 << "preconditioner factory has been set. Currently it is null!"); 00142 00143 return precFactory_->getRequestedParameters(); 00144 } 00145 00148 bool IterativePreconditionerFactory::updateRequestedParameters(const Teuchos::ParameterList & pl) 00149 { 00150 TEST_FOR_EXCEPTION(precFactory_==Teuchos::null,std::runtime_error, 00151 "ERROR: Teko::IterativePreconditionerFactory::updateRequestedParameters requires that a " 00152 << "preconditioner factory has been set. Currently it is null!"); 00153 00154 return precFactory_->updateRequestedParameters(pl); 00155 } 00156 00157 } // end namespace Teko
1.7.4