Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_ERK_ForwardEuler.cpp
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 
10 
12 
13 #include "../TestModels/SinCosModel.hpp"
14 #include "../TestModels/DahlquistTestModel.hpp"
15 
16 
17 namespace Tempus_Unit_Test {
18 
19 using Teuchos::RCP;
20 using Teuchos::rcp;
21 using Teuchos::rcp_const_cast;
22 using Teuchos::rcp_dynamic_cast;
23 
24 
25 // ************************************************************
26 // ************************************************************
27 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, Default_Construction)
28 {
29  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
31 
32  // Test stepper properties.
33  TEUCHOS_ASSERT(stepper->getOrder() == 1);
34  const auto rk_fe = stepper->getTableau();
35 
36  TEUCHOS_ASSERT( rk_fe->isTVD() );
37  TEUCHOS_ASSERT( rk_fe->getTVDCoeff() == 1 );
38 }
39 
40 
41 // ************************************************************
42 // ************************************************************
43 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, StepperFactory_Construction)
44 {
45  auto model = rcp(new Tempus_Test::SinCosModel<double>());
46  testFactoryConstruction("RK Forward Euler", model);
47 }
48 
49 
50 // ************************************************************
51 // ************************************************************
52 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, AppAction)
53 {
54  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
55  auto model = rcp(new Tempus_Test::SinCosModel<double>());
56  testRKAppAction(stepper, model, out, success);
57 }
58 
59 
60 // ************************************************************
61 // ************************************************************
62 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, FSAL)
63 {
64  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
66  model = rcp(new Tempus_Test::DahlquistTestModel<double>(-1.0, true));
67 
68  stepper->setModel(model);
69  stepper->setICConsistency("Consistent");
70  stepper->setUseFSAL(true);
71  stepper->initialize();
72 
73  // Create a SolutionHistory.
74  auto solutionHistory = Tempus::createSolutionHistoryME(model);
75 
76  // Take one time step.
77  stepper->setInitialConditions(solutionHistory);
78  solutionHistory->initWorkingState();
79  double dt = 1.0;
80  solutionHistory->getWorkingState()->setTimeStep(dt);
81  solutionHistory->getWorkingState()->setTime(dt);
82  stepper->takeStep(solutionHistory);
83 
84  // Test solution.
85  const double relTol = 1.0e-14;
86 
87  // ICs
88  auto currentState = solutionHistory->getCurrentState();
89  const double x_0 = get_ele(*(currentState->getX()), 0);
90  const double xDot_0 = get_ele(*(currentState->getXDot()), 0);
91  TEST_FLOATING_EQUALITY(x_0, 1.0, relTol);
92  TEST_FLOATING_EQUALITY(xDot_0, -1.0, relTol);
93  TEST_ASSERT(std::abs(currentState->getTime()) < relTol);
94 
95  // After one step.
96  auto workingState = solutionHistory->getWorkingState();
97  const double x_1 = get_ele(*(workingState->getX()), 0);
98  const double xDot_1 = get_ele(*(workingState->getXDot()), 0);
99  //std::cout << "xDot_1 = " << xDot_1 << std::endl;
100  TEST_ASSERT(std::abs(x_1 ) < relTol);
101  TEST_ASSERT(std::abs(xDot_1) < relTol);
102  TEST_FLOATING_EQUALITY(workingState->getTime(), 1.0, relTol);
103 
104 }
105 
106 
107 } // namespace Tempus_Test
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
The classic Dahlquist Test Problem.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
#define TEST_ASSERT(v1)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Forward Euler Runge-Kutta Butcher Tableau.
#define TEUCHOS_ASSERT(assertion_test)