Commit c2ca1ee7 authored by Sean Leavey's avatar Sean Leavey
Browse files

Fixed issues with n > 2 gratings and added a pass through test which takes a...

Fixed issues with n > 2 gratings and added a pass through test which takes a Finesse script, parses it and then outputs it again (to test input/output of component classes)
parent 1428c245
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 12 15:29:19 2013
Takes a set of Finesse commands as input, parses it and outputs it again.
Used to check whether Finesse components, detectors, etc. are properly
reproducing the parameters they are given.
@author: Sean Leavey
"""
from pykat import finesse
code = """
l l1 1 0 0 n1
s s1 10 1 n1 n2
m m1 1 0 0 n2 n3
gr4 grating 1500 n4 n5 n6 n7
pd refl n2
xaxis m1 r_ap lin 0.1e-3 2e-3 10
"""
kat = finesse.kat()
kat.parseCommands(code)
scriptList = kat.generateKatScript()
print ''.join(scriptList)
\ No newline at end of file
......@@ -479,19 +479,40 @@ class grating(Component):
values.pop(0) # remove initial value
if n == 2:
if len(values) != 4:
raise exceptions.RuntimeError("Two port grating must have 2 nodes defined")
return grating(values[0], values[2], values[3], None, None, n, values[1])
elif n == 3:
if len(values) != 5:
raise exceptions.RuntimeError("Three port grating must have 3 nodes defined")
return grating(values[0], values[2], values[3], values[4], None, n, values[1])
else:
if len(values) != 6:
raise exceptions.RuntimeError("Four port grating must have 4 nodes defined")
return grating(values[0], values[2], values[3], values[4], values[5], n, values[1])
def getFinesseText(self):
rtn = []
if self.__n == 2:
return 'gr{0} {1} {2} {3} {4}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name)
rtn.append('gr{0} {1} {2} {3} {4}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name))
elif self.__n == 3:
return 'gr{0} {1} {2} {3} {4} {5}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name)
rtn.append('gr{0} {1} {2} {3} {4} {5}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name))
else:
return 'gr{0} {1} {2} {3} {4}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name, self.nodes[3].name)
rtn.append('gr{0} {1} {2} {3} {4} {5} {6}'.format(self.__n, self.name, self.__d, self.nodes[0].name, self.nodes[1].name, self.nodes[2].name, self.nodes[3].name))
if self.eta_0 != 0: rtn.append("attr {0} eta_0 {1}".format(self.name,self.__eta_0))
if self.eta_1 != 0: rtn.append("attr {0} eta_1 {1}".format(self.name,self.__eta_1))
if self.eta_2 != 0: rtn.append("attr {0} eta_2 {1}".format(self.name,self.__eta_2))
if self.eta_3 != 0: rtn.append("attr {0} eta_3 {1}".format(self.name,self.__eta_3))
if self.rho_0 != 0: rtn.append("attr {0} rho_0 {1}".format(self.name,self.__rho_0))
if self.alpha != 0: rtn.append("attr {0} alpha {1}".format(self.name,self.__alpha))
# TODO: implement Rcx, Rcy, Rc
return rtn
def getQGraphicsItem(self):
if self._QItem == None:
......
Markdown is supported
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