Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tempus_IntegratorObserverBasic_impl.hpp
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
10#ifndef Tempus_IntegratorObserverBasic_impl_hpp
11#define Tempus_IntegratorObserverBasic_impl_hpp
12
13#include "Tempus_Stepper.hpp"
14
15namespace Tempus {
16
17template <class Scalar>
21
22template <class Scalar>
26
27template <class Scalar>
29 const Integrator<Scalar>& integrator)
30{
31 std::time_t begin = std::time(nullptr);
32 const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
33 out->setOutputToRootOnly(0);
34 Teuchos::OSTab ostab(out, 0, "ScreenOutput");
35 *out << "\nTempus - IntegratorBasic\n"
36 << std::asctime(std::localtime(&begin)) << "\n"
37 << " Stepper = " << integrator.getStepper()->description() << "\n"
38 << " Simulation Time Range ["
39 << integrator.getTimeStepControl()->getInitTime() << ", "
40 << integrator.getTimeStepControl()->getFinalTime() << "]\n"
41 << " Simulation Index Range ["
42 << integrator.getTimeStepControl()->getInitIndex() << ", "
43 << integrator.getTimeStepControl()->getFinalIndex() << "]\n"
44 << "===================================================================="
45 "========\n"
46 << " Step Time dt Abs Error Rel Error Order nFail "
47 "dCompTime"
48 << std::endl;
49}
50
51template <class Scalar>
56
57template <class Scalar>
62
63template <class Scalar>
68
69template <class Scalar>
74
75template <class Scalar>
80
81template <class Scalar>
83 const Integrator<Scalar>& integrator)
84{
85 using Teuchos::RCP;
86 auto cs = integrator.getSolutionHistory()->getCurrentState();
87
88 if ((cs->getOutputScreen() == true) || (cs->getOutput() == true) ||
89 (cs->getTime() == integrator.getTimeStepControl()->getFinalTime())) {
90 const Scalar steppertime = integrator.getStepperTimer()->totalElapsedTime();
91 // reset the stepper timer
92 integrator.getStepperTimer()->reset();
93
94 const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
95 out->setOutputToRootOnly(0);
96 Teuchos::OSTab ostab(out, 0, "ScreenOutput");
97 *out << std::scientific << std::setw(6) << std::setprecision(3)
98 << cs->getIndex() << std::setw(11) << std::setprecision(3)
99 << cs->getTime() << std::setw(11) << std::setprecision(3)
100 << cs->getTimeStep() << std::setw(11) << std::setprecision(3)
101 << cs->getErrorAbs() << std::setw(11) << std::setprecision(3)
102 << cs->getErrorRel() << std::fixed << std::setw(7)
103 << std::setprecision(1) << cs->getOrder() << std::scientific
104 << std::setw(7) << std::setprecision(3) << cs->getNFailures()
105 << std::setw(11) << std::setprecision(3) << steppertime << std::endl;
106 }
107}
108
109template <class Scalar>
111 const Integrator<Scalar>& integrator)
112{
113 std::string exitStatus;
114 // const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
115 if (integrator.getSolutionHistory()->getCurrentState()->getSolutionStatus() ==
117 integrator.getStatus() == Status::FAILED) {
118 exitStatus = "Time integration FAILURE!";
119 }
120 else {
121 exitStatus = "Time integration complete.";
122 }
123 std::time_t end = std::time(nullptr);
124 const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
125 const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
126 out->setOutputToRootOnly(0);
127 Teuchos::OSTab ostab(out, 0, "ScreenOutput");
128 *out << "===================================================================="
129 "========\n"
130 << " Total runtime = " << runtime << " sec = " << runtime / 60.0
131 << " min\n"
132 << std::asctime(std::localtime(&end)) << "\nNumber of Accepted Steps = "
133 << integrator.getSolutionHistory()->getCurrentState()->getIndex()
134 << "\nNumber of Failures = "
135 << integrator.getSolutionHistory()
136 ->getCurrentState()
137 ->getMetaData()
138 ->getNRunningFailures()
139 << "\n"
140 << exitStatus << "\n"
141 << std::endl;
142}
143
144} // namespace Tempus
145#endif // Tempus_IntegratorObserverBasic_impl_hpp
virtual void observeEndIntegrator(const Integrator< Scalar > &integrator) override
Observe the end of the time integrator.
virtual void observeEndTimeStep(const Integrator< Scalar > &integrator) override
Observe the end of the time step loop.
virtual void observeStartIntegrator(const Integrator< Scalar > &integrator) override
Observe the beginning of the time integrator.
virtual void observeBeforeTakeStep(const Integrator< Scalar > &integrator) override
Observe before Stepper takes step.
virtual void observeNextTimeStep(const Integrator< Scalar > &integrator) override
Observe after the next time step size is selected.
virtual void observeAfterTakeStep(const Integrator< Scalar > &integrator) override
Observe after Stepper takes step.
virtual void observeStartTimeStep(const Integrator< Scalar > &integrator) override
Observe the beginning of the time step loop.
virtual void observeAfterCheckTimeStep(const Integrator< Scalar > &integrator) override
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual Teuchos::RCP< Teuchos::Time > getIntegratorTimer() const =0
Returns the IntegratorTimer_ for this Integrator.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const =0
Returns the SolutionHistory for this Integrator.
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const =0
Returns the TimeStepControl for this Integrator.
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const =0
Get the stepper.
virtual Tempus::Status getStatus() const =0
Get the Status.
virtual Teuchos::RCP< Teuchos::Time > getStepperTimer() const =0