|
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 and the same explicit Forward Euler update used in Example 3: Introduce SolutionState.
New concepts introduced are:
Tempus::createSolutionHistoryState()initWorkingState()getCurrentState()getWorkingState()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 step result is now associated with the working state, and the history object manages the promotion of that state to the current state.
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.