15
15
from tidy3d .components .simulation import Simulation
16
16
from tidy3d .components .source .field import ModeSource
17
17
from tidy3d .components .source .time import GaussianPulse
18
- from tidy3d .components .types import Ax , Complex
18
+ from tidy3d .components .types import Ax
19
19
from tidy3d .components .viz import add_ax_if_none , equal_aspect
20
- from tidy3d .exceptions import SetupError
21
20
from tidy3d .plugins .smatrix .ports .modal import ModalPortDataArray , Port
22
21
from tidy3d .web .api .container import BatchData
23
22
27
26
Element = tuple [MatrixIndex , MatrixIndex ] # the 'ij' in S_ij
28
27
29
28
30
- class ComponentModeler (AbstractComponentModeler ):
29
+ class ComponentModeler (AbstractComponentModeler [ MatrixIndex , Element ] ):
31
30
"""
32
31
Tool for modeling devices and computing scattering matrix elements.
33
32
@@ -47,52 +46,6 @@ class ComponentModeler(AbstractComponentModeler):
47
46
"For each input mode, one simulation will be run with a modal source." ,
48
47
)
49
48
50
- element_mappings : tuple [tuple [Element , Element , Complex ], ...] = pd .Field (
51
- (),
52
- title = "Element Mappings" ,
53
- description = "Mapping between elements of the scattering matrix, "
54
- "as specified by pairs of ``(port name, mode index)`` matrix indices, where the "
55
- "first element of the pair is the output and the second element of the pair is the input."
56
- "Each item of ``element_mappings`` is a tuple of ``(element1, element2, c)``, where "
57
- "the scattering matrix ``Smatrix[element2]`` is set equal to ``c * Smatrix[element1]``."
58
- "If all elements of a given column of the scattering matrix are defined by "
59
- " ``element_mappings``, the simulation corresponding to this column "
60
- "is skipped automatically." ,
61
- )
62
-
63
- run_only : Optional [tuple [MatrixIndex , ...]] = pd .Field (
64
- None ,
65
- title = "Run Only" ,
66
- description = "If given, a tuple of matrix indices, specified by (:class:`.Port`, ``int``),"
67
- " to run only, excluding the other rows from the scattering matrix. "
68
- "If this option is used, "
69
- "the data corresponding to other inputs will be missing in the resulting matrix." ,
70
- )
71
- """Finally, to exclude some rows of the scattering matrix, one can supply a ``run_only`` parameter to the
72
- :class:`ComponentModeler`. ``run_only`` contains the scattering matrix indices that the user wants to run as a
73
- source. If any indices are excluded, they will not be run."""
74
-
75
- verbose : bool = pd .Field (
76
- False ,
77
- title = "Verbosity" ,
78
- description = "Whether the :class:`.ComponentModeler` should print status and progressbars." ,
79
- )
80
-
81
- callback_url : str = pd .Field (
82
- None ,
83
- title = "Callback URL" ,
84
- description = "Http PUT url to receive simulation finish event. "
85
- "The body content is a json file with fields "
86
- "``{'id', 'status', 'name', 'workUnit', 'solverVersion'}``." ,
87
- )
88
-
89
- @pd .validator ("simulation" , always = True )
90
- def _sim_has_no_sources (cls , val ):
91
- """Make sure simulation has no sources as they interfere with tool."""
92
- if len (val .sources ) > 0 :
93
- raise SetupError ("'ComponentModeler.simulation' must not have any sources." )
94
- return val
95
-
96
49
@cached_property
97
50
def sim_dict (self ) -> dict [str , Simulation ]:
98
51
"""Generate all the :class:`.Simulation` objects for the S matrix calculation."""
@@ -121,39 +74,6 @@ def matrix_indices_monitor(self) -> tuple[MatrixIndex, ...]:
121
74
matrix_indices .append ((port .name , mode_index ))
122
75
return tuple (matrix_indices )
123
76
124
- @cached_property
125
- def matrix_indices_source (self ) -> tuple [MatrixIndex , ...]:
126
- """Tuple of all the source matrix indices (port, mode_index) in the Component Modeler."""
127
- if self .run_only is not None :
128
- return self .run_only
129
- return self .matrix_indices_monitor
130
-
131
- @cached_property
132
- def matrix_indices_run_sim (self ) -> tuple [MatrixIndex , ...]:
133
- """Tuple of all the source matrix indices (port, mode_index) in the Component Modeler."""
134
-
135
- if self .element_mappings is None or self .element_mappings == {}:
136
- return self .matrix_indices_source
137
-
138
- # all the (i, j) pairs in `S_ij` that are tagged as covered by `element_mappings`
139
- elements_determined_by_map = [element_out for (_ , element_out , _ ) in self .element_mappings ]
140
-
141
- # loop through rows of the full s matrix and record rows that still need running.
142
- source_indices_needed = []
143
- for col_index in self .matrix_indices_source :
144
- # loop through columns and keep track of whether each element is covered by mapping.
145
- matrix_elements_covered = []
146
- for row_index in self .matrix_indices_monitor :
147
- element = (row_index , col_index )
148
- element_covered_by_map = element in elements_determined_by_map
149
- matrix_elements_covered .append (element_covered_by_map )
150
-
151
- # if any matrix elements in row still not covered by map, a source is needed for row.
152
- if not all (matrix_elements_covered ):
153
- source_indices_needed .append (col_index )
154
-
155
- return source_indices_needed
156
-
157
77
@cached_property
158
78
def port_names (self ) -> tuple [list [str ], list [str ]]:
159
79
"""List of port names for inputs and outputs, respectively."""
0 commit comments