|
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_MultPreconditionerFactory.hpp" 00048 00049 namespace Teko { 00050 00051 using Teuchos::RCP; 00052 00053 void MultPrecsLinearOp::implicitApply(const Teko::BlockedMultiVector & r, Teko::BlockedMultiVector & y, 00054 const double alpha, const double beta) const 00055 { 00056 // Casting is a bit delicate. We basically use 00057 // 00058 // 1) deepcopy to copy & cast BlockedMultiVectors to MultiVectors. 00059 // 00060 // 2) toMultiVector to cast BlockedMultiVectors to MultiVectors. 00061 // 00062 Teko::MultiVector MOne_r = Teko::deepcopy(r); 00063 Teko::MultiVector t = Teko::deepcopy(r); 00064 Teko::MultiVector w = Teko::toMultiVector(y); 00065 00066 Teko::applyOp(M1_, r, MOne_r); 00067 Teko::applyOp(A_, MOne_r, t); 00068 Teko::update(1.,r,-1.,t); 00069 Teko::applyOp(M2_, t, w); 00070 Teko::update(1.,MOne_r, 1., w); 00071 } 00072 00074 MultPreconditionerFactory 00075 ::MultPreconditionerFactory(const RCP<const Teko::BlockPreconditionerFactory> & FirstFactory, 00076 const RCP<const Teko::BlockPreconditionerFactory> & SecondFactory) 00077 : FirstFactory_(FirstFactory), SecondFactory_(SecondFactory) 00078 { } 00079 00080 MultPreconditionerFactory::MultPreconditionerFactory() 00081 { } 00082 00084 RCP<Teko::PreconditionerState> MultPreconditionerFactory::buildPreconditionerState() const 00085 { 00086 MultPrecondState* mystate = new MultPrecondState(); 00087 mystate->StateOne_ = Teuchos::rcp_dynamic_cast<BlockPreconditionerState>(FirstFactory_->buildPreconditionerState()); 00088 mystate->StateTwo_ = Teuchos::rcp_dynamic_cast<BlockPreconditionerState>(SecondFactory_->buildPreconditionerState()); 00089 return rcp(mystate); 00090 } 00091 00092 00094 Teko::LinearOp MultPreconditionerFactory 00095 ::buildPreconditionerOperator(Teko::BlockedLinearOp & blockOp, 00096 Teko::BlockPreconditionerState & state) const 00097 { 00098 00099 MultPrecondState *MyState = dynamic_cast<MultPrecondState *> (&state); 00100 00101 TEUCHOS_ASSERT(MyState != 0); 00102 00103 Teko::LinearOp M1 = FirstFactory_->buildPreconditionerOperator(blockOp, *MyState->StateOne_); 00104 Teko::LinearOp M2 = SecondFactory_->buildPreconditionerOperator(blockOp, *MyState->StateTwo_); 00105 00106 00107 /************************************************************************* 00108 A different way to create the same preconditioner using the funky 00109 matrix representation discussed above. At the present time, there 00110 appears to be some kind of bug in Thrya so this doesn't work. 00111 00112 const RCP<const Thyra::LinearOpBase<double>> Mat1= Thyra::block2x1(Teko::identity(Teko::rangeSpace(M1)) ,M1); 00113 const RCP<const Thyra::LinearOpBase<double>> Mat3= Thyra::block1x2(M2,Teko::identity(Teko::rangeSpace(M1))); 00114 const RCP<const Thyra::LinearOpBase<double>> Mat2= Thyra::block2x2( 00115 Teko::identity(Teko::rangeSpace(M1)), Teko::scale(-1.,Teko::toLinearOp(blockOp)), 00116 Thyra::zero<double>(Teko::rangeSpace(M1),Teko::domainSpace(M1)), Teko::identity(Teko::rangeSpace(M1))); 00117 Teko::LinearOp invA = Teko::multiply(Mat3,Mat2,Mat1); 00118 00119 return invA; 00120 *************************************************************************/ 00121 00122 // construct an implicit operator corresponding to multiplicative 00123 // preconditioning, wrap it in an rcp pointer and return. 00124 00125 return Teuchos::rcp(new MultPrecsLinearOp(blockOp,M1,M2)); 00126 } 00127 00129 void MultPreconditionerFactory::initializeFromParameterList(const Teuchos::ParameterList & pl) 00130 { 00131 RCP<const InverseLibrary> invLib = getInverseLibrary(); 00132 00133 // get string specifying inverse 00134 std::string aStr="", bStr=""; 00135 00136 // "parse" the parameter list 00137 aStr = pl.get<std::string>("Preconditioner A"); 00138 bStr = pl.get<std::string>("Preconditioner B"); 00139 00140 RCP<const Teuchos::ParameterList> aSettings = invLib->getParameterList(aStr); 00141 RCP<const Teuchos::ParameterList> bSettings = invLib->getParameterList(bStr); 00142 00143 // build preconditioner from the parameters 00144 std::string aType = aSettings->get<std::string>("Preconditioner Type"); 00145 RCP<Teko::PreconditionerFactory> precA 00146 = Teko::BlockPreconditionerFactory::buildPreconditionerFactory(aType,aSettings->sublist("Preconditioner Settings"),invLib); 00147 00148 // build preconditioner from the parameters 00149 std::string bType = bSettings->get<std::string>("Preconditioner Type"); 00150 RCP<Teko::PreconditionerFactory> precB 00151 = Teko::BlockPreconditionerFactory::buildPreconditionerFactory(bType,bSettings->sublist("Preconditioner Settings"),invLib); 00152 00153 // set precondtioners 00154 FirstFactory_ = Teuchos::rcp_dynamic_cast<const Teko::BlockPreconditionerFactory>(precA); 00155 SecondFactory_ = Teuchos::rcp_dynamic_cast<const Teko::BlockPreconditionerFactory>(precB); 00156 } 00157 00158 } // end namespace Teko
1.7.4