lkat_trace.py 1.25 KB
Newer Older
Daniel Brown's avatar
Daniel Brown committed
1
import pykat
2
3
4
5
6
import pylab
import numpy
import ctypes
import pylibkat								 

Daniel Brown's avatar
Daniel Brown committed
7
8
9
10
cmd = """
l l1 1 0 n1
s s1 1 n1 n2
m m1 0.99 0.01 0 n2 n3
11
s s2 1 n3 n4
Daniel Brown's avatar
Daniel Brown committed
12
13
14
15
m m2 0.99 0.01 0 n4 n5
pd circ n3

noxaxis
16
maxtem 0
Daniel Brown's avatar
Daniel Brown committed
17

Daniel Brown's avatar
Daniel Brown committed
18
attr m1 Rc 0
Daniel Brown's avatar
Daniel Brown committed
19
20
attr m2 Rc 1000 
cav c1 m1 n3 m2 n4
21
22
retrace force

Daniel Brown's avatar
Daniel Brown committed
23
24
25
26
27
28
29
30
"""

kat = pykat.finesse.kat()

kat.parseCommands(cmd)

info = kat.lkat_trace()

31
print "n1 qx =", info["n1"].qx
Daniel Brown's avatar
Daniel Brown committed
32
33
34

print "Cavity info ", info["c1"]

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
import numpy

Lengths = numpy.linspace(1, 999, 10000)
g_factors = []
        
lkat = ctypes.PyDLL("libkat.dylib")

try:
	lkat._pykat_preInit() # must always be called, sets up
	        # exception handling and such no simulation
	        # specifc code here

	# reads in the kat.ini and setups up other parts
	lkat._pykat_init()
	
	cmd = "".join(kat.generateKatScript())
	
	lkat._pykat_setup(cmd)
	
	inter = pylibkat.interferometer.in_dll(lkat, "inter")
	s2 = inter.space_list[1]
	cav = inter.cavity_list[0]
	
	inter.rebuild = 2
	inter.retrace = 1
	s2.rebuild = 2
	
	for L in Lengths:
		s2.L = L
		lkat._pykat_step()
		
		g_factors.append(cav.stability_x)

except Exception as ex: 
    print "Exception caught in python: ", ex.message
finally:
    # This should always be called no matter what
    lkat._pykat_finish(0)
	
pylab.plot(Lengths, g_factors)
pylab.show()