@@ -325,7 +325,7 @@ def get_integrator(u, v, dmap, minlength):
325
325
# speed (path length) will be in axes-coordinates
326
326
u_ax = u / dmap .grid .nx
327
327
v_ax = v / dmap .grid .ny
328
- speed = np .sqrt (u_ax ** 2 + v_ax ** 2 )
328
+ speed = np .ma . sqrt (u_ax ** 2 + v_ax ** 2 )
329
329
330
330
def forward_time (xi , yi ):
331
331
ds_dt = interpgrid (speed , xi , yi )
@@ -450,25 +450,32 @@ def _integrate_rk12(x0, y0, dmap, f):
450
450
stotal += ds
451
451
452
452
# recalculate stepsize based on step error
453
- ds = min (maxds , 0.85 * ds * (maxerror / error )** 0.5 )
453
+ if error == 0 :
454
+ ds = maxds
455
+ else :
456
+ ds = min (maxds , 0.85 * ds * (maxerror / error )** 0.5 )
454
457
455
458
return stotal , xf_traj , yf_traj
456
459
457
460
458
461
def _euler_step (xf_traj , yf_traj , dmap , f ):
459
- """Simple Euler integration step."""
462
+ """Simple Euler integration step that extends streamline to boundary ."""
460
463
ny , nx = dmap .grid .shape
461
464
xi = xf_traj [- 1 ]
462
465
yi = yf_traj [- 1 ]
463
466
cx , cy = f (xi , yi )
464
- if cx > 0 :
465
- dsx = ( nx - 1 - xi ) / cx
466
- else :
467
+ if cx == 0 :
468
+ dsx = np . inf
469
+ elif cx < 0 :
467
470
dsx = xi / - cx
468
- if cy > 0 :
469
- dsy = (ny - 1 - yi ) / cy
470
471
else :
472
+ dsx = (nx - 1 - xi ) / cx
473
+ if cy == 0 :
474
+ dsy = np .inf
475
+ elif cy < 0 :
471
476
dsy = yi / - cy
477
+ else :
478
+ dsy = (ny - 1 - yi ) / cy
472
479
ds = min (dsx , dsy )
473
480
xf_traj .append (xi + cx * ds )
474
481
yf_traj .append (yi + cy * ds )
0 commit comments