|
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 /* 00048 // @header 00049 // 00050 // *********************************************************************** 00051 // 00052 // teko: a package for block and physics based preconditioning 00053 // copyright 2010 sandia corporation 00054 // 00055 // under the terms of contract de-ac04-94al85000 with sandia corporation, 00056 // the u.s. government retains certain rights in this software. 00057 // 00058 // redistribution and use in source and binary forms, with or without 00059 // modification, are permitted provided that the following conditions are 00060 // met: 00061 // 00062 // 1. redistributions of source code must retain the above copyright 00063 // notice, this list of conditions and the following disclaimer. 00064 // 00065 // 2. redistributions in binary form must reproduce the above copyright 00066 // notice, this list of conditions and the following disclaimer in the 00067 // documentation and/or other materials provided with the distribution. 00068 // 00069 // 3. neither the name of the corporation nor the names of the 00070 // contributors may be used to endorse or promote products derived from 00071 // this software without specific prior written permission. 00072 // 00073 // this software is provided by sandia corporation "as is" and any 00074 // express or implied warranties, including, but not limited to, the 00075 // implied warranties of merchantability and fitness for a particular 00076 // purpose are disclaimed. in no event shall sandia corporation or the 00077 // contributors be liable for any direct, indirect, incidental, special, 00078 // exemplary, or consequential damages (including, but not limited to, 00079 // procurement of substitute goods or services; loss of use, data, or 00080 // profits; or business interruption) however caused and on any theory of 00081 // liability, whether in contract, strict liability, or tort (including 00082 // negligence or otherwise) arising in any way out of the use of this 00083 // software, even if advised of the possibility of such damage. 00084 // 00085 // questions? contact eric c. cyr (eccyr@sandia.gov) 00086 // 00087 // *********************************************************************** 00088 // 00089 // @header 00090 */ 00091 00092 #include "Teko_InverseFactory.hpp" 00093 00094 // Thyra includes 00095 #include "Thyra_DefaultLinearOpSource.hpp" 00096 #include "Thyra_DefaultInverseLinearOp.hpp" 00097 #include "Thyra_DefaultPreconditioner.hpp" 00098 00099 // Stratimikos includes 00100 #include "Stratimikos_DefaultLinearSolverBuilder.hpp" 00101 00102 // Teko includes 00103 #include "Teko_Utilities.hpp" 00104 #include "Teko_BlockPreconditionerFactory.hpp" 00105 #include "Teko_Preconditioner.hpp" 00106 #include "Teko_PreconditionerLinearOp.hpp" 00107 #include "Teko_SolveInverseFactory.hpp" 00108 #include "Teko_PreconditionerInverseFactory.hpp" 00109 00110 using Teuchos::rcp; 00111 using Teuchos::rcp_const_cast; 00112 using Teuchos::rcp_dynamic_cast; 00113 using Teuchos::RCP; 00114 00115 namespace Teko { 00116 00118 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & A) 00119 { 00120 InverseLinearOp inv; 00121 try { 00122 inv = factory.buildInverse(A); 00123 } 00124 catch(std::exception & e) { 00125 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00126 00127 *out << "Teko: \"buildInverse\" could not construct the inverse operator using "; 00128 *out << "\"" << factory.toString() << "\"" << std::endl; 00129 *out << std::endl; 00130 *out << "*** THROWN EXCEPTION ***\n"; 00131 *out << e.what() << std::endl; 00132 *out << "************************\n"; 00133 00134 throw e; 00135 } 00136 00137 return inv; 00138 } 00139 00143 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & A, 00144 const PreconditionerState & parentState) 00145 { 00146 Teko_DEBUG_SCOPE("buildInverse(factory,A,parentState)",10); 00147 InverseLinearOp inv; 00148 try { 00149 inv = factory.buildInverse(A,parentState); 00150 } 00151 catch(std::exception & e) { 00152 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00153 00154 *out << "Teko: \"buildInverse\" could not construct the inverse operator using "; 00155 *out << "\"" << factory.toString() << "\"" << std::endl; 00156 *out << std::endl; 00157 *out << "*** THROWN EXCEPTION ***\n"; 00158 *out << e.what() << std::endl; 00159 *out << "************************\n"; 00160 00161 throw e; 00162 } 00163 00164 return inv; 00165 } 00166 00178 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & A,const LinearOp & precOp) 00179 { 00180 Teko_DEBUG_SCOPE("buildInverse(factory,A,precOp)",10); 00181 InverseLinearOp inv; 00182 try { 00183 inv = factory.buildInverse(A,precOp); 00184 } 00185 catch(std::exception & e) { 00186 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00187 00188 *out << "Teko: \"buildInverse\" could not construct the inverse operator using "; 00189 *out << "\"" << factory.toString() << "\"" << std::endl; 00190 *out << std::endl; 00191 *out << "*** THROWN EXCEPTION ***\n"; 00192 *out << e.what() << std::endl; 00193 *out << "************************\n"; 00194 00195 throw e; 00196 } 00197 00198 return inv; 00199 } 00200 00214 InverseLinearOp buildInverse(const InverseFactory & factory,const LinearOp & linearOp, 00215 const LinearOp & precOp, 00216 const PreconditionerState & parentState) 00217 { 00218 Teko_DEBUG_SCOPE("buildInverse(factory,A,precOp,parentState)",10); 00219 InverseLinearOp inv; 00220 try { 00221 inv = factory.buildInverse(linearOp,precOp,parentState); 00222 } 00223 catch(std::exception & e) { 00224 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00225 00226 *out << "Teko: \"buildInverse\" could not construct the inverse operator using "; 00227 *out << "\"" << factory.toString() << "\"" << std::endl; 00228 *out << std::endl; 00229 *out << "*** THROWN EXCEPTION ***\n"; 00230 *out << e.what() << std::endl; 00231 *out << "************************\n"; 00232 00233 throw e; 00234 } 00235 00236 return inv; 00237 } 00238 00242 void rebuildInverse(const InverseFactory & factory, const LinearOp & A, InverseLinearOp & invA) 00243 { 00244 InverseLinearOp inv; 00245 try { 00246 factory.rebuildInverse(A,invA); 00247 } 00248 catch(std::exception & e) { 00249 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00250 00251 *out << "Teko: \"rebuildInverse\" could not construct the inverse operator using "; 00252 *out << "\"" << factory.toString() << "\"" << std::endl; 00253 *out << std::endl; 00254 *out << "*** THROWN EXCEPTION ***\n"; 00255 *out << e.what() << std::endl; 00256 *out << "************************\n"; 00257 00258 throw e; 00259 } 00260 } 00261 00277 void rebuildInverse(const InverseFactory & factory, const LinearOp & A,const LinearOp & precOp, InverseLinearOp & invA) 00278 { 00279 InverseLinearOp inv; 00280 try { 00281 factory.rebuildInverse(A,precOp,invA); 00282 } 00283 catch(std::exception & e) { 00284 RCP<Teuchos::FancyOStream> out = Teko::getOutputStream(); 00285 00286 *out << "Teko: \"rebuildInverse\" could not construct the inverse operator using "; 00287 *out << "\"" << factory.toString() << "\"" << std::endl; 00288 *out << std::endl; 00289 *out << "*** THROWN EXCEPTION ***\n"; 00290 *out << e.what() << std::endl; 00291 *out << "************************\n"; 00292 00293 throw e; 00294 } 00295 } 00296 00308 RCP<InverseFactory> invFactoryFromParamList(const Teuchos::ParameterList & list,const std::string & type) 00309 { 00310 RCP<Teuchos::ParameterList> myList = rcp(new Teuchos::ParameterList(list)); 00311 00312 Stratimikos::DefaultLinearSolverBuilder strat; 00313 strat.setParameterList(myList); 00314 00315 try { 00316 // try to build a preconditioner factory 00317 RCP<Thyra::PreconditionerFactoryBase<double> > precFact = strat.createPreconditioningStrategy(type); 00318 00319 // string must map to a preconditioner 00320 return rcp(new PreconditionerInverseFactory(precFact,Teuchos::null)); 00321 } 00322 catch(const Teuchos::Exceptions::InvalidParameterValue & exp) { } 00323 00324 try { 00325 // try to build a solver factory 00326 RCP<Thyra::LinearOpWithSolveFactoryBase<double> > solveFact = strat.createLinearSolveStrategy(type); 00327 00328 // if its around, build a InverseFactory 00329 return rcp(new SolveInverseFactory(solveFact)); 00330 } 00331 catch(const Teuchos::Exceptions::InvalidParameterValue & exp) { } 00332 00333 return Teuchos::null;; 00334 } 00335 00344 Teuchos::RCP<const Teuchos::ParameterList> invFactoryValidParameters() 00345 { 00346 Stratimikos::DefaultLinearSolverBuilder strat; 00347 00348 // extract valid parameter list from Stratimikos 00349 return strat.getValidParameters(); 00350 } 00351 00352 } // end namespace Teko
1.7.4