def interpolate_to_points(self, ff, x, y, fix_r=False, dzl=None, gil=None): key = self.get_interpolation_key(x, y, fix_r, dzl, gil) p = self.registered_partitions[key] # get the category numbers c1n, c2n, c3n = p.get_Ns() # initialize output vector output = np.empty(x.size) # interpolate appropriate portion with grid (polynomial, for now...) if c1n > 0: if False: zone1 = p.zone1 f = ff.get_grid_value() grid = self.grid lbds = [self.grid.x_bounds[0], self.grid.y_bounds[0]] ubds = [self.grid.x_bounds[1], self.grid.y_bounds[1]] hs = [self.grid.xh, self.grid.yh] interp = fast_interp.interp2d(lbds, ubds, hs, f, k=7, p=[True, True]) output[zone1] = interp(x[zone1], y[zone1]) else: # HERE zone1 = p.zone1 funch = np.fft.fft2(ff.get_smoothed_grid_value()) out = np.zeros(p.zone1_N, dtype=complex) if old_nufft: diagnostic = finufftpy.nufft2d2(p.x_transf, p.y_transf, out, 1, 1e-14, funch, modeord=1) else: diagnostic = finufft.nufft2d2(p.x_transf, p.y_transf, funch, out, isign=1, eps=1e-14, modeord=1) out.real / np.prod(funch.shape) output[zone1] = out.real / np.prod(funch.shape) if c2n > 0: for ind in range(self.N): ebdy = self[ind] z2l = p.zone2l[ind] z2transfr = p.zone2_transfr[ind] z2t = p.zone2t[ind] fr = ff[ind] output[z2l] = ebdy.interpolate_radial_to_points( fr, z2transfr, z2t) # fill in those that are exterior with nan if c3n > 0: for z3 in p.zone3l: output[z3] = np.nan return output
def poly_interpolate_grid_to_interface(self, f, order=None): """ Call through interpolate_grid_to_interface """ grid = self.grid lbds = [self.grid.x_bounds[0], self.grid.y_bounds[0]] ubds = [self.grid.x_bounds[1], self.grid.y_bounds[1]] hs = [self.grid.xh, self.grid.yh] interp = fast_interp.interp2d(lbds, ubds, hs, f, k=order, p=[True, True]) return interp(self.all_ivx, self.all_ivy)
def interpolate_grid_to_radial(self, f, order=3): """ This function will typically not produce correct results, unless f is smooth across the whole domain! However, it is included as it is useful for initializing certain kinds of problems. Order = Inf is currently not supported, though it could be, but it would involve transforming all of the radial grid values (eating a lot of memory) """ grid = self.grid lbds = [self.grid.x_bounds[0], self.grid.y_bounds[0]] ubds = [self.grid.x_bounds[1], self.grid.y_bounds[1]] hs = [self.grid.xh, self.grid.yh] if type(f) == EmbeddedFunction: f = f.get_grid_value() interp = fast_interp.interp2d(lbds, ubds, hs, f, k=order, p=[True, True]) radial_list = [] for ebdy in self: radial_list.append(interp(ebdy.radial_x, ebdy.radial_y)) return radial_list
print(' ...n =', n) a = 1/np.e v, h = np.linspace(a, 1, n, endpoint=True, retstep=True) x, y = np.meshgrid(v, v, indexing='ij') xo = x[:-1, :-1].flatten() yo = y[:-1, :-1].flatten() xo += np.random.rand(*xo.shape)*h yo += np.random.rand(*yo.shape)*h test_function = lambda x, y: np.exp(x)*np.cos(y) + x*y**3/(1 + x + y) f = test_function(x, y) + 2*(np.random.rand(*x.shape)-0.5)*random_noise_size fa = test_function(xo, yo) # run once to compile numba functions interpolater = interp2d([a,a], [1.0,1.0], [h,h], f, k=k) fe = interpolater(xo, yo) del interpolater gc.collect() # fast_interp st = time.time() interpolater = interp2d([a,a], [1.0,1.0], [h,h], f, k=k) my_setup_time[ni, ki] = (time.time()-st)*1000 st = time.time() fe = interpolater(xo, yo) my_eval_time[ni, ki] = (time.time()-st)*1000 my_errors[ni, ki] = np.abs(fe - fa).max() del interpolater gc.collect()