void reb_add(struct reb_simulation* const r, struct reb_particle pt){ #ifndef COLLISIONS_NONE if (pt.r>=r->max_radius[0]){ r->max_radius[1] = r->max_radius[0]; r->max_radius[0] = pt.r; }else{ if (pt.r>=r->max_radius[1]){ r->max_radius[1] = pt.r; } } #endif // COLLISIONS_NONE #ifdef GRAVITY_GRAPE if (pt.m<gravity_minimum_mass){ gravity_minimum_mass = pt.m; } #endif // GRAVITY_GRAPE #ifdef MPI int rootbox = reb_get_rootbox_for_particle(r, pt); int root_n_per_node = r->root_n/r->mpi_num; int proc_id = rootbox/root_n_per_node; if (proc_id != r->mpi_id && r->N >= r->N_active){ // Add particle to array and send them to proc_id later. reb_communication_mpi_add_particle_to_send_queue(r,pt,proc_id); return; } #endif // MPI // Add particle to local partical array. reb_add_local(r, pt); }
void reb_add(struct reb_simulation* const r, struct reb_particle pt){ if (r->N_var){ fprintf(stderr,"\n\033[1mWarning!\033[0m Trying to add particle after calling megno_init().\n"); } #ifndef COLLISIONS_NONE if (pt.r>=r->max_radius[0]){ r->max_radius[1] = r->max_radius[0]; r->max_radius[0] = pt.r; }else{ if (pt.r>=r->max_radius[1]){ r->max_radius[1] = pt.r; } } #endif // COLLISIONS_NONE #ifdef GRAVITY_GRAPE if (pt.m<gravity_minimum_mass){ gravity_minimum_mass = pt.m; } #endif // GRAVITY_GRAPE #ifdef MPI int rootbox = reb_get_rootbox_for_particle(r, pt); int root_n_per_node = root_n/mpi_num; int proc_id = rootbox/root_n_per_node; if (proc_id != mpi_id && r->N >= r->N_active){ // Add particle to array and send them to proc_id later. communication_mpi_add_particle_to_send_queue(pt,proc_id); return; } #endif // MPI // Add particle to local partical array. reb_add_local(r, pt); }
void reb_tree_add_particle_to_tree(struct reb_simulation* const r, int pt){ if (r->tree_root==NULL){ r->tree_root = calloc(r->root_nx*r->root_ny*r->root_nz,sizeof(struct reb_treecell*)); } struct reb_particle p = r->particles[pt]; int rootbox = reb_get_rootbox_for_particle(r, p); #ifdef MPI // Do not add particles that do not belong to this tree (avoid removing active particles) int root_n_per_node = r->root_n/r->mpi_num; int proc_id = rootbox/root_n_per_node; if (proc_id!=r->mpi_id) return; #endif // MPI r->tree_root[rootbox] = reb_tree_add_particle_to_cell(r, r->tree_root[rootbox],pt,NULL,0); }