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 "../TestModels/SinCosModel.hpp"
20 #include "../TestModels/VanDerPolModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
25 namespace Tempus_Test {
29 using Teuchos::ParameterList;
30 using Teuchos::sublist;
31 using Teuchos::getParametersFromXmlFile;
43 RCP<ParameterList> pList =
44 getParametersFromXmlFile(
"Tempus_Observer_SinCos.xml");
47 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
48 RCP<SinCosModel<double> > model =
52 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
53 RCP<Tempus::IntegratorBasic<double> > integrator =
54 Tempus::integratorBasic<double>(pl, model);
56 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs =
58 integrator->setObserver(loggingObs);
61 bool integratorStatus = integrator->advanceTime();
62 TEST_ASSERT(integratorStatus)
65 double time = integrator->getTime();
66 double timeFinal = pl->sublist(
"Demo Integrator")
67 .sublist(
"Time Step Control").get<
double>(
"Final Time");
68 TEST_FLOATING_EQUALITY(time, timeFinal, 1.0e-14);
71 std::map<std::string,int> refCounters;
72 std::list<std::string> refOrder;
74 refCounters[loggingObs->nameObserveStartIntegrator_ ] = 1;
75 refCounters[loggingObs->nameObserveStartTimeStep_ ] = 10;
76 refCounters[loggingObs->nameObserveNextTimeStep_ ] = 10;
77 refCounters[loggingObs->nameObserveBeforeTakeStep_ ] = 10;
78 refCounters[loggingObs->nameObserveAfterTakeStep_ ] = 10;
79 refCounters[loggingObs->nameObserveAfterCheckTimeStep_] = 10;
80 refCounters[loggingObs->nameObserveEndTimeStep_ ] = 10;
81 refCounters[loggingObs->nameObserveEndIntegrator_ ] = 1;
83 refOrder.push_back(loggingObs->nameObserveStartIntegrator_ );
84 for (
int i=0 ; i<10; ++i) {
85 refOrder.push_back(loggingObs->nameObserveStartTimeStep_ );
86 refOrder.push_back(loggingObs->nameObserveNextTimeStep_ );
87 refOrder.push_back(loggingObs->nameObserveBeforeTakeStep_ );
88 refOrder.push_back(loggingObs->nameObserveAfterTakeStep_ );
89 refOrder.push_back(loggingObs->nameObserveAfterCheckTimeStep_);
90 refOrder.push_back(loggingObs->nameObserveEndTimeStep_ );
92 refOrder.push_back(loggingObs->nameObserveEndIntegrator_ );
94 const std::map<std::string,int>& counters = *(loggingObs->getCounters());
95 const std::list<std::string>& order = *(loggingObs->getOrder());
99 counters.find(loggingObs->nameObserveStartIntegrator_ )->second,
100 refCounters.find(loggingObs->nameObserveStartIntegrator_ )->second);
102 counters.find(loggingObs->nameObserveStartTimeStep_ )->second,
103 refCounters.find(loggingObs->nameObserveStartTimeStep_ )->second);
105 counters.find(loggingObs->nameObserveNextTimeStep_ )->second,
106 refCounters.find(loggingObs->nameObserveNextTimeStep_ )->second);
108 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second,
109 refCounters.find(loggingObs->nameObserveBeforeTakeStep_ )->second);
111 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second,
112 refCounters.find(loggingObs->nameObserveAfterTakeStep_ )->second);
114 counters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second,
115 refCounters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second);
117 counters.find(loggingObs->nameObserveEndTimeStep_ )->second,
118 refCounters.find(loggingObs->nameObserveEndTimeStep_ )->second);
120 counters.find(loggingObs->nameObserveEndIntegrator_ )->second,
121 refCounters.find(loggingObs->nameObserveEndIntegrator_ )->second);
123 TEUCHOS_ASSERT(order.size() == refOrder.size());
124 std::list<std::string>::const_iterator orderIter = order.begin();
125 std::list<std::string>::const_iterator refOrderIter = refOrder.begin();
126 for ( ; orderIter != order.end(); ++orderIter,++refOrderIter) {
128 TEST_EQUALITY(*orderIter, *refOrderIter);
132 loggingObs->resetLogCounters();
134 counters.find(loggingObs->nameObserveStartIntegrator_ )->second, 0);
136 counters.find(loggingObs->nameObserveStartTimeStep_ )->second, 0);
138 counters.find(loggingObs->nameObserveNextTimeStep_ )->second, 0);
140 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second, 0);
142 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second, 0);
144 counters.find(loggingObs->nameObserveAfterCheckTimeStep_)->second, 0);
146 counters.find(loggingObs->nameObserveEndTimeStep_ )->second, 0);
148 counters.find(loggingObs->nameObserveEndIntegrator_ )->second, 0);
149 TEST_EQUALITY(order.size(), 0);
151 Teuchos::TimeMonitor::summarize();
157 RCP<ParameterList> pList =
158 getParametersFromXmlFile(
"Tempus_Observer_SinCos.xml");
161 RCP<ParameterList> scm_pl = sublist(pList,
"SinCosModel",
true);
162 RCP<SinCosModel<double> > model =
166 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
167 RCP<Tempus::IntegratorBasic<double> > integrator =
168 Tempus::integratorBasic<double>(pl, model);
170 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs =
174 RCP<Tempus::IntegratorObserverLogging<double> > loggingObs2 =
177 RCP<Tempus::IntegratorObserverComposite<double> > compObs =
180 compObs->addObserver(loggingObs);
181 compObs->addObserver(loggingObs2);
183 compObs->observeStartIntegrator(*integrator);
184 compObs->observeStartTimeStep(*integrator);
185 compObs->observeBeforeTakeStep(*integrator);
186 compObs->observeAfterTakeStep(*integrator);
187 compObs->observeAfterCheckTimeStep(*integrator);
188 compObs->observeEndTimeStep(*integrator);
191 for (
int i=0 ; i<10; ++i) {
192 compObs->observeStartTimeStep(*integrator);
193 compObs->observeBeforeTakeStep(*integrator);
194 compObs->observeAfterTakeStep(*integrator);
195 compObs->observeAfterCheckTimeStep(*integrator);
196 compObs->observeEndTimeStep(*integrator);
198 compObs->observeEndIntegrator(*integrator);
200 const std::map<std::string,int>& counters = *(loggingObs->getCounters());
203 counters.find(loggingObs->nameObserveStartIntegrator_ )->second, 1);
205 counters.find(loggingObs->nameObserveStartTimeStep_ )->second,11);
207 counters.find(loggingObs->nameObserveBeforeTakeStep_ )->second,11);
209 counters.find(loggingObs->nameObserveAfterTakeStep_ )->second,11);
211 counters.find(loggingObs->nameObserveAfterCheckTimeStep_ )->second,11);
213 counters.find(loggingObs->nameObserveEndTimeStep_ )->second,11);
215 counters.find(loggingObs->nameObserveEndIntegrator_ )->second, 1);
217 counters.find(loggingObs2->nameObserveStartIntegrator_ )->second, 1);
219 counters.find(loggingObs2->nameObserveStartTimeStep_ )->second,11);
221 counters.find(loggingObs2->nameObserveBeforeTakeStep_ )->second,11);
223 counters.find(loggingObs2->nameObserveAfterTakeStep_ )->second,11);
225 counters.find(loggingObs2->nameObserveAfterCheckTimeStep_)->second,11);
227 counters.find(loggingObs2->nameObserveEndTimeStep_ )->second,11);
229 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...