Hey

I'd like to loop through the position of my reflective flux detector, but my
many attempts haven't worked. I resorted to writing a script in python and
stepping through the various positions, but that is taking quite long. Any
suggestions would be much appreciated. Basically the relevant part is
towards the end, where I define a reflection detector in the x and in the y
directions and then begin to loop through angles at which I place that
detector.

Best,
Vijay Jain

---

(reset-meep)

; Some parameters to describe the geometry
(define-param polystyrene (* 1.59 1.59)) ; dielectric constant of the
scatterers
(define-param ayr 1) ; dielectric constant of air (background)
(define-param latx 60) ; lattice in x
(define-param laty 60) ; lattice in y
(define-param dpml 1.0) ; thickness of PML for z-direction

(define-param plain? false) ; if TRUE, there is no lattice structure
(define-param hex? false) ; if TRUE, there is a hexagonal lattice geometry
(define-param touch? false) ; if TRUE, they are in a touching geometry

(if touch?
    (define-param r 0.5) ; if touching, radius of rods
    (define-param r 0.1) ; if not touching, radius of rods
)
(if hex?
    (begin
      (define-param hexx (/ (sqrt 3) 2)) ; hexagonal spacing offset in
X-direction
      (define-param hexy 0.5) )
    (begin
      (define-param hexx 1.0) ; square spacing offset
      (define-param hexy 0) )
)

;(use-output-directory) ; put all output in a new directory
(define-param source-component Ez) ; field component to use

(define-param sx (+ latx (* 2 dpml)))
(define-param sy (+ laty (* 2 dpml)))

(set! geometry-lattice (make lattice (size sx sy no-size)))

(define-param dx 1)
(define-param dy dx)

(set! geometry (append geometry
      (list
       (make block
             (center 0 0)
             (size sx sy)
             (material (make dielectric (epsilon ayr))) )
       )))

(if (not plain?)
    (begin
; Defining the geometry - an array of spheres
(set! geometry
      (apply append
     (map (lambda (xx)
    (map (lambda (yy)
   (make sphere
     (center xx yy 0)
     (radius r)
     (material (make dielectric (epsilon polystyrene)))))
 ; the format is (arith-sequence y-min dy num-y)
 (arith-sequence (/ laty -2) dy laty) ))
  (arith-sequence 0 dx (- (/ latx 2) 1)) )))
))

(set-param! resolution 10)

; PML in the X direction
(set! pml-layers (list (make pml (thickness dpml))))

; pw-amp is a function that returns the amplitude exp(ik(x+x0)) at a
; given point x. (We need the x0 because current amplitude functions
; in Meep are defined relative to the center of the current source,
; whereas we want a fixed origin.) Actually, it is a function of k
; and x0 that returns a function of x ...
(define ((pw-amp k x0) x)
  (exp (* 0+1i (vector3-dot k (vector3+ x x0)))))

(define-param fcen 1.0) ; pulse center frequency
(define-param df 0.1) ; turn-on bandwidth

(define-param theta (/ pi -4)) ; Angle of incidence
(define-param thetan (* theta -1)) ; Angle of reflection

(define-param kdir (vector3 (cos theta) (sin theta))) ; direction of k
(length is irrelevant)

;(define k (vector3-scale (* 2 pi fcen)
(define k (vector3-scale fcen
                         (unit-vector3 kdir))) ; k with correct length
(define kxcos (vector3-x (unit-vector3 k))) ; direction cosine of k in x
(define kysin (vector3-y (unit-vector3 k))) ; direction sine of k in y

(set! sources
      (list

       ; left
       (make source
             (src (make gaussian-src (frequency fcen) (fwidth df)))
             (component Ez)
;             (center (* -0.5 sx (cos theta)) (* -0.5 sy (sin theta)))
             (center (* -0.5 latx) (* 0.5 laty))
             (size 0 sx)
             (amp-func (pw-amp k (vector3 (* -0.5 sx (cos theta)) (* 0.5 sy
(sin theta))))))

       ; bottom
       (make source
             (src (make gaussian-src (frequency fcen) (fwidth df)))
             (component Ez)
;             (center (* -0.5 sx (cos theta)) (* -0.5 sy (sin theta)))
             (center (* -0.5 latx) (* 0.5 laty))
             (size sy 0)
             (amp-func (pw-amp k (vector3 (* 0.5 sx (cos theta)) (* -0.5 sy
(sin theta))))))
))

(define-param nfreq 1) ; number of freqs at which to compute flux

(define trans ; transmitted flux
  (add-flux fcen df nfreq
    (make flux-region
      (center (/ latx 2) 0)
      (direction X)
      (size 0 sy) )))

(define (reflx thetax)  ; reflected flux in X
  (add-flux fcen df nfreq
    (make flux-region
      (center (* -0.5 sx (cos thetax)) (* 0.5 sy (sin thetax)))
              (direction X)
      (size 0 (/ sy 2)) )) )

(define (refly thetay) ; reflected flux in Y
  (add-flux fcen df nfreq
    (make flux-region
      (center (* -0.5 sx (cos thetay)) (* 0.5 sy (sin thetay)))
              (direction Y)
      (size (/ sx 2) 0) )) )

(map (lambda (thetan)
(begin
(if (not plain?)
    (load-minus-flux (string-append "refl-flux-x" (number->string thetan))
(reflx thetax)))
(if (not plain?)
    (load-minus-flux (string-append "refl-flux-y" (number->string thetan))
(refly thetay)))
;(run-sources+ 50 (at-beginning output-epsilon))
(run-until 50
           (at-beginning output-epsilon) )
(if plain? (save-flux (string-append "refl-flux-x" (number->string thetan))
(reflx thetax)))
(if plain? (save-flux (string-append "refl-flux-y" (number->string thetan))
(refly thetay)))

(display thetan)
(display-fluxes trans (reflx thetax) (refly thetay)) ; print out the flux
spectrum
))
(arith-sequence (/ pi -2) (/ pi 12) 16) )
_______________________________________________
meep-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/meep-discuss

Reply via email to