def f(n, p): N = 2 * n gd = GridDescriptor((N, N, N), (L, L, L)) a = gd.zeros() print(a.shape) #p = PoissonSolver(nn=1, relax=relax) p.set_grid_descriptor(gd) cut = N / 2.0 * 0.9 s = Spline(l=0, rmax=cut, f_g=np.array([1, 0.5, 0.0])) c = LFC(gd, [[s], [s]]) c.set_positions([(0, 0, 0), (0.5, 0.5, 0.5)]) c.add(a) I0 = gd.integrate(a) a -= I0 / L**3 b = gd.zeros() p.solve(b, a, charge=0, eps=1e-20) return gd.collect(b, broadcast=1)
def f(n, p): N = 2 * n gd = GridDescriptor((N, N, N), (L, L, L)) a = gd.zeros() print(a.shape) #p = PoissonSolver(nn=1, relax=relax) p.set_grid_descriptor(gd) p.initialize() cut = N / 2.0 * 0.9 s = Spline(l=0, rmax=cut, f_g=np.array([1, 0.5, 0.0])) c = LFC(gd, [[s], [s]]) c.set_positions([(0, 0, 0), (0.5, 0.5, 0.5)]) c.add(a) I0 = gd.integrate(a) a -= gd.integrate(a) / L**3 I = gd.integrate(a) b = gd.zeros() p.solve(b, a, charge=0)#, eps=1e-20) return gd.collect(b, broadcast=1)
cell_c = N_c / float(N) gd = GridDescriptor(N_c, cell_c, False) # Construct model density coord_vg = gd.get_grid_point_coordinates() x_g = coord_vg[0, :] y_g = coord_vg[1, :] z_g = coord_vg[2, :] rho_g = gd.zeros() for z0 in [1, 2]: rho_g += 10 * (z_g - z0) * \ np.exp(-20 * np.sum((coord_vg.T - np.array([.5, .5, z0])).T**2, axis=0)) if do_plot: big_rho_g = gd.collect(rho_g) if gd.comm.rank == 0: import matplotlib.pyplot as plt fig, ax_ij = plt.subplots(3, 4, figsize=(20, 10)) ax_i = ax_ij.ravel() ploti = 0 Ng_c = gd.get_size_of_global_array() plt.sca(ax_i[ploti]) ploti += 1 plt.pcolormesh(big_rho_g[Ng_c[0] / 2]) plt.sca(ax_i[ploti]) ploti += 1 plt.plot(big_rho_g[Ng_c[0] / 2, Ng_c[1] / 2]) def plot_phi(phi_g):
def playground(): np.set_printoptions(linewidth=176) #N_c = [4, 7, 9] N_c = [4, 4, 2] pbc_c = (1, 1, 1) # 210 distribute_dir = 1 reduce_dir = 0 parsize_c = (2, 2, 2) parsize2_c = list(parsize_c) parsize2_c[reduce_dir] = 1 parsize2_c[distribute_dir] *= parsize_c[reduce_dir] assert np.prod(parsize2_c) == np.prod(parsize_c) gd = GridDescriptor(N_c=N_c, pbc_c=pbc_c, cell_cv=0.2 * np.array(N_c), parsize_c=parsize_c) gd2 = get_compatible_grid_descriptor(gd, distribute_dir, reduce_dir) src = gd.zeros(dtype=complex) src[:] = gd.comm.rank src_global = gd.collect(src) if gd.comm.rank == 0: ind = np.indices(src_global.shape) src_global += 1j * (ind[0] / 10. + ind[1] / 100. + ind[2] / 1000.) #src_global[1] += 0.5j print('GLOBAL ARRAY', src_global.shape) print(src_global.squeeze()) gd.distribute(src_global, src) goal = gd2.zeros(dtype=float) goal[:] = gd.comm.rank # get_members()[gd2.comm.rank] goal_global = gd2.collect(goal) if gd.comm.rank == 0: print('GOAL GLOBAL') print(goal_global.squeeze()) gd.comm.barrier() #return recvbuf = redistribute(gd, gd2, src, distribute_dir, reduce_dir, operation='forth') recvbuf_master = gd2.collect(recvbuf) if gd2.comm.rank == 0: print('RECV') print(recvbuf_master) err = src_global - recvbuf_master print('MAXERR', np.abs(err).max()) hopefully_orig = redistribute(gd, gd2, recvbuf, distribute_dir, reduce_dir, operation='back') tmp = gd.collect(hopefully_orig) if gd.comm.rank == 0: print('FINALLY') print(tmp) err2 = src_global - tmp print('MAXERR', np.abs(err2).max())
gd = GridDescriptor((8, 1, 1), (8.0, 1.0, 1.0), comm=domain_comm) a = gd.zeros() dadx = gd.zeros() a[:, 0, 0] = np.arange(gd.beg_c[0], gd.end_c[0]) gradx = Gradient(gd, v=0) print a.itemsize, a.dtype, a.shape print dadx.itemsize, dadx.dtype, dadx.shape gradx.apply(a, dadx) # a = [ 0. 1. 2. 3. 4. 5. 6. 7.] # # da # -- = [-2.5 1. 1. 1. 1. 1. 1. -2.5] # dx dadx = gd.collect(dadx, broadcast=True) assert dadx[3, 0, 0] == 1.0 and np.sum(dadx[:, 0, 0]) == 0.0 gd = GridDescriptor((1, 8, 1), (1.0, 8.0, 1.0), (1, 0, 1), comm=domain_comm) dady = gd.zeros() a = gd.zeros() grady = Gradient(gd, v=1) a[0, :, 0] = np.arange(gd.beg_c[1], gd.end_c[1]) - 1 grady.apply(a, dady) # da # -- = [0.5 1. 1. 1. 1. 1. -2.5] # dy dady = gd.collect(dady, broadcast=True) assert dady[0, 0, 0] == 0.5 and np.sum(dady[0, :, 0]) == 3.0
from __future__ import print_function import numpy as np from gpaw.grid_descriptor import GridDescriptor from gpaw.xc.libvdwxc import vdw_df, vdw_df2, vdw_df_cx, \ vdw_optPBE, vdw_optB88, vdw_C09, vdw_beef, \ libvdwxc_has_mpi, libvdwxc_has_pfft # This test verifies that the results returned by the van der Waals # functionals implemented in libvdwxc do not change. N_c = np.array([23, 10, 6]) gd = GridDescriptor(N_c, N_c * 0.2, pbc_c=(1, 0, 1)) n_sg = gd.zeros(1) nG_sg = gd.collect(n_sg) if gd.comm.rank == 0: gen = np.random.RandomState(0) nG_sg[:] = gen.rand(*nG_sg.shape) gd.distribute(nG_sg, n_sg) for mode in ['serial', 'mpi', 'pfft']: if mode == 'serial' and gd.comm.size > 1: continue if mode == 'mpi' and not libvdwxc_has_mpi(): continue if mode == 'pfft' and not libvdwxc_has_pfft(): continue def test(vdwxcclass, Eref=np.nan, nvref=np.nan): xc = vdwxcclass(mode=mode) xc._initialize(gd)