difference operators.

Similar documents
Tutorial 2. Introduction to numerical schemes

Introduction to numerical schemes

2.2. Methods for Obtaining FD Expressions. There are several methods, and we will look at a few:

ENO and WENO schemes. Further topics and time Integration

Finite difference methods for the diffusion equation

Scientific Computing: An Introductory Survey

Basic Aspects of Discretization

FDM for parabolic equations

Lecture Notes on Numerical Schemes for Flow and Transport Problems

Numerical Methods for Conservation Laws WPI, January 2006 C. Ringhofer C2 b 2

Lecture Notes on Numerical Schemes for Flow and Transport Problems

Part 1. The diffusion equation

Finite Difference Method

2.29 Numerical Fluid Mechanics Spring 2015 Lecture 13

Finite Differences for Differential Equations 28 PART II. Finite Difference Methods for Differential Equations

Nonconstant Coefficients

Partial Differential Equations

PDEs, part 3: Hyperbolic PDEs

A review of stability and dynamical behaviors of differential equations:

Last time: Diffusion - Numerical scheme (FD) Heat equation is dissipative, so why not try Forward Euler:

Chapter 10 Exercises

Numerical Analysis of Differential Equations Numerical Solution of Parabolic Equations

Numerical Methods for PDEs

KINGS COLLEGE OF ENGINEERING DEPARTMENT OF MATHEMATICS ACADEMIC YEAR / EVEN SEMESTER QUESTION BANK

Strong Stability-Preserving (SSP) High-Order Time Discretization Methods

Numerical Solutions to Partial Differential Equations

7 Hyperbolic Differential Equations

Numerical Solutions to Partial Differential Equations

Consistency and Convergence

MTH 452/552 Homework 3

Multistep Methods for IVPs. t 0 < t < T

Advection / Hyperbolic PDEs. PHY 604: Computational Methods in Physics and Astrophysics II

FINITE DIFFERENCES. Lecture 1: (a) Operators (b) Forward Differences and their calculations. (c) Backward Differences and their calculations.

HIGH-ORDER ACCURATE METHODS BASED ON DIFFERENCE POTENTIALS FOR 2D PARABOLIC INTERFACE MODELS

Applied Math for Engineers

Development and stability analysis of the inverse Lax-Wendroff boundary. treatment for central compact schemes 1

Finite Difference Method for PDE. Y V S S Sanyasiraju Professor, Department of Mathematics IIT Madras, Chennai 36

AM 205: lecture 14. Last time: Boundary value problems Today: Numerical solution of PDEs

2 Multidimensional Hyperbolic Problemss where A(u) =f u (u) B(u) =g u (u): (7.1.1c) Multidimensional nite dierence schemes can be simple extensions of

CS205B / CME306 Homework 3. R n+1 = R n + tω R n. (b) Show that the updated rotation matrix computed from this update is not orthogonal.

Additive Manufacturing Module 8

Applied Mathematics 205. Unit III: Numerical Calculus. Lecturer: Dr. David Knezevic

Finite Difference Methods (FDMs) 2

Selected HW Solutions

MASSACHUSETTS INSTITUTE OF TECHNOLOGY DEPARTMENT OF MECHANICAL ENGINEERING CAMBRIDGE, MASSACHUSETTS NUMERICAL FLUID MECHANICS FALL 2011

Finite Difference Methods for

ME Computational Fluid Mechanics Lecture 5

THE METHOD OF LINES FOR PARABOLIC PARTIAL INTEGRO-DIFFERENTIAL EQUATIONS

Partial differential equations

Lecture 9 Approximations of Laplace s Equation, Finite Element Method. Mathématiques appliquées (MATH0504-1) B. Dewals, C.

Krylov single-step implicit integration factor WENO methods for advection-diffusion-reaction equations

HIGH-ORDER ACCURATE METHODS BASED ON DIFFERENCE POTENTIALS FOR 2D PARABOLIC INTERFACE MODELS

Mathematics Qualifying Exam Study Material

MIT (Spring 2014)

Chapter 5 Exercises. (a) Determine the best possible Lipschitz constant for this function over 2 u <. u (t) = log(u(t)), u(0) = 2.

The Initial Value Problem for Ordinary Differential Equations

