@@ -33,6 +33,108 @@ def __repr__(self):
3333 return "" .join (String )
3434
3535
36+
37+ class SuperPosition (ReprBase ):
38+ Description = 'Mode superposition class'
39+ ReprVar = ["SuperSet" , "Amplitudes" ]
40+
41+ def __init__ (self , SuperSet , InitialAmplitudes : list ):
42+ self .SuperSet = SuperSet
43+ self .InitialAmplitudes = np .asarray (InitialAmplitudes ).astype (complex )
44+ self ._CouplerLength = None
45+ self ._Amplitudes = None
46+
47+
48+ def ComputeAmpltiudes (self ):
49+ self .MatrixInterp = interp1d (self .Distance , self .SuperSet .Matrix , axis = - 1 )
50+
51+ def foo (t , y ):
52+ return 1j * self .MatrixInterp (t ).dot (y )
53+
54+ sol = solve_ivp (foo ,
55+ y0 = self .InitialAmplitudes ,
56+ t_span = [0 , self ._CouplerLength ],
57+ method = 'RK45' )
58+
59+ self .Amplitudes = sol .y
60+ self .Distances = sol .t
61+ self .AmplitudeInterpolation = interp1d (self .Distances , self .Amplitudes , axis = - 1 )
62+
63+ @property
64+ def ITRList (self ):
65+ return self .SuperSet .ITRList
66+
67+ @property
68+ def CouplerLength (self ):
69+ assert self ._CouplerLength is not None , "CouplerLength attribute has to be defined before computing propagation."
70+ return self ._CouplerLength
71+
72+ @CouplerLength .setter
73+ def CouplerLength (self , Value : float ):
74+ self ._CouplerLength = Value
75+ self .Distance = np .linspace (0 , self ._CouplerLength , self .ITRList .size )
76+
77+
78+ @property
79+ def Amplitudes (self ):
80+ if self ._Amplitudes is None :
81+ self .ComputeAmpltiudes ()
82+
83+ return self ._Amplitudes
84+
85+
86+ @Amplitudes .setter
87+ def Amplitudes (self , Value ):
88+ self ._Amplitudes = Value
89+
90+
91+ def PlotAmplitudes (self ):
92+ Scene = Scene2D (nCols = 1 , nRows = 1 , ColorBar = False )
93+ A = self .InitialAmplitudes .dot (self .Amplitudes )
94+ z = self .Distances
95+ Scene .AddLine (Row = 0 ,
96+ Col = 0 ,
97+ x = z ,
98+ y = A ,
99+ Fill = False ,
100+ Legend = None ,
101+ xLabel = r'Z-Distance [$\mu m$]' ,
102+ yLabel = r'Mode complex ampltiude' )
103+
104+ Scene .SetAxes (0 , 0 , Equal = False )
105+ Scene .Show ()
106+
107+
108+ def PlotFields (self ):
109+ if self ._Amplitudes is None : self .ComputeAmpltiudes ()
110+
111+ y = self .AmplitudeInterpolation (self .Distance )
112+
113+ z = self .Distance
114+
115+ Field = self .SuperSet [0 ].FullFields .astype (complex )* 0.
116+
117+ for mode , _ in enumerate (self .InitialAmplitudes ):
118+ a = y [0 ].astype (complex )
119+ field = self .SuperSet [0 ].FullFields .astype (complex )
120+ Field += np .einsum ('i, ijk->ijk' , a , field )
121+
122+ surface = mlab .surf ( np .abs ( Field [0 ] ) , warp_scale = "auto" )
123+
124+ @mlab .animate (delay = 100 )
125+ def anim_loc ():
126+ for n , _ in enumerate (self .Distance ):
127+ surface .mlab_source .scalars = np .abs ( Field [n ] )
128+
129+ yield
130+
131+ anim_loc ()
132+ mlab .show ()
133+
134+
135+
136+
137+
36138class SuperSet (SetProperties , SetPlottings , ReprBase ):
37139
38140 Description = 'SuperSet class'
@@ -88,9 +190,11 @@ def ComputeCouplingFactor(self, Length):
88190
89191 dITR = np .gradient (np .log (self .Geometry .ITRList ), 1 )
90192
91- factor = dITR / dx
193+ return dITR / dx
92194
93- return factor / 10
195+
196+ def GetSuperposition (self , Amplitudes ):
197+ return SuperPosition (SuperSet = self , InitialAmplitudes = Amplitudes )
94198
95199
96200 def Propagate (self , Amplitude = [1 ,1 , 0 , 0 , 0 ], Length = 1000 ):
@@ -140,28 +244,6 @@ def foo(t, y):
140244
141245 return sol
142246
143-
144- def PlotPropagation (self , Modes ):
145- Mode0 = self [0 ]
146- Mode1 = self [1 ]
147-
148- Field = Mode0 [0 ].GetFullField (Axes = False ) + Mode1 [0 ].GetFullField (Axes = False )
149-
150- surface = mlab .surf ( np .abs ( Field ) , warp_scale = "auto" )
151-
152- @mlab .animate (delay = 100 )
153- def anim_loc ():
154- for n , _ in Mode0 .IterateSlice ():
155- Field = Mode0 [n ].GetFullField (Axes = False ) + Mode1 [n ].GetFullField (Axes = False )
156-
157- surface .mlab_source .scalars = np .abs ( Field )
158-
159- yield
160-
161- anim_loc ()
162- mlab .show
163-
164-
165247 @property
166248 def Size (self ):
167249 return len (self .SuperModes )
@@ -221,7 +303,7 @@ class SuperMode(ReprBase):
221303 "PlotPropagation" ]
222304
223305 def __init__ (self , ParentSet , ModeNumber , CppSolver , BindingNumber ):
224- self .Binded = CppSolver .GetMode (ModeNumber )
306+ self .Binded = CppSolver .GetMode (BindingNumber )
225307 self .ModeNumber = ModeNumber
226308
227309 self .CppSolver = CppSolver
@@ -431,6 +513,12 @@ def ComputeFullFields(self):
431513 self ._FullxAxis = self .ExtendAxis (Axis = self ._FullxAxis , sign = "Minus" )
432514
433515
516+ def GetSlice (self , Slice : int , Full : bool = True ):
517+ if Full :
518+ return self .Betas [Slice ], self .FullFields [Slice ], self ._FullxAxis , self ._FullyAxis
519+ else :
520+ return self .Betas [Slice ], self .Fields [Slice ], self .Axis .X , self .Axis .Y
521+
434522
435523 def CompareSymmetries (self , Other ):
436524 assert isinstance (Other , SuperMode ), "Can only compare SuperMode instance with another"
@@ -440,9 +528,6 @@ def CompareSymmetries(self, Other):
440528 def AppendSlice (self , SliceNumber ):
441529 self .Slice .append ( SetSlice (ParentMode = self , SliceNumber = SliceNumber ) )
442530
443- def GetSlices (self , SlicesNumber : list ):
444- return [self [slice ] for slice in SlicesNumber ]
445-
446531
447532 def __getitem__ (self , N ):
448533 return self .Slice [N ]
0 commit comments