Rythmos - Transient Integration for Differential Equations Version of the Day
Rythmos_ImplicitBDFStepperErrWtVecCalc.hpp
00001 //@HEADER
00002 // ***********************************************************************
00003 //
00004 //                           Rythmos Package
00005 //                 Copyright (2006) 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 Todd S. Coffey (tscoffe@sandia.gov)
00025 //
00026 // ***********************************************************************
00027 //@HEADER
00028 
00029 #ifndef Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
00030 #define Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
00031 
00032 #include "Rythmos_ErrWtVecCalcBase.hpp"
00033 
00034 namespace Rythmos {
00035 
00036 template<class Scalar>
00037 class ImplicitBDFStepperErrWtVecCalc
00038   : virtual public ErrWtVecCalcBase<Scalar>
00039 {
00040   public:
00041 
00043     void errWtVecSet(
00044          Thyra::VectorBase<Scalar>* weight
00045          ,const Thyra::VectorBase<Scalar>& vector
00046          ,Scalar relTol
00047          ,Scalar absTol
00048          ) const;
00049 
00053     void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
00054 
00056     RCP<Teuchos::ParameterList> getNonconstParameterList();
00057 
00059     RCP<Teuchos::ParameterList> unsetParameterList();
00060 
00062     RCP<const Teuchos::ParameterList> getValidParameters() const;
00063 
00065 
00066   private:
00067     RCP<Teuchos::ParameterList> paramList_;
00068 };
00069 
00070 
00071 template<class Scalar>
00072 void ImplicitBDFStepperErrWtVecCalc<Scalar>::errWtVecSet(
00073      Thyra::VectorBase<Scalar>* weight
00074      ,const Thyra::VectorBase<Scalar>& vector
00075      ,Scalar relTol
00076      ,Scalar absTol
00077      ) const
00078 {
00079   typedef Teuchos::ScalarTraits<Scalar> ST;
00080   TEST_FOR_EXCEPT(weight==NULL);
00081   TEST_FOR_EXCEPTION(
00082       ( ( relTol == ST::zero() ) && ( absTol == ST::zero() ) ), std::logic_error,
00083       "Error, relTol and absTol cannot both be zero!\n"
00084       );
00085   Thyra::VectorBase<Scalar> &w = *weight;
00086   Thyra::abs(ptr(&w),vector);
00087   Vt_S(ptr(&w),relTol);
00088   Vp_S(ptr(&w),absTol);
00089   reciprocal(ptr(&w),w);
00090   Vt_StV(ptr(&w),ST::one(),w); // We square w because of how weighted norm_2 is computed.
00091   // divide by N to get RMS norm
00092   int N = vector.space()->dim();
00093   Vt_S(ptr(&w),Scalar(1.0/N));
00094   // Now you can compute WRMS norm as:
00095   // Scalar WRMSnorm = norm_2(w,y); // WRMS norm of y with respect to weights w.
00096 
00097   using Teuchos::as;
00098   RCP<Teuchos::FancyOStream> out = this->getOStream();
00099   Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
00100   Teuchos::OSTab ostab(out,1,"errWtVecSet");
00101 
00102   if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
00103     *out << "weight = " << std::endl;
00104     weight->describe(*out,verbLevel);
00105   }
00106 }
00107 
00108 template<class Scalar>
00109 void ImplicitBDFStepperErrWtVecCalc<Scalar>::setParameterList(
00110   RCP<Teuchos::ParameterList> const& paramList
00111   )
00112 {
00113   TEST_FOR_EXCEPT(paramList == Teuchos::null);
00114   paramList->validateParameters(*this->getValidParameters(),0);
00115   paramList_ = paramList;
00116   Teuchos::readVerboseObjectSublist(&*paramList_,this);
00117 }
00118 
00119 template<class Scalar>
00120 RCP<Teuchos::ParameterList>
00121 ImplicitBDFStepperErrWtVecCalc<Scalar>::unsetParameterList()
00122 {
00123   RCP<Teuchos::ParameterList> temp_param_list = paramList_;
00124   paramList_ = Teuchos::null;
00125   return(temp_param_list);
00126 }
00127 
00128 template<class Scalar>
00129 RCP<Teuchos::ParameterList>
00130 ImplicitBDFStepperErrWtVecCalc<Scalar>::getNonconstParameterList()
00131 {
00132   return(paramList_);
00133 }
00134 
00135 template<class Scalar>
00136 RCP<const Teuchos::ParameterList>
00137 ImplicitBDFStepperErrWtVecCalc<Scalar>::getValidParameters() const
00138 {
00139   static RCP<Teuchos::ParameterList> validPL;
00140   if (is_null(validPL)) {
00141     RCP<Teuchos::ParameterList>
00142       pl = Teuchos::parameterList();
00143     Teuchos::setupVerboseObjectSublist(&*pl);
00144     validPL = pl;
00145   }
00146   return (validPL);
00147 }
00148 
00149 } // namespace Rythmos
00150 
00151 #endif // Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
00152 
 All Classes Functions Variables Typedefs Friends