Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_Stepper_ErrorNorm.cpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
11 
12 #include "Thyra_DefaultSpmdVectorSpace.hpp"
13 
15 #include "Tempus_Stepper_ErrorNorm.hpp"
16 
17 #include "../TestModels/DahlquistTestModel.hpp"
18 
19 namespace Tempus_Unit_Test {
20 
21 // ************************************************************
22 // ************************************************************
23 TEUCHOS_UNIT_TEST(Stepper_ErrorNorm, computeWRMSNorm)
24 {
25  int N = 3;
27  Thyra::defaultSpmdVectorSpace<double>(N);
28  auto x = Thyra::createMember(xSpace);
29  auto xNext = Thyra::createMember(xSpace);
30  auto eVec = Thyra::createMember(xSpace);
31 
32  auto tol = Tempus::numericalTol<double>();
33  auto eNorm = Teuchos::rcp(new Tempus::Stepper_ErrorNorm<double>(tol, 0.0));
34 
35  Thyra::assign(x.ptr(), 0.0);
36  Thyra::assign(xNext.ptr(), 0.0);
37  Thyra::assign(eVec.ptr(), 0.0);
38  double rmsNorm = eNorm->computeWRMSNorm(x, xNext, eVec);
39  TEST_FLOATING_EQUALITY(rmsNorm, 0.0, 1.0e-12);
40 
41  Thyra::assign(x.ptr(), 1.0);
42  Thyra::assign(xNext.ptr(), 1.0 + tol);
43  Thyra::assign(eVec.ptr(), tol);
44  rmsNorm = eNorm->computeWRMSNorm(x, xNext, eVec);
45  TEST_FLOATING_EQUALITY(rmsNorm, 1.0 / std::sqrt(N), 1.0e-12);
46 }
47 
48 // ************************************************************
49 // ************************************************************
50 TEUCHOS_UNIT_TEST(Stepper_ErrorNorm, errorNorm)
51 {
53  Thyra::defaultSpmdVectorSpace<double>(3);
54  auto x = Thyra::createMember(xSpace);
55 
56  auto tol = Tempus::numericalTol<double>();
57  auto eNorm = Teuchos::rcp(new Tempus::Stepper_ErrorNorm<double>(tol, tol));
58 
59  Thyra::assign(x.ptr(), 0.0);
60  double norm = eNorm->errorNorm(x);
61  TEST_FLOATING_EQUALITY(norm, tol, 1.0e-12);
62 
63  Thyra::assign(x.ptr(), 1.0);
64  norm = eNorm->errorNorm(x);
65  TEST_FLOATING_EQUALITY(norm, 1.0 / (2.0 * tol), 1.0e-12);
66 }
67 
68 } // namespace Tempus_Unit_Test
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Stepper_ErrorNorm provides error norm calcualtions for variable time stepping.