Thyra Package Browser (Single Doxygen Collection) Version of the Day
Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_def.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //    Thyra: Interfaces and Support for Abstract Numerical Algorithms
00005 //                 Copyright (2004) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
00030 #define THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
00031 
00032 
00033 #include "Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_decl.hpp"
00034 #include "Thyra_LinearOpWithSolveBase.hpp"
00035 #include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
00036 #include "Thyra_PhysicallyBlockedLinearOpBase.hpp"
00037 #include "Thyra_PhysicallyBlockedLinearOpWithSolveBase.hpp" // Interface
00038 #include "Thyra_DefaultBlockedTriangularLinearOpWithSolve.hpp" // Implementation
00039 #include "Thyra_DefaultLinearOpSource.hpp"
00040 
00041 
00042 namespace Thyra {
00043 
00044 
00045 // Overridden from Constructors/Initializers/Accessors
00046 
00047   
00048 template<class Scalar>
00049 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::DefaultBlockedTriangularLinearOpWithSolveFactory(
00050   const RCP<LinearOpWithSolveFactoryBase<Scalar> > &lowsf
00051   )
00052 {
00053 #ifdef TEUCHOS_DEBUG
00054   TEST_FOR_EXCEPT(is_null(lowsf));
00055 #endif
00056   lowsf_.initialize(lowsf);
00057 }
00058 
00059   
00060 template<class Scalar>
00061 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::DefaultBlockedTriangularLinearOpWithSolveFactory(
00062   const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
00063   )
00064 {
00065 #ifdef TEUCHOS_DEBUG
00066   TEST_FOR_EXCEPT(is_null(lowsf));
00067 #endif
00068   lowsf_.initialize(lowsf);
00069 }
00070 
00071 
00072 template<class Scalar>
00073 RCP<LinearOpWithSolveFactoryBase<Scalar> >
00074 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getUnderlyingLOWSF()
00075 {
00076   return lowsf_.getNonconstObj();
00077 }
00078 
00079 
00080 template<class Scalar>
00081 RCP<const LinearOpWithSolveFactoryBase<Scalar> >
00082 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getUnderlyingLOWSF() const
00083 {
00084   return lowsf_.getConstObj();
00085 }
00086 
00087 
00088 // Overridden from Teuchos::Describable
00089 
00090 
00091 template<class Scalar>
00092 std::string
00093 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::description() const
00094 {
00095   std::ostringstream oss;
00096   oss << this->Teuchos::Describable::description()
00097       << "{"
00098       << "lowsf=";
00099   if (!is_null(lowsf_.getConstObj()))
00100     oss << lowsf_.getConstObj()->description();
00101   else
00102     oss << "NULL";
00103   oss << "}";
00104   return oss.str();
00105 }
00106 
00107 
00108 // Overridden from ParameterListAcceptor
00109 
00110 
00111 template<class Scalar>
00112 void
00113 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::setParameterList(
00114   RCP<ParameterList> const& paramList
00115   )
00116 {
00117   lowsf_.getNonconstObj()->setParameterList(paramList);
00118 }
00119 
00120 
00121 template<class Scalar>
00122 RCP<ParameterList>
00123 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getNonconstParameterList()
00124 {
00125   return lowsf_.getNonconstObj()->getNonconstParameterList();
00126 }
00127 
00128 
00129 template<class Scalar>
00130 RCP<ParameterList> 
00131 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::unsetParameterList()
00132 {
00133   return lowsf_.getNonconstObj()->unsetParameterList();
00134 }
00135 
00136 
00137 template<class Scalar>
00138 RCP<const ParameterList>
00139 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getParameterList() const
00140 {
00141   return lowsf_.getConstObj()->getParameterList();
00142 }
00143 
00144 
00145 template<class Scalar>
00146 RCP<const ParameterList>
00147 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getValidParameters() const
00148 {
00149   return lowsf_.getConstObj()->getValidParameters();
00150 }
00151 
00152 
00153 // Overridden from LinearOpWithSolveFactoyBase
00154 
00155 
00156 template<class Scalar>
00157 bool
00158 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::acceptsPreconditionerFactory() const
00159 {
00160   return false;
00161 }
00162 
00163 
00164 template<class Scalar>
00165 void
00166 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::setPreconditionerFactory(
00167   const RCP<PreconditionerFactoryBase<Scalar> > &precFactory,
00168   const std::string &precFactoryName
00169   )
00170 {
00171   TEST_FOR_EXCEPTION(true,std::logic_error,
00172     "Error, we don't support a preconditioner factory!");
00173 }
00174 
00175 
00176 template<class Scalar>
00177 RCP<PreconditionerFactoryBase<Scalar> >
00178 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::getPreconditionerFactory() const
00179 {
00180   return Teuchos::null;
00181 }
00182 
00183 
00184 template<class Scalar>
00185 void DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::unsetPreconditionerFactory(
00186   RCP<PreconditionerFactoryBase<Scalar> > *precFactory,
00187   std::string *precFactoryName
00188   )
00189 {
00190   TEST_FOR_EXCEPTION(true,std::logic_error,
00191     "Error, we don't support a preconditioner factory!");
00192 }
00193 
00194 
00195 template<class Scalar>
00196 bool
00197 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::isCompatible(
00198   const LinearOpSourceBase<Scalar> &fwdOpSrc
00199   ) const
00200 {
00201   TEST_FOR_EXCEPT(true);
00202   return false;
00203 }
00204 
00205 
00206 template<class Scalar>
00207 RCP<LinearOpWithSolveBase<Scalar> >
00208 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::createOp() const
00209 {
00210   return defaultBlockedTriangularLinearOpWithSolve<Scalar>();
00211 }
00212 
00213 
00214 template<class Scalar>
00215 void
00216 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::initializeOp(
00217   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00218   LinearOpWithSolveBase<Scalar> *Op,
00219   const ESupportSolveUse supportSolveUse
00220   ) const
00221 {
00222 
00223   using Teuchos::dyn_cast;
00224   using Teuchos::rcp_dynamic_cast;
00225 
00226 #ifdef TEUCHOS_DEBUG
00227   TEST_FOR_EXCEPT(0==Op);
00228 #endif
00229 
00230   // Set the verbosity settings for the wrapped LOWSF object!
00231   lowsf_.getConstObj()->setOStream(this->getOStream());
00232   lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
00233 
00234   // Get the block interface to get at the blocks
00235   typedef PhysicallyBlockedLinearOpBase<Scalar> PBLOB;
00236   const RCP<const PBLOB> blo =
00237     rcp_dynamic_cast<const PBLOB>(fwdOpSrc->getOp().assert_not_null());
00238   
00239   // Dynamic cast to get the DefaultBlockedTriangularLinearOpWithSolveBase
00240   // interface that we will fill.
00241 
00242   typedef DefaultBlockedTriangularLinearOpWithSolve<Scalar> DBTLOWS;
00243   DBTLOWS &btlows = dyn_cast<DBTLOWS>(*Op);
00244 
00245   // Determine if this is the first time through or if we have already
00246   // initialized before.  This will be needed to allow efficient reuse of the
00247   // LOWSB objects for the diagonal blocks.
00248   const bool firstTime = is_null(btlows.range());
00249 
00250   // If this is the first time through, we need to fill and create the block
00251   // structure
00252   if (firstTime)
00253     btlows.beginBlockFill(blo->productRange(),blo->productDomain());
00254 
00255   const int N = blo->productRange()->numBlocks();
00256   for ( int k = 0; k < N; ++k ) {
00257     const RCP<const LinearOpBase<Scalar> > fwdOp_k =
00258       blo->getBlock(k,k).assert_not_null();
00259     if (firstTime) {
00260       // This is the first time through so reate and initialize a new LOWSB
00261       // object for each block
00262       btlows.setNonconstLOWSBlock( k, k,
00263         linearOpWithSolve<Scalar>(*lowsf_.getConstObj(),fwdOp_k)
00264         );
00265     }
00266     else {
00267       // This is not the first time through so we need to just reinitiallize
00268       // the object that is already created.  This allows us to efficiently
00269       // reuse precreated structure and storage.
00270       RCP<LinearOpWithSolveBase<Scalar> >
00271         invOp_k = btlows.getNonconstLOWSBlock(k,k).assert_not_null();
00272       Thyra::initializeOp<Scalar>(*lowsf_.getConstObj(), fwdOp_k, invOp_k.ptr());
00273     }
00274   }
00275 
00276   // If this is the first time through, then we need to finalize the block
00277   // structure.
00278   if (firstTime)
00279     btlows.endBlockFill();
00280 
00281   // After the block structure has been setup, set the off-diagonal blocks.
00282   // Note that this also sets the diagonal blocks but these are ignored since
00283   // the LOWSB blocks created above override these.
00284   btlows.setBlocks(blo);
00285 
00286   // Set the verbosity settings
00287   btlows.setOStream(this->getOStream());
00288   btlows.setVerbLevel(this->getVerbLevel());
00289 
00290 }
00291 
00292 
00293 template<class Scalar>
00294 void
00295 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::initializeAndReuseOp(
00296   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00297   LinearOpWithSolveBase<Scalar> *Op
00298   ) const
00299 {
00300   TEST_FOR_EXCEPT(true);
00301 }
00302 
00303 
00304 template<class Scalar>
00305 void
00306 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::uninitializeOp(
00307   LinearOpWithSolveBase<Scalar> *Op,
00308   RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
00309   RCP<const PreconditionerBase<Scalar> > *prec,
00310   RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
00311   ESupportSolveUse *supportSolveUse
00312   ) const
00313 {
00314   using Teuchos::dyn_cast;
00315   using Teuchos::rcp_implicit_cast;
00316   using Teuchos::rcp_dynamic_cast;
00317   typedef DefaultBlockedTriangularLinearOpWithSolve<Scalar> DBTLOWS;
00318   TEST_FOR_EXCEPT(0==Op);
00319   DBTLOWS &btlowsOp = dyn_cast<DBTLOWS>(*Op);
00320   if (fwdOpSrc) {
00321     const RCP<const LinearOpBase<Scalar> > fwdOp = btlowsOp.getBlocks();
00322     if (!is_null(fwdOp))
00323       *fwdOpSrc = defaultLinearOpSource<Scalar>(fwdOp);
00324     else
00325       *fwdOpSrc = Teuchos::null;
00326   }
00327   if (prec) *prec = Teuchos::null;
00328   if (approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
00329 }
00330 
00331 
00332 template<class Scalar>
00333 bool
00334 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::supportsPreconditionerInputType(
00335   const EPreconditionerInputType precOpType
00336   ) const
00337 {
00338   // We don't support any external preconditioners!
00339   return false;
00340   // 20071006: rabartl: Note: We could support external preconditioners but it
00341   // will take some work.  We would have to extract out the individual
00342   // preconditioners from each block.  This would be pretty easy to do but I
00343   // am not going to do this until we have to.
00344 }
00345 
00346 
00347 template<class Scalar>
00348 void
00349 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::initializePreconditionedOp(
00350   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00351   const RCP<const PreconditionerBase<Scalar> > &prec,
00352   LinearOpWithSolveBase<Scalar> *Op,
00353   const ESupportSolveUse supportSolveUse
00354   ) const
00355 {
00356   TEST_FOR_EXCEPTION(true,std::logic_error,
00357     "Error, we don't support an external preconditioner!");
00358 }
00359 
00360 
00361 template<class Scalar>
00362 void
00363 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::initializeApproxPreconditionedOp(
00364   const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
00365   const RCP<const LinearOpSourceBase<Scalar> > &approxFwdOpSrc,
00366   LinearOpWithSolveBase<Scalar> *Op,
00367   const ESupportSolveUse supportSolveUse
00368   ) const
00369 {
00370   TEST_FOR_EXCEPTION(true,std::logic_error,
00371     "Error, we don't support an external preconditioner!");
00372 }
00373 
00374 
00375 // protected
00376 
00377 
00378 template<class Scalar>
00379 void
00380 DefaultBlockedTriangularLinearOpWithSolveFactory<Scalar>::informUpdatedVerbosityState() const
00381 {
00382   lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
00383   lowsf_.getConstObj()->setOStream(this->getOStream());
00384 }
00385 
00386 
00387 } // namespace Thyra
00388 
00389 
00390 #endif // THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines