ste 6239 simulering monday, week 2: 6. object-oriented / template- based programming implementation...
TRANSCRIPT
STE 6239 Simulering
Monday, Week 2:6. Object-oriented / template-based Programming Implementation in C++
6.1. From structure-oriented procedural approach (FORTRAN, C, MATLAB) to object-oriented approach (C++)
6.1.1. Motivation Example: programming with full (dense) matrices
FORTRAN F77 C++
A dense matrix class Member functions and efficiency Functions vs. Operators
Example: programming with sparse matrices Sparse matrices (revision from Friday, Week 1) FORTRAN F77 C++
Hierarchy of matrix classes
6.1.2. Object-oriented programming (OOP)
Efficiency vs. OO techniques Example: A problem-solving environment (PSE)
for object-oriented numerics: Diffpack Matrices in Diffpack Partial case: a hierachy of vector classes
Constructors, destructors, assignment operators Redimensioning the length (one of the possible ways) The const concept Inlining Printing the vector Application: inner product Operator overloading
6.1.3. Parametrization in OOP: templates
Example: a template version of the vector class Example: constructing an n-dimensional array for
arbitrary n The naive use of arrays (structure-oriented) Improvement: using 1D array with ’book-keeping’ (structure-
oriented: F77; C, MATLAB, etc.) Big improvement: using array of pointers (object-oriented: C++) Big improvement : using recursive templates (template-based
object oriented: C++) Task (preparation for the course STE6247 Advanced
Geometry and Special Effects): Implement the 4 versions of a multidimensional array given above, within the framework of GM_lib (Hint: for the recursive-template version, read this text).
6.1.4. Some conclusions
Low-level C++/C programming involves intricate details (e.g., pointers, memory handling)
C++ hides low-level details that diminate C and F77 programs
Use recursive templates (but check if they work with your C++ compiler!)
Rely on ready-made tools and use libraries, but be prepared in special cases to use your own implementations.
Example: vectors in Diffpack Task (preparation for the course STE6247 Advanced
Geometry and Special Effects): Implement the vector classes of Diffpack, within the framework
of GM_lib Implement every Diffpack code given in the course, within the
framework of GM_lib
6.2. Programming ODE-based simulators
Basic steps
6.3. Programming PDE-based simulators
Considerably more complex (see also Wednesday and Thursday of Week 1)
6.4. Programming implementations of basic solvers
(more to come)