Rythmos - Transient Integration for Differential Equations  Version of the Day
 All Classes Functions Variables Typedefs Pages
Rythmos_ImplicitBDFStepperErrWtVecCalc.hpp
1 //@HEADER
2 // ***********************************************************************
3 //
4 // Rythmos Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // USA
24 // Questions? Contact Todd S. Coffey (tscoffe@sandia.gov)
25 //
26 // ***********************************************************************
27 //@HEADER
28 
29 #ifndef Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
30 #define Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
31 
32 #include "Rythmos_ErrWtVecCalcBase.hpp"
33 
34 namespace Rythmos {
35 
36 template<class Scalar>
37 class ImplicitBDFStepperErrWtVecCalc
38  : virtual public ErrWtVecCalcBase<Scalar>
39 {
40  public:
41 
43  void errWtVecSet(
44  Thyra::VectorBase<Scalar>* weight
45  ,const Thyra::VectorBase<Scalar>& vector
46  ,Scalar relTol
47  ,Scalar absTol
48  ) const;
49 
53  void setParameterList(RCP<Teuchos::ParameterList> const& paramList);
54 
56  RCP<Teuchos::ParameterList> getNonconstParameterList();
57 
59  RCP<Teuchos::ParameterList> unsetParameterList();
60 
62  RCP<const Teuchos::ParameterList> getValidParameters() const;
63 
65 
66  private:
67  RCP<Teuchos::ParameterList> paramList_;
68 };
69 
70 
71 template<class Scalar>
72 void ImplicitBDFStepperErrWtVecCalc<Scalar>::errWtVecSet(
73  Thyra::VectorBase<Scalar>* weight
74  ,const Thyra::VectorBase<Scalar>& vector
75  ,Scalar relTol
76  ,Scalar absTol
77  ) const
78 {
79  using Teuchos::as;
80  using Teuchos::ptrFromRef;
81  typedef Teuchos::ScalarTraits<Scalar> ST;
82  TEUCHOS_TEST_FOR_EXCEPT(weight==NULL);
83  TEUCHOS_TEST_FOR_EXCEPTION(
84  ( ( relTol == ST::zero() ) && ( absTol == ST::zero() ) ), std::logic_error,
85  "Error, relTol and absTol cannot both be zero!\n"
86  );
87  Thyra::VectorBase<Scalar> &w = *weight;
88  Thyra::abs(vector, ptrFromRef(w));
89  Vt_S(ptrFromRef(w), relTol);
90  Vp_S(ptrFromRef(w), absTol);
91  reciprocal(w, ptrFromRef(w));
92  Vt_StV(ptrFromRef(w), ST::one(), w); // We square w because of how weighted norm_2 is computed.
93  // divide by N to get RMS norm
94  int N = vector.space()->dim();
95  Vt_S(ptrFromRef(w), as<Scalar>(1.0/N));
96  // Now you can compute WRMS norm as:
97  // Scalar WRMSnorm = norm_2(w,y); // WRMS norm of y with respect to weights w.
98 
99  RCP<Teuchos::FancyOStream> out = this->getOStream();
100  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
101  Teuchos::OSTab ostab(out,1,"errWtVecSet");
102 
103  if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
104  *out << "weight = " << std::endl;
105  weight->describe(*out,verbLevel);
106  }
107 }
108 
109 template<class Scalar>
110 void ImplicitBDFStepperErrWtVecCalc<Scalar>::setParameterList(
111  RCP<Teuchos::ParameterList> const& paramList
112  )
113 {
114  TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
115  paramList->validateParameters(*this->getValidParameters(),0);
116  paramList_ = paramList;
117  Teuchos::readVerboseObjectSublist(&*paramList_,this);
118 }
119 
120 template<class Scalar>
121 RCP<Teuchos::ParameterList>
122 ImplicitBDFStepperErrWtVecCalc<Scalar>::unsetParameterList()
123 {
124  RCP<Teuchos::ParameterList> temp_param_list = paramList_;
125  paramList_ = Teuchos::null;
126  return(temp_param_list);
127 }
128 
129 template<class Scalar>
130 RCP<Teuchos::ParameterList>
131 ImplicitBDFStepperErrWtVecCalc<Scalar>::getNonconstParameterList()
132 {
133  return(paramList_);
134 }
135 
136 template<class Scalar>
137 RCP<const Teuchos::ParameterList>
138 ImplicitBDFStepperErrWtVecCalc<Scalar>::getValidParameters() const
139 {
140  static RCP<Teuchos::ParameterList> validPL;
141  if (is_null(validPL)) {
142  RCP<Teuchos::ParameterList>
143  pl = Teuchos::parameterList();
144  Teuchos::setupVerboseObjectSublist(&*pl);
145  validPL = pl;
146  }
147  return (validPL);
148 }
149 
150 } // namespace Rythmos
151 
152 #endif // Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
153