Skip to content

Commit a3859b3

Browse files
fix #160
1 parent 5ec293f commit a3859b3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

PySpice/Spice/HighLevelElement.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222

2323
"""This module implements high level elements built on top of Spice elements."""
2424

25+
# Fixme: check NgSpice for discrepancies
26+
2527
####################################################################################################
2628

2729
from ..Math import rms_to_amplitude, amplitude_to_rms
28-
from ..Tools.StringTools import join_list, join_dict, str_spice
30+
from ..Tools.StringTools import join_list, join_dict, str_spice, str_spice_list
2931
from ..Unit import as_s, as_V, as_A, as_Hz
3032
from .BasicElement import VoltageSource, CurrentSource
3133

@@ -82,6 +84,8 @@ class SinusoidalMixin(SourceMixinAbc):
8284
8385
Public Attributes:
8486
87+
:attr:`ac_magnitude`
88+
8589
:attr:`amplitude`
8690
8791
:attr:`damping_factor`
@@ -100,10 +104,12 @@ class SinusoidalMixin(SourceMixinAbc):
100104

101105
def __init__(self,
102106
dc_offset=0,
107+
ac_magnitude=1,
103108
offset=0, amplitude=1, frequency=50,
104109
delay=0, damping_factor=0):
105110

106111
self.dc_offset = self.__as_unit__(dc_offset)
112+
self.ac_magnitude = self.__as_unit__(ac_magnitude)
107113
self.offset = self.__as_unit__(offset)
108114
self.amplitude = self.__as_unit__(amplitude)
109115
self.frequency = as_Hz(frequency) # Fixme: protect by setter?
@@ -114,7 +120,8 @@ def __init__(self,
114120

115121
@property
116122
def rms_voltage(self):
117-
return amplitude_to_rms(self.amplitude)
123+
# Fixme: ok ???
124+
return amplitude_to_rms(self.amplitude * self.ac_magnitude)
118125

119126
##############################################
120127

@@ -128,9 +135,8 @@ def format_spice_parameters(self):
128135

129136
sin_part = join_list((self.offset, self.amplitude, self.frequency, self.delay, self.damping_factor))
130137
return join_list((
131-
'DC {}'.format(str_spice(self.dc_offset)),
132-
# 'AC SIN({})'.format(sin_part), # Fixme: To be fixed
133-
'AC 1 SIN({})'.format(sin_part),
138+
'DC {} AC {}'.format(*str_spice_list(self.dc_offset, self.ac_magnitude)),
139+
'SIN({})'.format(sin_part),
134140
))
135141

136142
####################################################################################################

PySpice/Tools/StringTools.py

+15
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
#
1919
####################################################################################################
2020

21+
__all__ = [
22+
'join_dict',
23+
'join_lines'
24+
'join_list',
25+
'str_spice',
26+
'str_spice_list',
27+
]
28+
29+
####################################################################################################
30+
2131
import os
2232

2333
####################################################################################################
@@ -42,6 +52,11 @@ def str_spice(obj, unit=True):
4252

4353
####################################################################################################
4454

55+
def str_spice_list(*args):
56+
return [str_spice(x) for x in args]
57+
58+
####################################################################################################
59+
4560
def join_lines(items, prefix=''):
4661
return os.linesep.join([prefix + str(item)
4762
for item in items

0 commit comments

Comments
 (0)