9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
13 #include "Thyra_VectorStdOps.hpp"
15 #include "Tempus_IntegratorBasic.hpp"
16 #include "Tempus_IntegratorObserverLogging.hpp"
17 #include "Tempus_IntegratorObserverComposite.hpp"
19 #include "Tempus_StepperExplicitRK.hpp"
21 #include "Tempus_StepperRKObserverLogging.hpp"
22 #include "Tempus_StepperRKObserverComposite.hpp"
24 #include "../TestModels/SinCosModel.hpp"
25 #include "../TestModels/VanDerPolModel.hpp"
26 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
30 namespace Tempus_Test {
34 using Teuchos::ParameterList;
35 using Teuchos::sublist;
36 using Teuchos::getParametersFromXmlFile;
49 RCP<ParameterList> pList =
50 getParametersFromXmlFile(
"Tempus_Observer_SinCos.xml");
53 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
54 RCP<SinCosModel<double> > model =
58 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
59 RCP<Tempus::IntegratorBasic<double> > integrator =
60 Tempus::integratorBasic<double>(pl, model);
62 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs =
64 integrator->setObserver(loggingObs);
67 bool integratorStatus = integrator->advanceTime();
68 TEST_ASSERT(integratorStatus)
71 double time = integrator->getTime();
72 double timeFinal = pl->sublist(
"Demo Integrator")
73 .sublist(
"Time Step Control").get<
double>(
"Final Time");
74 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
77 std::map<std::string,int> refCounters;
78 std::list<std::string> refOrder;
80 refCounters[loggingObs->nameObserveStartIntegrator_ ] = 1;
81 refCounters[loggingObs->nameObserveStartTimeStep_ ] = 10;
82 refCounters[loggingObs->nameObserveNextTimeStep_ ] = 10;
83 refCounters[loggingObs->nameObserveBeforeTakeStep_ ] = 10;
84 refCounters[loggingObs->nameObserveAfterTakeStep_ ] = 10;
85 refCounters[loggingObs->nameObserveAfterCheckTimeStep_] = 10;
86 refCounters[loggingObs->nameObserveEndTimeStep_ ] = 10;
87 refCounters[loggingObs->nameObserveEndIntegrator_ ] = 1;
89 refOrder.push_back(loggingObs->nameObserveStartIntegrator_ );
90 for (
int i=0 ; i<10; ++i) {
91 refOrder.push_back(loggingObs->nameObserveStartTimeStep_ );
92 refOrder.push_back(loggingObs->nameObserveNextTimeStep_ );
93 refOrder.push_back(loggingObs->nameObserveBeforeTakeStep_ );
94 refOrder.push_back(loggingObs->nameObserveAfterTakeStep_ );
95 refOrder.push_back(loggingObs->nameObserveAfterCheckTimeStep_);
96 refOrder.push_back(loggingObs->nameObserveEndTimeStep_ );
98 refOrder.push_back(loggingObs->nameObserveEndIntegrator_ );
100 const std::map<std::string,int>& counters = *(loggingObs->getCounters());
101 const std::list<std::string>& order = *(loggingObs->getOrder());
105 counters.find(loggingObs->nameObserveStartIntegrator_ )->second,
106 refCounters.find(loggingObs->nameObserveStartIntegrator_ )->second);
108 counters.find(loggingObs->nameObserveStartTimeStep_ )->second,
109 refCounters.find(loggingObs->nameObserveStartTimeStep_ )->second);
111 counters.find(loggingObs->nameObserveNextTimeStep_ )->second,
112 refCounters.find(loggingObs->nameObserveNextTimeStep_ )->second);
114 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second,
115 refCounters.find(loggingObs->nameObserveBeforeTakeStep_ )->second);
117 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second,
118 refCounters.find(loggingObs->nameObserveAfterTakeStep_ )->second);
120 counters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second,
121 refCounters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second);
123 counters.find(loggingObs->nameObserveEndTimeStep_ )->second,
124 refCounters.find(loggingObs->nameObserveEndTimeStep_ )->second);
126 counters.find(loggingObs->nameObserveEndIntegrator_ )->second,
127 refCounters.find(loggingObs->nameObserveEndIntegrator_ )->second);
129 TEUCHOS_ASSERT(order.size() == refOrder.size());
130 std::list<std::string>::const_iterator orderIter = order.begin();
131 std::list<std::string>::const_iterator refOrderIter = refOrder.begin();
132 for ( ; orderIter != order.end(); ++orderIter,++refOrderIter) {
134 TEST_EQUALITY(*orderIter, *refOrderIter);
138 loggingObs->resetLogCounters();
140 counters.find(loggingObs->nameObserveStartIntegrator_ )->second, 0);
142 counters.find(loggingObs->nameObserveStartTimeStep_ )->second, 0);
144 counters.find(loggingObs->nameObserveNextTimeStep_ )->second, 0);
146 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second, 0);
148 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second, 0);
150 counters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second, 0);
152 counters.find(loggingObs->nameObserveEndTimeStep_ )->second, 0);
154 counters.find(loggingObs->nameObserveEndIntegrator_ )->second, 0);
155 TEST_EQUALITY(order.size(), 0);
157 Teuchos::TimeMonitor::summarize();
164 RCP<ParameterList> pList =
165 getParametersFromXmlFile(
"Tempus_Observer_SinCos.xml");
168 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
169 RCP<SinCosModel<double> > model =
173 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
174 RCP<Tempus::IntegratorBasic<double> > integrator =
175 Tempus::integratorBasic<double>(pl, model);
177 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs =
181 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs2 =
184 RCP<Tempus::IntegratorObserverComposite<double> > compObs =
187 compObs->addObserver(loggingObs);
188 compObs->addObserver(loggingObs2);
190 compObs->observeStartIntegrator(*integrator);
191 compObs->observeStartTimeStep(*integrator);
192 compObs->observeBeforeTakeStep(*integrator);
193 compObs->observeAfterTakeStep(*integrator);
194 compObs->observeAfterCheckTimeStep(*integrator);
195 compObs->observeEndTimeStep(*integrator);
198 for (
int i=0 ; i<10; ++i) {
199 compObs->observeStartTimeStep(*integrator);
200 compObs->observeBeforeTakeStep(*integrator);
201 compObs->observeAfterTakeStep(*integrator);
202 compObs->observeAfterCheckTimeStep(*integrator);
203 compObs->observeEndTimeStep(*integrator);
205 compObs->observeEndIntegrator(*integrator);
207 const std::map<std::string,int>& counters = *(loggingObs->getCounters());
210 counters.find(loggingObs->nameObserveStartIntegrator_ )->second, 1);
212 counters.find(loggingObs->nameObserveStartTimeStep_ )->second,11);
214 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second,11);
216 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second,11);
218 counters.find(loggingObs->nameObserveAfterCheckTimeStep_ )->second,11);
220 counters.find(loggingObs->nameObserveEndTimeStep_ )->second,11);
222 counters.find(loggingObs->nameObserveEndIntegrator_ )->second, 1);
224 counters.find(loggingObs2->nameObserveStartIntegrator_ )->second, 1);
226 counters.find(loggingObs2->nameObserveStartTimeStep_ )->second,11);
228 counters.find(loggingObs2->nameObserveBeforeTakeStep_ )->second,11);
230 counters.find(loggingObs2->nameObserveAfterTakeStep_ )->second,11);
232 counters.find(loggingObs2->nameObserveAfterCheckTimeStep_)->second,11);
234 counters.find(loggingObs2->nameObserveEndTimeStep_ )->second,11);
236 counters.find(loggingObs2->nameObserveEndIntegrator_ )->second, 1);
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
This observer logs calls to observer functions. This observer simply logs and counts the calls to eac...
TEUCHOS_UNIT_TEST(BackwardEuler, SinCos_ASA)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
This observer is a composite observer,.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...