Skip to content

Instantly share code, notes, and snippets.

@maxnuf
Created May 29, 2013 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxnuf/5669273 to your computer and use it in GitHub Desktop.
Save maxnuf/5669273 to your computer and use it in GitHub Desktop.
calculate dipolemoment of silver nanosphere in meep
;******************* OPTIONS
;(set! eps-averaging? false)
;(set! force-complex-fields? false)
;(set! output-single-precision? true)
;******************* PARAMETERS
(define-param res 32)
(define-param scale 100)
(define-param r 25) ; radius of sphere
(define-param source-wavelength 363)
(set-param! resolution res)
;******************* NORMALIZE
(define norm-r (/ r scale))
(define norm-wavelength (/ source-wavelength scale))
;******************* MATERIAL
(define-param epsilonB 5.45) ; dielectric
(define-param eta 0.73)
(define-param g 4.4329e-5)
(define-param plasmaFreq 0.0091312)
(define norm-g (* g scale))
(define norm-plasmaFreq (* plasmaFreq scale))
(define drude-silver (make medium (epsilon epsilonB)
(E-susceptibilities
(make drude-susceptibility
(sigma eta) (gamma norm-g) (frequency norm-plasmaFreq)
)
)
))
;******************* DOMAIN
(define-param pad 100); padding to edge of pml
(define-param dpml 100); thickness of pml
(define norm-pad (/ pad scale))
(define norm-dpml (/ dpml scale))
(define sx (* 4 (+ norm-r norm-pad))) ; cell size
(define sx0 (+ sx norm-dpml norm-dpml)) ; grid size
(define sy (* 4 (+ norm-r norm-pad))) ; cell size
(define sy0 (+ sy norm-dpml norm-dpml)) ; grid size
(define sz (* 4 (+ norm-r norm-pad))) ; cell height
(set! geometry-lattice
(make lattice (size sx0 sy0 (+ sz norm-dpml norm-dpml)))
)
;******************* GEOMETRY
(set! geometry (append geometry (list
(make sphere
(center 0 0 0)
(radius norm-r)
(material drude-silver)
)
)))
;******************* PML
(set! pml-layers (list
(make pml (thickness norm-dpml))
))
;******************* SOURCES
(set! sources (list
(make source
(src (make continuous-src
(wavelength norm-wavelength)
))
(component Ex)
(center 0 0 (* sz 0.5))
(size sx0 sy0 0)
)
))
;******************* SYMMETRIES
(set! symmetries (list
(make mirror-sym (direction X) (phase -1))
(make mirror-sym (direction Y))
))
;******************* MONITORS
(define integrating-volume (volume
(center 0 0 0)
(size (* 2 norm-r) (* 2 norm-r) (* 2 norm-r))
))
;******************* FDTD Run
(run-until (* 60 norm-wavelength))
;******************* calculate polarization
(define (pol r ei di)
(- di ei)
)
(define (my-pol-output) (print
"Dipolemoment-x: " (integrate-field-function (list Ex Dx) pol integrating-volume) "\n"
"Dipolemoment-y: " (integrate-field-function (list Ey Dy) pol integrating-volume) "\n"
"Dipolemoment-z: " (integrate-field-function (list Ez Dz) pol integrating-volume) "\n"
))
(run-until norm-wavelength
(at-every (/ 1 scale) my-pol-output)
)
@vishalvashistha87
Copy link

Could you please tell me, how to run this file ? This is neither a .ctl file nor .py file. I cannot run neither in meep nor in python meep. Please give some advice. My mail ID is vishal.vashistha87@gmail.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment