def plot_from_files(time, mpi_size, dt, input = False): fig = plt.figure(figsize = (figsize_x, figsize_y)) colors = 'brcykgmk' for rank in range (mpi_size): # load particles id, active, XY = IO.load_grid_of_particles(rank, time, input) plt.scatter(XY[0,active], XY[1,active], marker = '.', s = 6, label = 'rank = %s' % rank, color = colors[rank])#label = 'rank = %s' % rank)#, linewidth = 1)# s = size #plt.text(iter(['rank 0', 'rank 1', 'rank 2', 'rank 3'])) #plt.text(1.65, 0.9, 'rank = %s\n$t = %s$' % (rank, time), size = 36) # print('rank', rank) # print('x', XY[0,active]) # print('\n') # print('y', XY[1,active]) plt.xlim(x_min, x_max) plt.ylim(y_min, y_max) plt.legend(scatterpoints = 1) #plt.show() plt.savefig(os.path.join('plots', 'allranks_particles_time%s_dt%s%s' % (time, dt, file_extension)))
# get initial positions, from file or random or other # option 1: create from function #ids, active, XY = IO.create_grid_of_particles(N = 10**2, w = 0.1) # option 2: load from file # set all particles initially to rank 0, so the other ranks will load empty arrays # id_init, active_init, XY_init = IO.create_grid_of_particles(N = 10**2, w = 0.1) # if rank == 0: # IO.save_grid_of_particles(id_init, active_init, XY_init, t_0, rank, input = True) # else: # IO.save_empty_grid_to_input(t_0, rank) # then load the particle grid for the given rank ids, active, XY = IO.load_grid_of_particles(rank, time = 0, input = True) if rank == 0: Nparticles = np.sum(active) # start at initial time t = t_0 IO.save_grid_of_particles(ids, active, XY, t, rank) #plot.plot(rank, XY[:,active], t, dt) # main loop print('\nstart time = %s' % t) # Communicating, to avoid bad load balancing at the beginning print('This is rank %s, communicating before mainloop' % (rank)) ids, XY, active = communication.exchange(comm, mpi_size, rank, ids, XY[0,:], XY[1,:], active)