Skip to content

Commit

Permalink
Punt for critical damping
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Jun 4, 2024
1 parent e286170 commit 62c4e63
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lcapy/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -3018,14 +3018,15 @@ def poles(self, aslist=False, damping=None, pairs=False):
"""

if self._ratfun is None:
ratfun = self._ratfun
if ratfun is None:
# Handle expressions such as A(s) * (1 - exp(-s * T)) / B(s).
return self.D.roots(aslist, pairs)

try:
poles = self._poles
except AttributeError:
poles = self._ratfun.poles(damping=damping)
poles = ratfun.poles(damping=damping)
self._poles = poles

polesdict = {}
Expand Down
4 changes: 4 additions & 0 deletions lcapy/inverse_laplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def ratfun(self, expr, s, t, **kwargs):

uresult = 0

if damping == 'critical':
# This can be gnarly so punt for now.
damping = None

QP = [Root(p, 1, damping) for p in P]

for m in range(len(R)):
Expand Down
8 changes: 6 additions & 2 deletions lcapy/quadraticroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,9 @@ def from_expr(cls, expr, damping=None):
dexpr = -dexpr
scale /= I
elif damping == 'critical':
# This puts constraints on variables in dexpr.
dexpr = 0
# This puts constraints on variables in dexpr. For example,
# if have sqrt(a - b) then a = b.
pass
elif damping == 'under':
if not scale.is_imaginary:
dexpr = -dexpr
Expand All @@ -134,6 +135,9 @@ def from_expr(cls, expr, damping=None):
if dexpr == 0:
return None

if damping == 'critical':
dexpr = 0

return cls(offset, scale, dexpr, damping)

def is_conjugate_pair(self, d):
Expand Down
6 changes: 4 additions & 2 deletions lcapy/ratfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,13 +836,15 @@ def as_QRPO(self, damping=None, method=None):
var = self.var

sexpr = Ratfun(expr, var)
poles = sexpr.poles(damping=damping)

if damping == 'critical':
# Critical damping puts constraints on variables. If
# these variables do not occur in numerator of expr
# perhaps the following code will work.
raise ValueError('Critical damping not supported')
warn('Critical damping not supported')
damping = None

poles = sexpr.poles(damping=damping)

if len(poles) == 0:
return Q, [], [], [], delay, undef
Expand Down

0 comments on commit 62c4e63

Please sign in to comment.