12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_StepperFactory.hpp"
17 #include "Tempus_TimeStepControl.hpp"
20 #include "../TestModels/SinCosModel.hpp"
21 #include "../TestModels/DahlquistTestModel.hpp"
22 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
27 namespace Tempus_Unit_Test {
31 using Teuchos::rcp_const_cast;
32 using Teuchos::rcp_dynamic_cast;
34 using Teuchos::sublist;
35 using Teuchos::getParametersFromXmlFile;
49 TEUCHOS_TEST_FOR_EXCEPT(tscs->getReductFactor() != 0.5);
50 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMinEta() != 0.0);
51 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMaxEta() != 1.0e+16);
54 tscs->setAmplFactor(1.33); tscs->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
55 tscs->setReductFactor(0.75); tscs->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
56 tscs->setMinEta(0.01); tscs->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
57 tscs->setMaxEta(0.05); tscs->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
59 TEUCHOS_TEST_FOR_EXCEPT(tscs->getAmplFactor() != 1.33);
60 TEUCHOS_TEST_FOR_EXCEPT(tscs->getReductFactor() != 0.75);
61 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMinEta() != 0.01);
62 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMaxEta() != 0.05);
71 1.33, 0.75, 0.01, 0.05));
77 TEUCHOS_TEST_FOR_EXCEPT(tscs->getReductFactor() != 0.75);
78 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMinEta() != 0.01);
79 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMaxEta() != 0.05);
87 auto pl = Tempus::getTimeStepControlStrategyBasicVS_PL<double>();
89 pl->set<
double>(
"Amplification Factor", 1.33);
90 pl->set<
double>(
"Reduction Factor" , 0.75);
91 pl->set<
double>(
"Minimum Value Monitoring Function", 0.01);
92 pl->set<
double>(
"Maximum Value Monitoring Function", 0.05);
94 auto tscs = Tempus::createTimeStepControlStrategyBasicVS<double>(pl);
99 TEUCHOS_TEST_FOR_EXCEPT(tscs->getReductFactor() != 0.75);
100 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMinEta() != 0.01);
101 TEUCHOS_TEST_FOR_EXCEPT(tscs->getMaxEta() != 0.05);
110 tscs->setAmplFactor(1.1);
111 tscs->setReductFactor(0.5);
112 tscs->setMinEta(0.01);
113 tscs->setMaxEta(0.05);
119 tsc->setTimeStepControlStrategy(tscs);
120 tsc->setInitTime(0.0);
121 tsc->setFinalTime(10.0);
122 tsc->setMinTimeStep (0.01);
123 tsc->setInitTimeStep(0.1);
124 tsc->setMaxTimeStep (1.0);
125 tsc->setFinalIndex(100);
132 auto inArgsIC = model->getNominalValues();
134 auto icState = Tempus::createSolutionStateX<double>(icSolution);
139 solutionHistory->addState(icState);
140 solutionHistory->getCurrentState()->setTimeStep(0.5);
141 solutionHistory->getCurrentState()->setTime(0.0);
142 solutionHistory->getCurrentState()->setIndex(0);
145 for (
int i = 0; i < 2; i++) {
146 solutionHistory->initWorkingState();
148 tsc->setNextTimeStep(solutionHistory, status);
151 auto currentState = solutionHistory->getCurrentState();
152 auto workingState = solutionHistory->getWorkingState();
153 auto xN = workingState->getX();
154 Thyra::Vp_S(xN.ptr(), 1.0);
156 workingState->computeNorms(currentState);
159 solutionHistory->promoteWorkingState();
164 auto currentState = solutionHistory->getCurrentState();
171 solutionHistory->clear();
172 solutionHistory->addState(icState);
173 solutionHistory->getCurrentState()->setTimeStep(0.5);
174 solutionHistory->getCurrentState()->setTime(0.0);
175 solutionHistory->getCurrentState()->setIndex(0);
178 for (
int i = 0; i < 2; i++) {
179 solutionHistory->initWorkingState();
181 tsc->setNextTimeStep(solutionHistory, status);
184 auto currentState = solutionHistory->getCurrentState();
185 auto workingState = solutionHistory->getWorkingState();
186 auto xN = workingState->getX();
187 Thyra::Vp_S(xN.ptr(), 0.0);
189 workingState->computeNorms(currentState);
192 solutionHistory->promoteWorkingState();
197 auto currentState = solutionHistory->getCurrentState();
210 auto pl = tscs->getValidParameters();
212 TEST_COMPARE ( pl->get<std::string>(
"Strategy Type"), ==,
"Basic VS");
219 std::ostringstream unusedParameters;
220 pl->unused(unusedParameters);
StepControlStrategy class for TimeStepControl.
The classic Dahlquist Test Problem.
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
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...
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)