30 crete maximum principle, which all imply the bound-preserving property. But most

Chapter 3. Finite Difference Methods for Hyperbolic Equations Introduction Linear convection 1-D wave equation

Index. higher order methods, 52 nonlinear, 36 with variable coefficients, 34 Burgers equation, 234 BVP, see boundary value problems

Jim Lambers MAT 772 Fall Semester Lecture 21 Notes

AMS 147 Computational Methods and Applications Lecture 17 Copyright by Hongyun Wang, UCSC

Time stepping methods

Linear Multistep Methods I: Adams and BDF Methods

Numerical Methods for Engineers and Scientists

Method of Lines. Received April 20, 2009; accepted July 9, 2009

Numerical Solutions to Partial Differential Equations

Finite Difference and Finite Element Methods

Solution of Differential Equation by Finite Difference Method

Review Higher Order methods Multistep methods Summary HIGHER ORDER METHODS. P.V. Johnson. School of Mathematics. Semester

Lecture 1. Finite difference and finite element methods. Partial differential equations (PDEs) Solving the heat equation numerically

Ordinary differential equations. Phys 420/580 Lecture 8

Numerical Solutions to Partial Differential Equations

2.3. Quantitative Properties of Finite Difference Schemes. Reading: Tannehill et al. Sections and

MA/CS 615 Spring 2019 Homework #2

Applied Math Qualifying Exam 11 October Instructions: Work 2 out of 3 problems in each of the 3 parts for a total of 6 problems.

Lecture 4: Numerical solution of ordinary differential equations

Finite Difference Methods for Boundary Value Problems

Finite Differences: Consistency, Stability and Convergence

Multi-Factor Finite Differences

Finite difference method for heat equation

Lecture 5: Single Step Methods

1 Introduction to MATLAB

PARTIAL DIFFERENTIAL EQUATIONS. Lecturer: D.M.A. Stuart MT 2007

BOUNDARY-VALUE PROBLEMS IN RECTANGULAR COORDINATES

Finite difference method for elliptic problems: I

Numerical Algorithms for ODEs/DAEs (Transient Analysis)

Defect-based a-posteriori error estimation for implicit ODEs and DAEs

Lecture 42 Determining Internal Node Values

Weighted ENO Schemes

Finite Volume Method

Chapter 3 Second Order Linear Equations

Numerical Methods for PDEs

Math 7824 Spring 2010 Numerical solution of partial differential equations Classroom notes and homework

The method of lines (MOL) for the diffusion equation

First, Second, and Third Order Finite-Volume Schemes for Diffusion

ECE539 - Advanced Theory of Semiconductors and Semiconductor Devices. Numerical Methods and Simulation / Umberto Ravaioli

Basics of Discretization Methods

Inverse Lax-Wendroff Procedure for Numerical Boundary Conditions of. Conservation Laws 1. Abstract

Lecture V: The game-engine loop & Time Integration

3.4. Monotonicity of Advection Schemes

Transcription:

