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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
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() ) ),
85  std::logic_error,
86  "Error, relTol and absTol cannot both be zero!\n");
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
93  // weighted norm_2 is computed.
94  // divide by N to get RMS norm
95  int N = vector.space()->dim();
96  Vt_S(ptrFromRef(w), as<Scalar>(1.0/N));
97  // Now you can compute WRMS norm as:
98  // Scalar WRMSnorm = norm_2(w,y); // WRMS norm of y with respect to weights w.
99 
100  RCP<Teuchos::FancyOStream> out = this->getOStream();
101  Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel();
102  Teuchos::OSTab ostab(out,1,"errWtVecSet");
103 
104  if ( as<int>(verbLevel) >= as<int>(Teuchos::VERB_EXTREME) ) {
105  *out << "weight = " << std::endl;
106  weight->describe(*out,verbLevel);
107  }
108 }
109 
110 template<class Scalar>
111 void ImplicitBDFStepperErrWtVecCalc<Scalar>::setParameterList(
112  RCP<Teuchos::ParameterList> const& paramList
113  )
114 {
115  TEUCHOS_TEST_FOR_EXCEPT(paramList == Teuchos::null);
116  paramList->validateParameters(*this->getValidParameters(),0);
117  paramList_ = paramList;
118  Teuchos::readVerboseObjectSublist(&*paramList_,this);
119 }
120 
121 template<class Scalar>
122 RCP<Teuchos::ParameterList>
123 ImplicitBDFStepperErrWtVecCalc<Scalar>::unsetParameterList()
124 {
125  RCP<Teuchos::ParameterList> temp_param_list = paramList_;
126  paramList_ = Teuchos::null;
127  return(temp_param_list);
128 }
129 
130 template<class Scalar>
131 RCP<Teuchos::ParameterList>
132 ImplicitBDFStepperErrWtVecCalc<Scalar>::getNonconstParameterList()
133 {
134  return(paramList_);
135 }
136 
137 template<class Scalar>
138 RCP<const Teuchos::ParameterList>
139 ImplicitBDFStepperErrWtVecCalc<Scalar>::getValidParameters() const
140 {
141  static RCP<Teuchos::ParameterList> validPL;
142  if (is_null(validPL)) {
143  RCP<Teuchos::ParameterList>
144  pl = Teuchos::parameterList();
145  Teuchos::setupVerboseObjectSublist(&*pl);
146  validPL = pl;
147  }
148  return (validPL);
149 }
150 
151 } // namespace Rythmos
152 
153 #endif // Rythmos_IMPLICITBDF_STEPPER_ERR_WT_VEC_CALC_H
154