Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_TimeStepControlStrategyConstant.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 "Tempus_TimeStepControl.hpp"
14 
15 
16 namespace Tempus_Unit_Test {
17 
18 using Teuchos::RCP;
19 using Teuchos::rcp;
20 using Teuchos::rcp_const_cast;
21 using Teuchos::rcp_dynamic_cast;
23 using Teuchos::sublist;
24 
25 
26 // ************************************************************
27 // ************************************************************
28 TEUCHOS_UNIT_TEST(TimeStepControlStrategyConstant, Default_Construction)
29 {
31  TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
32 
33  // Test the get functions (i.e., defaults).
34  TEUCHOS_TEST_FOR_EXCEPT(tscs->getStrategyType() != "Constant");
35  TEUCHOS_TEST_FOR_EXCEPT(tscs->getStepType() != "Constant");
36  TEUCHOS_TEST_FOR_EXCEPT(tscs->getName() != "Constant");
37  TEST_FLOATING_EQUALITY (tscs->getConstantTimeStep(), 0.0, 1.0e-14);
38 
39  // Test the set functions.
40  tscs->setConstantTimeStep(0.989); tscs->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
41 
42  TEST_FLOATING_EQUALITY (tscs->getConstantTimeStep(), 0.989, 1.0e-14);
43 
44 }
45 
46 
47 // ************************************************************
48 // ************************************************************
49 TEUCHOS_UNIT_TEST(TimeStepControlStrategyConstant, Full_Construction)
50 {
52  0.123, "Full_Construction_Test"));
53  TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
54 
55  TEUCHOS_TEST_FOR_EXCEPT(tscs->getStrategyType() != "Constant");
56  TEUCHOS_TEST_FOR_EXCEPT(tscs->getStepType() != "Constant");
57  TEUCHOS_TEST_FOR_EXCEPT(tscs->getName() != "Full_Construction_Test");
58  TEST_FLOATING_EQUALITY (tscs->getConstantTimeStep(), 0.123, 1.0e-14);
59 }
60 
61 
62 // ************************************************************
63 // ************************************************************
64 TEUCHOS_UNIT_TEST(TimeStepControlStrategyConstant, Create_Construction)
65 {
66  auto pl = Tempus::getTimeStepControlStrategyConstantPL<double>();
67 
68  // Set strategy parameters.
69  pl->set<double>("Time Step", 0.02);
70 
71  auto tscsc = Tempus::createTimeStepControlStrategyConstant<double>(pl);
72  TEUCHOS_TEST_FOR_EXCEPT(!tscsc->isInitialized());
73 
74  TEST_FLOATING_EQUALITY (tscsc->getConstantTimeStep(), 0.02, 1.0e-14);
75 }
76 
77 
78 // ************************************************************
79 // ************************************************************
80 TEUCHOS_UNIT_TEST(TimeStepControlStrategyConstant, setNextTimeStep)
81 {
83  TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
84 
85  double initTime = 1.0;
86  int initIndex = -100;
87 
88  // Setup the SolutionHistory --------------------------------
89  auto model = rcp(new Tempus_Test::SinCosModel<double>());
90  auto inArgsIC = model->getNominalValues();
91  auto icSolution = rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
92  auto icState = Tempus::createSolutionStateX<double>(icSolution);
93  auto solutionHistory = rcp(new Tempus::SolutionHistory<double>());
94  solutionHistory->addState(icState);
95  solutionHistory->getCurrentState()->setTimeStep(0.9);
96  solutionHistory->getCurrentState()->setTime(initTime);
97  solutionHistory->getCurrentState()->setIndex(initIndex);
98 
99  // Setup the TimeStepControl --------------------------------
100  auto tsc = rcp(new Tempus::TimeStepControl<double>());
101  tsc->setTimeStepControlStrategy(tscs);
102  tsc->setInitTime(initTime);
103  tsc->setFinalTime(100.0);
104  tsc->setMinTimeStep(0.01);
105  tsc->setInitTimeStep(0.02);
106  tsc->setMaxTimeStep(0.05);
107  tsc->setInitIndex(initIndex);
108  tsc->setFinalIndex(100);
109  tsc->initialize();
110  TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
112 
113  // ** Mock Timestep ** //
114  solutionHistory->initWorkingState();
115 
116  tsc->setNextTimeStep(solutionHistory, status);
117  // ** Mock Timestep ** //
118 
119  auto workingState = solutionHistory->getWorkingState();
120  TEST_FLOATING_EQUALITY( workingState->getTimeStep(), 0.02, 1.0e-14);
121  TEST_FLOATING_EQUALITY( workingState->getTime(), 1.02, 1.0e-14);
122 }
123 
124 
125 // ************************************************************
126 // ************************************************************
127 TEUCHOS_UNIT_TEST(TimeStepControlStrategyConstant, getValidParameters)
128 {
130 
131  auto pl = tscsc->getValidParameters();
132 
133  TEST_COMPARE ( pl->get<std::string>("Strategy Type"), ==,"Constant");
134  TEST_FLOATING_EQUALITY( pl->get<double>("Time Step"), 0.0, 1.0e-14);
135 
136  { // Ensure that parameters are "used", excluding sublists.
137  std::ostringstream unusedParameters;
138  pl->unused(unusedParameters);
139  TEST_COMPARE ( unusedParameters.str(), ==, "");
140  }
141 }
142 
143 
144 } // namespace Tempus_Unit_Test
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Status
Status for the Integrator, the Stepper and the SolutionState.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepControlStrategy class for TimeStepControl.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)