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