@@ -302,16 +302,29 @@ def run(self, path_dir: str = DEFAULT_DATA_DIR):
302
302
return TerminalComponentModelerData (simulation = self , data = smatrix_data )
303
303
304
304
##### Backwards compatibility methods #####
305
+ @staticmethod
306
+ def _check_port_impedance_sign (Z_numpy : np .ndarray ):
307
+ from tidy3d .plugins .smatrix .utils import _check_port_impedance_sign
305
308
306
- def compute_power_wave_amplitudes_at_each_port (
307
- self , port_reference_impedances : PortDataArray , sim_data : SimulationData
308
- ) -> tuple [PortDataArray , PortDataArray ]:
309
- from tidy3d .plugins .smatrix .run import compute_power_wave_amplitudes_at_each_port
309
+ return _check_port_impedance_sign (Z_numpy )
310
310
311
- data = compute_power_wave_amplitudes_at_each_port (
312
- simulation = self , port_reference_impedances = port_reference_impedances , sim_data = sim_data
313
- )
314
- return data
311
+ @staticmethod
312
+ def _compute_F (Z_numpy : np .array ):
313
+ """Helper to convert port impedance matrix to F, which is used for
314
+ computing generalized scattering parameters."""
315
+ from tidy3d .plugins .smatrix .utils import _compute_F
316
+
317
+ return _compute_F (Z_numpy )
318
+
319
+ def _construct_smatrix (self ) -> TerminalPortDataArray :
320
+ from tidy3d .plugins .smatrix .run import construct_smatrix
321
+
322
+ return construct_smatrix (self )
323
+
324
+ def _internal_construct_smatrix (self , batch_data : typing .Any = None ) -> TerminalPortDataArray :
325
+ from tidy3d .plugins .smatrix .run import construct_smatrix
326
+
327
+ return construct_smatrix (self )
315
328
316
329
def _monitor_data_at_port_amplitude (
317
330
self ,
@@ -333,11 +346,7 @@ def _monitor_data_at_port_amplitude(
333
346
)
334
347
return data
335
348
336
- def get_antenna_metrics_data (
337
- self ,
338
- port_amplitudes : Optional [dict [str , complex ]] = None ,
339
- monitor_name : Optional [str ] = None ,
340
- ) -> AntennaMetricsData :
349
+ def _port_reference_impedances (self , batch_data ) -> PortDataArray :
341
350
from tidy3d .plugins .smatrix .data .data import (
342
351
MicrowaveSMatrixData ,
343
352
TerminalComponentModelerData ,
@@ -346,55 +355,33 @@ def get_antenna_metrics_data(
346
355
smatrix_data = MicrowaveSMatrixData (data = self ._construct_smatrix ())
347
356
data = TerminalComponentModelerData (
348
357
simulation = self , data = smatrix_data
349
- ).get_antenna_metrics_data ( port_amplitudes = port_amplitudes , monitor_name = monitor_name )
358
+ ).port_reference_impedances
350
359
return data
351
360
352
- @staticmethod
353
- def _check_port_impedance_sign (Z_numpy : np .ndarray ):
354
- from tidy3d .plugins .smatrix .utils import _check_port_impedance_sign
355
-
356
- return _check_port_impedance_sign (Z_numpy )
357
-
358
- @staticmethod
359
- def _compute_F (Z_numpy : np .array ):
360
- """Helper to convert port impedance matrix to F, which is used for
361
- computing generalized scattering parameters."""
362
- from tidy3d .plugins .smatrix .utils import _compute_F
363
-
364
- return _compute_F (Z_numpy )
365
-
366
361
@cached_property
367
- def port_reference_impedances (self ) -> PortDataArray :
368
- from tidy3d .plugins .smatrix .data .data import (
369
- MicrowaveSMatrixData ,
370
- TerminalComponentModelerData ,
371
- )
372
-
373
- smatrix_data = MicrowaveSMatrixData (data = self ._construct_smatrix ())
374
- data = TerminalComponentModelerData (
375
- simulation = self , data = smatrix_data
376
- ).port_reference_impedances
377
- return data
362
+ def _terminal_modeler_path (self ) -> str :
363
+ """Where we store the for this :class:`TerminalComponentModeler` instance after the run."""
364
+ return os .path .join (self .path_dir , "tcp_" + str (hash (self )) + ".hdf5" )
378
365
379
- def _port_reference_impedances (self , batch_data ) -> PortDataArray :
380
- from tidy3d .plugins .smatrix .data .data import (
381
- MicrowaveSMatrixData ,
382
- TerminalComponentModelerData ,
383
- )
366
+ def _upload_terminal_modeler (self ):
367
+ # TODO properly refactor, plugins data types should not have web methods.
368
+ from tidy3d .web .api .container import Job
384
369
385
- smatrix_data = MicrowaveSMatrixData (data = self ._construct_smatrix ())
386
- data = TerminalComponentModelerData (
387
- simulation = self , data = smatrix_data
388
- ).port_reference_impedances
389
- return data
370
+ # first try loading the terminal_component_modeler from file, if it exists
371
+ terminal_modeler_path = self ._terminal_modeler_path
390
372
391
- @staticmethod
392
- def s_to_z (
393
- s_matrix : TerminalPortDataArray , reference : Union [complex , PortDataArray ]
394
- ) -> DataArray :
395
- from tidy3d .plugins .smatrix .utils import s_to_z
373
+ if os .path .exists (terminal_modeler_path ):
374
+ return Job .from_file (fname = terminal_modeler_path )
396
375
397
- return s_to_z (s_matrix = s_matrix , reference = reference )
376
+ return Job (
377
+ simulation = self ,
378
+ task_name = self .name ,
379
+ folder_name = self .folder_name ,
380
+ callback_url = self .callback_url ,
381
+ verbose = self .verbose ,
382
+ solver_version = self .solver_version ,
383
+ simulation_type = "microwave" ,
384
+ )
398
385
399
386
@staticmethod
400
387
def ab_to_s (
@@ -404,6 +391,24 @@ def ab_to_s(
404
391
405
392
return ab_to_s (a_matrix = a_matrix , b_matrix = b_matrix )
406
393
394
+ @staticmethod
395
+ def compute_port_VI (
396
+ port_out : TerminalPortType , sim_data : SimulationData
397
+ ) -> tuple [FreqDataArray , FreqDataArray ]:
398
+ from tidy3d .plugins .smatrix .utils import compute_port_VI
399
+
400
+ return compute_port_VI (port_out = port_out , sim_data = sim_data )
401
+
402
+ def compute_power_wave_amplitudes_at_each_port (
403
+ self , port_reference_impedances : PortDataArray , sim_data : SimulationData
404
+ ) -> tuple [PortDataArray , PortDataArray ]:
405
+ from tidy3d .plugins .smatrix .run import compute_power_wave_amplitudes_at_each_port
406
+
407
+ data = compute_power_wave_amplitudes_at_each_port (
408
+ simulation = self , port_reference_impedances = port_reference_impedances , sim_data = sim_data
409
+ )
410
+ return data
411
+
407
412
@staticmethod
408
413
def compute_power_delivered_by_port (
409
414
port : Union [LumpedPort , CoaxialLumpedPort ], sim_data : SimulationData
@@ -420,45 +425,39 @@ def compute_power_wave_amplitudes(
420
425
421
426
return compute_power_wave_amplitudes (port = port , sim_data = sim_data )
422
427
423
- @staticmethod
424
- def compute_port_VI (
425
- port_out : TerminalPortType , sim_data : SimulationData
426
- ) -> tuple [FreqDataArray , FreqDataArray ]:
427
- from tidy3d .plugins .smatrix .utils import compute_port_VI
428
+ def get_antenna_metrics_data (
429
+ self ,
430
+ port_amplitudes : Optional [dict [str , complex ]] = None ,
431
+ monitor_name : Optional [str ] = None ,
432
+ ) -> AntennaMetricsData :
433
+ from tidy3d .plugins .smatrix .data .data import (
434
+ MicrowaveSMatrixData ,
435
+ TerminalComponentModelerData ,
436
+ )
428
437
429
- return compute_port_VI (port_out = port_out , sim_data = sim_data )
438
+ smatrix_data = MicrowaveSMatrixData (data = self ._construct_smatrix ())
439
+ data = TerminalComponentModelerData (
440
+ simulation = self , data = smatrix_data
441
+ ).get_antenna_metrics_data (port_amplitudes = port_amplitudes , monitor_name = monitor_name )
442
+ return data
430
443
431
444
@cached_property
432
- def _terminal_modeler_path (self ) -> str :
433
- """Where we store the for this :class:`TerminalComponentModeler` instance after the run."""
434
- return os .path .join (self .path_dir , "tcp_" + str (hash (self )) + ".hdf5" )
435
-
436
- def _upload_terminal_modeler (self ):
437
- # TODO properly refactor, plugins data types should not have web methods.
438
- from tidy3d .web .api .container import Job
439
-
440
- # first try loading the terminal_component_modeler from file, if it exists
441
- terminal_modeler_path = self ._terminal_modeler_path
442
-
443
- if os .path .exists (terminal_modeler_path ):
444
- return Job .from_file (fname = terminal_modeler_path )
445
-
446
- return Job (
447
- simulation = self ,
448
- task_name = self .name ,
449
- folder_name = self .folder_name ,
450
- callback_url = self .callback_url ,
451
- verbose = self .verbose ,
452
- solver_version = self .solver_version ,
453
- simulation_type = "microwave" ,
445
+ def port_reference_impedances (self ) -> PortDataArray :
446
+ from tidy3d .plugins .smatrix .data .data import (
447
+ MicrowaveSMatrixData ,
448
+ TerminalComponentModelerData ,
454
449
)
455
450
456
- def _construct_smatrix (self ) -> TerminalPortDataArray :
457
- from tidy3d .plugins .smatrix .run import _construct_smatrix
458
-
459
- return _construct_smatrix (self )
451
+ smatrix_data = MicrowaveSMatrixData (data = self ._construct_smatrix ())
452
+ data = TerminalComponentModelerData (
453
+ simulation = self , data = smatrix_data
454
+ ).port_reference_impedances
455
+ return data
460
456
461
- def _internal_construct_smatrix (self , batch_data : typing .Any = None ) -> TerminalPortDataArray :
462
- from tidy3d .plugins .smatrix .run import _construct_smatrix
457
+ @staticmethod
458
+ def s_to_z (
459
+ s_matrix : TerminalPortDataArray , reference : Union [complex , PortDataArray ]
460
+ ) -> DataArray :
461
+ from tidy3d .plugins .smatrix .utils import s_to_z
463
462
464
- return _construct_smatrix ( self )
463
+ return s_to_z ( s_matrix = s_matrix , reference = reference )
0 commit comments