Skip to content

Commit

Permalink
fix #160
Browse files Browse the repository at this point in the history
  • Loading branch information
FabriceSalvaire committed May 4, 2020
1 parent 5ec293f commit a3859b3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
16 changes: 11 additions & 5 deletions PySpice/Spice/HighLevelElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@

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

# Fixme: check NgSpice for discrepancies

####################################################################################################

from ..Math import rms_to_amplitude, amplitude_to_rms
from ..Tools.StringTools import join_list, join_dict, str_spice
from ..Tools.StringTools import join_list, join_dict, str_spice, str_spice_list
from ..Unit import as_s, as_V, as_A, as_Hz
from .BasicElement import VoltageSource, CurrentSource

Expand Down Expand Up @@ -82,6 +84,8 @@ class SinusoidalMixin(SourceMixinAbc):
Public Attributes:
:attr:`ac_magnitude`
:attr:`amplitude`
:attr:`damping_factor`
Expand All @@ -100,10 +104,12 @@ class SinusoidalMixin(SourceMixinAbc):

def __init__(self,
dc_offset=0,
ac_magnitude=1,
offset=0, amplitude=1, frequency=50,
delay=0, damping_factor=0):

self.dc_offset = self.__as_unit__(dc_offset)
self.ac_magnitude = self.__as_unit__(ac_magnitude)
self.offset = self.__as_unit__(offset)
self.amplitude = self.__as_unit__(amplitude)
self.frequency = as_Hz(frequency) # Fixme: protect by setter?
Expand All @@ -114,7 +120,8 @@ def __init__(self,

@property
def rms_voltage(self):
return amplitude_to_rms(self.amplitude)
# Fixme: ok ???
return amplitude_to_rms(self.amplitude * self.ac_magnitude)

##############################################

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

sin_part = join_list((self.offset, self.amplitude, self.frequency, self.delay, self.damping_factor))
return join_list((
'DC {}'.format(str_spice(self.dc_offset)),
# 'AC SIN({})'.format(sin_part), # Fixme: To be fixed
'AC 1 SIN({})'.format(sin_part),
'DC {} AC {}'.format(*str_spice_list(self.dc_offset, self.ac_magnitude)),
'SIN({})'.format(sin_part),
))

####################################################################################################
Expand Down
15 changes: 15 additions & 0 deletions PySpice/Tools/StringTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
#
####################################################################################################

__all__ = [
'join_dict',
'join_lines'
'join_list',
'str_spice',
'str_spice_list',
]

####################################################################################################

import os

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

####################################################################################################

def str_spice_list(*args):
return [str_spice(x) for x in args]

####################################################################################################

def join_lines(items, prefix=''):
return os.linesep.join([prefix + str(item)
for item in items
Expand Down

0 comments on commit a3859b3

Please sign in to comment.