2D1263 : Scientific Computing Lecture 8 (2) 2D1263 : Scientific Computing Lecture 8 (1) Difference operators Let xi m i=0 be equidistant points in [a, b], x i = a + (b a)i/m, and define the forward difference operator D+ by, = b a m, 0 i < m. D+ui = u(x i+1) u(xi) By Taylor expansion around xi, ) (u(xi) + u (xi) + 2 2 u (xi) + O( 3 ) u(xi) D+ui = 1 = u (xi) + 2 u (xi) + O( 2 ) D+ui(t) ux(xi, t) as 0 if u(x, t) sufficiently smooth (in x). Difference operators Some other common operators include Backward difference: D u i = u i u i 1 Central difference: D 0 u i = u i+1 u i 1 2 Second difference : = u x (x i ) + O() = u x (x i ) + O( 2 ) D + D u i = u i+1 2u i + u i 1 2 = u xx (x i )+O( 2 ) Systematic way of formulating semidiscrete system. Replace spatial derivatives with difference operators. Example, u t + au x = ɛu xx approximated by du i dt + ad 0u i = ɛd + D u i, 0 i n Boundary conditions are used to determine u 1 and u m+1. 2D1263 : Scientific Computing Lecture 8 (4) 2D1263 : Scientific Computing Lecture 8 (3) Time discretization Discretization in time using similar formulas. Forward Euler for ut = f(u): f(u(t)) = ut(t) + 2 u tt(t) + O( 2 ) f(u(t)) = 2 u tt(t) + O( 2 ) u(t + ) u(t) Backward Euler: Function f evaluated at time t +. Example, ut + aux = ɛuxx with forward Euler u n i = u n 1 i + ( ɛd+d u n 1 i ad0u n 1 ) i, 0 i m, n 1 where the superscript denotes the time level. Consider ODE y (t) = f(y). Linear Multistep Method: c i y n i = d i f(y n i ) i=0 i=0 Explicit scheme if d 0 = 0. Implicit if d 0 0. Explicit: y n = 1 c 0 ( d i f(y n i ) ) c i y n i Solution at new time level given explicitly in terms of previous solutions. Implicit: c 0 y n d 0 f(y n ) = d i f(y n i ) c i y n i Solution given implicitly by (possibly nonlinear) equation.

2D1263 : Scientific Computing Lecture 8 (5) y (t) = y(t) y(0) = 1 Forward Euler (explicit): y n y n 1 = y n 1 y n = (1 ) n Backward Euler (implicit): 10 1 10 0 y n y n 1 = y n y n = (1 + ) n 2D1263 : Scientific Computing Lecture 8 (6) Explicit: + fast: known expression for solution at next time level stability restrictions on. Implicit: + less restrictive conditions on must solve equation to update solution ln( error ) 10 1 10 2 10 3 10 4 Forward Euler Backward Euler 10 5 0 2 4 6 8 10 Time Note: For > 2 forward Euler leads to growth. Unstable! For PDEs: stability restrictions depend on grid spacing (CFL condition) must solve systems of equations for implicit discretization 2D1263 : Scientific Computing Lecture 8 (7) Full discretization A general linear difference scheme in one dimension can be written m different time levels different grid points k l m= q r k= p cm,ku n+m j+k. The cm,k are not necessarily determined by the method of lines. We can insert u(x, t) in the formula, and determine cm,k such that only desired terms disappear in the Taylor expansion. See for example Lax-Wendroff scheme, p. 46 in the lecture notes. 2D1263 : Scientific Computing Lecture 8 (8) Difference schemes Three important characteristics of a scheme: 1. Consistency difference scheme should approach PDE as, 0. 2. Accuracy The scheme is said to be accurate of order α and β in space and time respectively, if l m= q r k= p cm,ku(x + k, t + m) = O ( ( α + β)), when the exact solution u(x, t) is inserted. 3. Stability The solution from the difference scheme grows at most exponentially in time (independent of, ). If a scheme is consistent & stable convergence to u(x, t) is obtained as, 0. Rate determined by order of accuracy.

2D1263 : Scientific Computing Lecture 8 (9) 2D1263 : Scientific Computing Lecture 8 (10) Difference schemes Order of accuracy: Taylor expansion and investigation of local truncation error. Measure of how well scheme approximates PDE. Consistency: Order of accuracy (α, β) > 0. Stability: Exponential growth must be allowed to solve e.g. u t + au x = bu, u(x, t) = exp(bt)u 0 (x at). Techniques for stability analysis: Fourier method Fourier components The CFL condition For time-dependent problems explicit methods are subject to an additional CFL condition, which ensures stability. Generically: Hyperbolic equations u t + au x = 0: a c 0 Parabolic equations u t = bu xx : b c 0 () 2 Energy method norm of discrete solution Normal mode analysis Laplace transform 2D1263 : Scientific Computing Lecture 8 (11) Non uniform grids (outlook) Consider a non uniform grid: a = x 0 < x 1 < < x m 1 < x m = b, Ansatz (cf D 0 ): u (x j ) a u(x j 1 ) + a 0 u(x j ) + a + u(x j+1 ) Taylor expansion gives a = j+1/2 j 1/2 ( j+1/2 + j 1/2 ) a 0 = j+1/2 j 1/2 j+1/2 j 1/2 a + = j 1/2 j+1/2 ( j+1/2 + j 1/2 ) Note: For generalizing to higher dimensions, grid mapping techniques are better suited. j+1/2 = x j+1 x 2D1263 : Scientific Computing Lecture 8 (12) Several space dimensions (outlook) In case of a cartesian grid (grid lines aligned with the coordiante axis in physical space), it is natural to sum up one-dimensional approximations: Example: divu(xi, yj) = ux + vy a x u(xi 1, yj) + a x 0u(xi, yj) + a x +u(xi+1, yj) + a y u(xi, yj 1) + a y 0 u(x i, yj) + a y +u(xi, yj+1)

2D1263 : Scientific Computing Lecture 8 (13) 2D1263 : Scientific Computing Lecture 8 (14) Several space dimensions (cont) The immediate generalization to general structured grids is 2D l,m α l,m u i+l,j+m 3D where α l,m,n u i+l,j+m,k+n l,m,n u i,j u(x i,j, y i,j ), u i,j,k u(x i,j,k, y i,j,k, z i,j,k ). The sets (l, m) α l,m 0 (in 2D) and (l, m, n) α l,m,n 0 are called the stencil of the approximation. Second order approximation of u x + v y Physical domain Grid mapped Array representations Computationally, dd-dimensional grids as well as dd-dimensional grid data are conveniently mapped to dd-dimensional arrays. Note: An array does not necessarily represent a matrix! Which basic operations are really necessary? There are many standard libraries available for this purpose: Blitz++, Lapack++, MTL, MET, and many many others. Aditionally, there are C++-interfaces to standard libraries available. We will have a look at some basics. Note: Compare chapter 5.3 of the Lecture Notes. 2D1263 : Scientific Computing Lecture 8 (15) 2D1263 : Scientific Computing Lecture 8 (16) A basic array class in C++ class arc2 private: double *w; int ni, nj; arc2() ; public: arc2(int nii, int nji) ni = nii; nj = nji; double ind(int i, int j) return w[i+j*ni]; arc2 operator+(const arc2 &b); ~arc2() delete [] w; ; Comments on arc2 The array is stored in column major order just like in Fortran. This is the convention in many standard libraries. We used (C-style) indexing starting with 0. This leads to the index mapping ind = i + j ni. It is easy to generalize to 3D arrays. array elements can be accessed by a.ind(i,j). The standard constructor is private thus preventing anybody from using it! There is no security checking! Do it! Operators can be overloaded.

2D1263 : Scientific Computing Lecture 8 (18) 2D1263 : Scientific Computing Lecture 8 (17) Operator overloading C++ allows operators to be overloaded similarly to functions. arc2 arc2::operator+(const arc2 &b) if ((ni!= b.ni) (nj!= b.nj)) exit(-1); arc2 c(ni, nj); for (int i = 0; i < ni*nj; i++) c.w[i] = w[i] + b.w[i]; return c; Hint: For large objects, use reference arguments in order to avoid excessive copying. An indexing operator double& arc2::operator()(int i, int j) if (i < 0 i >= ni j < 0 j >= nj) exit(-1); return w[i+j*ni]; Remarks: The elements can now be accessed by a.ind(i,j) or a(i,j). The latter can be used on the left-hand side of an assinment a(1,2)=1.0. The previous must be modified. Stroustrup s recommendation: use functions for speed, operators for debugging purposes. Try to overload [], too. 2D1263 : Scientific Computing Lecture 8 (19) 2D1263 : Scientific Computing Lecture 8 (20) Copy assignment Let arc2 a(n,m), b(n,m);. The assignment b = a; copies each member of a to b: b.ni = a.ni; b.nj = a.nj; b.w = a.w; The arrays are not copied such that both a and b use the same data! Therefore, the copy assignment operator = must be overloaded: arc2& arc2::operator=(const arc2 & a) if (ni!= a.ni nj!= a.nj) delete [] w; ni = a.ni; nj = a.nj; for (int i = 0; i < ni*nj; i++) w[i] = a.w[i]; return *this; An (almost) complete header class arc2 private: double *w; int ni, nj; arc2() ; public: arc2(int nii, int nji) ni = nii; nj = nji; arc2(const arc2&); double ind(int i, int j) return w[i+j*ni]; double& operator()(int i, int j); double& operator[](int l) return w[l]; arc2& operator=(const arc2 & a); arc2 operator+(const arc2 &b); ~arc2() delete [] w; ;