Skip to content

Commit

Permalink
Remove x key
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Jan 5, 2025
1 parent 38b483e commit b3ead70
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 75 deletions.
5 changes: 2 additions & 3 deletions lcapy/classmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
classmap = {'s': LaplaceDomainExpression,
'ivp': LaplaceDomainExpression,
'laplace': LaplaceDomainExpression,
'transient': LaplaceDomainExpression,
't': TimeDomainExpression,
'time': TimeDomainExpression,
'f': FourierDomainExpression,
Expand All @@ -23,8 +22,8 @@
'f': '(f)',
'dc': ''}

domainmap = {'constant': 't',
'constant time': 't',
domainmap = {'constant': 'dc',
'constant time': 'dc',
'constant frequency response': 'dc', # ????
'time': 't',
'laplace': 's',
Expand Down
16 changes: 3 additions & 13 deletions lcapy/netlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def describe_analysis(method, sources, omega=None):
s += describe_analysis('Noise', sources)
elif kind == 'dc':
s += describe_analysis('DC', sources)
elif kind == 'transient':
elif kind == 's':
s += describe_analysis('Laplace', sources)
elif kind in ('t', 'time'):
s += describe_analysis('Time-domain', sources)
Expand Down Expand Up @@ -703,7 +703,7 @@ def transient(self):
See also: ac, dc, laplace, noise, time.
"""
return self.select('transient')
return self.select('s')

def transient_time(self):
"""Return netlist for transient components of independent sources in
Expand All @@ -712,17 +712,7 @@ def transient_time(self):
See also: ac, dc, laplace, noise, time.
"""
return self.select('tranient_time')

def transient_laplace(self):
"""Return netlist for transient components of independent sources in
Laplace-domain. Note, unlike the similar laplace method, dc
and ac components are ignored.
See also: ac, dc, laplace, noise, time.
"""
return self.select('tranient_laplace')
return self.transient().time()

def _new(self):

Expand Down
6 changes: 3 additions & 3 deletions lcapy/subnetlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

class SubNetlist(NetlistMixin, NetlistSimplifyMixin, NetfileMixin):
"""This is a representation of a netlist for a particular
transformation domain, such as ac, dc, transient, or noise. It is
transformation domain, such as ac, dc, s, or noise. It is
for internal use only. Unlike Netlist, SubNetlist is not mutable.
"""

def __new__(cls, netlist, kind):

kinds = ('dc', 'transient', 'time', 'ivp', 'laplace')
kinds = ('t', 'dc', 's', 'time', 'ivp', 'laplace')
if not isinstance(kind, str) or kind[0] == 'n':
pass
elif kind not in kinds:
Expand All @@ -39,7 +39,7 @@ def __new__(cls, netlist, kind):
return obj

def __init__(self, netlist, kind):
"""kind can be 'dc', 'transient', 'time', 'ivp', 'n*' or
"""kind can be 't', 'dc', 's', 'time', 'ivp', 'n*' or
omega, where 'n*' is a noise identifer and omega is an angular
frequency."""

Expand Down
79 changes: 24 additions & 55 deletions lcapy/superposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,8 @@ class Superposition(SuperpositionDomain, ExprDict):

# Where possible this class represents a signal in the time-domain.
# It can decompose a signal into AC, DC, and transient components.

# The 't' key is the component defined in the time domain.
# The 's' key is the component defined in the Laplace domain.

# (Vstep(10) + C('C1', 5)).Voc produces a combination of s: 5/s, t: 10 u(t)
# The 't' key is the transient component viewed in the time domain.
# The 's' key is the transient component viewed in the Laplace domain.

def __init__(self, *args, **kwargs):
super(Superposition, self).__init__()
Expand Down Expand Up @@ -89,15 +86,12 @@ def _representation(self):
key = list(decomp)[0]
if key in ('dc', 't'):
return decomp[key]
elif key in ('s', 'f', 'omega'):
if key in ('s', 'f', 'omega'):
expr = decomp[key]
if expr.has(expr.var):
return decomp[key]
# Have something like s * 0 + 1 so don't display as 1
# since not a dc value.
elif not isinstance(key, str):
# Have phasor
return decomp[key]

# Have a superposition.
# It is probably less confusing to a user to display
Expand Down Expand Up @@ -275,7 +269,7 @@ def is_s_transient(self):
@property
def is_t_transient(self):
"""True if only has t-domain transient component."""
return list(self.decompose().keys()) == ['x']
return list(self.decompose().keys()) == ['t']

@property
def is_transient(self):
Expand All @@ -285,7 +279,7 @@ def is_transient(self):

@property
def is_causal(self):
return (self.is_transient and self.transient.is_causal) or self == 0
return (self.is_transient and self.s.is_causal) or self == 0

@property
def is_superposition(self):
Expand Down Expand Up @@ -358,11 +352,8 @@ def _is_s_arg(x):

x = expr(x)
# Perhaps check if a constant?
try:
if x.is_undefined:
x = x.as_quantity(self.quantity)
except:
pass
if x.is_undefined:
x = x.as_quantity(self.quantity)

if x.quantity != self.quantity:
raise ValueError('Incompatible quantities %s and %s' %
Expand Down Expand Up @@ -458,7 +449,9 @@ def _decompose_timedomain_expr(self, expr1):
return result

# The remaining components are considered transient
result['x'] = expr1
# so convert to Laplace representation.
sval = expr1.laplace()
result['s'] = sval
return result

def decompose(self):
Expand All @@ -472,10 +465,10 @@ def decompose(self):
for kind, value in self.items():
if kind == 't':
decomp = new._decompose_timedomain_expr(value)
for key, value in decomp.items():
new[key] = value
for value in decomp.values():
new.add(value)
else:
new[kind] = value
new.add(value)

self._decomposition = new
return new
Expand All @@ -484,15 +477,14 @@ def select(self, kind, transform=False):
"""Select a component of the signal representation by kind where:
- ``'super'`` : the entire superposition
- ``'time'`` : the time domain representation (equivalent to self.time())
- ``'laplace'`` : the Laplace domain representation (equivalent to self.laplace())
- ``'transient'`` : the transient component (equivalent to self.transient())
- ``'ivp'`` : the s-domain representation (equivalent to self.laplace())
- ``'time'`` : the time domain representation (equivalent to self.time())
- ``'laplace'`` : the laplace domain representation (equivalent to self.laplace())
- ``'ivp'`` : the s-domain representation (equivalent to self.laplace())
- ``'dc'`` : the DC component
- ``'omega'`` : the AC component with angular frequency omega
- ``'s'`` : the component defined in the Laplace-domain
- ``'s'`` : the transient component in the s-domain
- ``'n'`` : the noise component
- ``'t'`` : the component defined in the time-domain.
- ``'t'`` : the time-domain transient component (this may or may not include the DC and AC components).
"""

Expand All @@ -505,8 +497,6 @@ def select(self, kind, transform=False):
return self.laplace()
elif kind == 'noise':
return self.n
elif kind == 'transient':
return self.transient_laplace if transform else self.transient

# Select a specific noise component
if isinstance(kind, str) and kind[0] == 'n':
Expand All @@ -530,22 +520,10 @@ def kinds(self, transform=False):
transient)."""

if transform:
kinds = list(self.decompose().keys())

if 'x' in kinds:
kinds.pop(kinds.index('x'))
kinds.append('transient')

if 's' in kinds:
kinds.pop(kinds.index('s'))
if 'transient_laplace' not in kinds:
kinds.append('transient')

return kinds
return list(self.decompose().keys())

return list(self.keys())


def netval(self, kind):

def kind_keyword(kind):
Expand All @@ -556,12 +534,12 @@ def kind_keyword(kind):
return 'noise'
elif kind in ('ivp', 'laplace'):
return 's'
elif kind in ('t', 'time', 'transient'):
elif kind in ('t', 'time'):
return ''
return kind

val = self.select(kind)
if (isinstance(kind, str) and kind == 's' and
if (isinstance(kind, str) and kind in ('s', 'ivp') and
(val.is_causal or val.is_dc or val.is_ac)):
# Convert to time representation so that can re-infer
# causality, etc.
Expand Down Expand Up @@ -738,22 +716,13 @@ def ac(self):
@property
def transient(self):
"""Return the transient component in the time-domain."""

result = domain_quantity_to_class('time', quantity=self.quantity)(0)

decomp = self.decompose()
if 'x' in decomp:
result += decomp['x']
if 's' in self:
result += self['s'].inverse_laplace()

return result
return self.select('s').time()

@property
def transient_laplace(self):
"""Return the transient component in the laplace-domain."""

return self.transient.laplace()
return self.select('s')

@property
def s(self):
Expand All @@ -762,7 +731,7 @@ def s(self):
laplace method V.laplace() or V(s).
This attribute may be deprecated due to possible confusion."""
return self.transient_laplace
return self.select('s')

@property
def n(self):
Expand Down
2 changes: 1 addition & 1 deletion lcapy/tests/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def test_causal1(self):
a.add('L1 2 3 2; down')
a.add('W 0 3; right')

self.assertEqual(a.sub['transient'].is_causal, True, "Causal incorrect")
self.assertEqual(a.sub['s'].is_causal, True, "Causal incorrect")
self.assertEqual2(a.L1.v, voltage(
2 * exp(-t) * u(t)), "L current incorrect")

Expand Down

0 comments on commit b3ead70

Please sign in to comment.