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 
11 #include "../TestModels/DahlquistTestModel.hpp"
12 
13 namespace Tempus_Unit_Test {
14 
15 using Teuchos::RCP;
16 using Teuchos::rcp;
17 using Teuchos::rcp_const_cast;
18 using Teuchos::rcp_dynamic_cast;
19 
20 // ************************************************************
21 // ************************************************************
22 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, Default_Construction)
23 {
24  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
26 
27  // Test stepper properties.
28  TEUCHOS_ASSERT(stepper->getOrder() == 1);
29  const auto rk_fe = stepper->getTableau();
30 
31  TEUCHOS_ASSERT(rk_fe->isTVD());
32  TEUCHOS_ASSERT(rk_fe->getTVDCoeff() == 1);
33 }
34 
35 // ************************************************************
36 // ************************************************************
37 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, StepperFactory_Construction)
38 {
39  auto model = rcp(new Tempus_Test::SinCosModel<double>());
40  testFactoryConstruction("RK Forward Euler", model);
41 }
42 
43 // ************************************************************
44 // ************************************************************
45 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, AppAction)
46 {
47  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
48  auto model = rcp(new Tempus_Test::SinCosModel<double>());
49  testRKAppAction(stepper, model, out, success);
50 }
51 
52 // ************************************************************
53 // ************************************************************
54 TEUCHOS_UNIT_TEST(ERK_ForwardEuler, FSAL)
55 {
56  auto stepper = rcp(new Tempus::StepperERK_ForwardEuler<double>());
59 
60  stepper->setModel(model);
61  stepper->setICConsistency("Consistent");
62  stepper->setUseFSAL(true);
63  stepper->initialize();
64 
65  // Create a SolutionHistory.
66  auto solutionHistory = Tempus::createSolutionHistoryME(model);
67 
68  // Take one time step.
69  stepper->setInitialConditions(solutionHistory);
70  solutionHistory->initWorkingState();
71  double dt = 1.0;
72  solutionHistory->getWorkingState()->setTimeStep(dt);
73  solutionHistory->getWorkingState()->setTime(dt);
74  stepper->takeStep(solutionHistory);
75 
76  // Test solution.
77  const double relTol = 1.0e-14;
78 
79  // ICs
80  auto currentState = solutionHistory->getCurrentState();
81  const double x_0 = get_ele(*(currentState->getX()), 0);
82  const double xDot_0 = get_ele(*(currentState->getXDot()), 0);
83  TEST_FLOATING_EQUALITY(x_0, 1.0, relTol);
84  TEST_FLOATING_EQUALITY(xDot_0, -1.0, relTol);
85  TEST_ASSERT(std::abs(currentState->getTime()) < relTol);
86 
87  // After one step.
88  auto workingState = solutionHistory->getWorkingState();
89  const double x_1 = get_ele(*(workingState->getX()), 0);
90  const double xDot_1 = get_ele(*(workingState->getXDot()), 0);
91  // out << "xDot_1 = " << xDot_1 << std::endl;
92  TEST_ASSERT(std::abs(x_1) < relTol);
93  TEST_ASSERT(std::abs(xDot_1) < relTol);
94  TEST_FLOATING_EQUALITY(workingState->getTime(), 1.0, relTol);
95 }
96 
97 } // namespace Tempus_Unit_Test
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.
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.
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.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double >> &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
#define TEUCHOS_ASSERT(assertion_test)