Presentation is loading. Please wait.

Presentation is loading. Please wait.

STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++

Similar presentations


Presentation on theme: "STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++"— Presentation transcript:

1 STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++

2 6.1. From structure-oriented procedural approach (FORTRAN, C, MATLAB) to object-oriented approach (C++) 6.1.1. MotivationMotivation Example: programming with full (dense) matricesmatrices  FORTRAN F77 FORTRAN  C++ C++ A dense matrix classdense matrix class Member functions and efficiency Functions vs. Operators Example: programming with sparse matricessparse matrices  Sparse matrices (revision from Friday, Week 1) Sparse matrices  FORTRAN F77 FORTRAN  C++ C++ Hierarchy of matrix classes Hierarchy

3 6.1.2. Object-oriented programming (OOP)OOP Efficiency vs. OO techniques Example: A problem-solving environment (PSE) for object-oriented numerics: DiffpackDiffpack  Matrices in Diffpack Matrices  Partial case: a hierachy of vector classeshierachy of vector classes Constructors, destructors, assignment operators Redimensioning the length (one of the possible ways) Redimensioning The const conceptconst Inlining Printing the vector Printing Application: inner productinner product Operator overloading

4 6.1.3. Parametrization in OOP: templates Example: a template version of the vector classtemplate Example: constructing an n-dimensional array for arbitrary n Example  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).this text

5 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 Diffpackvectors 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 6.2. Programming ODE-based simulators Basic steps

7 6.3. Programming PDE-based simulators Considerably more complex (see also Wednesday and Thursday of Week 1)

8 6.4. Programming implementations of basic solvers (more to come)


Download ppt "STE 6239 Simulering Monday, Week 2: 6. Object-oriented / template- based Programming Implementation in C++"

Similar presentations


Ads by Google