Skip to content

Commit f5db01a

Browse files
committed
TL: quick fix on jumper generators
1 parent 48b4a59 commit f5db01a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

qmat/qdelta/min.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
from qmat.qcoeff.collocation import Collocation
2828

2929

30+
def check(k):
31+
"""Utility function to check k parameter for k-dependent generators"""
32+
if k is None: k = 1
33+
if k < 1:
34+
raise ValueError(f"k must be greater than 0 ({k})")
35+
return k
36+
37+
3038
@register
3139
class MIN(QDeltaGenerator):
3240
"""Naive diagonal coefficients based on spectral radius optimization."""
@@ -251,9 +259,7 @@ class MIN_SR_FLEX(MIN_SR_S):
251259
aliases = ["MIN-SR-FLEX"]
252260

253261
def computeQDelta(self, k=1):
254-
if k is None: k = 1
255-
if k < 1:
256-
raise ValueError(f"k must be greater than 0 ({k})")
262+
k = check(k)
257263
if k <= self.size:
258264
return np.diag(self.coll.nodes/k)
259265
else:
@@ -270,18 +276,18 @@ class Jumper(MIN_SR_NS):
270276

271277
aliases = ["JUMPER", "FB"]
272278

273-
def computeQDelta(self, k=None):
274-
if k is None: k = 1
279+
def computeQDelta(self, k=1):
280+
k = check(k)
275281
return np.diag(self.nodes)/(2*k)
276282

277283

278284
@register
279285
class FlexJumper(Jumper):
280-
"""Diagonal coefficients allowing order jump while still maintining high stability"""
286+
"""Diagonal coefficients allowing order jump while still maintaining high stability"""
281287

282288
aliases = ["FLEX-JUMPER", "FB2"]
283289

284-
def computeQDelta(self, k=None):
285-
if k is None: k = 1
290+
def computeQDelta(self, k=1):
291+
k = check(k)
286292
divider = 1 if k == 1 else 2*(k-1)
287293
return np.diag(self.nodes)/divider

0 commit comments

Comments
 (0)