@@ -392,7 +392,12 @@ def streamline(function, point, direction=+1, tolerance=3e-3, loc_tolerance=1e-1
392
392
x = np .array (point )
393
393
v1 = toreal (direction * function .at (x , tolerance = loc_tolerance ), complex_component )
394
394
r = toreal (cell_sizes .at (x , tolerance = loc_tolerance ), "real" )
395
- dt = 0.5 * r / np .sqrt (np .sum (v1 ** 2 ))
395
+ v1norm = np .sqrt (np .sum (v1 ** 2 ))
396
+ if np .isclose (v1norm , 0.0 ):
397
+ # Bail early for zero fields.
398
+ return
399
+
400
+ dt = 0.5 * r / v1norm
396
401
397
402
while True :
398
403
try :
@@ -622,7 +627,10 @@ def streamplot(function, resolution=None, min_length=None, max_time=None,
622
627
if max_time is None :
623
628
area = assemble (Constant (1 ) * dx (mesh ))
624
629
average_speed = np .sqrt (assemble (inner (function , function ) * dx ) / area )
625
- max_time = 50 * min_length / average_speed
630
+ if np .isclose (average_speed , 0.0 ):
631
+ max_time = 50 * min_length / average_speed
632
+ else :
633
+ max_time = 0.
626
634
627
635
streamplotter = Streamplotter (function , resolution , min_length , max_time ,
628
636
tolerance , loc_tolerance ,
@@ -666,9 +674,13 @@ def streamplot(function, resolution=None, min_length=None, max_time=None,
666
674
widths = np .array (widths )
667
675
668
676
points = np .asarray (points )
669
- vmin = kwargs .pop ("vmin" , speeds .min ())
670
- vmax = kwargs .pop ("vmax" , speeds .max ())
671
- norm = kwargs .pop ("norm" , matplotlib .colors .Normalize (vmin = vmin , vmax = vmax ))
677
+ if speeds .size > 0 :
678
+ vmin = kwargs .pop ("vmin" , speeds .min ())
679
+ vmax = kwargs .pop ("vmax" , speeds .max ())
680
+ norm = kwargs .pop ("norm" , matplotlib .colors .Normalize (vmin = vmin , vmax = vmax ))
681
+ else :
682
+ norm = None
683
+
672
684
cmap = plt .get_cmap (kwargs .pop ("cmap" , None ))
673
685
674
686
collection = LineCollection (points , cmap = cmap , norm = norm , linewidth = widths )
0 commit comments