首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MEEP:如何制作通量探测器阵列?

MEEP:如何制作通量探测器阵列?
EN

Stack Overflow用户
提问于 2016-02-23 23:40:15
回答 1查看 401关注 0票数 0

我一直在使用麻省理工学院的MEEP来模拟硅光子学中THz频率的光传输。我需要在麻省理工学院的MEEP中创建一个通量检测器数组,这样我就不必编写很多(add- flux )代码块了。

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

MEEP wiki的文档中,添加通量检测器的方式如下:

代码语言:javascript
复制
(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个反射检测器,我必须通过硬编码them...not good来定义40个块。

EN

回答 1

Stack Overflow用户

发布于 2016-02-23 23:40:15

有许多变体可以在此代码上生成。下面给出的是直线上的检测器。也可以为圆形排列的检测器实现一个;但是,这需要在另一个函数中计算角度,并将另一个变量添加到检测器函数中。

代码语言:javascript
复制
; 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”,因为你是在一个列表上使用它,而不是直接在函数中使用它。希望这能有所帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35581808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档