簡體   English   中英

MEEP:如何制作一個磁通檢測器陣列?

[英]MEEP: How to make an array of flux detectors?

我一直在使用MIT的MEEP來模擬硅光子學中的THz頻率光傳輸。 我需要在MIT的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個塊...不好。

此代碼可以有許多變體。 下面介紹的是一個直線檢測器。 也可以為圓形放置的檢測器實現一個。 但是,這需要在另一個函數中計算角度並將另一個變量添加到檢測器函數。

; 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) 

要記住的最重要的事情是檢測器必須包含在列表中。 Map本質上就是一個列表,所以這就是為什么您沒有在“檢測器”功能中定義列表的原因。 Append只是將所有列表加入一個更大的列表中。 而且,您必須對“ display-fluxes”使用“ apply”,因為您是在列表中而不是直接在函數中使用它。 希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM