Skip to content

bssw-tutorial/simple-heateq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hello Numerical World

This repository includes programs computing the time-dependent solution of the heat equation in 1D.

This simple problem is used to show some best-practices in object-oriented programming and numerical simulation:

  • Encapsulate program state in high-level objects. Here, we use Params to collect run-time parameters Energy to store coefficients of the energy function.

    Better definition in your data structures can often lead to simpler, smaller main-loops.

  • Resource-aquisition-is-initialization (RAII) pattern. The Params and Energy objects automatically allocate memory on creation and de-allocate on destruction.

    Ideally, all resources are allocated (objects are created) outside the main loop. This prevents wasting simulation time.

  • Parameterize floating-point types. Often, codes can achieve speedup by using mixed-precision. This requires testing the solution accuracy with different precisions used for each part of the calculation.

  • Parse input parameters (or include configuration code) to support multiple run configurations. This is more of a necessity to avoid repeating code fragments (DRY principle).

  • Keep only small instruction-lists in main() (and other imperative functions like simulate()). This allows later code to organize sequences of instruction-listing code.

  • Minimize loops and function calls in python. Rely on the numpy external module API instead.

The included code also provides a demonstration of make and cmake build styles. The cmake build includes tests and documentation.

References

Several Fortran references that helped me write this include: