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 template<class Scalar>
21 
22 template<class Scalar>
25 
26  std::time_t begin = std::time(nullptr);
27  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
28  out->setOutputToRootOnly(0);
29  Teuchos::OSTab ostab(out,0,"ScreenOutput");
30  *out << "\nTempus - IntegratorBasic\n"
31  << std::asctime(std::localtime(&begin)) << "\n"
32  << " Stepper = " << integrator.getStepper()->description() << "\n"
33  << " Simulation Time Range [" << integrator.getTimeStepControl()->getInitTime()
34  << ", " << integrator.getTimeStepControl()->getFinalTime() << "]\n"
35  << " Simulation Index Range [" << integrator.getTimeStepControl()->getInitIndex()
36  << ", " << integrator.getTimeStepControl()->getFinalIndex() << "]\n"
37  << "============================================================================\n"
38  << " Step Time dt Abs Error Rel Error Order nFail dCompTime"
39  << std::endl;
40 }
41 
42 template<class Scalar>
44 observeStartTimeStep(const Integrator<Scalar>& /* integrator */){}
45 
46 template<class Scalar>
48 observeNextTimeStep(const Integrator<Scalar>& /* integrator */){}
49 
50 template<class Scalar>
52 observeBeforeTakeStep(const Integrator<Scalar>& /* integrator */){}
53 
54 template<class Scalar>
56 observeAfterTakeStep(const Integrator<Scalar>& /* integrator */){}
57 
58 template<class Scalar>
61 
62 template<class Scalar>
65 
66  using Teuchos::RCP;
67  auto cs = integrator.getSolutionHistory()->getCurrentState();
68 
69  if ((cs->getOutputScreen() == true) ||
70  (cs->getOutput() == true) ||
71  (cs->getTime() == integrator.getTimeStepControl()->getFinalTime())) {
72 
73  const Scalar steppertime = integrator.getStepperTimer()->totalElapsedTime();
74  // reset the stepper timer
75  integrator.getStepperTimer()->reset();
76 
77  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
78  out->setOutputToRootOnly(0);
79  Teuchos::OSTab ostab(out,0,"ScreenOutput");
80  *out<<std::scientific
81  <<std::setw( 6)<<std::setprecision(3)<<cs->getIndex()
82  <<std::setw(11)<<std::setprecision(3)<<cs->getTime()
83  <<std::setw(11)<<std::setprecision(3)<<cs->getTimeStep()
84  <<std::setw(11)<<std::setprecision(3)<<cs->getErrorAbs()
85  <<std::setw(11)<<std::setprecision(3)<<cs->getErrorRel()
86  <<std::fixed <<std::setw( 7)<<std::setprecision(1)<<cs->getOrder()
87  <<std::scientific<<std::setw( 7)<<std::setprecision(3)<<cs->getNFailures()
88  <<std::setw(11)<<std::setprecision(3)<<steppertime
89  <<std::endl;
90  }
91 
92 }
93 
94 template<class Scalar>
97 
98  std::string exitStatus;
99  //const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
100  if (integrator.getSolutionHistory()->getCurrentState()->getSolutionStatus() ==
101  Status::FAILED || integrator.getStatus() == Status::FAILED) {
102  exitStatus = "Time integration FAILURE!";
103  } else {
104  exitStatus = "Time integration complete.";
105  }
106  std::time_t end = std::time(nullptr);
107  const Scalar runtime = integrator.getIntegratorTimer()->totalElapsedTime();
108  const Teuchos::RCP<Teuchos::FancyOStream> out = integrator.getOStream();
109  out->setOutputToRootOnly(0);
110  Teuchos::OSTab ostab(out,0,"ScreenOutput");
111  *out << "============================================================================\n"
112  << " Total runtime = " << runtime << " sec = "
113  << runtime/60.0 << " min\n"
114  << std::asctime(std::localtime(&end))
115  << "\nNumber of Accepted Steps = " << integrator.getSolutionHistory()->getCurrentState()->getIndex()
116  << "\nNumber of Failures = " << integrator.getSolutionHistory()->getCurrentState()->getMetaData()->getNRunningFailures()
117  << "\n"
118  << exitStatus << "\n"
119  << std::endl;
120 }
121 
122 } // namespace Tempus
123 #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
Observe after checking time step. Observer can still fail the time step here.
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.