Skip to content

Commit 8c43fda

Browse files
committed
update
1 parent f03bcae commit 8c43fda

13 files changed

Lines changed: 293 additions & 362 deletions

File tree

ExportedPDF.pdf

-4.76 KB
Binary file not shown.

SuPyMode/Geometry.py

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
from SuPyMode.Tools.Directories import RootPath
2020
from SuPyMode.Tools.Special import gradientO4
2121
from SuPyMode.Tools.utils import ToList, Axes
22-
from SuPyMode.Plotting.Plots import Scene2D
22+
from SuPyMode.Plotting.PlotsUtils import FieldMap
23+
from SuPyMode.Plotting.Plots import Scene, Axis, Mesh, Contour
2324
from SuPyMode.Tools.utils import ObjectUnion
2425

2526
Mlogger = logging.getLogger(__name__)
@@ -114,6 +115,29 @@ def __init__(self, Clad, Objects, Xbound, Ybound, Nx, Ny, GConv=0, BackGroundInd
114115
self.GetAllIndex()
115116

116117

118+
def GetFullMesh(self, LeftSymmetry, RightSymmetry, TopSymmetry, BottomSymmetry):
119+
120+
FullMesh = self._Mesh
121+
122+
if BottomSymmetry in [1,-1]:
123+
FullMesh = np.concatenate((FullMesh[::-1, :], FullMesh), axis=1)
124+
125+
126+
if TopSymmetry in [1, -1]:
127+
FullMesh = np.concatenate((FullMesh, FullMesh[::-1, :]), axis=1)
128+
129+
130+
if RightSymmetry in [1, -1]:
131+
FullMesh = np.concatenate((FullMesh[...], FullMesh[::-1, :]), axis=0)
132+
133+
134+
if LeftSymmetry in [1, -1]:
135+
FullMesh = np.concatenate((FullMesh[::-1, :], FullMesh[...]), axis=0)
136+
137+
138+
return FullMesh
139+
140+
117141
@property
118142
def Mesh(self):
119143
if self._Mesh is None:
@@ -169,7 +193,7 @@ def CreateBackGround(self):
169193
def GetAllIndex(self,):
170194
self.AllIndex = []
171195
for obj in self.AllObjects:
172-
self.AllIndex.append(obj.Index)
196+
self.AllIndex.append(float(obj.Index))
173197

174198

175199

@@ -259,27 +283,35 @@ def Plot(self):
259283

260284
self.CreateMesh()
261285

262-
Scene = Scene2D(nCols=1, nRows=1, UnitSize=(6, 6))
263-
264-
Scene.AddContour(Row = 0,
265-
Col = 0,
266-
x = self.X,
267-
y = self.Y,
268-
Scalar = self._Mesh,
269-
ColorMap = 'coolwarm',
270-
xLabel = r'X-distance [$\mu$m]',
271-
yLabel = r'Y-distance [$\mu$m]',
272-
IsoLines = np.sort( [0.99] + list(set(self._Mesh.flatten())) + [1.6] )
273-
)
274-
275-
Scene.SetAxes(Col=0,
276-
Row=0,
277-
xLimits=[self.xMin, self.xMax],
278-
yLimits=[self.yMin, self.yMax],
279-
Equal=True,
286+
Fig = Scene('SuPyMode Figure', UnitSize=(4,4))
287+
288+
ax = Axis(Row = 0,
289+
Col = 0,
290+
xLabel = r'x [$\mu m$]',
291+
yLabel = r'y [$\mu m$]',
292+
Title = f'Refractive index structure',
293+
Legend = False,
294+
ColorBar = True,
295+
ColorbarPosition = 'right',
296+
Grid = False,
297+
Equal = True,
298+
xScale = 'linear',
299+
yScale = 'linear')
300+
301+
artist = Mesh(X = self.X,
302+
Y = self.Y,
303+
Scalar = self._Mesh,
304+
ColorMap = 'cool',
305+
DiscretNorm = self.AllIndex,
280306
)
281307

282-
Scene.Show()
308+
ax.AddArtist(artist)
309+
310+
Fig.AddAxes(ax)
311+
312+
Fig.Show()
313+
314+
283315

284316

285317
def _Gradient(self):

SuPyMode/Plotting/Plots.py

Lines changed: 12 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,28 @@ def Render(self, Ax):
7373

7474

7575
class Mesh:
76-
def __init__(self, X, Y, Scalar, ColorMap='viridis', DiscretNorm=None, Label=''):
76+
def __init__(self, X, Y, Scalar, ColorMap='viridis', DiscretNorm=False, Label=''):
7777
self.X = X
7878
self.Y = Y
7979
self.Scalar = Scalar
8080
self.ColorMap=ColorMap
8181
self.Label = Label
8282

83-
#norm = colors.BoundaryNorm(DiscretNorm, ColorMap) if DiscretNorm is not None else None
83+
84+
self.Norm = colors.BoundaryNorm(DiscretNorm, 200, extend='both') if DiscretNorm is not False else None
85+
8486

8587
def Render(self, Ax):
8688
Image = Ax.pcolormesh(self.X,
8789
self.Y,
8890
self.Scalar,
89-
cmap=self.ColorMap,
90-
shading='auto',
91-
vmin=-np.max(np.abs(self.Scalar)),
92-
vmax=+np.max(np.abs(self.Scalar)))
91+
cmap = self.ColorMap,
92+
shading = 'auto',
93+
#vmin = -np.max(np.abs(self.Scalar)),
94+
#vmax = +np.max(np.abs(self.Scalar)),
95+
norm = self.Norm
96+
97+
)
9398

9499
return Image
95100

@@ -207,7 +212,7 @@ def GenerateAxis(self):
207212
self.Figure, Ax = plt.subplots(ncols=ColMax+1, nrows=RowMax+1, figsize=FigSize)
208213

209214
if not isinstance(Ax, np.ndarray): Ax = np.asarray([[Ax]])
210-
if Ax.shape == 1: Ax = np.asarray([A])
215+
if Ax.ndim == 1: Ax = np.asarray([Ax])
211216

212217
self.Figure.suptitle(self.Title)
213218

@@ -234,170 +239,6 @@ def Show(self):
234239

235240

236241

237-
238-
239-
240-
241-
242-
243-
244-
245-
246-
247-
class Scene2D:
248-
UnitSize = (10, 3)
249-
250-
def __init__(self, nCols, nRows, ColorBar=True, Projection=None, Grid=True, UnitSize=None):
251-
self.nCols = nCols
252-
self.nRows = nRows
253-
self.ColorBar = ColorBar
254-
self.Projection = Projection
255-
self.Grid = Grid
256-
self.Boundaries = {'x': [0, 0], 'y': [0, 0]}
257-
if UnitSize is not None: self.UnitSize = UnitSize
258-
259-
self.InitScene()
260-
261-
def InitScene(self):
262-
plt.rcParams['axes.grid'] = self.Grid
263-
plt.rcParams['ytick.labelsize'] = 8
264-
plt.rcParams['xtick.labelsize'] = 8
265-
plt.rcParams["font.size"] = 10
266-
plt.rcParams["font.family"] = "serif"
267-
268-
FigSize = [ self.UnitSize[0]*self.nCols, self.UnitSize[1]*self.nRows ]
269-
270-
self.Figure, self.Axes = plt.subplots(self.nRows,
271-
self.nCols,
272-
figsize=FigSize,
273-
subplot_kw=dict(projection=self.Projection))
274-
275-
if np.size(self.Axes) == 1:
276-
self.Axes = np.reshape(np.asarray( [self.Axes] ), (1, 1))
277-
else:
278-
self.Axes = np.reshape(np.asarray( [self.Axes] ), (self.nRows, self.nCols))
279-
280-
281-
def AddLine(self, x, y, Col, Row, Title=None, Fill=True, Color=None, xLabel=None, yLabel=None, Legend=None):
282-
ax = self.Axes[Row, Col]
283-
284-
ax.plot(x, y, color=Color, label=Legend)
285-
286-
if Title:
287-
ax.set_title(Title)
288-
289-
if Fill:
290-
ax.fill_between(x, y.min(), y, color=Color, alpha=0.7)
291-
292-
if xLabel:
293-
ax.set_xlabel(xLabel)
294-
295-
if yLabel:
296-
ax.set_ylabel(yLabel)
297-
298-
299-
def AddShapely(self, Col, Row, Object, Text=None):
300-
ax = self.Axes[Row, Col]
301-
302-
if isinstance(Object, Point):
303-
ax.scatter(Object.x, Object.y, linewidth=7)
304-
self.UpdateBoundary(x=Object.x, y=Object.y)
305-
306-
if isinstance(Object, (Polygon, MultiPolygon) ):
307-
Image = ax.add_patch( PolygonPatch(Object, alpha=0.5) )
308-
Coord = np.array( list(zip(*Object.exterior.coords.xy)) )
309-
self.UpdateBoundary(x=Coord[:,0], y=Coord[:,1])
310-
311-
if Text:
312-
ax.text(Object.x, Object.y, Text)
313-
314-
315-
def UpdateBoundary(self, x=None, y=None):
316-
if x is not None:
317-
xMax, xMin = np.max(x), np.min(x)
318-
XBound = min(self.Boundaries['x'][0], xMin), max(self.Boundaries['x'][1], xMax)
319-
self.Boundaries['x'] = XBound
320-
321-
if y is not None:
322-
yMax, yMin = np.max(y), np.min(y)
323-
YBound = min(self.Boundaries['y'][0], yMin), max(self.Boundaries['y'][1], yMax)
324-
self.Boundaries['y'] = XBound
325-
326-
327-
def SetAxes(self, Col, Row, Equal=None, Legend=None, xLimits=None, yLimits=None, xScale='linear', yScale='linear', LegendTitle=None):
328-
ax = self.Axes[Row, Col]
329-
330-
if Equal is True:
331-
ax.set_aspect('equal')
332-
if Equal is False:
333-
ax.set_aspect('auto')
334-
335-
if Legend is not None:
336-
ax.legend().set_visible(Legend)
337-
338-
if xLimits == 'auto': ax.set_xlim(self.Boundaries['x'])
339-
if yLimits == 'auto': ax.set_ylim(self.Boundaries['y'])
340-
341-
if isinstance(xLimits, list): ax.set_xlim(xLimits)
342-
if isinstance(yLimits, list): ax.set_ylim(yLimits)
343-
344-
ax.set_yscale(yScale)
345-
ax.set_xscale(xScale)
346-
347-
if LegendTitle: ax.legend().set_title(LegendTitle)
348-
349-
350-
351-
def AddMesh(self, Col, Row, x, y, Scalar, ColorMap='viridis', Title=None, xLabel=None, yLabel=None, DiscretNorm=None):
352-
ax = self.Axes[Row, Col]
353-
354-
norm = colors.BoundaryNorm(DiscretNorm, ColorMap) if DiscretNorm is not None else None
355-
356-
Image = ax.pcolormesh(x, y, Scalar, cmap=ColorMap, shading='auto', vmin=-np.max(np.abs(Scalar)), vmax=+np.max(np.abs(Scalar)) )
357-
358-
if Title is not None:
359-
ax.set_title(Title)
360-
361-
if xLabel is not None:
362-
ax.set_xlabel(xLabel)
363-
364-
if yLabel is not None:
365-
ax.set_ylabel(yLabel)
366-
367-
if self.ColorBar:
368-
plt.colorbar(Image, ax=ax, location='bottom')
369-
370-
self.UpdateBoundary(x=x, y=y)
371-
plt.tight_layout(pad=3)
372-
373-
374-
def AddContour(self, Col, Row, x, y, Scalar, ColorMap='viridis', Title=None, xLabel=None, yLabel=None, IsoLines=None):
375-
ax = self.Axes[Row, Col]
376-
377-
ax.contour(x, y, Scalar, levels=IsoLines, colors='black', linewidth=.5)
378-
Image = ax.contourf(x, y, Scalar, levels=IsoLines, cmap='jet', norm=colors.LogNorm() )
379-
380-
if Title is not None:
381-
ax.set_title(Title)
382-
383-
if xLabel is not None:
384-
ax.set_xlabel(xLabel)
385-
386-
if yLabel is not None:
387-
ax.set_ylabel(yLabel)
388-
389-
if self.ColorBar:
390-
plt.colorbar(Image, ax=ax, location='bottom', format="%.3f")
391-
392-
self.UpdateBoundary(x=x, y=y)
393-
plt.tight_layout(pad=3)
394-
395-
396-
def Show(self):
397-
#plt.tight_layout(pad=3)
398-
plt.show()
399-
400-
401242
class Scene3D:
402243
Size = (600, 350)
403244
BackGround = (1,1,1)

SuPyMode/Plotting/PlotsUtils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838

3939

4040

41-
42-
4341
class MidPointNorm(Normalize):
4442
def __init__(self, midpoint=0, vmin=None, vmax=None, clip=False):
4543
Normalize.__init__(self,vmin, vmax, clip)

SuPyMode/Solver.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ def AddModes(self,
7272

7373
CppSolver.LoopOverITR(ITR=self.ITRList, ExtrapolationOrder=3)
7474

75-
CppSolver.SortModes(Sorting=Sorting)
75+
CppSolver.SortModes(Sorting='Field')
7676

77-
CppSolver.ComputeCouplingAdiabatic()
77+
#CppSolver.ComputeCouplingAdiabatic()
7878

7979

8080
for BindingNumber in range(CppSolver.sMode):
@@ -86,11 +86,8 @@ def AddModes(self,
8686

8787

8888
def GetSet(self):
89-
return self.Set
90-
91-
92-
9389

90+
return self.Set
9491

9592

9693

0 commit comments

Comments
 (0)