|
Tempus Version of the Day
Time Integration
|
The primary goal of Example 1: Utilize Thyra is to replace the raw arrays with Thyra vectors, while preserving the same van der Pol problem and the same Forward Euler stepping logic used in Example 0: Basic Problem.
New concepts introduced from Teuchos and Thyra are
std::shared_ptrThis allows Tempus and other Trilinos packages to operate on abstract numerical interfaces rather than concrete array types. Moving from raw arrays to Thyra vectors is the first step toward interoperability with Tempus steppers, model evaluators, and solver infrastructure.
Below are select code snippets and comments on the uses Teuchos::RCP and Thyra functionality.
Setup Thyra vectors. The raw double arrays are replaced by Thyra vectors, which are created from a Thyra::VectorSpaceBase. This step also introduces Teuchos::RCP, Trilinos's reference-counted smart pointer.
Before
After
The state is now represented through abstract vector interfaces rather than fixed-size arrays.
Initialize Thyra vectors. Initial values are assigned through Thyra::DetachedVectorView. The local scope ensures the detached views are destroyed immediately after use.
Before
After
Evaluating the Right-Hand Side The van der Pol right-hand side is still evaluated directly in the application code, but element access now goes through detached vector views.
Before
After
Element-wise access is still possible, but it now uses Thyra utilities.
Use Thyra vector algebra. The Forward Euler update is expressed with Thyra::V_VpStV, which performs the vector operation 
Before
After
Use Thyra vector assignment. The accepted solution is copied into the current state using Thyra::V_V.
Before
After
A more detailed comparison can be viewed by diffing:
From 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 (for example, #include statements and Doxygen comments) and trailing regression-testing lines.