This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (gaussian-beam zR k z) (lambda (x) | |
(let | |
((z-prime (/ z zR)) | |
(k-norm (vector3-norm k)) | |
(x2 (vector3-dot x x))) | |
(* | |
(/ 1 (sqrt (+ 1 (* z-prime z-prime)))) | |
(exp (+ | |
(/ (* -1 k-norm x2) (* 2 zR (+ 1 (* z-prime z-prime)))) | |
(/ (* 0-1i z-prime k-norm x2) (* 2 zR (+ 1 (* z-prime z-prime)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (make-volume x-min x-max y-min y-max) | |
(volume | |
(center (/ (+ x-max x-min) 2) (/ (+ y-max y-min) 2) 0) | |
(size (- x-max x-min) (- y-max y-min) 0))) | |
(define (freq-field-monitor monitor-name dt vol output-comp) | |
(at-every dt (to-appended monitor-name (in-volume vol output-comp)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; HDF5 METADATA helpers | |
(define (attr->string attr-pair) | |
(string-append " -attr " (car attr-pair) " " (number->string (exact->inexact (second attr-pair))))) | |
(define (add-attributes fname attributes) | |
(let | |
((command (string-append "./add_attr.py -fname " (get-filename-prefix) "-" fname ".h5 ")) | |
(attribute-string (string-join (map attr->string attributes)))) | |
(string-append command attribute-string))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# May need to pad with zeros the input fields to FFT to get the | |
# desired amount of frequency points. | |
n_sample_points = 2 * int(n_freq_points/(max_freq - min_freq) * max_freq) | |
fft_field = abs(np.fft.fft(field, n=n_sample_points, axis=-1).real) | |
fft_field = fft_field[:, :, :fft_field.shape[-1]//2] | |
freqs = np.fft.fftfreq(n_sample_points, d=dt)[:(n_sample_points/2)] | |
# We are only interested on the frequencies inside the source bandwidth | |
mask = (freqs >= min_freq) * (freqs <= max_freq) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(set! sources | |
(list | |
(make source | |
(src (make continuous-src (frequency fcen) (fwidth df))) | |
(component Ez) | |
(center x-pos y-pos) | |
(size 0 sy-source) | |
(amp-func (gaussian-beam zR k z))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define* (add-DBR n1 n2 n-pairs wl y-pos #:optional (growth-dir +) (dbr-width infinity)) | |
(let | |
((layer1-t (* 0.25 (/ wl n1))) | |
(layer2-t (* 0.25 (/ wl n2))) | |
(make-layer (lambda (layer-t index pos) (make block | |
(center 0 (growth-dir pos (/ layer-t 2)) 0) | |
(material (make dielectric (epsilon (* index index)))) | |
(size dbr-width layer-t dbr-width))))) | |
(let | |
((make-pair (lambda (pos) (list |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import git | |
def _get_main_file(repo): | |
path_to_dir = os.path.dirname(os.path.abspath(__file__)) | |
abs_path = os.path.join(path_to_dir, os.path.split(sys.argv[0])[-1]) | |
return os.path.relpath(abs_path, repo.working_tree_dir) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def MonteCarloIntegral(f, N, dim, fractional_error_tolerance=0.05): | |
relative_error = 1. | |
function_evaluations = list() | |
while relative_error > fractional_error_tolerance: | |
for _ in range(int(N)): | |
F = f(np.random.rand(dim)) | |
function_evaluations.append(F) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy.random import uniform | |
class MISER: | |
def __init__(self, miser_params): | |
""" | |
Parameters | |
---------- | |
MNBS : int | |
If less than MNBS evaluations are left we do | |
vanilla MC. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{amsmath} | |
\begin{document} | |
Transformation matrix from $|jm>$ to $|m_1 m_2>$ basis | |
This is not the actual matrix; elements are represented as in the | |
CG tables. Do element-wise sqrt but keep the sign for the matrix. |
OlderNewer