7/0/07 Instructor r. Ramond Rump (9) 747 698 rcrump@utep.edu EE 337 Computatonal Electromagnetcs (CEM) Lecture #0 Fnte erence Method Lecture 0 These notes ma contan coprghted materal obtaned under ar use rules. strbuton o these materals s strctl prohbted Slde Outlne Fnte erence Appromatons Fnte erence Method Numercal Boundar Condtons Matr Operators Lecture 0 Slde
7/0/07 Fnte erence Appromatons Lecture 0 Slde 3 The Basc Fnte erence Appromaton d d. second order accurate rst order dervatve d d Ths s the onl nte derence appromaton we wll use n ths course! Lecture 0 Slde 4
7/0/07 Tpes o Fnte erence Appromatons Backward Fnte erence d d Central Fnte erence d d. Forward Fnte erence d d Lecture 0 Slde The Generalzed Fnte erence n d d n a In act, an lnear operaton on the uncton can be appromated as a lnear sum o known ponts o that uncton. L a The dervatve o an order o a uncton at an poston can be appromated as a lnear sum o known ponts o that uncton. Lecture 0 Slde 6 3
7/0/07 Fnte erence Atoms An nte derence appromaton can be summarzed graphcall as an atom. d d d d, j 4, j, j, j, j, j, j, j, j, j, j Lecture 0 Slde 7 Fnte erence Method Lecture 0 Slde 8 4
7/0/07 Overvew o Our FM. Ident and wrte the governng equaton(s). a b c g. Wrte the matr orm o ths equaton gong term b term. a b c g A B C g 3. Put matr equaton n the standard orm o [L][] = [g]. L g L A B C 4. Solve [L][] = [g]. L g where L = A*X + *B*X + C; Lecture 0 Slde 9 What s the Catch? LA B C How do we construct these matrces? What do the mean? A B C Lecture 0 Slde 0
7/0/07 Functons Vs. Operatons ( o ) a b g c Operatons Everthng else n a derental equaton s somethng that operates on a uncton. a, b, c pont-b-pont multplcaton on, calculates dervatves o scales entre Functons The onl tme unctons appear n a derental equaton s as the unknown or as the ectaton. g unknown ectaton Lecture 0 Slde Functons Vs. Operatons ( o ) A B C g Operatons Operatons are alwas stored n square matrces. An lnear operaton can be put nto matr orm. L l l l l l l l l l M M M M MM Functons Functons are stored as column vectors. g g g g M M Lecture 0 Slde 6
7/0/07 Interpretaton o Matrces aa a3 z b aa a3z b a3a3 a33z b3 EQUATION FOR a a a3 b a a a b 3 a3 a3 a 33 z b 3 RELATION TO Equaton or Equaton or Equaton or z a a a a a a a a a 3 3 3 3 33 a a a a a a a a a 3 3 3 3 33 From a purel mathematcal perspectve, ths nterpretaton does not make sense. Ths nterpretaton wll be hghl useul and nsghtul because o how we derve the equatons. Lecture 0 Slde 3 Representng Functons on a Grd Eample phscal (contnuous) uncton A grd s constructed b dvdng space nto dscrete cells Functon s known onl at dscrete ponts Representaton o what s actuall stored n memor Lecture 0 Slde 4 7
7/0/07 Grd Cells Whole Grd A Sngle Grd Cell A uncton value s assgned to a specc pont wthn the grd cell., grd resoluton parameters Lecture 0 Slde Functons are Put Into Column Vectors Sstems 4 3 3 4 Sstems 9 3 6 0 4 3 7 4 8 6 3 4 6 7 8 9 0 3 4 6 Lecture 0 Slde 6 8
7/0/07 Puttng Functons nto Column Vectors 9 3 6 0 4 3 7 4 8 6 MATLAB reshape command = F(:); F = reshape(,n,n); 3 4 6 7 8 9 0 3 4 6 3 4 6 7 8 9 0 3 4 6 Lecture 0 Slde 7 Locatng Nodes n Column Vectors Grds Node located at n m = n Grds Node located at n,n m = (n )*N + n 3 Grds Node located at n,n,nz m = (nz )*N*N + (n )*N + n Lecture 0 Slde 8 9
7/0/07 The Fnte erence Method Conventonal FM k Tedous, but not dcult. erental Equaton to Solve d a g d k a k k g k Ver dcult and tedous. L g Eas. L g Most tme consumng step. Almost eortless. a g Eas. Ver eas and clean L g L a Improved FM Lecture 0 Slde 9 Conventonal FM ( o 3) Step We start wth a derental equaton that we wsh to solve. d d a b c d d Step We appromate the dervatves wth nte derences. k k k k k a k b k k c k IMPORTANT RULE: Ever term n a nte derence equaton must est at the same pont. Step 3 The equaton s epanded and we collect common terms Lecture 0 Slde 0 a k a k k k k k k b k k c k a k a k k bk k k c k 0
7/0/07 Conventonal FM ( o 3) Step 4 The nal equaton s used to populate a matr equaton. k a a k k bk k k k c Fllng n the matr lke ths can be a ver dcult and tedous task or more complcated derental equatons or or sstems o derental equatons. c c 3 c 3 4 c 4 c N cn N cn Lecture 0 Slde Conventonal FM (3 o 3) Step The matr equaton s solved or the unknown uncton () L c L c L c L c Lecture 0 Slde
7/0/07 Improved FM We want a ver eas wa to mmedatel wrte derental equatons n matr orm. Startng wth the same derental equaton a b c We wll develop a procedure b whch ths wll be drectl wrtten n matr orm wthout havng to eplctl handle an nte derences. a b c, A,, and B are square matrces that perorm lnear operatons on the vector. A B =c Lecture 0 Slde 3 A B =c LL L c Locatng Nodes n Matrces m or n = n m or n = (n )*N + n 3 m or n = (nz )*N*N + (n )*N + n Column n Relaton to node (n,n,nz) Row m Equaton or node (n,n,nz) Lecture 0 Slde 4
7/0/07 Numercal Boundar Condtons Lecture 0 Slde The Problem at the Boundares Suppose t s desred to solve the ollowng derental equaton on a 33 grd.,, g,, j, j, j, j, j, j g, j 0, 0, 0,3,0,0 3,0,4,4 3,4 The terms n red est outsde o the grd. How ths s handled s called a boundar condton. 4, 4, 4,3 3,,,,, 4, 3,, 3, 3,,,,, 0,,0,0 3,0,, 0,,3,, 4, 0,3,4,4 4,3 3,4 3,,,,3,, 3,, 3,3 3, 3,,3,3,3, 3,3,3,3,3, 3,3,3 3,3 3, g, g g g, 3,, g g g, 3,,3 g g,3 3,3 Lecture 0 Slde 6 3
7/0/07 rchlet Boundar Condtons ( o ) The smplest boundar condton s to assume that all values o (,) outsde o the grd are zero. 0, 0, 0,3,0,0 3,0,4,4 3,4 4, 4, 4,3,, 0,, 0 g 3,,,,, 0 g 03,, 3, 3, 0 g 0,,,3,, 0 3,,,,3,, 3,, 3,3 3, 3, g 3, 0 0 0 0 0,3,3,3, 3,3,3,3,3, 3,3,3 3,3 3,, g, 3,, g g,,3 g g,3 3,3 Lecture 0 Slde 7 rchlet Boundar Condtons ( o ) rchlet boundar condtons assume uncton values rom outsde o the grd are zero.,, 0 N, 0 N,,, 0, N 0, N,,, 0 N, 0 N, N,,,, 0, N 0,, N N Lecture 0 Slde 8 4
7/0/07 Perodc Boundar Condtons ( o ) I the uncton (,) s perodc, then the values rom outsde o the grd can be mapped to a value rom nsde the grd at the other sde.,,, and 0, j 3, j 4, j, j,0,3,4, 0, 0, 0,3,0,0 3,0,4,4 3,4 4, 4, 4,3 3,,,,,, 3,, 3, 3,,,,, 3,,3,3 3,3,, 3,,3,,, 3,3,,,3 3, 3,,,,3,, 3,, 3,3 3, 3,,3,3,3, 3,3,3,3,3, 3,3,3 3,3 3, g, g g g, 3,, g g g, 3,,3 g g,3 3,3 Lecture 0 Slde 9 Perodc Boundar Condtons ( o ) Perodc boundar condtons assume uncton values rom outsde o the grd can be taken rom the opposte sde o the grd.,, N, N,,, N,,, N, N,, N,,, N, N,,,, N N,,,, N, N,,, N N Lecture 0 Slde 30
7/0/07 Neumann Boundar Condtons We use Neumann boundar condtons or non perodc unctons or unctons that are not zero at the boundar. Here the uncton contnues lnearl outsde o the grd. Spatall varant gratng that s not perodc and not zero at the boundares. Here s a uncton wth Neumann boundares Lecture 0 Slde 3 Neumann BC s or Functon The nte derence appromaton or a uncton s d d At =, we have a problem d d 0 Ths term doesn t est! d d At =N, we have another problem d N N d N Ths term doesn t est! N N Lecture 0 Slde 3 d d N 6
7/0/07 What About the nd Order ervatves or the Neumann Boundar Condton? In order or the uncton to contnue n a straght lne, the second order dervate should be set to zero at the boundar. IMPORTANT: Ths s NOT rchlet boundar condtons. A rchlet BC sets the uncton tsel to zero outsde o the grd, not the dervatve. Here, the nd order dervatve s set to zero. d d d 0 0 d d d N N N 0 N d N d Lecture 0 Slde 33 Neumann Boundar Condtons or Functons Neumann boundar condtons are used when a uncton should be contnuous at the boundar. That s, the rst order dervatve s contnuous and the second order dervatve s zero.,,, N, N, N,,,,, N,, N N, N,,, N 0 0 0 0 Lecture 0 Slde 34 7
7/0/07 Matr Operators Lecture 0 Slde 3 Orgn o Matr Operators We start wth a governng equaton. We appromate the governng equaton wth nte derences and then wrte the ntederence equaton at each pont the grd. d d, g,,, 0 g, 3,, g 0 3, g,,, 0 g, 3,, g 0 3, g,,3,3 0 g,3 3,3,3 g 0 3,3 g,3,, 3,,, 3,,3,3 3,3 We collect the large set o equatons nto a sngle matr equaton. 0 0 0 0 0 0 0, g, 0 0 0 0 0 0, g, 0 0 0 0 0 0 0 3, g 3, 0 0 0 0 0 0 0, g, 0 0 0 0 0 0, g, 0 0 0 0 0 0 0 3, g3, 0 0 0 0 0 0 0,3 g,3 0 0 0 0 0 0,3 g,3 0 0 0 0 0 0 0 3,3 g 3,3 We construct a grd to store the unctons. Ths matr calculates the dervatve o (,) and puts the answer n g(,). Ths s a matr operator. Lecture 0 Slde 36 8
7/0/07 Other Matr Operators A square matr can alwas be constructed to perorm an lnear operaton on a uncton that s stored n a column vector.? 3 d d N FFT F d Lecture 0 Slde 37 g G h H Pont b Pont Multplcaton ( o ) b b b b 3 4 b b6 Snce we are storng our unctons n vector orm, how do we perorm a pont b pont multplcaton usng a square matr? 6 3 4 b B 3 4 6 b 0 0 0 0 0 b 0 b 0 0 0 0 b? 0 0 b3 0 0 0 3 b3 3 0 0 0 b4 0 04 b4 4 0 0 0 0 b 0 b 0 0 0 0 0 b6 6 b6 6 B B Lecture 0 Slde 38 9
7/0/07 Pont b Pont Multplcaton ( o ) b b b b 3 4 b b6 Snce we are storng our unctons n vector orm, how do we perorm a pont b pont multplcaton usng a square matr? 6 3 4 b B 3 4 6 b 0 0 0 0 0 b 0 b 0 0 0 0 b 0 0 b3 0 0 0 3 b3 3 0 0 0 b4 0 04 b4 4 0 0 0 0 b 0 b 0 0 0 0 0 b6 6 b6 6 B B Lecture 0 Slde 39 Frst Order Partal ervatve ( o ) How do we construct a square matr so that when t premultples a vector, we get a vector contanng the rst order partal dervatve? 6 3 4 3 4 6 0 0 0 0 0 0 0 0 0 0 3? 0 0 0 0 3 4 0 0 0 0 4 3 0 0 0 0 6 4 0 0 0 0 0 6 7 Lecture 0 Slde 40 0
7/0/07 Frst Order Partal ervatve ( o ) How do we construct a square matr so that when t premultples a vector, we get a vector contanng the rst order partal dervatve? 6 3 4 3 4 6 0 0 0 0 0 0 0 0 0 0 3 0 0 0 0 3 4 0 0 0 0 4 3 0 0 0 0 6 4 0 0 0 0 0 6 7 Lecture 0 Slde 4 Second Order Partal ervatve ( o ) How do we construct a square matr so that when t premultples a vector, we get a vector contanng the second order partal dervatve? 6 3 4 3 4 6 0 0 0 0 0 0 0 0 3? 0 0 0 3 4 3 0 0 0 4 4 3 0 0 0 6 4 0 0 0 0 6 7 6 Lecture 0 Slde 4
7/0/07 Second Order Partal ervatve ( o ) How do we construct a square matr so that when t premultples a vector, we get a vector contanng the second order partal dervatve? 6 3 4 3 4 6 0 0 0 0 0 0 0 0 3 0 0 0 3 4 3 0 0 0 4 4 3 0 0 0 6 4 0 0 0 0 6 7 6 Lecture 0 Slde 43 What About Grds ( o )? Two dmensonal grds are a lttle more dcult, Lecture 0 Slde 44 3 4 6 7 8 9??? 3 0 3??? 3 0 4 4??? 6 4 0 6??? 6 0 7 8 7??? 8 9 8 7 9??? 9 8
7/0/07 What About Grds ( o )? Two dmensonal grds are a lttle more dcult, 3 4 6 7 8 9 0 0 4??? 0 0 0??? 0 0 0 0 3 6 3??? 0 0 0 0 4 7 4 0 0 0 0 8 0 0 0 0 6 9 6 3 0 0 0 0 7??? 7 4 0 0 0 8??? 8 0 0 9??? 9 6 Lecture 0 Slde 4 ervatve Operators wth rchlet Boundar Condtons 0 0 0 0 0 0 0 Both o these matrces onl have 0 0 0 0 0 0 numbers along three o ther dagonals. 0 0 0 0 0 0 0 Ths s called trdagonal. 0 0 0 0 0 0 0 Ths suggests a ast wa to construct 0 0 0 0 0 0 these matrces. 0 0 0 0 0 0 0 () has some correctons shown n 0 0 0 0 0 0 0 blue along two o ts dagonals. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 These matrces contan mostl zeros. 0 0 0 0 0 0 0 0 0 0 0 0 0 These are called a sparse matrces. 0 0 0 0 0 0 0 0 0 0 0 0 See MATLAB sparse() command. 0 0 0 0 0 0 0 Also see MATLAB spdags() command. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Lecture 0 Slde 46 3
7/0/07 Wh o We Need Separate Matr Operators or Frst and Second Order ervatves? We know that, Can we just calculate () rom ()??? Yes, but ths does not make ecent use o the grd. For a pont, grd, we have 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Ths s not as accurate because t calculates the dervatve wth poorer grd resoluton than s avalable. Ths matr operator makes optmal use o the avalable grd resoluton. Lecture 0 Slde 47 ervatve Operators or Grds When N= and N> When N> and N= Z zero matr s standard or grd s standard or grd Z zero matr 0 0 0 0 0 0 0 0 0 0 Lecture 0 Slde 48 4
7/0/07 USE SPARSE MATRICES!!!!!!! The dervatve operators wll be EXTREMELY large matrces. For a small grd that s just 0000 ponts: Total Number o Ponts: 0,000 Sze o ervate Operators: 0,000 0,000 Total Elements n Matrces: 400,000,000 Memor to Store One Full Matr: 6 Gb Memor to Store One Sparse Matr: Mb NEVER AT ANY POINT should ou use FULL MATRICES n the nte derence method. Not even or ntermedate steps. NEVER! Lecture 0 Slde 49