ste 6239 simulering monday, week 2: 6. object-oriented / template- based programming implementation...
TRANSCRIPT
![Page 1: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/1.jpg)
STE 6239 Simulering
Monday, Week 2:6. Object-oriented / template-based Programming Implementation in C++
![Page 2: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/2.jpg)
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
![Page 3: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/3.jpg)
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
![Page 4: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/4.jpg)
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).
![Page 5: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/5.jpg)
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
![Page 6: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/6.jpg)
6.2. Programming ODE-based simulators
Basic steps
![Page 7: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/7.jpg)
6.3. Programming PDE-based simulators
Considerably more complex (see also Wednesday and Thursday of Week 1)
![Page 8: STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++](https://reader036.vdocuments.us/reader036/viewer/2022083007/56649e025503460f94aed579/html5/thumbnails/8.jpg)
6.4. Programming implementations of basic solvers
(more to come)