bu_interp = interp1d(0, 2 * np.pi, bdy.dt, ub, p=True) bv_interp = interp1d(0, 2 * np.pi, bdy.dt, vb, p=True) # old boundary velocity values have to be in the correct place ubo_new_parm = bu_interp(new_t) vbo_new_parm = bv_interp(new_t) ubo = ub.copy() vbo = vb.copy() x_tracers.append(bx) y_tracers.append(by) # take gradients of the velocity fields dx = lambda f: fd_x_4(f, grid.xh, periodic_fix=True) dy = lambda f: fd_y_4(f, grid.yh, periodic_fix=True) if u_differentiation_type == 'spectral': ux, uy = ebdyc.gradient2(u, xder, yder, cutoff=True) vx, vy = ebdyc.gradient2(v, xder, yder, cutoff=True) elif u_differentiation_type == 'fourth': ux, uy = ebdyc.gradient2(u, dx, dy, cutoff=False) vx, vy = ebdyc.gradient2(v, dx, dy, cutoff=False) else: ux = EmbeddedFunction(ebdyc) uy = EmbeddedFunction(ebdyc) vx = EmbeddedFunction(ebdyc) vy = EmbeddedFunction(ebdyc) ux.define_via_function(lambda x, y: ux_function(x, y, t)) uy.define_via_function(lambda x, y: uy_function(x, y, t)) vx.define_via_function(lambda x, y: vx_function(x, y, t)) vy.define_via_function(lambda x, y: vy_function(x, y, t)) # now generate a new ebdy based on the moved boundary
# move the boundary with Forward Euler bx = ebdy.bdy.x + dt * ub by = ebdy.bdy.y + dt * vb # repararmetrize the boundary bx, by, new_t = arc_length_parameterize(bx, by, return_t=True) bu_interp = interp1d(0, 2 * np.pi, bdy.dt, ub, p=True) bv_interp = interp1d(0, 2 * np.pi, bdy.dt, vb, p=True) # old boundary velocity interpolated to new parametrization ubo_new_parm = bu_interp(new_t) vbo_new_parm = bv_interp(new_t) # old boundary velocity at old parametrization ubo = ub.copy() vbo = vb.copy() # take gradients of the velocity fields ux, uy = ebdyc.gradient2(u) vx, vy = ebdyc.gradient2(v) # now generate a new ebdy based on the moved boundary new_bdy = GSB(x=bx, y=by) bh = new_bdy.dt * new_bdy.speed.min() # construct embedded boundary new_ebdy = EmbeddedBoundary(new_bdy, True, M, bh / radial_upsampling, pad_zone=0, heaviside=MOL.step, qfs_fsuf=4, coordinate_scheme='nufft', coordinate_tolerance=1e-12)
vb = ebdyc.interpolate_radial_to_boundary(v) print('Time to interp u to bdy: {:0.1f}'.format( (time.time() - st) * 1000)) st = time.time() # first, move the boundary with the fluid velocity bx = ebdy.bdy.x + dt * ub.bdy_value_list[0] by = ebdy.bdy.y + dt * vb.bdy_value_list[0] print('Time to move bdy: {:0.1f}'.format( (time.time() - st) * 1000)) st = time.time() # take gradients of the velocity fields dx = lambda f: fd_x_4(f, grid.xh, periodic_fix=True) dy = lambda f: fd_y_4(f, grid.yh, periodic_fix=True) ux, uy = ebdyc.gradient2(u, dx, dy, cutoff=False) vx, vy = ebdyc.gradient2(v, dx, dy, cutoff=False) print('Time to compute u gradients: {:0.1f}'.format( (time.time() - st) * 1000)) st = time.time() # now generate a new ebdy based on the moved boundary new_bdy = GSB(*arc_length_parameterize(bx, by)) bh = new_bdy.dt * new_bdy.speed.min() # construct embedded boundary new_ebdy = EmbeddedBoundary(new_bdy, True, M, bh, pad_zone, MOL.step) new_ebdyc = EmbeddedBoundaryCollection([ new_ebdy, ]) new_ebdyc.register_grid(grid) print('Time to generate new ebdy and register grid: {:0.1f}'.format(
bx, by, new_t = arc_length_parameterize(bx, by, return_t=True) bu_interp = interp1d(0, 2 * np.pi, bdy.dt, ub, p=True) bv_interp = interp1d(0, 2 * np.pi, bdy.dt, vb, p=True) # old boundary velocity interpolated to new parametrization ubo_new_parm = bu_interp(new_t) vbo_new_parm = bv_interp(new_t) # old boundary velocity at old parametrization ubo = ub.copy() vbo = vb.copy() # keep track of boundary motion x_tracers.append(bx) y_tracers.append(by) # take gradients of the velocity fields ux, uy = ebdyc.gradient2(u) vx, vy = ebdyc.gradient2(v) # now generate a new ebdy based on the moved boundary new_bdy = GSB(x=bx, y=by) bh = new_bdy.dt * new_bdy.speed.min() # construct embedded boundary new_ebdy = EmbeddedBoundary(new_bdy, True, M, bh / radial_upsampling, pad_zone=pad_zone, heaviside=MOL.step, qfs_fsuf=qfs_fsuf, coordinate_scheme=coordinate_scheme, coordinate_tolerance=1e-8)