Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_IntegratorObserverBasic_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_IntegratorObserverBasic_impl_hpp
10 #define Tempus_IntegratorObserverBasic_impl_hpp
11 
12 #include "Tempus_Stepper.hpp"
13 
14 namespace Tempus {
15 
16 template <class Scalar>
18 {
19 }
20 
21 template <class Scalar>
23 {
24 }
25 
26 template <class Scalar>
28  const Integrator<Scalar>& integrator)
29 {
30  std::time_t begin = std::time(nullptr);
31  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
32  out->setOutputToRootOnly(0);
33  Teuchos::OSTab ostab(out, 0, "ScreenOutput");
34  *out << "\nTempus - IntegratorBasic\n"
35  << std::asctime(std::localtime(&begin)) << "\n"
36  << " Stepper = " << integrator.getStepper()->description() << "\n"
37  << " Simulation Time Range ["
38  << integrator.getTimeStepControl()->getInitTime() << ", "
39  << integrator.getTimeStepControl()->getFinalTime() << "]\n"
40  << " Simulation Index Range ["
41  << integrator.getTimeStepControl()->getInitIndex() << ", "
42  << integrator.getTimeStepControl()->getFinalIndex() << "]\n"
43  << "===================================================================="
44  "========\n"
45  << " Step Time dt Abs Error Rel Error Order nFail "
46  "dCompTime"
47  << std::endl;
48 }
49 
50 template <class Scalar>
52  const Integrator<Scalar>& /* integrator */)
53 {
54 }
55 
56 template <class Scalar>
58  const Integrator<Scalar>& /* integrator */)
59 {
60 }
61 
62 template <class Scalar>
64  const Integrator<Scalar>& /* integrator */)
65 {
66 }
67 
68 template <class Scalar>
70  const Integrator<Scalar>& /* integrator */)
71 {
72 }
73 
74 template <class Scalar>
76  const Integrator<Scalar>& /* integrator */)
77 {
78 }
79 
80 template <class Scalar>
82  const Integrator<Scalar>& integrator)
83 {
84  using Teuchos::RCP;
85  auto cs = integrator.getSolutionHistory()->getCurrentState();
86 
87  if ((cs->getOutputScreen() == true) || (cs->getOutput() == true) ||
88  (cs->getTime() == integrator.getTimeStepControl()->getFinalTime())) {
89  const Scalar steppertime = integrator.getStepperTimer()->totalElapsedTime();
90  // reset the stepper timer
91  integrator.getStepperTimer()->reset();
92 
93  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
94  out->setOutputToRootOnly(0);
95  Teuchos::OSTab ostab(out, 0, "ScreenOutput");
96  *out << std::scientific << std::setw(6) << std::setprecision(3)
97  << cs->getIndex() << std::setw(11) << std::setprecision(3)
98  << cs->getTime() << std::setw(11) << std::setprecision(3)
99  << cs->getTimeStep() << std::setw(11) << std::setprecision(3)
100  << cs->getErrorAbs() << std::setw(11) << std::setprecision(3)
101  << cs->getErrorRel() << std::fixed << std::setw(7)
102  << std::setprecision(1) << cs->getOrder() << std::scientific
103  << std::setw(7) << std::setprecision(3) << cs->getNFailures()
104  << std::setw(11) << std::setprecision(3) << steppertime << std::endl;
105  }
106 }
107 
108 template <class Scalar>
110  const Integrator<Scalar>& integrator)
111 {
112  std::string exitStatus;
113  // const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
114  if (integrator.getSolutionHistory()->getCurrentState()->getSolutionStatus() ==
115  Status::FAILED ||
116  integrator.getStatus() == Status::FAILED) {
117  exitStatus = "Time integration FAILURE!";
118  }
119  else {
120  exitStatus = "Time integration complete.";
121  }
122  std::time_t end = std::time(nullptr);
123  const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
124  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
125  out->setOutputToRootOnly(0);
126  Teuchos::OSTab ostab(out, 0, "ScreenOutput");
127  *out << "===================================================================="
128  "========\n"
129  << " Total runtime = " << runtime << " sec = " << runtime / 60.0
130  << " min\n"
131  << std::asctime(std::localtime(&end)) << "\nNumber of Accepted Steps = "
132  << integrator.getSolutionHistory()->getCurrentState()->getIndex()
133  << "\nNumber of Failures = "
134  << integrator.getSolutionHistory()
135  ->getCurrentState()
136  ->getMetaData()
137  ->getNRunningFailures()
138  << "\n"
139  << exitStatus << "\n"
140  << std::endl;
141 }
142 
143 } // namespace Tempus
144 #endif // Tempus_IntegratorObserverBasic_impl_hpp
virtual Teuchos::RCP< Teuchos::Time > getStepperTimer() const =0
virtual Teuchos::RCP< Teuchos::Time > getIntegratorTimer() const =0
Returns the IntegratorTimer_ for this Integrator.
virtual void observeEndIntegrator(const Integrator< Scalar > &integrator) override
Observe the end of the time integrator.
virtual void observeNextTimeStep(const Integrator< Scalar > &integrator) override
Observe after the next time step size is selected.
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const =0
Returns the TimeStepControl for this Integrator.
virtual void observeStartIntegrator(const Integrator< Scalar > &integrator) override
Observe the beginning of the time integrator.
virtual Tempus::Status getStatus() const =0
Get the Status.
virtual void observeAfterCheckTimeStep(const Integrator< Scalar > &integrator) override
basic_FancyOStream & setOutputToRootOnly(const int rootRank)
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual void observeStartTimeStep(const Integrator< Scalar > &integrator) override
Observe the beginning of the time step loop.
virtual void observeAfterTakeStep(const Integrator< Scalar > &integrator) override
Observe after Stepper takes step.
virtual void observeEndTimeStep(const Integrator< Scalar > &integrator) override
Observe the end of the time step loop.
double totalElapsedTime(bool readCurrentTime=false) const
virtual void observeBeforeTakeStep(const Integrator< Scalar > &integrator) override
Observe before Stepper takes step.
virtual RCP< FancyOStream > getOStream() const
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const =0
Get the stepper.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const =0
Returns the SolutionHistory for this Integrator.