Tempus  Version of the Day
Time Integration
Tempus_Stepper_ErrorNorm_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_Stepper_ErrorNorm_impl_hpp
10 #define Tempus_Stepper_ErrorNorm_impl_hpp
11 
12 #include "Teuchos_ScalarTraitsDecl.hpp"
13 #include "Thyra_DefaultSerialDenseLinearOpWithSolve_decl.hpp"
14 #include "Thyra_MultiVectorStdOps_decl.hpp"
15 #include "Thyra_VectorSpaceBase_decl.hpp"
16 #include "Thyra_VectorStdOps_decl.hpp"
17 namespace Tempus {
18 
19 template<class Scalar>
20 Stepper_ErrorNorm<Scalar>::Stepper_ErrorNorm() : relTol_(1.0e-4), abssTol_(1.0e-4)
21 {}
22 
23 template<class Scalar>
24 Stepper_ErrorNorm<Scalar>::Stepper_ErrorNorm(const Scalar relTol, const Scalar absTol) :
25  relTol_(relTol), abssTol_(absTol)
26 {}
27 
28 template<class Scalar>
30 computeWRMSNorm(const Teuchos::RCP<const Thyra::VectorBase<Scalar>> &x,
31  const Teuchos::RCP<const Thyra::VectorBase<Scalar>> &xNext,
32  const Teuchos::RCP<const Thyra::VectorBase<Scalar>> &err)
33 {
34  if (errorWeightVector_ == Teuchos::null)
35  errorWeightVector_ = Thyra::createMember(x->space());
36 
37  if (u_ == Teuchos::null)
38  u_ = Thyra::createMember(x->space());
39 
40  if (uNext_ == Teuchos::null)
41  uNext_ = Thyra::createMember(x->space());
42 
43  // Compute: Atol + max(|u^n|, |u^{n+1}| ) * Rtol
44  Thyra::abs(*x, u_.ptr());
45  Thyra::abs(*xNext, uNext_.ptr());
46  Thyra::pair_wise_max_update(relTol_, *u_, uNext_.ptr());
47  Thyra::add_scalar(abssTol_, uNext_.ptr());
48 
49  Thyra::assign(errorWeightVector_.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
50  Thyra::ele_wise_divide(Teuchos::as<Scalar>(1.0), *err, *uNext_, errorWeightVector_.ptr());
51 
52  const auto space_dim = err->space()->dim();
53  Scalar err_norm = std::abs( Thyra::norm(*errorWeightVector_) / space_dim);
54  return err_norm;
55 }
56 
57 
58 template<class Scalar>
60 errorNorm(const Teuchos::RCP<const Thyra::VectorBase<Scalar>> &x)
61 {
62  if (scratchVector_ == Teuchos::null)
63  scratchVector_ = Thyra::createMember(x->space());
64 
65  Thyra::assign(scratchVector_.ptr(), *x); // | U |
66  Thyra::abs(*x, scratchVector_.ptr());
67  Thyra::Vt_S(scratchVector_.ptr(), relTol_);
68  Thyra::Vp_S(scratchVector_.ptr(), abssTol_);
69  Thyra::ele_wise_divide(Teuchos::as<Scalar>(1.0), *x, *scratchVector_, scratchVector_.ptr());
70  Scalar err = Thyra::norm_inf(*scratchVector_);
71  return err;
72 
73 }
74 
75 
76 }
77 
78 #endif
Scalar computeWRMSNorm(const Teuchos::RCP< const Thyra::VectorBase< Scalar >> &x, const Teuchos::RCP< const Thyra::VectorBase< Scalar >> &xNext, const Teuchos::RCP< const Thyra::VectorBase< Scalar >> &err)
Scalar errorNorm(const Teuchos::RCP< const Thyra::VectorBase< Scalar >> &x)