Commit 8b9184bc authored by Daniel Brown's avatar Daniel Brown
Browse files

Merge branch 'master' of gitmaster.atlas.aei.uni-hannover.de:pykat/pykat

parents 9b6d80a6 91b44d57
from pykat import finesse
from pykat.commands import *
import copy
import pylab as pl
from collections import namedtuple
from collections import OrderedDict
import matplotlib
formatter = matplotlib.ticker.EngFormatter(unit='', places=0)
formatter.ENG_PREFIXES[-6] = 'u'
import matplotlib.backends.backend_pdf
def printPDF(self, filename):
pdfp = matplotlib.backends.backend_pdf.PdfPages(filename)
pdfp.savefig(self,dpi=300,bbox_inches='tight')
pdfp.close()
def main():
print """
--------------------------------------------------------------
Example file for using PyKat to automate Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat: http://www.gwoptics.org/pykat
The file runs through some Finesse simulations for the
Glasgow speedmeter experiment, using the file:
sagnac_base.kat
Andreas Freise 30.10.2014
--------------------------------------------------------------
"""
# defining variables as global for debugging
global kat
global out
global result
global legend
# for debugging we might need to see the temporay file:
kat = finesse.kat(tempdir=".",tempname="test")
kat.verbose = False
kat.loadKatFile('sagnac_base.kat')
extra = kat._kat__blocks['NO_BLOCK']
# adding homodyne detector
extra.contents.append('qhdS sens 180 nout1 nout2')
extra.contents.append('scale meter sens')
kat.maxtem='off'
Lambda=1064.0e-9
result=OrderedDict()
legend = {}
# getting mass of the light mirror of cavity a
global m
m = kat.M1a.mass.value
global f
f = namedtuple('f', ('start','stop','points','data'))
f.start=100
f.stop = 2e4
f.points = 100
kat.parseKatCode('xaxis sig1 f log {0} {1} {2}'.format(f.start, f.stop, f.points-1))
print "--------------------------------------------------------"
print " 0. Run default file"
out = kat.run()
#f.data = np.logspace(np.log10(f.start), np.log10(f.stop), f.points)
f.data=out.x # getting frequency vector from Finesse instead
print "--------------------------------------------------------"
print " 1. Computing SQL"
hbar=6.62606957E-34/(2.0 *np.pi)
SQL_x= np.sqrt( 4 * hbar / ( m * f.data**2 * 4 * np.pi * np.pi ))
legend['SQL']=mylegend('SQL','k')
result['SQL']=SQL_x
result['default']=out.y
legend['default']=mylegend('Stefan D. example file','b')
print "--------------------------------------------------------"
print " 2. Open ETM ports, i.e. replacing dump nodes"
kat.M2a.remove()
kat.M3a.remove()
kat.parseCommands('bs1 M2a $T_ETM 0 0 0 nM2aw nM2an nM2aT1 nM2aT2')
kat.parseCommands('bs1 M3a $T_ETM 0 0 0 nM3aw nM3an nM3aT1 nM3aT2')
kat.M2b.remove()
kat.M3b.remove()
kat.parseCommands('bs1 M2b $T_ETM 0 0 0 nM2bw nM2bn nM2bT1 nM2bT2')
kat.parseCommands('bs1 M3b $T_ETM 0 0 0 nM3bw nM3bn nM3bT1 nM3bT2')
out=kat.run()
result['open']=out.y
legend['open']=mylegend('Opening M2/M3 ports','r')
print "--------------------------------------------------------"
print " 3. Imbalanced BS"
result['bs']=imbalanced_bs(kat)
legend['bs']=mylegend('Imbalanced BS 49:51','g')
print "--------------------------------------------------------"
print " 3. Mass asymmetry"
result['mass']=mass(kat)
legend['mass']=mylegend('Mass asymmetry 10%','c')
print "--------------------------------------------------------"
print " Plotting results"
plot_results(f, result, legend)
# custom class to store text, color, line type and line width for
# legend entries
class mylegend():
def __init__(self, _text, _color):
self.text=_text
self.color=_color;
lw=2
lt='-'
def mass(tmpkat):
kat = copy.deepcopy(tmpkat)
kat.M1a.mass=m*0.9
kat.M1b.mass=m*1.1
out=kat.run()
return out.y
def imbalanced_bs(tmpkat):
kat = copy.deepcopy(tmpkat)
kat.M6.R=0.49
kat.M6.T=0.51
out=kat.run()
return out.y
def plot_results(f, result, legend):
fig=pl.figure()
N=len(result)
for i, T in enumerate(result.keys()):
data=result[str(T)]
pl.plot(f.data, data,legend[str(T)].lt, color=legend[str(T)].color, label=legend[str(T)].text, lw=legend[str(T)].lw)
#line.set_dashes([12, 4])
ax=pl.gca()
ax.set_yscale('log')
ax.set_xscale('log')
pl.xlabel("f [Hz}")
pl.ylabel("Sensitivity [m/sqrt(hz)]")
pl.xlim([f.start,f.stop])
pl.ylim([1E-20, 2E-17])
pl.grid()
pl.legend(loc=1)
pl.draw()
pl.show(block=0)
printPDF(fig, "speedmeter_plots.pdf")
if __name__ == '__main__':
main()
#################################################################
# Finesse input file of the Glasgow Speedmeter Experiment,
# based on an OptoCAD export, cleaned and prepared in this form
# during the Speedmeter Workshop, October 2014. For help and
# questions, feel free to contact me at: adf@star.sr.bham.ac.uk
# Andreas Freise, 30.10.2014
#
# The parameters below don't necessarily match the current
# speedmeter design, instead they were chosen to match Stefan
# Danilishin's Matlab example for comparison. However, you can
# easily change the parameters to an updated design without
# problem. No special tuning or so is required.
#################################################################
## general constants
const Pin 0.6 # double the power at the BS, which for this example is 0.3W
const MassM1 1m # Mass M1 in [kg]: 1 gramm
const MassM23 100m # Mass M2, M3: 100 gramm
const T_ETM 12.5u # transmission of cavity end mirrors (cavity loss)
## lengths of some ray segments
const lrs2 0.250
const lrs3 0.167
const lrs4 0.258
const lrs5 0.0721
const lrs7 0.0958
const lrs8 0.2971
const lrs17 0.365
const lrs23 0.499
const lrs25 0.261
const lrs26 0.549
#################################################################
l i1 $Pin 0 n0
s rs2 $lrs2 n0 nM4w
bs M4 1 0 0 45 nM4w nM4n dump dump
s rs3 $lrs3 nM4n nM5n
bs M5 1 0 0 45 nM5w nM5n dump dump
s rs4 $lrs4 nM5w nM11w
bs M11 .5 .5 0 45 nM11w nM11n nM11e nM11s
s rs5 $lrs5 nM11n nM6w
#################################################################
# central BS
bs M6 0.5 0.5 0 29.19505498 nM6w nM6n nM6e nM6s
#################################################################
## Cavity a
s rs7 $lrs7 nM6e nM7w
bs M7 1 0 0 49.39870535E0 nM7w nM7n dump dump
s rs8 $lrs8 nM7n nM1an
bs1 M1a 500u 0 0 0 nM1aw nM1an nM1ae nM1as
attr M1a Rc -7.91
attr M1a mass $MassM1
s rs12 1.315 nM3an nM1ae
##################################################################
# Note that the following lines are 'wrong'. The 'dump' notes
# are not open ports, i.e. even with the transmssion of the ETMs
# non-zero, no quantum noise will enter through this port.
# I am using dump notes here to match Stefan's example calculation,
# but you should not use 'dump' nodes with any mirror or BS that
# has non-zero losses or transmission
bs1 M3a $T_ETM 0 0 0 nM3aw nM3an dump dump #nM3aT1 nM3aT2
attr M3a mass $MassM23
s rs11 0.2 1. nM2an nM3aw
bs1 M2a $T_ETM 0 0 0 nM2aw nM2an dump dump #nM2aT1 nM2aT2
attr M2a mass $MassM23
s rs10 1.315 nM1as nM2aw
cav AC_a M1a nM1as M1a nM1ae
#################################################################
# path between cavity a and b
s rs23 $lrs23 1. nM1aw nM10n
bs M10 1 0 0 42.25439783E0 nM10w nM10n dump dump
s rs24 326.5506374E-3 nM10w nM9n
bs M9 1 0 0 5.477377081 nM9w nM9n nX1 nX2
attr M9 Rc 5.05
s rs25 $lrs25 nM9w nM8w
bs M8 1 0 0 43.33405689 nM8w nM8n dump dump
s rs26 $lrs26 nM8n nM1bw
#################################################################
## Cavity b
bs1 M1b 500u 0 0 0 nM1bw nM1bn nM1be nM1bs
attr M1b Rc -7.91
attr M1b mass $MassM1
s rs19 1.315 nM1be nM2bw
##################################################################
# Note that the following lines are 'wrong'. The 'dump' notes
# are not open ports, i.e. even with the transmssion of the ETMs
# non-zero, no quantum noise will enter through this port.
# I am using dump notes here to match Stefan's example calculation,
# but you should not use 'dump' nodes with any mirror or BS that
# has non-zero losses or transmission
bs1 M2b $T_ETM 0 0 0 nM2bw nM2bn dump dump #nM2bT1 nM2bT2
attr M2b mass $MassM23
s rs20 0.2 nM2bn nM3bw
bs1 M3b $T_ETM 0 0 0 nM3bw nM3bn dump dump #nM3bT1 nM3bT2
attr M3b mass $MassM23
s rs21 1.315 nM3bn nM1bs
cav AC_b M1b nM1bs M1b nM1be
s rs17 $lrs17 nM6n nM1bn
#################################################################
# reflected light from central BS: nM11s, main output of Sagnac: nM6s
# -> sagnac output
s out1 1n nM6s nHD1
# -> sagnac reflection through M11
s out3 1n nM11s nHD2
# apply differential signal with amplitide of 0.5
# to match with custom defintion of \Delta L = L1 - L2
fsig sig1 M2a 1 0 0.5
fsig sig2 M2b 1 180 0.5
# dummy laser for LO in homodyne detector
l l2 1 0 nl2
s sl2 1n nl2 nl3
# set homodyne angle by adjusting this beam splitter's tuning:
bs dHD .5 .5 0 0 nHD1 nout1 nout2 nl3
# homodyne detector, use 180 deg phase for normal use, i.e. output=nout1-nout2
#qhdS sens 180 nout1 nout2
# scale output to m/sqrt(Hz)
#scale meter sens
%xaxis sig1 f log 100 100k 99
yaxis log abs
maxtem off
# you can use the following for checking cavity parameters,
# such as FSR, length etc.
#maxtem 0
#retrace force
#trace 2
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment