from PART II - SOOP TO NUTS AND BOLTS
Published online by Cambridge University Press: 01 June 2011
“However beautiful the strategy, you should occasionally look at the results.”
Winston ChurchillThe Problem
This chapter introduces the GoF strategy pattern along with a Fortran-specific, enabling pattern: surrogate. In scientific programming, one finds context for a strategy when the choice of numerical algorithms must evolve dynamically. Multiphysics modeling, for example, typically implies multi-numerics modeling. As the physics changes, so must the numerical methods.
A problem arises when the software does not separate its expression of the physics from its expression of the discrete algorithms. In the Lorenz system, for example, equation (4.5) expresses the physics, whereas equation (4.6) expresses the discretization. Consider a concrete ADT that solves the same equations as the abstractions presented in Section 6.2 and extends the integrand ADT but requires a new time integration algorithm. The extended type must overload the integrate name. This would be a simple task when changing one algorithm in one particular ADT. However, when numerous algorithms exist, one faces the dilemma of either putting all possible algorithms in the parent type or leaving to extended types the task of each implementing their own algorithms. Section 7.3 explains the adverse impact the first option has on code maintainability. The second option could lead to redundant (and possibly inconsistent) implementations.
The Lorenz equation solver described in Chapter 6 uses explicit Euler time advancement. That solver updates the solution vector at each time step without explicitly storing a corresponding time coordinate.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.