ot.set_weights( weights ) ot.set_masses( np.ones( positions.shape[ 0 ] ) * np.pi * target_radius ** 2 ) for i in range( nb_timesteps ): print("iteration %d/%d for na=%d" % (i, nb_timesteps,na)) # optimal weights ot.set_positions( positions ) ot.adjust_weights() centroids = ot.get_centroids() # display if i in display_timesteps: print(i) j = display_timesteps.tolist().index(i) ot.display_asy( directory + "/pd_{:03}.asy".format( j ), values=color_values, linewidth=0.0005, dotwidth=target_radius * 0, closing=domain_asy, avoid_bounds=True ) ot.display_vtk( directory + "/pd_{:03}.vtk".format( j ) ) h_positions.append( positions ) h_weights.append( weights ) # update positions descent_direction = np.zeros_like(positions) for n in range( positions.shape[ 0 ] ): descent_direction[n,:] = g.grad( positions[ n, : ], 4 * target_radius ) positions += timestep*(descent_direction + (centroids-positions)/epsilon) for n in range( positions.shape[ 0 ] ): if timeout[ n ] == 0 and positions[ n, 0 ] > 4*alpha/3: timeout[ n ] = i + 1
ot.set_weights( weights ) ot.set_masses( np.ones( positions.shape[ 0 ] ) * np.pi * target_radius ** 2 ) for i in range( nb_timesteps ): print("iteration %d/%d for na=%d" % (i, nb_timesteps,na)) # optimal weights ot.set_positions( positions ) ot.adjust_weights() centroids = ot.get_centroids() # display if i in display_timesteps: print(i) j = display_timesteps.tolist().index(i) ot.display_asy( directory + "/pd_{:03}.asy".format( j ), values=color_values, linewidth=0.0005, dotwidth=target_radius * 0, closing=domain_asy, avoid_bounds=True ) ot.display_vtk( directory + "/pd_{:03}.vtk".format( j ) ) if i in save_timesteps: h_positions.append( positions.copy() ) # update positions descent_direction = np.zeros_like(positions) for n in range( positions.shape[ 0 ] ): descent_direction[n,:] = g.grad( positions[ n, : ], 4 * target_radius ) positions += timestep*(descent_direction + (centroids-positions)/epsilon) for n in range( positions.shape[ 0 ] ): if timeout[ n ] == 0 and positions[ n, 0 ] > 4*alpha/3: timeout[ n ] = i + 1
min_w = 0 ot = OptimalTransport(domain, RadialFuncEntropy(eps)) ot.set_masses(np.ones(positions.shape[0])) weights = np.zeros(positions.shape[0]) for i in range(101): # optimal weights ot.set_positions(positions) ot.adjust_weights() weights = ot.get_weights() min_w = np.min(weights) max_w = np.max(weights) # display if i % 10 == 0: ot.display_asy(directory + "/we_{:03}.asy".format(int(i / 10)), values=(weights - min_w) / (max_w - min_w), linewidth=0.002) ot.display_asy(directory + "/pd_{:03}.asy".format(int(i / 10)), values=(weights - min_w) / (max_w - min_w), linewidth=0.002, min_rf=0, max_rf=0.35) ot.display_vtk(directory + "/pd_{:03}.vtk".format(i)) # update positions d = 0.75 positions = d * ot.get_centroids() + (1 - d) * positions
h_positions = [] for i in range(niter): #print("iteration %d/%d" % (i,niter)) # optimal weights ot.set_positions(positions) ot.adjust_weights() weights = ot.get_weights() # display if i in display_timesteps: print(i) j = display_timesteps.tolist().index(i) diffpos = ot.get_centroids() - positions rho = np.exp(-(diffpos[:, 0]**2 + diffpos[:, 1]**2 - weights) / eps) #if max_rho<0: max_rho = max(rho) ot.display_asy(directory + "/pd_{:03}.asy".format(int(j)), values=rho / max_rho, linewidth=0.00002) #ot.display_vtk( directory + "/pd_{:03}.vtk".format( i ) ) if i in save_timesteps: h_positions.append(positions.copy()) # update positions positions = positions + (tau / eps) * (ot.get_centroids() - positions) np.save(directory + "/positions.npy", h_positions)