Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tempus_StepperSubcycling_impl.hpp
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
9#ifndef Tempus_StepperSubcycling_impl_hpp
10#define Tempus_StepperSubcycling_impl_hpp
11
12#include "Thyra_VectorStdOps.hpp"
13
14#include "Tempus_StepperForwardEuler.hpp"
18#include "Tempus_IntegratorObserverSubcycling.hpp"
19#include "Tempus_IntegratorObserverNoOp.hpp"
20
21
22namespace Tempus {
23
24
25template<class Scalar>
27{
28 using Teuchos::RCP;
29 using Teuchos::ParameterList;
30
31 this->setStepperName( "Subcycling");
32 this->setStepperType( "Subcycling");
33 this->setUseFSAL( false);
34 this->setICConsistency( "None");
35 this->setICConsistencyCheck( false);
36
37 this->setAppAction(Teuchos::null);
38 scIntegrator_ = Teuchos::rcp(new IntegratorBasic<Scalar>());
39
40 scIntegrator_->setObserver(
41 Teuchos::rcp(new IntegratorObserverNoOp<Scalar>()));
42
43 RCP<ParameterList> tempusPL =
44 Teuchos::rcp_const_cast<Teuchos::ParameterList> (
45 scIntegrator_->getValidParameters());
46
47 { // Set default subcycling Stepper to Forward Euler.
48 tempusPL->sublist("Default Integrator")
49 .set("Stepper Name", "Default Subcycling Stepper");
50 RCP<ParameterList> stepperPL = Teuchos::parameterList();
51 stepperPL->set("Stepper Type", "Forward Euler");
52 tempusPL->set("Default Subcycling Stepper", *stepperPL);
53
54 auto stepperFE = Teuchos::rcp(new StepperForwardEuler<Scalar>());
55 setSubcyclingStepper(stepperFE);
56 }
57
58 // Keep the default SolutionHistory settings:
59 // * 'Storage Type' = "Undo"
60 // * 'Storage Limit' = 2
61 // Also
62 // * No checkpointing within the subcycling, but can restart from
63 // failed subcycle step.
64
65 // Keep the default TimeStepControl settings for subcycling:
66 // * Finish exactly on the full timestep.
67 // * No solution output during the subcycling.
68 // * Variable time step size.
69 // Set the default initial time step size.
70 {
71 tempusPL->sublist("Default Integrator")
72 .sublist("Time Step Control")
73 .set("Initial Time Step", std::numeric_limits<Scalar>::max());
74 }
75
76 scIntegrator_->setTimeStepControl();
77 this->setSubcyclingPrintDtChanges(false);
78
79}
80
81
82template<class Scalar>
84 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel,
85 const Teuchos::RCP<IntegratorBasic<Scalar> >& scIntegrator,
86 bool useFSAL,
87 std::string ICConsistency,
88 bool ICConsistencyCheck,
89 const Teuchos::RCP<StepperSubcyclingAppAction<Scalar> >& stepperSCAppAction)
90{
91 this->setStepperName( "Subcycling");
92 this->setStepperType( "Subcycling");
93 this->setUseFSAL( useFSAL);
94 this->setICConsistency( ICConsistency);
95 this->setICConsistencyCheck( ICConsistencyCheck);
96 this->setAppAction(stepperSCAppAction);
97 scIntegrator_ = scIntegrator;
98 this->setSubcyclingPrintDtChanges(false);
99
100 if (appModel != Teuchos::null) {
101 this->setModel(appModel);
102 this->initialize();
103 }
104}
105
106template<class Scalar>
108 Teuchos::RCP<Stepper<Scalar> > stepper)
109{
110 scIntegrator_->setStepper(stepper);
111 this->isInitialized_ = false;
112}
113
114
115template<class Scalar>
117{
118 scIntegrator_->getNonConstTimeStepControl()->setMinTimeStep(MinTimeStep);
119 this->isInitialized_ = false;
120}
121
122
123template<class Scalar>
125{
126 scIntegrator_->getNonConstTimeStepControl()->setInitTimeStep(InitTimeStep);
127 this->isInitialized_ = false;
128}
129
130
131template<class Scalar>
133{
134 scIntegrator_->getNonConstTimeStepControl()->setMaxTimeStep(MaxTimeStep);
135 this->isInitialized_ = false;
136}
137
138
139template<class Scalar>
141{
142 scIntegrator_->getNonConstTimeStepControl()->setMaxFailures(MaxFailures);
143 this->isInitialized_ = false;
144}
145
146
147template<class Scalar>
149setSubcyclingMaxConsecFailures(int MaxConsecFailures)
150{
151 scIntegrator_->getNonConstTimeStepControl()->setMaxConsecFailures(MaxConsecFailures);
152 this->isInitialized_ = false;
153}
154
155
156template<class Scalar>
159{
160 scIntegrator_->setScreenOutputIndexInterval(i);
161 this->isInitialized_ = false;
162}
163
164
165template<class Scalar>
168{
169 scIntegrator_->setScreenOutputIndexList(s);
170 this->isInitialized_ = false;
171}
172
173
174template<class Scalar>
177 Teuchos::RCP<TimeStepControlStrategy<Scalar> > tscs)
178{
179 scIntegrator_->getNonConstTimeStepControl()->setTimeStepControlStrategy(tscs);
180 this->isInitialized_ = false;
181}
182
183
184template<class Scalar>
186 Teuchos::RCP<IntegratorObserver<Scalar> > obs)
187{
188 scIntegrator_->setObserver(obs);
189 this->isInitialized_ = false;
190}
191
192
193template<class Scalar>
195 bool printDtChanges)
196{
197 scIntegrator_->getNonConstTimeStepControl()->setPrintDtChanges(printDtChanges);
198 this->isInitialized_ = false;
199}
200
201
202template<class Scalar>
203Teuchos::RCP<const Stepper<Scalar> >
205{ return scIntegrator_->getStepper(); }
206
207
208template<class Scalar>
210{ return scIntegrator_->getTimeStepControl()->getMinTimeStep(); }
211
212
213template<class Scalar>
215{ return scIntegrator_->getTimeStepControl()->getInitTimeStep(); }
216
217
218template<class Scalar>
220{ return scIntegrator_->getTimeStepControl()->getMaxTimeStep(); }
221
222
223template<class Scalar>
225{ return scIntegrator_->getTimeStepControl()->getStepType(); }
226
227
228template<class Scalar>
230{ return scIntegrator_->getTimeStepControl()->getMaxFailures(); }
231
232
233template<class Scalar>
235{ return scIntegrator_->getTimeStepControl()->getMaxConsecFailures(); }
236
237
238template<class Scalar>
240{ return scIntegrator_->getScreenOutputIndexInterval(); }
241
242
243template<class Scalar>
245{ return scIntegrator_->getScreenOutputIndexListString(); }
246
247
248template<class Scalar>
249Teuchos::RCP<TimeStepControlStrategy<Scalar> >
251{ return scIntegrator_->getTimeStepControl()->getTimeStepControlStrategy(); }
252
253template<class Scalar>
254Teuchos::RCP<IntegratorObserver<Scalar> >
256{ return scIntegrator_->getObserver(); }
257
258template<class Scalar>
260{ return scIntegrator_->getTimeStepControl()->getPrintDtChanges(); }
261
262
263template<class Scalar>
265 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel)
266{
267 scIntegrator_->setModel(appModel);
268 this->isInitialized_ = false;
269}
270
271
272template<class Scalar>
274 const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel)
275{
276 setModel(appModel);
277 this->isInitialized_ = false;
278}
279
280
281template<class Scalar>
283 Teuchos::RCP<StepperSubcyclingAppAction<Scalar> > appAction)
284 {
285 if (appAction == Teuchos::null) {
286 // Create default appAction
287 stepperSCAppAction_ =
288 Teuchos::rcp(new StepperSubcyclingModifierDefault<Scalar>());
289 } else {
290 stepperSCAppAction_ = appAction;
291 }
292 this->isInitialized_ = false;
293}
294
295template<class Scalar>
297{
298 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
299 bool isValidSetup = true;
300
301 if ( !(this->getICConsistency() == "None" ||
302 this->getICConsistency() == "Zero" ||
303 this->getICConsistency() == "App" ||
304 this->getICConsistency() == "Consistent") ) {
305 isValidSetup = false;
306 *out << "The IC consistency does not have a valid value!\n"
307 << "('None', 'Zero', 'App' or 'Consistent')\n"
308 << " ICConsistency = " << this->getICConsistency() << "\n";
309 }
310 scIntegrator_->initialize();
311
312 if (stepperSCAppAction_ == Teuchos::null) {
313 isValidSetup = false;
314 *out << "The Subcycling AppAction is not set!\n";
315 }
316
317 if (isValidSetup)
318 this->isInitialized_ = true; // Only place it is set to true.
319 else
320 this->describe(*out, Teuchos::VERB_MEDIUM);
321}
322
323
324template<class Scalar>
326{ return scIntegrator_->getStepper()->isExplicit(); }
327
328
329template<class Scalar>
331{ return scIntegrator_->getStepper()->isImplicit(); }
332
333
334template<class Scalar>
336{ return scIntegrator_->getStepper()->isExplicitImplicit(); }
337
338
339template<class Scalar>
341{ return scIntegrator_->getStepper()->isOneStepMethod(); }
342
343
344template<class Scalar>
346{ return scIntegrator_->getStepper()->isMultiStepMethod(); }
347
348
349template<class Scalar>
351{ return scIntegrator_->getStepper()->getOrder(); }
352
353
354template<class Scalar>
356{ return scIntegrator_->getStepper()->getOrderMin(); }
357
358
359template<class Scalar>
361{ return scIntegrator_->getStepper()->getOrderMax(); }
362
363
364template<class Scalar>
366{ return scIntegrator_->getStepper()->getOrderODE(); }
367
368
369template<class Scalar>
371 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory) const
372{ return scIntegrator_->getStepper()->getInitTimeStep(solutionHistory); }
373
374
375template<class Scalar>
377 Teuchos::RCP<const Thyra::VectorBase<Scalar> > initialGuess)
378{
379 scIntegrator_->getStepper()->setInitialGuess(initialGuess);
380 this->isInitialized_ = false;
381}
382
383
384template<class Scalar>
386 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
387{
388 scIntegrator_->getStepper()->setInitialConditions(solutionHistory);
389 scIntegrator_->setSolutionHistory(solutionHistory);
390}
391
392
393template<class Scalar>
395 Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver)
396{
397 scIntegrator_->getStepper()->setSolver(solver);
398 this->isInitialized_ = false;
399}
400
401
402template<class Scalar>
403Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >
405{ return scIntegrator_->getStepper()->getSolver(); }
406
407
408template<class Scalar>
410 const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory)
411{
412 using Teuchos::RCP;
413
414 TEMPUS_FUNC_TIME_MONITOR("Tempus::StepperSubcycling::takeStep()");
415 {
416 TEUCHOS_TEST_FOR_EXCEPTION(solutionHistory->getNumStates() < 2,
417 std::logic_error,
418 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
419 "Need at least two SolutionStates for Subcycling.\n"
420 " Number of States = " << solutionHistory->getNumStates() << "\n"
421 "Try setting in \"Solution History\" \"Storage Type\" = \"Undo\"\n"
422 " or \"Storage Type\" = \"Static\" and \"Storage Limit\" = \"2\"\n");
423
424 RCP<StepperSubcycling<Scalar> > thisStepper = Teuchos::rcpFromRef(*this);
425 stepperSCAppAction_->execute(solutionHistory, thisStepper,
427 RCP<SolutionState<Scalar> > currentState=solutionHistory->getCurrentState();
428 RCP<SolutionState<Scalar> > workingState=solutionHistory->getWorkingState();
429
430 auto scTSC = scIntegrator_->getNonConstTimeStepControl();
431 scTSC->setInitTime (currentState->getTime());
432 scTSC->setInitIndex (0);
433 scTSC->setFinalTime (workingState->getTime());
434
435 auto subcyclingState = currentState->clone();
436 subcyclingState->setTimeStep(scTSC->getInitTimeStep());
437 subcyclingState->setOrder(scIntegrator_->getStepper()->getOrder());
438 subcyclingState->setIndex(0);
439 subcyclingState->setNFailures(0);
440 subcyclingState->setNRunningFailures(0);
441 subcyclingState->setNConsecutiveFailures(0);
442 subcyclingState->setOutput(false);
443 subcyclingState->setOutputScreen(false);
444
445 TEUCHOS_TEST_FOR_EXCEPTION(!subcyclingState->getIsSynced(),std::logic_error,
446 "Error - StepperSubcycling<Scalar>::takeStep(...)\n"
447 " Subcycling requires the the solution is synced!\n"
448 " (i.e., x, xDot, and xDotDot at the same time level.\n");
449
450 auto scSH = rcp(new Tempus::SolutionHistory<Scalar>());
451 scSH->setName("Subcycling States");
452 scSH->setStorageType(Tempus::STORAGE_TYPE_STATIC);
453 scSH->setStorageLimit(3);
454 scSH->addState(subcyclingState);
455
456 scIntegrator_->setSolutionHistory(scSH);
457
458 bool pass = scIntegrator_->advanceTime();
459
460 RCP<SolutionState<Scalar> > scCS = scSH->getCurrentState();
461
462 RCP<Thyra::VectorBase<Scalar> > x = workingState->getX();
463 RCP<Thyra::VectorBase<Scalar> > scX = scCS->getX();
464 Thyra::V_V(x.ptr(), *(scX));
465
466 RCP<Thyra::VectorBase<Scalar> > xDot = workingState->getXDot();
467 if (xDot != Teuchos::null) {
468 RCP<Thyra::VectorBase<Scalar> > scXDot = scCS->getXDot();
469 Thyra::V_V(xDot.ptr(), *(scXDot));
470 }
471
472 RCP<Thyra::VectorBase<Scalar> > xDotDot = workingState->getXDotDot();
473 if (xDotDot != Teuchos::null) {
474 RCP<Thyra::VectorBase<Scalar> > scXDotDot = scCS->getXDotDot();
475 Thyra::V_V(xDotDot.ptr(), *(scXDotDot));
476 }
477
478 if (pass == true) workingState->setSolutionStatus(Status::PASSED);
479 else workingState->setSolutionStatus(Status::FAILED);
480 workingState->setOrder(scCS->getOrder());
481 workingState->computeNorms(currentState);
482 scSH->clear();
483 stepperSCAppAction_->execute(solutionHistory, thisStepper,
485 }
486 return;
487}
488
489
496template<class Scalar>
497Teuchos::RCP<Tempus::StepperState<Scalar> > StepperSubcycling<Scalar>::
499{
500 Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState =
501 rcp(new StepperState<Scalar>(this->getStepperType()));
502 return stepperState;
503}
504
505
506template<class Scalar>
508 Teuchos::FancyOStream &out,
509 const Teuchos::EVerbosityLevel verbLevel) const
510{
511 out.setOutputToRootOnly(0);
512 out << std::endl;
513 Stepper<Scalar>::describe(out, verbLevel);
514
515 out << "--- StepperSubcycling ---\n";
516 out << " stepperSCAppAction = " << stepperSCAppAction_ << std::endl;
517 out << " scIntegrator = " << scIntegrator_ << std::endl;
518 out << "-------------------------" << std::endl;
519 scIntegrator_->getStepper()->describe(out, verbLevel);
520}
521
522
523template<class Scalar>
524Teuchos::RCP<const Teuchos::ParameterList>
526{
527 TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
528 "Error - StepperSubcycling<Scalar>::getValidParameters()\n"
529 " is not implemented yet.\n");
530
531 return this->getValidParametersBasic();
532}
533
534
535// Nonmember constructor - ModelEvaluator and ParameterList
536// ------------------------------------------------------------------------
537template<class Scalar>
538Teuchos::RCP<StepperSubcycling<Scalar> >
540 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
541 Teuchos::RCP<Teuchos::ParameterList> pl)
542{
543 auto stepper = Teuchos::rcp(new StepperSubcycling<Scalar>());
544
545 TEUCHOS_TEST_FOR_EXCEPTION(pl != Teuchos::null, std::logic_error,
546 "Error - Construction of StepperSubcycling with a ParameterList\n"
547 "is not implemented yet!\n");
548
549 if (pl != Teuchos::null) {
550 stepper->setStepperValues(pl);
551 }
552
553 if (model != Teuchos::null) {
554 stepper->setModel(model);
555 stepper->initialize();
556 }
557
558 return stepper;
559}
560
561
562} // namespace Tempus
563#endif // Tempus_StepperSubcycling_impl_hpp
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Application Action for StepperSubcycling.
virtual void setSubcyclingStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
virtual Teuchos::RCP< IntegratorObserver< Scalar > > getSubcyclingIntegratorObserver() const
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory) const
virtual void setSubcyclingPrintDtChanges(bool printDtChanges)
virtual void initialize()
Initialize during construction and after changing input parameters.
virtual Teuchos::RCP< const Stepper< Scalar > > getSubcyclingStepper() const
virtual int getSubcyclingScreenOutputIndexInterval() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setAppAction(Teuchos::RCP< StepperSubcyclingAppAction< Scalar > > appAction=Teuchos::null)
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
virtual void setSubcyclingMaxTimeStep(Scalar MaxTimeStep)
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setSubcyclingIntegratorObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs)
virtual void setSubcyclingInitTimeStep(Scalar InitTimeStep)
virtual std::string getSubcyclingStepType() const
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess)
Pass initial guess to Newton solver (only relevant for implicit solvers)
virtual void setSubcyclingMinTimeStep(Scalar MinTimeStep)
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void setSubcyclingScreenOutputIndexInterval(int i)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
virtual Teuchos::RCP< TimeStepControlStrategy< Scalar > > getSubcyclingTimeStepControlStrategy() const
virtual std::string getSubcyclingScreenOutputIndexList() const
virtual void setSubcyclingMaxFailures(int MaxFailures)
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions, make them consistent, and set needed memory.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void setSubcyclingMaxConsecFailures(int MaxConsecFailures)
virtual void setSubcyclingScreenOutputIndexList(std::string s)
virtual void setSubcyclingTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar > > tscs)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
Teuchos::RCP< StepperSubcycling< Scalar > > createStepperSubcycling(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.