MEEP:如何制作一系列通量检测器?

时间:2016-02-23 15:40:15

标签: mit-scheme meep

我一直在使用麻省理工学院的MEEP来模拟硅光子学中的THz频率光传输。我需要在麻省理工学院的MEEP中制作一系列通量检测器,这样我就不必编写许多(加通量)代码块。

Scheme的地图似乎是一个很好的解决方案,然而,尽管许多论坛中有很多人在寻找一种方法来实现这一点,但这种代码的实现在网上很少。因此,我想分享一种方法。

MEEP wiki的文档中,添加助焊剂检测器的方法如下:

(define-param fcen 0.25) ; pulse center frequency
(define-param df 0.4)    ; pulse width (in frequency)
(define-param nfreq 4001) ; number of frequencies at which to compute flux

(define refl-det       ; reflection detector
    (add-flux freq_c pulse_width num_freqs
      (make flux-region
          (center some-x some-y)
          (size 1 0))))

(define trans-det       ; transmission detector
    (add-flux freq_c pulse_width num_freqs
      (make flux-region
          (center some-other-x some-other-y)
          (size 1 0))))

;;...;; code for running sources

(display-fluxes refl-det trans-det)    ; MEEP's function for outputting flux for frequencies

所以,如果我想要20个传输探测器和20个反射探测器,我将不得不通过硬编码来定义40个块...不好。

1 个答案:

答案 0 :(得分:0)

可以在此代码上进行许多变体。下面介绍的是直线探测器。对于以圆形布置放置的探测器也可以实施一个;但是,这需要在另一个函数中计算角度,并在检测器函数中添加另一个变量。

; The following is a sample algorithm you can use to get the x values
(define det-sample-length 5)
(define det-start-x-position 25)
(define (refl-det-x-position n)  (+ det-start-x-position (* n det-sample-length)))

; Here you use map to return a list of the x positions for the detectors
(define det-positions-x (map refl-det-x-position (list 1 2 3 4 5 6 7 8 9))) 

; This is a function to make the array of detectors. It takes the x position as an argument.
(define (detectors det-position-x)
    (add-flux freq_c pulse_width num_freqs
      (make flux-region
          (center det-position-x 0)
          (size 0 1))))

; To return a list of detectors based on the above function, map it against the x position list.
(define my-refl-flux-list
    (map detectors det-positions-x))

; If you need to put another detector not part of the above series, define it as a "list"    
(define source-top-det
    (list (add-flux freq_c pulse_width num_freqs
      (make flux-region
          (center some-x some-y)
          (size 1 0)))))

; Here, again, you can make another detector as a list or another array of detectors.   
(define source-bottom-det
    (list (add-flux freq_c pulse_width num_freqs
      (make flux-region
          (center some-other-x some-other-y)
          (size 1 0)))))

; Finally, before you use "display-fluxes", you must append the detectors into a list.    
(define my-flux-list (append source-top-det source-bottom-det my-refl-flux-list))

; And last, but not least, use Scheme's "apply" on "display-fluxes" over "my-flux-list"
(apply display-fluxes my-flux-list) 

最重要的是要记住检测器必须包含在列表中。按地址划分地图会产生一个列表,因此这就是为什么你不在"探测器中定义一个列表"功能。追加只是将所有列表加入到更大的列表中。你必须使用" apply" for" display-fluxes"因为您在列表中使用它,而不是直接在函数内使用它。希望这有帮助!