PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

Embed Size (px)

Citation preview

  • 7/28/2019 PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    http:///reader/full/ph2150weeknineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 1/5

  • 7/28/2019 PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    http:///reader/full/ph2150weeknineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 2/5

    k2 = hf(xn +h

    2, yn +

    k1

    2)

    k3 = hf(xn +h

    2, yn +

    k2

    2)

    k4 = hf(xn + h, yn + k3)

    yn+1 = yn +k1

    6+

    k2

    3+

    k3

    3+

    k4

    6

    1.1 Wk9Ex1:

    Modify the field simulation.py code to use a 4th order Runge-Kutta method, plot and com-pare with the Eulers method result. Try increasing the total time interval to see how theerrors vary with time.

    1 from numpy im port from pylab im port

    from m p l t o o l k i t s . m pl o t3 d im port Axes3D The f o l l o w i n g e xa mp le t r a c e s t h e movement o f a c ha rg e d p a r t i c l e u nd er t h e

    i n f lu e n ce o f e l e c t r i c and6 m ag ne ti c f i e l d s . You c an e d i t t h e pr og ram t o c ha ng e t h e c om po ne nt s o f t h e

    f i e l d s to s ee t h ei r e f f e c t ont he t r a j e c t o r y . E x = 0 . 0 # Components o f a p p l i e d E l e c t r i c F i e l dE y = 2 . 0

    11 E z = 0 . 0B x = 0 . 0 # C omp on ent s o f a p p l i e d M ag ne ti c f i e l dB y = 0 . 0

    B z = 5 . 0m = 2 . 0 # Mass o f t he p a r t i c l e

    16 q = 5 . 0 # Chargex = 0 . 0 # i n i t i a l p os it io n xy = 0 . 0 # i n i t i a l p os it io n yz = 0 . 0 # i n i t i a l p os it io n zv x = 2 0 . 0 # i n i t i a l v e l o ci t y vx

    21 v y = 0 . 0 # i n i t i a l v e l o ci t y vyv z = 2 . 0 # i n i t i a l v e l o ci t y v za = [ ]b = [ ]c = [ ]

    26 t = 0 .0d t = 0 . 0 1w h i l e t < 6 : # t ra c e p at h u n t i l t im e r e a c h es v al u e

    F x = q ( E x + ( v y Bz ) ( vz By ) )vx = vx + Fx/m dt # A c c e l e r a t i o n = F/m; dv = a . d t

    31 F y = q (Ey ( vx B z ) + ( v z Bx ) )vy = vy + Fy/m dtF z = q ( E z + ( v x By) ( vy Bx ) )

    2

  • 7/28/2019 PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    http:///reader/full/ph2150weeknineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 3/5

    v z = v z + F z / m dtx = x + v x dt

    36 y = y + v y dtz = z + v z dta . append( x)b . append(y )

    c . append( z )41 t = t + dt

    f i g =f i g u r e ( )ax = Axes3D( fig )ax . s e t t i t l e ( Path o f c ha rg ed p a r t i c l e under i n f l u e nc e o f e l e c t r i c and

    m ag ne ti c f i e l d s )46 ax . s e t x l a b e l ( X )

    ax . s e t y l a b e l ( Y )ax . s e t z l a b e l ( Z )a x . p l o t3 D ( a , b , c , c o l o r = blu e , l a b el= path )ax . leg end ( loc= l ow er l e f t )

    51

    show()

    field simulation.py

    2 Vector Fields

    The code vectorfield.py is a basic script for generating a simple vector field around a pointcharge using Mayavi. Download the code from moodle and run it. Exlpore the functionalityof the Mayavi toolbar, the first button opens a dialog for the Mayavi pipeline that allowsyou to control many aspects of the view.

    Figure 1: The Mayavi toolbar, the first button launches the Mayavi pipeline

    2.1 Wk9Ex2:

    Modify the code such that the vector field is only calculated and plotted in the x,y plane.Add axis labels and a title to the plot and save a .png output of the plot.

    from numpy im port mg ri d , a r ra y , s q r tfrom mayavi . mlab im port q u i v e r 3 d

    3 # t h i s c r e a te s a 3D g r i d which i s r an ge s from 100 t o 100 i n a l l# co o r di n at e s , w it h i n t e r s e c t i o n s a t e ve ry 20 th v al u e# (100, 80 , 60 , . . . ) . S ee h e l p m gr id f o r d e t a i l s .x , y , z = m grid [ 1 0 0 . : 1 0 1 . : 2 0 . , 1 0 0 . : 1 0 1 . : 2 0 . , 1 0 0 . : 1 0 1 . : 2 0 . ]# We w i l l now s t o r e t he c o o r di n a t e s o f o ur c ha rg e a s a

    3

  • 7/28/2019 PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    http:///reader/full/ph2150weeknineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 4/5

    8 # v e ct o r . A l l v e c t or s i n Python s ho ul d be s t o re d a s a r ra y s .# Note t ha t we a r e p l a c i ng t h i s c ha rg e i n b et wee n t he g r i d p o i nt s .# This i s to g et the b es t p o s si b l e symmetry i n t h i s s p e c i f i c f i e l d# I f y ou p la ce t he c har ge o n th e g ri d , you g e t a d i v i si o n o f z er o# when c a l c u l a t i n g t he Ef i e l d .

    13 q po s = a rr a y ( [ 1 0 . , 1 0 . , 1 0 . ] )

    # t h e m ag ni tu de o f o ur c h a r ge . T h is c o u l d b e a n y n umber# at the moment.q c h a r g e = 1 . 0

    # Create a g ri d f o r the e l e c t r i c f i e l d . This has th e s i z e o f 18 # x , y and z , b ut a l l t he v a l ue s a r e now s e t t o z e ro .

    Ex , Ey , Ez = x0 , y0 , z0

    # C al c ul a te t he x , y a nd z d i st a nc e t o t he c ha rg e a t e ve ry p oi nt i n t he g r id :r x = x q p os [ 0 ]

    23 r y = y q p os [ 1 ]r z = z q p os [ 2 ]

    # C al c ul a te t he d i st a nc e a t e ve ry p oi nt i n t he g r id :

    r = s q r t ( r x 2 + r y 2 + r z 2 )28

    # C al c u la t e t he f i e l d f o r e ac h c omponent a t e ve ry p o in t i n t he g r i d :Ex = ( q c h ar g e / r 2) ( rx / r )Ey = ( q c h ar g e / r 2) ( ry / r )Ez = ( q c h ar g e / r 2) ( r z / r )

    33

    # Draw t h e v e c to r f i e l d i n 3Dq u i v e r 3 d ( x , y , z , Ex , Ey , Ez )

    vectorfield.py

    2.2 Wk9Ex3:

    The expressions needed for question 3 are contained within the moodle pdf EM StandingWaves in Resonant Cavities. Consider a rectangular cavity with perfectly reflecting walls(dimensions a x b x d).

    Figure 2: Rectangular resonant cavity

    Write code to calculate the resonant frequencies as a function of the mode numbers,use reduced units scale everything to a/v (v speed of light)

    4

  • 7/28/2019 PH2150_WeekNineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

    http:///reader/full/ph2150weeknineaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 5/5

    Make a list of the 10 first frequencies for a cavity 36 x 33 x 23 cm. This is about the sizeof my microwave oven, comment on the typical operating frequency of a microwave.

    Plot the E, B field lines for the two first TE modes

    Plot the current intensity on the wall, find the nodes location

    Repeat the last two plots with the 2 first TM modes.

    TE modes (Transverse Electric) no electric field in the direction of propagation. TMmodes (Transverse Magnetic) no magnetic field in the direction of propagation.

    An alternative description of the physics can be found at: http:cas.web.cern.chcasDenmark-2010LecturesWolski-2.pdf (page 32)

    5