@@ -58,7 +58,6 @@ def to_list(self):
58
58
##############################################
59
59
60
60
def __str__ (self ):
61
-
62
61
return '.{0.analysis_name} {1}' .format (self , join_list (self .to_list ()))
63
62
64
63
####################################################################################################
@@ -80,7 +79,6 @@ class DcSensitivityAnalysisParameters(AnalysisParameters):
80
79
##############################################
81
80
82
81
def __init__ (self , output_variable ):
83
-
84
82
self ._output_variable = output_variable
85
83
86
84
##############################################
@@ -92,7 +90,6 @@ def output_variable(self):
92
90
##############################################
93
91
94
92
def to_list (self ):
95
-
96
93
return (
97
94
self ._output_variable ,
98
95
)
@@ -144,7 +141,6 @@ def stop_frequencyr(self):
144
141
##############################################
145
142
146
143
def to_list (self ):
147
-
148
144
return (
149
145
self ._output_variable ,
150
146
self ._variation ,
@@ -183,7 +179,6 @@ def parameters(self):
183
179
##############################################
184
180
185
181
def to_list (self ):
186
-
187
182
return self ._parameters
188
183
189
184
####################################################################################################
@@ -297,6 +292,37 @@ def to_list(self):
297
292
298
293
####################################################################################################
299
294
295
+ class MeasureParameters (AnalysisParameters ):
296
+
297
+ """This class defines measurements on analysis.
298
+
299
+ """
300
+
301
+ __analysis_name__ = 'meas'
302
+
303
+ ##############################################
304
+
305
+ def __init__ (self , analysis_type , name , * args ):
306
+
307
+ _analysis_type = str (analysis_type ).upper ()
308
+ if (_analysis_type not in ('AC' , 'DC' , 'OP' , 'TRAN' , 'TF' , 'NOISE' )):
309
+ raise ValueError ('Incorrect analysis type {}' .format (analysis_type ))
310
+
311
+ self ._parameters = [_analysis_type , name , * args ]
312
+
313
+ ##############################################
314
+
315
+ @property
316
+ def parameters (self ):
317
+ return self ._parameters
318
+
319
+ ##############################################
320
+
321
+ def to_list (self ):
322
+ return self ._parameters
323
+
324
+ ####################################################################################################
325
+
300
326
class CircuitSimulation :
301
327
302
328
"""Define and generate the spice instruction to perform a circuit simulation.
@@ -315,6 +341,7 @@ def __init__(self, circuit, **kwargs):
315
341
self ._circuit = circuit
316
342
317
343
self ._options = {} # .options
344
+ self ._measures = [] # .measure
318
345
self ._initial_condition = {} # .ic
319
346
self ._saved_nodes = set ()
320
347
self ._analyses = {}
@@ -424,27 +451,27 @@ def save_currents(self, value):
424
451
##############################################
425
452
426
453
def reset_analysis (self ):
427
-
428
454
self ._analyses .clear ()
429
455
430
456
##############################################
431
457
432
458
def analysis_iter (self ):
433
-
434
459
return self ._analyses .values ()
435
460
436
461
##############################################
437
462
438
463
def _add_analysis (self , analysis_parameters ):
439
-
440
464
self ._analyses [analysis_parameters .analysis_name ] = analysis_parameters
441
465
442
466
##############################################
443
467
444
- def operating_point (self ):
468
+ def _add_measure (self , measure_parameters ):
469
+ self ._measures .append (measure_parameters )
445
470
446
- """Compute the operating point of the circuit with capacitors open and inductors shorted."""
471
+ ##############################################
447
472
473
+ def operating_point (self ):
474
+ """Compute the operating point of the circuit with capacitors open and inductors shorted."""
448
475
self ._add_analysis (OperatingPointAnalysisParameters ())
449
476
450
477
##############################################
@@ -586,6 +613,29 @@ def ac(self, variation, number_of_points, start_frequency, stop_frequency):
586
613
587
614
##############################################
588
615
616
+ def measure (self , analysis_type , name , * args ):
617
+
618
+ """Add a measure in the circuit.
619
+
620
+ Examples of usage::
621
+
622
+ simulator.measure('TRAN', 'tdiff', 'TRIG AT=10m', 'TARG v(n1) VAL=75.0 CROSS=1')
623
+ simulator.measure('tran', 'tdiff', 'TRIG AT=0m', f"TARG par('v(n1)-v(derate)') VAL=0 CROSS=1")
624
+
625
+ Note: can be used with the .options AUTOSTOP to stop the simulation at Trigger.
626
+
627
+ Spice syntax:
628
+
629
+ .. code:: spice
630
+
631
+ .meas tran tdiff TRIG AT=0m TARG v(n1) VAL=75.0 CROSS=1
632
+
633
+ """
634
+
635
+ self ._add_measure (MeasureParameters (analysis_type , name , * args ))
636
+
637
+ ##############################################
638
+
589
639
def transient (self , step_time , end_time , start_time = 0 , max_time = None ,
590
640
use_initial_condition = False ):
591
641
@@ -646,6 +696,8 @@ def __str__(self):
646
696
else :
647
697
all_str = ''
648
698
netlist += '.save ' + all_str + join_list (saved_nodes ) + os .linesep
699
+ for measure_parameters in self ._measures :
700
+ netlist += str (measure_parameters ) + os .linesep
649
701
for analysis_parameters in self ._analyses .values ():
650
702
netlist += str (analysis_parameters ) + os .linesep
651
703
netlist += '.end' + os .linesep
@@ -732,29 +784,24 @@ def _run(self, analysis_method, *args, **kwargs):
732
784
##############################################
733
785
734
786
def operating_point (self , * args , ** kwargs ):
735
-
736
787
return self ._run ('operating_point' , * args , ** kwargs )
737
788
738
789
##############################################
739
790
740
791
def dc (self , * args , ** kwargs ):
741
-
742
792
return self ._run ('dc' , * args , ** kwargs )
743
793
744
794
##############################################
745
795
746
796
def dc_sensitivity (self , * args , ** kwargs ):
747
-
748
797
return self ._run ('dc_sensitivity' , * args , ** kwargs )
749
798
750
799
##############################################
751
800
752
801
def ac (self , * args , ** kwargs ):
753
-
754
802
return self ._run ('ac' , * args , ** kwargs )
755
803
756
804
##############################################
757
805
758
806
def transient (self , * args , ** kwargs ):
759
-
760
807
return self ._run ('transient' , * args , ** kwargs )
0 commit comments