Skip to content

Commit

Permalink
max radius
Browse files Browse the repository at this point in the history
  • Loading branch information
hannorein committed Aug 25, 2023
1 parent 2bd85c1 commit 610ff50
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/collision.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ static void reb_tree_get_nearest_neighbour_in_cell(struct reb_simulation* const
double dy = gb.shifty - c->y;
double dz = gb.shiftz - c->z;
double r2 = dx*dx + dy*dy + dz*dz;
double rp = p1_r + r->max_radius[1] + 0.86602540378443*c->w;
double rp = p1_r + r->max_radius1 + 0.86602540378443*c->w;
// Check if we need to decent into daughter cells
if (r2 < rp*rp ){
for (int o=0;o<8;o++){
Expand Down
2 changes: 1 addition & 1 deletion src/communication_mpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void reb_communication_mpi_prepare_essential_cell_for_collisions_for_proc(struct
r->particles_send_N[proc]++;
}else{ // Not a leaf. Check if we need to transfer daughters.
double distance2 = reb_communication_distance2_of_proc_to_node(r, proc,node);
double rp = 2.*r->max_radius[0] + 0.86602540378443*node->w;
double rp = 2.*r->max_radius0 + 0.86602540378443*node->w;
if (distance2 < rp*rp ){
for (int o=0;o<8;o++){
struct reb_treecell* d = node->oct[o];
Expand Down
8 changes: 8 additions & 0 deletions src/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,14 @@ int reb_input_field(struct reb_simulation* r, FILE* inf, enum reb_input_binary_m
}

switch (field.type){
case 35:
{ // Only kept for backwards compatability. Can be removed in future version.
double max_radius[2];
reb_fread(&max_radius, field.size,1,inf,mem_stream);
r->max_radius0 = max_radius[0];
r->max_radius1 = max_radius[1];
}
break;
CASE(SASIZEFIRST, &r->simulationarchive_size_first);
case REB_BINARY_FIELD_TYPE_END:
return 0;
Expand Down
2 changes: 0 additions & 2 deletions src/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,6 @@ void reb_output_binary_to_stream(struct reb_simulation* r, char** bufp, size_t*
i++;
}


WRITE_FIELD(MAXRADIUS, &r->max_radius, 2*sizeof(double));
int functionpointersused = 0;
if (r->coefficient_of_restitution ||
r->collision_resolve ||
Expand Down
10 changes: 5 additions & 5 deletions src/particle.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ static void reb_add_local(struct reb_simulation* const r, struct reb_particle pt

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;
if (pt.r>=r->max_radius0){
r->max_radius1 = r->max_radius0;
r->max_radius0 = pt.r;
}else{
if (pt.r>=r->max_radius[1]){
r->max_radius[1] = pt.r;
if (pt.r>=r->max_radius1){
r->max_radius1 = pt.r;
}
}
#endif // COLLISIONS_NONE
Expand Down
8 changes: 5 additions & 3 deletions src/rebound.c
Original file line number Diff line number Diff line change
Expand Up @@ -538,8 +538,8 @@ void reb_init_simulation(struct reb_simulation* r){
r->var_config = NULL;
r->exit_min_distance = 0;
r->exit_max_distance = 0;
r->max_radius[0] = 0.;
r->max_radius[1] = 0.;
r->max_radius0 = 0.;
r->max_radius1 = 0.;
r->status = REB_RUNNING;
r->exact_finish_time = 1;
r->force_is_velocity_dependent = 0;
Expand Down Expand Up @@ -976,7 +976,7 @@ const struct reb_binary_field_descriptor reb_binary_field_descriptor_list[]= {
{ 32, REB_INT, "collision_resolve_keep_sorted", offsetof(struct reb_simulation, collision_resolve_keep_sorted)},
{ 33, REB_DOUBLE, "minimum_collision_velocity", offsetof(struct reb_simulation, minimum_collision_velocity)},
{ 34, REB_DOUBLE, "collisions_plog", offsetof(struct reb_simulation, collisions_plog)},
{ 35, REB_OTHER, "max_radius", offsetof(struct reb_simulation, max_radius)},
// { 35, REB_OTHER, "max_radius", offsetof(struct reb_simulation, max_radius)},
{ 36, REB_LONG, "collisions_Nlog", offsetof(struct reb_simulation, collisions_Nlog)},
{ 37, REB_INT, "calculate_megno", offsetof(struct reb_simulation, calculate_megno)},
{ 38, REB_DOUBLE, "megno_Ys", offsetof(struct reb_simulation, megno_Ys)},
Expand Down Expand Up @@ -1156,6 +1156,8 @@ const struct reb_binary_field_descriptor reb_binary_field_descriptor_list[]= {
{ 393, REB_OTHER, "ri_whfast512.allocated_N", offsetof(struct reb_simulation, ri_whfast512.allocated_N)},
{ 394, REB_OTHER, "ri_whfast512.pjh", offsetof(struct reb_simulation, ri_whfast512.p_jh)},
{ 395, REB_OTHER, "ri_whfast512.pjh0", offsetof(struct reb_simulation, ri_whfast512.p_jh0)},
{ 396, REB_DOUBLE, "max_radius0", offsetof(struct reb_simulation, max_radius0)},
{ 397, REB_DOUBLE, "max_radius1", offsetof(struct reb_simulation, max_radius1)},
{ 1329743186, REB_OTHER,"header", 0},
{ 9998, REB_OTHER, "sablob", 0},
{ 9999, REB_OTHER, "end", 0}
Expand Down
3 changes: 2 additions & 1 deletion src/rebound.h
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ struct reb_simulation {
int collisions_allocatedN;
double minimum_collision_velocity;
double collisions_plog;
double max_radius[2]; // Two largest particle radii, set automatically, needed for collision search.
double max_radius0; // Two largest particle radii, set automatically, needed for collision search.
double max_radius1; // Two largest particle radii, set automatically, needed for collision search.
long collisions_Nlog;

// MEGNO
Expand Down

0 comments on commit 610ff50

Please sign in to comment.