|
Tempus Version of the Day
Time Integration
|
The primary goal of Example 4: Add SolutionHistory is to move from a single Tempus::SolutionState to a Tempus::SolutionHistory while preserving the same Thyra::ModelEvaluator-based model, the same explicit Forward Euler update, the same simple tabular output, and the same regression-testing workflow used in Example 3: Introduce SolutionState.
New concepts introduced are:
Tempus::createSolutionHistoryState()initWorkingState()getCurrentState()getWorkingState()getCurrentTime()getCurrentIndex()promoteWorkingState()This is the first step in moving from state-based solution management to history-based solution management. That transition is important because many time integration algorithms require access to multiple states, including the current solution, tentative working states, and previously accepted states.


The code excerpts below highlight the main changes needed to move from a single Tempus::SolutionState to a Tempus::SolutionHistory.
Create a SolutionHistory. The initial condition is still stored in a Tempus::SolutionState, but that state is now inserted into a Tempus::SolutionHistory.
Before
After
The initial condition remains the same, but it is now managed through a Tempus::SolutionHistory.
Use SolutionHistory to access states. Instead of working directly with a single solution state, the application now asks the history object for the current and working states.
Before
After
The current and tentative states are now obtained through the history object rather than being managed manually.
Assign metadata to the working state. The timestep index, time, and timestep size are associated with the working state created by the history object.
Before
After
The working state is initialized by the history object and then updated with the time information for the tentative step.
Promote the accepted working state. The step outcome is recorded on the working state, and the history object promotes it when the step completes.
Before
After
The new solution is written into the working state, the step result is associated with that state, and the history object manages promotion of that state to become the new current state.
As in the updated examples, the regression comparison remains separate from step status. Final tutorial success is determined after the loop by combining the final state status with the result of the regression test.
A more detailed comparison can be made by diffing:
examples/03_Intro_SolutionState/03_Intro_SolutionState.cppexamples/04_Adding_SolutionHistory/04_Adding_SolutionHistory.cppFrom the packages/tempus directory, a focused comparison of the main time-integration logic between these two examples can be generated locally in bash or zsh with:
This ignores leading header lines (e.g., #include statements and Doxygen comments) and trailing regression-testing lines.