def test_apply(self, path_to_ref, rtol, flag): comm = MPI.COMM_WORLD root = 0 rank = comm.rank # Load reference data n = None expected = None if rank == root: npz_file = np.load(path_to_ref) x = npz_file['x'] expected = npz_file['y'] n = x.shape[:-1] # Broadcast global size of grid n = comm.bcast(n, root) # Create local FFT object, and send local grid-size to root process transform = fft.create_real(n, comm, flags=FFTW_ESTIMATE) n_locs = comm.gather((transform.ishape[0], transform.offset0), root) green = self.greend( material.create(0.75, 0.3, len(n)).green_operator(), n, 1., transform) # Scatter x x_locs = None if rank == root: x_locs = [x[offset0:offset0 + n0] for n0, offset0 in n_locs] x_loc = comm.scatter(x_locs, root) # if flag == 0: # y_loc = green.apply(x_loc) # elif flag == 1: # y_loc = green.apply(x_loc, x_loc) # elif flag == 2: # base = np.empty(transform.ishape + (green.oshape[-1],), # dtype=np.float64) # y_loc = green.apply(x_loc, base) # else: # raise ValueError() y_loc = np.empty(transform.ishape + (green.oshape[-1], ), dtype=np.float64) green.apply(x_loc, y_loc) # Gather y y_locs = comm.gather(y_loc, root) if rank == root: actual = np.empty_like(expected) for y_loc, (n0, offset0) in zip(y_locs, n_locs): actual[offset0:offset0 + n0] = y_loc assert_allclose(actual, expected, rtol, 10 * ULP)
def test_apply(self, path_to_ref, rtol, flag): comm = MPI.COMM_WORLD root = 0 rank = comm.rank # Load reference data n = None expected = None if rank == root: npz_file = np.load(path_to_ref) x = npz_file['x'] expected = npz_file['y'] n = x.shape[:-1] # Broadcast global size of grid n = comm.bcast(n, root) # Create local FFT object, and send local grid-size to root process transform = fft.create_real(n, comm, flags=FFTW_ESTIMATE) n_locs = comm.gather((transform.ishape[0], transform.offset0), root) green = self.greend(material.create(0.75, 0.3, len(n)) .green_operator(), n, 1., transform) # Scatter x x_locs = None if rank == root: x_locs = [x[offset0:offset0 + n0] for n0, offset0 in n_locs] x_loc = comm.scatter(x_locs, root) # if flag == 0: # y_loc = green.apply(x_loc) # elif flag == 1: # y_loc = green.apply(x_loc, x_loc) # elif flag == 2: # base = np.empty(transform.ishape + (green.oshape[-1],), # dtype=np.float64) # y_loc = green.apply(x_loc, base) # else: # raise ValueError() y_loc = np.empty(transform.ishape + (green.oshape[-1],), dtype=np.float64) green.apply(x_loc, y_loc) # Gather y y_locs = comm.gather(y_loc, root) if rank == root: actual = np.empty_like(expected) for y_loc, (n0, offset0) in zip(y_locs, n_locs): actual[offset0:offset0 + n0] = y_loc assert_allclose(actual, expected, rtol, 10 * ULP)
def __init__(self, a, mat_i, mat_m, mat_0, n, comm=MPI.COMM_WORLD): transform = fft.create_real((n, n), comm) self.n0 = transform.ishape[0] self.n1 = transform.ishape[1] self.offset0 = transform.offset0 self.green = green.truncated(mat_0.green_operator(), (n, n), 1., transform) aux_i = operators.isotropic_4(1. / (2. * (mat_i.k - mat_0.k)), 1. / (2. * (mat_i.g - mat_0.g)), dim=2) aux_m = operators.isotropic_4(1. / (2. * (mat_m.k - mat_0.k)), 1. / (2. * (mat_m.g - mat_0.g)), dim=2) ops = np.empty(transform.ishape, dtype=object) ops[:, :] = aux_m imax = int(np.ceil(n * a - 0.5)) ops[:imax - self.offset0, :imax] = aux_i self.tau2eps = operators.BlockDiagonalOperator2D(ops)