SuPyMode 2.4.3__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- SuPyMode/__init__.py +9 -0
- SuPyMode/_version.py +24 -0
- SuPyMode/boundaries.cp313-win_amd64.pyd +0 -0
- SuPyMode/directories.py +51 -0
- SuPyMode/eigensolver.cp313-win_amd64.pyd +0 -0
- SuPyMode/mesh.cp313-win_amd64.pyd +0 -0
- SuPyMode/model_parameters.cp313-win_amd64.pyd +0 -0
- SuPyMode/plotter.py +325 -0
- SuPyMode/propagation.py +202 -0
- SuPyMode/representation/__init__.py +23 -0
- SuPyMode/representation/adiabatic.py +111 -0
- SuPyMode/representation/beating_length.py +95 -0
- SuPyMode/representation/beta.py +78 -0
- SuPyMode/representation/eigen_value.py +79 -0
- SuPyMode/representation/field.py +486 -0
- SuPyMode/representation/index.py +80 -0
- SuPyMode/representation/normalized_coupling.py +98 -0
- SuPyMode/solver.py +203 -0
- SuPyMode/supermode.cp313-win_amd64.pyd +0 -0
- SuPyMode/superset.py +701 -0
- SuPyMode/superset_plots.py +497 -0
- SuPyMode/taper.cp313-win_amd64.pyd +0 -0
- SuPyMode/utils.py +196 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP01-LP02.csv +98 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP01-LP21.csv +88 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP01-LP41.csv +86 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP11-LP12.csv +82 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP11-LP31.csv +95 -0
- SuPyMode/validation_data/SBB_figure_4_16_a/LP11-LP51.csv +81 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP01-LP02.csv +285 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP01-LP21.csv +75 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP01-LP41.csv +237 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP11-LP12.csv +126 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP11-LP31.csv +156 -0
- SuPyMode/validation_data/SBB_figure_4_16_b/LP11-LP51.csv +224 -0
- SuPyMode/workflow.py +253 -0
- supymode-2.4.3.dist-info/METADATA +241 -0
- supymode-2.4.3.dist-info/RECORD +40 -0
- supymode-2.4.3.dist-info/WHEEL +5 -0
- supymode-2.4.3.dist-info/licenses/LICENSE +21 -0
SuPyMode/solver.py
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
|
|
4
|
+
# Third-party imports
|
|
5
|
+
import numpy
|
|
6
|
+
from PyFinitDiff.finite_difference_2D import FiniteDifference
|
|
7
|
+
from PyFinitDiff.finite_difference_2D import Boundaries
|
|
8
|
+
|
|
9
|
+
# Local imports
|
|
10
|
+
from SuPyMode.superset import SuperSet
|
|
11
|
+
from SuPyMode.eigensolver import EIGENSOLVER # type: ignore
|
|
12
|
+
from SuPyMode.model_parameters import ModelParameters # type: ignore
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SuPySolver(EIGENSOLVER):
|
|
16
|
+
"""
|
|
17
|
+
A solver for computing eigenvalues and supermodes of optical fiber geometries using a C++ eigensolver.
|
|
18
|
+
|
|
19
|
+
This class manages the eigenvalue problem for optical structures and returns computed supermodes. The solver utilizes
|
|
20
|
+
a C++ backend for efficient eigenvalue computation and integrates with finite difference methods to solve for various
|
|
21
|
+
boundary conditions.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
mesh : numpy.ndarray
|
|
26
|
+
The refractive index geometry of the optical structure.
|
|
27
|
+
x : numpy.ndarray
|
|
28
|
+
The x-coordinate vector of the mesh.
|
|
29
|
+
y : numpy.ndarray
|
|
30
|
+
The y-coordinate vector of the mesh.
|
|
31
|
+
tolerance : float, optional
|
|
32
|
+
Absolute tolerance for the propagation constant computation (default is 1e-8).
|
|
33
|
+
max_iteration : int, optional
|
|
34
|
+
Maximum iterations for the C++ eigensolver (default is 10,000).
|
|
35
|
+
accuracy : int, optional
|
|
36
|
+
Accuracy level of the finite difference method (default is 2).
|
|
37
|
+
extrapolation_order : int, optional
|
|
38
|
+
Order of Taylor series used to extrapolate eigenvalues (default is 2).
|
|
39
|
+
debug_mode : int, optional
|
|
40
|
+
Debug output level from the C++ binding, where 0 is no output and higher values provide more detail (default is 1).
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
mesh: numpy.typing.NDArray,
|
|
46
|
+
x: numpy.typing.NDArray,
|
|
47
|
+
y: numpy.typing.NDArray,
|
|
48
|
+
tolerance: float = 1e-8,
|
|
49
|
+
max_iteration: int = 10_000,
|
|
50
|
+
accuracy: int = 2,
|
|
51
|
+
extrapolation_order: int = 2,
|
|
52
|
+
debug_mode: int = 1,
|
|
53
|
+
) -> None:
|
|
54
|
+
"""
|
|
55
|
+
Initialize the solver with the given parameters.
|
|
56
|
+
"""
|
|
57
|
+
self.mesh = mesh
|
|
58
|
+
|
|
59
|
+
dx = abs(x[0] - x[1])
|
|
60
|
+
dy = abs(y[0] - y[1])
|
|
61
|
+
|
|
62
|
+
model_parameters = ModelParameters(
|
|
63
|
+
dx=dx,
|
|
64
|
+
dy=dy,
|
|
65
|
+
mesh=mesh,
|
|
66
|
+
x_vector=x,
|
|
67
|
+
y_vector=y,
|
|
68
|
+
debug_mode=debug_mode,
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
super().__init__(
|
|
72
|
+
model_parameters=model_parameters,
|
|
73
|
+
max_iteration=max_iteration,
|
|
74
|
+
tolerance=tolerance,
|
|
75
|
+
accuracy=accuracy,
|
|
76
|
+
extrapolation_order=extrapolation_order,
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
def get_finit_difference_array(self, boundaries: Boundaries) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Initialize and configure the C++ solver binding for eigenvalue computations.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
n_sorted_mode : int
|
|
86
|
+
Number of modes to sort and retrieve from the solver.
|
|
87
|
+
boundaries : Boundaries
|
|
88
|
+
Boundary conditions for the finite difference system.
|
|
89
|
+
n_added_mode : int
|
|
90
|
+
Number of extra modes calculated for accuracy and reliability.
|
|
91
|
+
|
|
92
|
+
Returns
|
|
93
|
+
-------
|
|
94
|
+
EigenSolver
|
|
95
|
+
Configured C++ solver instance.
|
|
96
|
+
"""
|
|
97
|
+
finit_diff_matrix = FiniteDifference(
|
|
98
|
+
n_x=self.model_parameters.nx,
|
|
99
|
+
n_y=self.model_parameters.ny,
|
|
100
|
+
dx=self.model_parameters.dx,
|
|
101
|
+
dy=self.model_parameters.dy,
|
|
102
|
+
derivative=2,
|
|
103
|
+
accuracy=self.accuracy,
|
|
104
|
+
boundaries=boundaries,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
finit_diff_matrix.construct_triplet()
|
|
108
|
+
|
|
109
|
+
return numpy.c_[
|
|
110
|
+
finit_diff_matrix._triplet.array[:, 1],
|
|
111
|
+
finit_diff_matrix._triplet.array[:, 0],
|
|
112
|
+
finit_diff_matrix._triplet.array[:, 2],
|
|
113
|
+
]
|
|
114
|
+
|
|
115
|
+
def init_superset(
|
|
116
|
+
self,
|
|
117
|
+
wavelength: float,
|
|
118
|
+
n_step: int = 300,
|
|
119
|
+
itr_initial: float = 1.0,
|
|
120
|
+
itr_final: float = 0.1,
|
|
121
|
+
) -> None:
|
|
122
|
+
"""
|
|
123
|
+
Initialize a SuperSet instance containing computed supermodes over a range of inverse taper ratios (ITR).
|
|
124
|
+
|
|
125
|
+
Parameters
|
|
126
|
+
----------
|
|
127
|
+
wavelength : float
|
|
128
|
+
Wavelength for the mode computation.
|
|
129
|
+
n_step : int, optional
|
|
130
|
+
Number of steps for the ITR interpolation (default is 300).
|
|
131
|
+
itr_initial : float, optional
|
|
132
|
+
Initial ITR value (default is 1.0).
|
|
133
|
+
itr_final : float, optional
|
|
134
|
+
Final ITR value (default is 0.1).
|
|
135
|
+
"""
|
|
136
|
+
self.model_parameters.initialize(
|
|
137
|
+
wavelength=wavelength,
|
|
138
|
+
itr_initial=itr_initial,
|
|
139
|
+
itr_final=itr_final,
|
|
140
|
+
n_step=n_step,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
self.superset = SuperSet(
|
|
144
|
+
model_parameters=self.model_parameters,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def add_modes(
|
|
148
|
+
self,
|
|
149
|
+
n_sorted_mode: int,
|
|
150
|
+
boundaries: Boundaries,
|
|
151
|
+
n_added_mode: int = 4,
|
|
152
|
+
index_guess: float = 0.0,
|
|
153
|
+
auto_label: bool = True,
|
|
154
|
+
) -> None:
|
|
155
|
+
"""
|
|
156
|
+
Compute and add a specified number of supermodes to the solver's collection.
|
|
157
|
+
|
|
158
|
+
Parameters
|
|
159
|
+
----------
|
|
160
|
+
n_sorted_mode : int
|
|
161
|
+
Number of modes to output and sort from the solver.
|
|
162
|
+
boundaries : Boundaries
|
|
163
|
+
Boundary conditions for the finite difference calculations.
|
|
164
|
+
n_added_mode : int, optional
|
|
165
|
+
Additional modes computed to ensure mode matching accuracy (default is 4).
|
|
166
|
+
index_guess : float, optional
|
|
167
|
+
Starting guess for the refractive index used in calculations (default is 0., auto-evaluated if set to 0).
|
|
168
|
+
auto_label : bool, optional
|
|
169
|
+
If True, enables automatic labeling of modes based on symmetry (default is True).
|
|
170
|
+
|
|
171
|
+
Returns
|
|
172
|
+
-------
|
|
173
|
+
None
|
|
174
|
+
This method updates the solver's internal state but does not return any value.
|
|
175
|
+
"""
|
|
176
|
+
finit_difference_array = self.get_finit_difference_array(
|
|
177
|
+
boundaries=boundaries,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
self.reset_solver()
|
|
181
|
+
|
|
182
|
+
self.set_boundaries(
|
|
183
|
+
left=boundaries.left.value.lower(),
|
|
184
|
+
right=boundaries.right.value.lower(),
|
|
185
|
+
top=boundaries.top.value.lower(),
|
|
186
|
+
bottom=boundaries.bottom.value.lower(),
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
self.initialize(
|
|
190
|
+
model_parameters=self.model_parameters,
|
|
191
|
+
finit_matrix=finit_difference_array.T,
|
|
192
|
+
n_computed_mode=n_sorted_mode + n_added_mode,
|
|
193
|
+
n_sorted_mode=n_sorted_mode,
|
|
194
|
+
)
|
|
195
|
+
|
|
196
|
+
self.loop_over_itr(guess_index=index_guess, auto_label=auto_label)
|
|
197
|
+
|
|
198
|
+
for binding_number in range(n_sorted_mode):
|
|
199
|
+
supermode = self.get_sorted_mode(binding_number)
|
|
200
|
+
|
|
201
|
+
self.superset.supermodes.append(supermode)
|
|
202
|
+
|
|
203
|
+
setattr(self.superset, supermode.label, supermode)
|
|
Binary file
|