remove_add_components.py 1.66 KB
Newer Older
Andreas Freise's avatar
Andreas Freise committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""
--------------------------------------------------------------
Example file for using PyKat to remove objects from a 'kat'
object for Finesse simulations
Finesse: http://www.gwoptics.org/finesse
PyKat:   http://www.gwoptics.org/pykat

Example showing how to remove and add components with Pykat.
Commands that get parsed into a pykat object can be interacted 
with in a object orientated manner. So you can call kat.component.remove()
to remove it for example.

This example shows how a kat object can be manipulated when pykat objects
are available.

If the a Finesse command hasn't been implemented as a pykat object yet
the command will be added as an "extra line", these can still be removed
and added to using the kat.removeLine and kat.addLine commands.
Andreas Freise's avatar
Andreas Freise committed
19
20
21
You can set
  kat.verbose = True
to print a warning message when "extra lines" are generated
Andreas Freise's avatar
Andreas Freise committed
22
23
24
Daniel Brown 17/12/14
--------------------------------------------------------------
"""
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

import pykat
from pykat.components import *

kat = pykat.finesse.kat()

kat.parseCommands("""
m m1 0.9 0.1 0 n1 n2
s s1 1 n2 n3
m m2 0.9 0.1 0 n3 n4
""")

print "Before..."
print "".join(kat.generateKatScript())

kat.s1.remove()

print "After remove..."
print "".join(kat.generateKatScript())

# Adding in with commands
kat.parseCommands("""
s s2 1 n2 n2a
m m3 0.9 0.1 0 n2a n3a
s s3 1 n3a n3
""")

print "After add with commands..."
print "".join(kat.generateKatScript())

kat.s2.remove()
kat.s3.remove()
kat.m3.remove()

# Adding in with objects
kat.add(space("s2", "n2", "n2a", L=1))
kat.add(space("s3", "n3", "n3a", L=1))
kat.add(mirror("m3", "n2a", "n3a", R=0.9, T=0.1, phi=0))

print "After add with objects..."
Andreas Freise's avatar
Andreas Freise committed
65
print "".join(kat.generateKatScript())