-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate-xml.lisp
executable file
·193 lines (176 loc) · 7.35 KB
/
generate-xml.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/usr/bin/sbcl --script
(setf *read-default-float-format* 'double-float)
(defun safe-read ()
"Somewhat hardened against malicious read-macros"
(with-standard-io-syntax
(let* ((*read-eval* nil))
(read))))
(defun ask-for-number (prompt)
(let ((entry))
(loop
(fresh-line)
(format t prompt)
(finish-output)
(setf entry (safe-read))
(when (numberp entry)
(return entry))
(format t "~&Not a valid number: ~a" entry))))
(defparameter seq-list (list "free propagation"
"interferometer"))
(let ((xml-form "<SIMULATION>
<DIM>~d</DIM>
<FILENAME>0.0000_1.bin</FILENAME>
<FILENAME_2>0.0000_2.bin</FILENAME_2>
<CONSTANTS>
<Beta>-0.00134248</Beta>
<laser_k>8.05289</laser_k>
<laser_k_2>8.05289</laser_k_2>
<laser_domh>0.0471239</laser_domh>
<laser_domh_2>0.0471239</laser_domh_2>
<laser_dk>0</laser_dk>
<rabi_threshold>4</rabi_threshold>
<chirp>0</chirp>
</CONSTANTS>
<VCONSTANTS>
<Amp_1>-14.0496,-14.0496</Amp_1>
<Amp_2>-14.0496,-14.0496</Amp_2>
<Alpha_1>~,6e~{,~,6e~}</Alpha_1>~:[~1*~;~:*~% <Alpha_2>~,6e~{,~,6e~}</Alpha_2>~]
<Delta_L>0,-6283.19</Delta_L>
<GS_1>~,6e,~,6e</GS_1>
<GS_2>~,6e,~,6e</GS_2>
<Beta>~,6e~{,~,6e~}</Beta>~:[~1*~;~:*~% <Beta_2>~,6e~{,~,6e~}</Beta_2>~]
</VCONSTANTS>
<ALGORITHM>
<NK>25</NK>
<NA>700</NA>
</ALGORITHM>
~-[<SEQUENCE>
<freeprop dt=\"0.2\" Nk=\"10\" output_freq=\"last\" pn_freq=\"last\">1000</freeprop>
</SEQUENCE>~;<SEQUENCE>
<bragg_ad dt=\"0.1\" Nk=\"100\" output_freq=\"last\" pn_freq=\"last\" rabi_output_freq=\"each\" >100</bragg_ad>
<freeprop dt=\"0.1\" Nk=\"10\" output_freq=\"last\" pn_freq=\"last\">7000</freeprop>
<bragg_ad dt=\"0.1\" Nk=\"100\" output_freq=\"last\" pn_freq=\"last\" rabi_output_freq=\"last\" >200</bragg_ad>
<freeprop dt=\"0.1\" Nk=\"10\" output_freq=\"last\" pn_freq=\"last\">7000</freeprop>
<bragg_ad dt=\"0.1\" Nk=\"100\" output_freq=\"last\" pn_freq=\"last\" rabi_output_freq=\"each\" phase_scan=\"20\">100</bragg_ad>
</SEQUENCE>~]
</SIMULATION>
"))
(defun write-xml (filename dimension alpha alpha2 beta beta2 gs sequence)
(with-open-file (out filename :direction :output :if-exists :supersede :if-does-not-exist :create)
(format out xml-form dimension (car alpha) (cdr alpha) (car alpha2) (cdr alpha2) (nth 0 gs) (nth 1 gs) (nth 2 gs) (nth 3 gs) (car beta) (cdr beta) (car beta2) (cdr beta2) sequence)
(format t "~&~a written.~%" filename))))
(defun generate-xml ()
(let ((hbar 1.0545718e-34) ; reduced Planck constant
(kg/u 1.66053904e-27) ; u -> kg conversion constant
(two-species-p nil)
(dimension)
(length 1e-6) ; Length scale
(time 1e-6) ; Time scale
(gravity 0)
(mass1 87) ; Mass of species 1
(mass2 85) ; Mass of species 2
(alpha) ; Kinetic factor in Hamiltonian
(alpha2) ; Kinetic factor in Hamiltonian for second species
(beta) ; Gravity
(beta2)
(gs) ; Non-linearity
(sequence))
;; local functions
(flet ((calculate-alpha (mass)
(/ (* hbar time ) 2 (* mass kg/u) (expt length 2)))
(calculate-beta (mass)
(/ (* time length gravity (* mass kg/u))
hbar))
(calculate-gs (mass1 mass2 a)
(/ (* 2 pi hbar time a (+ mass1 mass2))
mass1
mass2
(expt length dimension)))
(print-settings (dim)
(format t "~&~%Settings along dimension: ~a" (nth dim (list "x" "y" "z")))
(format t "
Current Setting:
Length scale (in m): ~a
Time scale (in s): ~a
Gravity (in m/s^2): ~a
~:[Mass (in u): ~a~1*~;Mass1 (in u): ~a~% Mass2 (in u): ~a~]
What would you change?
1 - Length
2 - Time
3 - Gravity
~:[4 - Mass~;4 - Mass1~%5 - Mass2~]
p - print current settings
c - continue
q - abort~%" length time gravity two-species-p mass1 mass2 two-species-p)))
;; Start
(setf two-species-p (yes-or-no-p "Two species?"))
;; Set number of dimensions
(loop
(format t "Number of dimensions? (1-3) ")
(finish-output)
(setf dimension (parse-integer (read-line) :junk-allowed t))
(when (and (numberp dimension)
(some (lambda (x) (= dimension x)) (list 1 2 3)))
(return))
(format t "~&Dimension not supported: ~a~%" dimension))
;; Set configuration per dimension
(loop :for dim :from 0 :below dimension
:do
(print-settings dim)
(format t "> ")
(finish-output)
(loop :for c = (read-line)
:until (string= c "c")
:do
(cond ((string= c "1")
(setf length (ask-for-number "Length scale (in m): "))
(format t "~&Length scale updated.~%"))
((string= c "2")
(setf time (ask-for-number "Time scale (in s): "))
(format t "~&Time scale updated.~%"))
((string= c "3")
(setf gravity (ask-for-number "Gravity (in m/s^2): "))
(format t "~&Gravity updated.~%"))
((string= c "4")
(setf mass1 (ask-for-number "Mass (in atomic mass units, u): "))
(unless two-species-p
(setf mass2 mass1))
(format t "~&Mass updated.~%"))
((and two-species-p (string= c "5"))
(setf mass2 (ask-for-number "Mass2 (in atomic mass units, u): "))
(format t "~&Mass2 updated.~%"))
((string= c "p")
(print-settings dim))
((string= c "q")
(format t "~&Quit.~%")
(quit))
(t (format t "~&Unknown command.~%")))
(format t "> ")
(finish-output))
(setf alpha (cons (calculate-alpha mass1) alpha))
(setf beta (cons (calculate-beta mass1) beta))
(when two-species-p
(setf alpha2 (cons (calculate-alpha mass2) alpha2))
(setf beta2 (cons (calculate-beta mass2) beta2))))
;; Set nonlinearity
(setf gs (if (yes-or-no-p "Calculate nonlinearity?")
(list (calculate-gs mass1 mass1 (ask-for-number "a_11: "))
(calculate-gs mass1 mass2 (ask-for-number "a_12: "))
(calculate-gs mass2 mass1 (ask-for-number "a_21: "))
(calculate-gs mass2 mass2 (ask-for-number "a_22: ")))
(list 0.0 0.0 0.0 0.0)))
;; Set sequence
(format t "~&Select Sequence:~%~{~a - ~a~%~}> "
(loop :for seq :in seq-list
:for i :from 0
:append (list i seq)))
(finish-output)
(setf sequence (loop :for c = (parse-integer (read-line) :junk-allowed t)
:do
(if (and (numberp c) (>= c 0) (< c (length seq-list)))
(return c)
(progn (format t "~&Not valid: ~a Try again.~%> " c)
(finish-output)))))
(write-xml "output.xml" dimension alpha alpha2 beta beta2 gs sequence))))
;; Call program
(generate-xml)