def test_fourier_interpolate_nyquist(plot=False): # asserts that the interpolation follows the "minimal-osciallation" # assumption for the nyquist frequency topography = Topography(np.array([[1], [-1]]), physical_sizes=(1., 1.)) interpolated_topography = topography.interpolate_fourier((64, 1)) if plot: import matplotlib.pyplot as plt fig, ax = plt.subplots() x, y = topography.positions() ax.plot(x.flat, topography.heights().flat, "+") x, y = interpolated_topography.positions() ax.plot(x.flat, interpolated_topography.heights().flat, "-") fig.show() x, y = interpolated_topography.positions() np.testing.assert_allclose(interpolated_topography.heights(), np.cos(2 * np.pi * x), atol=1e-14)
def test_positions(comm): nx, ny = (12 * comm.Get_size(), 10 * comm.Get_size() + 1) sx = 33. sy = 54. fftengine = FFT((nx, ny), fft='mpi', communicator=comm) surf = Topography(np.zeros(fftengine.nb_subdomain_grid_pts), physical_sizes=(sx, sy), decomposition='subdomain', nb_grid_pts=(nx, ny), subdomain_locations=fftengine.subdomain_locations, communicator=comm) x, y = surf.positions() assert x.shape == fftengine.nb_subdomain_grid_pts assert y.shape == fftengine.nb_subdomain_grid_pts assert Reduction(comm).min(x) == 0 assert abs(Reduction(comm).max(x) - sx * (1 - 1. / nx)) \ < 1e-8 * sx / nx, "{}".format(x) assert Reduction(comm).min(y) == 0 assert abs(Reduction(comm).max(y) - sy * (1 - 1. / ny)) < 1e-8