Skip to content

Commit e6b5e5b

Browse files
committed
update
1 parent 7d68e2b commit e6b5e5b

4 files changed

Lines changed: 743 additions & 19 deletions

File tree

SuPyMode/SuperMode.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def __repr__(self):
3636

3737
class SuperPosition(ReprBase):
3838
Description = 'Mode superposition class'
39-
ReprVar = ["SuperSet", "Amplitudes"]
39+
ReprVar = ["Amplitudes"]
4040

4141
def __init__(self, SuperSet, InitialAmplitudes: list):
4242
self.SuperSet = SuperSet
@@ -45,7 +45,7 @@ def __init__(self, SuperSet, InitialAmplitudes: list):
4545
self._Amplitudes = None
4646

4747

48-
def ComputeAmpltiudes(self):
48+
def ComputeAmpltiudes(self, rTol=1e-8, aTol=1e-7, MaxStep=np.inf):
4949
self.MatrixInterp = interp1d(self.Distance, self.SuperSet.Matrix, axis=-1)
5050

5151
def foo(t, y):
@@ -54,7 +54,10 @@ def foo(t, y):
5454
sol = solve_ivp(foo,
5555
y0 = self.InitialAmplitudes,
5656
t_span = [0, self._CouplerLength],
57-
method = 'RK45')
57+
method = 'RK45',
58+
rtol = rTol,
59+
atol = aTol,
60+
max_step = MaxStep)
5861

5962
self.Amplitudes = sol.y
6063
self.Distances = sol.t
@@ -95,17 +98,49 @@ def PlotAmplitudes(self):
9598
Scene.AddLine(Row = 0,
9699
Col = 0,
97100
x = z,
98-
y = A,
101+
y = A.real,
102+
Fill = False,
103+
Legend = r"$\Re${A}",
104+
xLabel = r'Z-Distance [$\mu m$]',
105+
yLabel = r'Mode complex ampltiude [normalized]')
106+
107+
Scene.AddLine(Row = 0,
108+
Col = 0,
109+
x = z,
110+
y = np.abs(A),
99111
Fill = False,
100-
Legend = None,
112+
Legend = r"|A|",
101113
xLabel = r'Z-Distance [$\mu m$]',
102-
yLabel = r'Mode complex ampltiude')
114+
yLabel = r'Mode complex ampltiude [normalized]')
115+
116+
117+
Scene.SetAxes(0, 0, Equal=False, Legend=True)
118+
Scene.Show()
119+
120+
def PlotField(self, Slice):
121+
if self._Amplitudes is None: self.ComputeAmpltiudes()
122+
Scene = Scene2D(nCols=1, nRows=1, ColorBar=False)
123+
124+
Field = self.SuperSet[0].FullFields[0]*0.
103125

104-
Scene.SetAxes(0, 0, Equal=False)
126+
for a, mode in zip(self.InitialAmplitudes, self.SuperSet.SuperModes):
127+
field = np.real(a)*mode.FullFields[Slice]
128+
Field += field
129+
130+
131+
Scene.AddMesh(Row = 0,
132+
Col = 0,
133+
x = self.SuperSet[0].FullxAxis,
134+
y = self.SuperSet[0].FullyAxis,
135+
Scalar = Field.T.real,
136+
xLabel = r'X-Direction [$\mu m$]',
137+
yLabel = r'Y-direction [$\mu m$]')
138+
139+
Scene.SetAxes(Row=0, Col=0, Equal=True, Legend=False)
105140
Scene.Show()
106141

107142

108-
def PlotFields(self):
143+
def PlotPropagation(self):
109144
if self._Amplitudes is None: self.ComputeAmpltiudes()
110145

111146
y = self.AmplitudeInterpolation(self.Distance)
@@ -115,16 +150,16 @@ def PlotFields(self):
115150
Field = self.SuperSet[0].FullFields.astype(complex)*0.
116151

117152
for mode, _ in enumerate(self.InitialAmplitudes):
118-
a = y[0].astype(complex)
119-
field = self.SuperSet[0].FullFields.astype(complex)
153+
a = y[mode].astype(complex)
154+
field = self.SuperSet[mode].FullFields.astype(complex)
120155
Field += np.einsum('i, ijk->ijk', a, field)
121156

122157
surface = mlab.surf( np.abs( Field[0] ) , warp_scale="auto" )
123158

124159
@mlab.animate(delay=100)
125160
def anim_loc():
126161
for n, _ in enumerate(self.Distance):
127-
surface.mlab_source.scalars = np.abs( Field[n] )
162+
surface.mlab_source.scalars = np.abs(np.abs( Field[n] ) )
128163

129164
yield
130165

@@ -143,7 +178,7 @@ class SuperSet(SetProperties, SetPlottings, ReprBase):
143178
"Size",
144179
"Geometry"]
145180

146-
Methods = [ "Propagate"]
181+
Methods = ["GetSuperposition", "Matrix"]
147182

148183
def __init__(self, ParentSolver):
149184
self.ParentSolver = ParentSolver

SuPyMode/Tools/BaseClass.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def _PlotFields(self, Slices=0):
142142

143143
Scene.AddMesh(Row = s,
144144
Col = supermode.ModeNumber,
145-
x = np.arange(x.size),
146-
y = np.arange(y.size),
145+
x = x,
146+
y = y,
147147
Scalar = Field.T,
148148
ColorMap = FieldMap,
149149
xLabel = r'X-distance [$\mu$m]',
@@ -163,6 +163,7 @@ def PlotFields(self, Slices=0):
163163

164164
Scene.Show()
165165

166+
166167
def GetCombination(self, Combination):
167168
if Combination is None:
168169
return tuple( combinations( self.SuperModes, 2 ) )

0 commit comments

Comments
 (0)