22
22
import numpy as np
23
23
import copy
24
24
from scipy .interpolate import interp1d
25
+ import time
25
26
26
27
from . import models
27
28
from . import netlist as nl
@@ -49,10 +50,13 @@ class MathPrefixes:
49
50
50
51
class Simulation :
51
52
def __init__ (self , netlist ):
53
+ start = time .time ()
52
54
self .s_matrix , self .frequency , self .ports , self .external_components = nl .get_sparameters (netlist )
53
55
self .external_port_list = [- int (x ) for x in self .ports ]
54
56
self .external_port_list .sort ()
55
57
self ._rearrangeSMatrix ()
58
+ stop = time .time ()
59
+ print ("Simulation time:" , stop - start , "seconds." )
56
60
return
57
61
58
62
def _rearrangeSMatrix (self ):
@@ -105,7 +109,6 @@ def exportSMatrix(self):
105
109
106
110
import matplotlib .pyplot as plt
107
111
from scipy .io import savemat
108
- import time
109
112
110
113
class MonteCarloSimulation :
111
114
DEF_NUM_SIMS = 10
@@ -214,10 +217,15 @@ def __init__(self, netlist):
214
217
super ().__init__ (netlist )
215
218
216
219
def multi_input_simulation (self , inputs : list = []):
220
+ """
221
+ Parameters
222
+ ----------
223
+ inputs : list
224
+ A 0-indexed list of the ports to be used as inputs.
225
+ """
217
226
active = [0 ] * len (self .ports )
218
227
for val in inputs :
219
- # Inputs is 1-indexed, while active is 0-indexed
220
- active [val - 1 ] = 1
228
+ active [val ] = 1
221
229
self .simulated_matrix = self ._measure_s_matrix (active )
222
230
223
231
def _measure_s_matrix (self , inputs ):
@@ -238,11 +246,23 @@ def plot(self, output_port):
238
246
plt .show ()
239
247
240
248
def get_magnitude_by_frequency_thz (self , output_port ):
249
+ """
250
+ Parameters
251
+ ----------
252
+ output_port : int
253
+ Gets the values at that output port (0-indexed).
254
+ """
241
255
freq = np .divide (self .frequency , MathPrefixes .TERA )
242
256
mag = np .power (np .absolute (self .simulated_matrix [:, output_port ]), 2 )
243
257
return freq , mag
244
258
245
259
def get_magnitude_by_wavelength_nm (self , output_port ):
260
+ """
261
+ Parameters
262
+ ----------
263
+ output_port : int
264
+ Gets the values at that output port (0-indexed).
265
+ """
246
266
wl = self .frequencyToWavelength (self .frequency ) / MathPrefixes .NANO
247
267
mag = np .power (np .absolute (self .simulated_matrix [:, output_port ]), 2 )
248
268
return wl , mag
0 commit comments