What is object-orientation? Object Oriented Program Construction for Scientific Computing 2D1263
Transcription
What is object-orientation? Object Oriented Program Construction for Scientific Computing 2D1263
2D1263 : Scientific Computing Lecture 1 2D1263 : Scientific Computing (3) What is object-orientation? Lecture 1 (1) Object Oriented Program Construction for Scientific Computing “Organisation of software as a collection of discrete objects that incorporate both data structure and behaviour.” 2D1263 Some key concepts: http://www.nada.kth.se/kurser/kth/2D1263/ • Identity – data quantized into distinguashable entities (objects). Marco Kupiainen marcok@nada.kth.se http://www.nada.kth.se/marcok • Abstraction – separate external aspects of an object from internal (functionality from implementation) • Inheritance – build new abstractions out of existing ones • Polymorphism – ability to provide the same interface to objects with different implementations. Objects are similar to C structures but have associated functions. NADA There are no widely accepted definitions of OO requirements. Marco Kupiainen marcok@nada.kth.se Marco Kupiainen marcok@nada.kth.se NADA NADA 2D1263 : Scientific Computing Lecture 1 2D1263 : Scientific Computing NADA Golub and Ortega: “Scientific computing is the collection of tools, techniques and theories required to solve on a computer mathematical models of problems in science and engineering.” Or a more narrow definition: “Development and use of numerical methods and mathematical models to solve real-world problems efficiently on computers.” Goals To give students knowledge of Interdisciplinary field requiring: • knowledge about the underlying (physical) problem, • ability to formulate a mathematical model, • stable & accurate numerical schemes, Lecture 1 • formulation of PDEs from fluid dynamics, • their numerical approximation on non-trivial grids using finite differences, • object-oriented implementation in C++, • parallel programming for distributed memory architectures (SPMD) Prerequisites • a second course in numerical analysis, e.g. Applied Numerical Methods (2D1250) • previous programming experience (preferably but not necessarily C) Marco Kupiainen marcok@nada.kth.se Familiarity with basic C can help, see e.g. http://www.nada.kth.se/kurser/master/intro/ lectures 2–4 (apart from input/output). What is scientific computing? • efficient implementation on high performance computers. (4) Marco Kupiainen marcok@nada.kth.se NADA (2) 2D1263 : Scientific Computing Lecture 1 (5) 2D1263 : Scientific Computing Lecture 1 (6) Literature The course literature will consist of handouts, Examination • lecture notes written by Bj¨ orn Sj¨ ogren Written exam (2 credits): • brief notes on topics not in lecture notes • first exam by end of May or beginning of June 2002 • copies of transparencies Additional online references can be found on the course homepage. • at least three times per year Computer laborations (2 credits): Good C++ books (≈ $50 each): 1. Algebraic grid generation (due 15/2) 2. Distributed parallel arrays (due 22/3) • “The C++ Programming Language”, Bjarne Stroustrup 3. A parallel PDE solver (due 17/5) • “C++ Primer”, Lippman & Lajoie It will not be assumed that you buy any C++ books for the course. The laborations can be done individually or in groups of two students. There are many other C++ books (e.g. at the KTH library). Ask me if you’d like a second opinion on a book. Marco Kupiainen marcok@nada.kth.se Marco Kupiainen marcok@nada.kth.se NADA NADA 2D1263 : Scientific Computing Lecture 1 (7) 2D1263 : Scientific Computing (Preliminary) schedule (Preliminary) schedule Computer exercises Lectures Monday 21/1 13.15 – 15.00 4523 Period 3 Weeks 5, 7, 9 Friday 25/1 13.15 – 15.00 4523 Period 4 Weeks 12, 17, 19 Monday 28/1 13.15 – 15.00 4523 Friday 1/2 13.15 – 15.00 4523 Monday 4/2 13.15 – 15.00 4523 Friday 8/2 13.15 – 15.00 4523 Monday 11/2 13.15 – 15.00 4523 Friday 15/2 13.15 – 15.00 4523 Wednesday 20/2 10.15 – 12.00 4523 Wednesday 27/2 10.15 – 12.00 4523 Wednesday 13/3 10.15 – 12.00 4523 Wednesday 20/3 10.15 – 12.00 4523 Tuesday or Thursday mornings? Afternoons? You will probably have to work more than this to complete the laborations. Outside of scheduled classes any questions should be directed to the teaching assistants • Kyoung-Sook Moon (moon@nada.kth.se) • Sandy Sefi (sandy@nada.kth.se) They can be reached by email, and also answer questions in person (subject to office hours). Marco Kupiainen marcok@nada.kth.se NADA Lecture 1 Marco Kupiainen marcok@nada.kth.se NADA (8) Lecture 1 (9) • Basic C/C++ constructs Marco Kupiainen marcok@nada.kth.se Marco Kupiainen marcok@nada.kth.se NADA • Overview of computational grids This course focuses mainly on structured boundary-fitted grids. 2D1263 : Scientific Computing Today – Structured 4. Implement a solver in e.g. C++ – Boundary-fitted 3. Find a tool for solving the discretized PDE, or – Unstructured 2. Approximate the PDE on the grid by e.g. finite differences or finite elements – Cartesian 1. Discretize the domain (generate a grid) • Boundary-fitted we need to • Structured grids • initial & boundary conditions • Cartesian Different types of grids • a partial differential equation • Unstructured grids • a geometry Boundary representation Given Structure Numerical approximation Subdivision of domain Ω into small cells or a finite set of points intended for approximating PDEs by algebraic equations. Lecture 1 (10) 2D1263 : Scientific Computing NADA Marco Kupiainen marcok@nada.kth.se Lecture 1 (12) Unstructured grids x = [(1/2 + ξ1 ) cos(πξ2 ), (1/2 + ξ1 ) sin(πξ2 )] + Generality – Handles complex geometries – “Straightforward” generation & refinement – Inefficiency – Indirect addressing ⇒ inefficient cache usage & many dereferences – Parallelization difficult double x[n],y[n]; // Node coordinates int tri[m,3]; // Nodes in triangle Coordinates for first node in triangle i: x[tri[i,0]], y[tri[i,0]]. NADA ξ¯ = [“radius” , “angle”] 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 2D1263 : Scientific Computing Structured grids are indexed along coordinate directions: −1.5 0 0.5 ⇒ 1 1.5 −1 A structured grid −0.5 0 0.5 1 1.5 Lecture 1 (11) 2D1263 : Scientific Computing Marco Kupiainen marcok@nada.kth.se NADA 2D1263 : Scientific Computing Lecture 1 (13) 2D1263 : Scientific Computing Structured grids Lecture 1 (14) Cartesian grids ¯ Mapping from unit square to geometry, x(ξ). (only cells intersecting domain shown) + Efficiency Rectangular grid with objects “carved out”. – Memory usage (regular connectivity) + works for any geometry (simple) – Numerical methods (structured matrices) – accuracy in boundary conditions + Simple to use – numerical stability – How to do local refinement? It is possible but cumbersome to get accurate boundary conditions (immersed boundary method ). ¯ – Difficulties with complex geometries (x(ξ)) ⇒ may have to divide domain into smaller blocks before grid generation. Can be useful for “inexact” domains, e.g. a lake shore. Block subdivision may be good for parallel computations (c.f. domain decomposition) Marco Kupiainen marcok@nada.kth.se NADA Marco Kupiainen marcok@nada.kth.se NADA