# Setting Up the Stopping Conditions in PH4 stopping_condition = gravity.stopping_conditions.collision_detection stopping_condition.enable() sys.stdout.flush() # Adding and Committing Particles to PH4 gravity.particles.add_particles(MasterSet) gravity.commit_particles() # Starting the AMUSE Channel for PH4 grav_channel = gravity.particles.new_channel_to(MasterSet) # Initializing Kepler and SmallN kep = Kepler(None, redirection="none") kep.initialize_code() util.init_smalln() # Initializing MULTIPLES multiples_code = multiples.Multiples(gravity, util.new_smalln, kep) multiples_code.neighbor_distance_factor = 1.0 multiples_code.neighbor_veto = True multiples_code.evolve_model(time) gravity.synchronize_model() # Copy values from the module to the set in memory. grav_channel.copy() # Copy the index (ID) as used in the module to the id field in # memory. The index is not copied by default, as different # codes may have different indices for the same particle and # we don't want to overwrite silently.
# Adding and Committing Particles to PH4 gravity.particles.add_particles(MasterSet) gravity.commit_particles() #print gravity.particles[-5:] # Starting the AMUSE Channel for PH4 grav_to_MS_channel = gravity.particles.new_channel_to(MasterSet) MS_to_grav_channel = MasterSet.new_channel_to(gravity.particles, attributes=["x","y","z","vx","vy","vz"]) SmallScaleConverter = nbody_system.nbody_to_si(2*np.mean(MasterSet.mass), 2*np.mean(MasterSet.radius)) # Initializing Kepler and SmallN kep = Kepler(unit_converter=SmallScaleConverter, redirection = "none") kep.initialize_code() util.init_smalln(unit_converter=SmallScaleConverter) # Initializing MULTIPLES, Testing to See if a Crash Exists First if read_from_file and crash: time, multiples_code = read.recover_crash(crash_file, gravity, kep, util.new_smalln) else: multiples_code = multiples.Multiples(gravity, util.new_smalln, kep, gravity_constant=units.constants.G) multiples_code.neighbor_perturbation_limit = 0.05 #multiples_code.neighbor_distance_factor = 1.0 multiples_code.neighbor_veto = True # Initializing Stellar Evolution (SeBa) sev_code = SeBa() sev_code.particles.add_particles(MasterSet)
# Initializing PH4 with Initial Conditions gravity.initialize_code() gravity.parameters.set_defaults() gravity.parameters.begin_time = time gravity.parameters.epsilon_squared = eps2 gravity.parameters.timestep_parameter = delta_t.number # Setting up the Code to Run with GPUs Provided by Command Line gravity.parameters.use_gpu = use_gpu gravity.parameters.gpu_id = gpu_ID # Initializing Kepler and SmallN kep = Kepler(None, redirection = "none") kep.initialize_code() util.init_smalln() print time time, multiples_code = read.recover_crash(crash_file, gravity, kep, util.new_smalln) # Setting Up the Stopping Conditions in PH4 stopping_condition = gravity.stopping_conditions.collision_detection stopping_condition.enable() sys.stdout.flush() # Starting the AMUSE Channel for PH4 grav_channel = gravity.particles.new_channel_to(MasterSet)
def GetValues(cluster_name, num_workers=1, use_gpu=1, gpu_ID=0, eps2=0.0 | nbody_system.length**2, delta_t=0.05 | nbody_system.time): # This function uses calls upon the restart fuction to reload the multiples from the simulation to use # the multiples function to get the Energy and it correction, num_files can probably be replaced if we # can measure how many files are in a cluster, maybe glob.glob can do that. # This function returns the arrays below: Energy = [] UncorrectedEnergy = [] Time = [] Kinetic = [] Potential = [] L = [] P = [] i = 0 # You will need to change the File Path varibale to run this on anyone else's account file_path = "/home/draco/jthornton/Tycho/Restart/" file_loc = file_path + cluster_name search = glob.glob(file_loc + "*.hdf5") for key in search: if i % 2 == 0: # This loop will go through the restart files of the cluster and append energy and momentum values to the corresponding arrays # First get the restart naming correct restart_file = key[:-11] # Second retrieve the timestep from the file and convert it to a float time_grab = [] time_grab = key.split("_") time = float(time_grab[2]) | nbody_system.time if use_gpu == 1: gravity = ph4(number_of_workers=num_workers, redirection="none", mode="gpu") else: gravity = grav(number_of_workers=num_workers, redirection="none") # Initializing PH4 with Initial Conditions print "Initializing gravity" gravity.initialize_code() gravity.parameters.set_defaults() gravity.parameters.begin_time = time gravity.parameters.epsilon_squared = eps2 gravity.parameters.timestep_parameter = delta_t.number # Setting up the Code to Run with GPUs Provided by Command Line gravity.parameters.use_gpu = use_gpu gravity.parameters.gpu_id = gpu_ID # Initializing Kepler and SmallN print "Initializing Kepler" kep = Kepler(None, redirection="none") kep.initialize_code() print "Initializing SmallN" util.init_smalln() MasterSet = [] print "Retrieving data" MasterSet, multiples_code = read.read_state_from_file( restart_file, gravity, kep, util.new_smalln()) # Setting Up the Stopping Conditions in PH4 stopping_condition = gravity.stopping_conditions.collision_detection stopping_condition.enable() sys.stdout.flush() # Starting the AMUSE Channel for PH4 grav_channel = gravity.particles.new_channel_to(MasterSet) print "Reload Successful" U = multiples_code.potential_energy T = multiples_code.kinetic_energy Etop = T + U print "T: " print T print "U: " print U angular_momentum = MasterSet.total_angular_momentum() momentum = MasterSet.total_momentum() Nmul, Nbin, Emul = multiples_code.get_total_multiple_energy() tmp1, tmp2, Emul2 = multiples_code.get_total_multiple_energy2() Etot = Etop + Emul Eext = multiples_code.multiples_external_tidal_correction Eint = multiples_code.multiples_internal_tidal_correction Eerr = multiples_code.multiples_integration_energy_error Edel = multiples_code.multiples_external_tidal_correction \ + multiples_code.multiples_internal_tidal_correction \ + multiples_code.multiples_integration_energy_error Ecor = Etot - Edel print "Ecor: " print Ecor gravity.stop() kep.stop() util.stop_smalln() Energy.append(Ecor.number) UncorrectedEnergy.append(Etop.number) Time.append(time.number) Kinetic.append(T.number) Potential.append(U.number) L.append(angular_momentum.number) P.append(momentum.number) i += 1 return Energy, UncorrectedEnergy, Time, Kinetic, Potential, L, P