Skip to content

Commit

Permalink
changed function name
Browse files Browse the repository at this point in the history
  • Loading branch information
PhoebeSandhaus committed Jul 29, 2024
1 parent 8df4f28 commit b2c0d72
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 86 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
/**
* Gas Damping Forces Example
*
* This example shows how to add gas damping forces to a REBOUND simulation.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include "rebound.h"
#include "reboundx.h"

void heartbeat(struct reb_simulation* sim);

int main(int argc, char* argv[]){

/* start the rebound simulation here */
struct reb_simulation* sim = reb_simulation_create();

sim->heartbeat = heartbeat;

// add the host star
struct reb_particle star = {0};
star.m = 1.;
reb_simulation_add(sim, star);

double m = 3.e-6; // roughly 1 Earth Mass in Solar Masses
double a = 0.1;
double e = 0.05;
double inc = 5.*M_PI/180.; // 5 degrees in radians
double Omega = 0.;
double omega = 0.;
double f = 0.;

struct reb_particle planet = reb_particle_from_orbit(sim->G, star, m, a, e, inc, Omega, omega, f);
reb_simulation_add(sim,planet);

// move simulation to center-of-mass frame
reb_simulation_move_to_com(sim);

// add in reboundx and load/add new force
struct rebx_extras* rebx = rebx_attach(sim);
struct rebx_force* gd = rebx_load_force(rebx, "gas_damping_forces");
rebx_add_force(rebx, gd);

// Set the total simulation time
double tmax = 5.e2*2*M_PI; // 500 years in yr/2pi

// Set parameter for particle
rebx_set_param_double(rebx, &sim->particles[1].ap, "d_factor", 10.); // set depletion factor to 10

// integrate simulation
reb_simulation_integrate(sim, tmax);
rebx_free(rebx); // free all the memory allocated by reboundx
reb_simulation_free(sim); // free all the memory allocated by rebound
}

void heartbeat(struct reb_simulation* sim){
// output a e i of the planet
if(reb_simulation_output_check(sim, 50.*2*M_PI)){
const struct reb_particle star = sim->particles[0];
const struct reb_orbit orbit = reb_orbit_from_particle(sim->G, sim->particles[1], star); // calculate orbit of planet
printf("%f\t%f\t%f\t%f\n",sim->t, orbit.a, orbit.e, orbit.inc);
}
}
/**
* Gas Damping Timescale Example
*
* This example shows how to add gas damping forces to a REBOUND simulation.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include "rebound.h"
#include "reboundx.h"

void heartbeat(struct reb_simulation* sim);

int main(int argc, char* argv[]){

/* start the rebound simulation here */
struct reb_simulation* sim = reb_simulation_create();

sim->heartbeat = heartbeat;

// add the host star
struct reb_particle star = {0};
star.m = 1.;
reb_simulation_add(sim, star);

double m = 3.e-6; // roughly 1 Earth Mass in Solar Masses
double a = 0.1;
double e = 0.05;
double inc = 5.*M_PI/180.; // 5 degrees in radians
double Omega = 0.;
double omega = 0.;
double f = 0.;

struct reb_particle planet = reb_particle_from_orbit(sim->G, star, m, a, e, inc, Omega, omega, f);
reb_simulation_add(sim,planet);

// move simulation to center-of-mass frame
reb_simulation_move_to_com(sim);

// add in reboundx and load/add new force
struct rebx_extras* rebx = rebx_attach(sim);
struct rebx_force* gd = rebx_load_force(rebx, "gas_damping_timescale");
rebx_add_force(rebx, gd);

// Set the total simulation time
double tmax = 5.e2*2*M_PI; // 500 years in yr/2pi

// Set parameter for particle
rebx_set_param_double(rebx, &sim->particles[1].ap, "d_factor", 10.); // set depletion factor to 10

// integrate simulation
reb_simulation_integrate(sim, tmax);
rebx_free(rebx); // free all the memory allocated by reboundx
reb_simulation_free(sim); // free all the memory allocated by rebound
}

void heartbeat(struct reb_simulation* sim){
// output a e i of the planet
if(reb_simulation_output_check(sim, 50.*2*M_PI)){
const struct reb_particle star = sim->particles[0];
const struct reb_orbit orbit = reb_orbit_from_particle(sim->G, sim->particles[1], star); // calculate orbit of planet
printf("%f\t%f\t%f\t%f\n",sim->t, orbit.a, orbit.e, orbit.inc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Gas Damping Forces\n",
"# Gas Damping Timescale\n",
"\n",
"`gas_damping_forces` updates orbits with prescribed timescales by directly changing orbital elements after each timestep, based on Dawson et al. 2016. Outlined in Equation 16 from Dawson et al. 2016, the gas damping timescale $\\tau$ is:\n",
"`gas_damping_timescale` updates orbits with prescribed timescales by directly changing orbital elements after each timestep, based on Dawson et al. 2016. Outlined in Equation 16 from Dawson et al. 2016, the gas damping timescale $\\tau$ is:\n",
"\n",
"$$ \\tau= 0.003 d \\left(\\frac{a}{\\text{AU}}\\right)^2 \\left(\\frac{M_\\odot}{M_p}\\right) \\text{yr} \\times \\left\\{\n",
"\\begin{array}{ll}\n",
Expand Down Expand Up @@ -38,7 +38,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Good News**: You don't need to worry about the equations above since `gas_damping_forces` figures out which regime (part of the piecewise function) to use at each timestep for each body in your simulation. \n",
"**Good News**: You don't need to worry about the equations above since `gas_damping_timescale` figures out which regime (part of the piecewise function) to use at each timestep for each body in your simulation. \n",
"\n",
"The only thing you need to define is `d_factor` which corresponds to the depletion factor $d$ in the above equation."
]
Expand Down Expand Up @@ -158,7 +158,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"We now add in ``reboundx`` and load our new force ``gas_damping_forces``. After loading in our force, we set the parameter for the depletion factor ``d_factor`` to 10. \n",
"We now add in ``reboundx`` and load our new force ``gas_damping_timescale``. After loading in our force, we set the parameter for the depletion factor ``d_factor`` to 10. \n",
"\n",
"(Note: for every particle you add other than the central body, you need to specify a depletion factor.)"
]
Expand All @@ -170,7 +170,7 @@
"outputs": [],
"source": [
"rebx = reboundx.Extras(sim)\n",
"gdf = rebx.load_force('gas_damping_forces')\n",
"gdf = rebx.load_force('gas_damping_timescale')\n",
"rebx.add_force(gdf)\n",
"\n",
"ps[1].params['d_factor'] = 10"
Expand Down Expand Up @@ -309,7 +309,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "virt_env",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -323,7 +323,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
"version": "3.8.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def finalize_options(self):
print("***", rebdir, "***", sitepackagesdir, "***", editable_rebdir, "***")
self.include_dirs.append(rebdir)
#self.include_dirs.append(editable_rebdir)
sources = [ 'src/central_force.c', 'src/core.c', 'src/exponential_migration.c', 'src/gas_damping_forces.c', 'src/gas_dynamical_friction.c', 'src/gr.c', 'src/gr_full.c', 'src/gr_potential.c', 'src/gravitational_harmonics.c', 'src/inner_disk_edge.c', 'src/input.c', 'src/integrate_force.c', 'src/integrator_euler.c', 'src/integrator_implicit_midpoint.c', 'src/integrator_rk2.c', 'src/integrator_rk4.c', 'src/interpolation.c', 'src/lense_thirring.c', 'src/linkedlist.c', 'src/modify_mass.c', 'src/modify_orbits_direct.c', 'src/modify_orbits_forces.c', 'src/output.c', 'src/radiation_forces.c', 'src/rebxtools.c', 'src/steppers.c', 'src/stochastic_forces.c', 'src/tides_constant_time_lag.c', 'src/tides_spin.c', 'src/track_min_distance.c', 'src/type_I_migration.c', 'src/yarkovsky_effect.c'],
sources = [ 'src/central_force.c', 'src/core.c', 'src/exponential_migration.c', 'src/gas_damping_timescale.c', 'src/gas_dynamical_friction.c', 'src/gr.c', 'src/gr_full.c', 'src/gr_potential.c', 'src/gravitational_harmonics.c', 'src/inner_disk_edge.c', 'src/input.c', 'src/integrate_force.c', 'src/integrator_euler.c', 'src/integrator_implicit_midpoint.c', 'src/integrator_rk2.c', 'src/integrator_rk4.c', 'src/interpolation.c', 'src/lense_thirring.c', 'src/linkedlist.c', 'src/modify_mass.c', 'src/modify_orbits_direct.c', 'src/modify_orbits_forces.c', 'src/output.c', 'src/radiation_forces.c', 'src/rebxtools.c', 'src/steppers.c', 'src/stochastic_forces.c', 'src/tides_constant_time_lag.c', 'src/tides_spin.c', 'src/track_min_distance.c', 'src/type_I_migration.c', 'src/yarkovsky_effect.c'],

self.library_dirs.append(rebdir+'/../')
self.library_dirs.append(sitepackagesdir)
Expand Down Expand Up @@ -90,7 +90,7 @@ def finalize_options(self):
extra_compile_args.append('-ffp-contract=off')

libreboundxmodule = Extension('libreboundx',
sources = [ 'src/central_force.c', 'src/core.c', 'src/exponential_migration.c', 'src/gas_damping_forces.c', 'src/gas_dynamical_friction.c', 'src/gr.c', 'src/gr_full.c', 'src/gr_potential.c', 'src/gravitational_harmonics.c', 'src/inner_disk_edge.c', 'src/input.c', 'src/integrate_force.c', 'src/integrator_euler.c', 'src/integrator_implicit_midpoint.c', 'src/integrator_rk2.c', 'src/integrator_rk4.c', 'src/interpolation.c', 'src/lense_thirring.c', 'src/linkedlist.c', 'src/modify_mass.c', 'src/modify_orbits_direct.c', 'src/modify_orbits_forces.c', 'src/output.c', 'src/radiation_forces.c', 'src/rebxtools.c', 'src/steppers.c', 'src/stochastic_forces.c', 'src/tides_constant_time_lag.c', 'src/tides_spin.c', 'src/track_min_distance.c', 'src/type_I_migration.c', 'src/yarkovsky_effect.c'],
sources = [ 'src/central_force.c', 'src/core.c', 'src/exponential_migration.c', 'src/gas_damping_timescale.c', 'src/gas_dynamical_friction.c', 'src/gr.c', 'src/gr_full.c', 'src/gr_potential.c', 'src/gravitational_harmonics.c', 'src/inner_disk_edge.c', 'src/input.c', 'src/integrate_force.c', 'src/integrator_euler.c', 'src/integrator_implicit_midpoint.c', 'src/integrator_rk2.c', 'src/integrator_rk4.c', 'src/interpolation.c', 'src/lense_thirring.c', 'src/linkedlist.c', 'src/modify_mass.c', 'src/modify_orbits_direct.c', 'src/modify_orbits_forces.c', 'src/output.c', 'src/radiation_forces.c', 'src/rebxtools.c', 'src/steppers.c', 'src/stochastic_forces.c', 'src/tides_constant_time_lag.c', 'src/tides_spin.c', 'src/track_min_distance.c', 'src/type_I_migration.c', 'src/yarkovsky_effect.c'],
include_dirs = ['src'],
library_dirs = [],
runtime_library_dirs = ["."],
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ifndef REBXGITHASH
PREDEF+= -DREBXGITHASH=$(REBXGITHASH)
endif

SOURCES=central_force.c core.c exponential_migration.c gas_damping_forces.c gas_dynamical_friction.c gr.c gr_full.c gr_potential.c gravitational_harmonics.c inner_disk_edge.c input.c integrate_force.c integrator_euler.c integrator_implicit_midpoint.c integrator_rk2.c integrator_rk4.c interpolation.c lense_thirring.c linkedlist.c modify_mass.c modify_orbits_direct.c modify_orbits_forces.c output.c radiation_forces.c rebxtools.c steppers.c stochastic_forces.c tides_constant_time_lag.c tides_spin.c track_min_distance.c type_I_migration.c yarkovsky_effect.c
SOURCES=central_force.c core.c exponential_migration.c gas_damping_timescale.c gas_dynamical_friction.c gr.c gr_full.c gr_potential.c gravitational_harmonics.c inner_disk_edge.c input.c integrate_force.c integrator_euler.c integrator_implicit_midpoint.c integrator_rk2.c integrator_rk4.c interpolation.c lense_thirring.c linkedlist.c modify_mass.c modify_orbits_direct.c modify_orbits_forces.c output.c radiation_forces.c rebxtools.c steppers.c stochastic_forces.c tides_constant_time_lag.c tides_spin.c track_min_distance.c type_I_migration.c yarkovsky_effect.c

OBJECTS=$(SOURCES:.c=.o)
HEADERS=rebxtools.h reboundx.h linkedlist.h
Expand Down
4 changes: 2 additions & 2 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ struct rebx_force* rebx_load_force(struct rebx_extras* const rebx, const char* n
force->update_accelerations = rebx_modify_orbits_forces;
force->force_type = REBX_FORCE_VEL;
}
else if (strcmp(name, "gas_damping_forces") == 0){
force->update_accelerations = rebx_gas_damping_forces;
else if (strcmp(name, "gas_damping_timescale") == 0){
force->update_accelerations = rebx_gas_damping_timescale;
force->force_type = REBX_FORCE_VEL;
}
else if (strcmp(name, "exponential_migration") == 0){
Expand Down
2 changes: 1 addition & 1 deletion src/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void rebx_gr_potential(struct reb_simulation* const sim, struct rebx_force* cons
void rebx_radiation_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_stochastic_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_modify_orbits_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_gas_damping_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_gas_damping_timescale(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_exponential_migration(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_tides_constant_time_lag(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
void rebx_central_force(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N);
Expand Down
12 changes: 6 additions & 6 deletions src/gas_damping_forces.c → src/gas_damping_timescale.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file gas_damping_forces.c
* @file gas_damping_timescale.c
* @brief Update orbits with prescribed timescales by directly changing orbital elements after each timestep
* @author Phoebe Sandhaus <[email protected]>
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* Authors Phoebe Sandhaus
* Implementation Paper `Sandhaus et al. in prep`
* Based on `Dawson et al. 2016 <https://ui.adsabs.harvard.edu/abs/2016ApJ...822...54D/abstract>; Kominami & Ida 2002 <https://ui.adsabs.harvard.edu/abs/2002Icar..157...43K/abstract>`_
* C Example :ref:`c_example_gas_damping_forces`
* Python Example `GasDampingForces.ipynb <https://github.com/PhoebeSandhaus/reboundx_gas_damping/tree/main/ipython_examples/GasDampingForces.ipynb>`_
* C Example :ref:`c_example_gas_damping_timescale`
* Python Example `GasDampingTimescale.ipynb <https://github.com/PhoebeSandhaus/reboundx_gas_damping/tree/main/ipython_examples/GasDampingTimescale.ipynb>`_
* ======================= ===============================================
*
* This updates particles' positions and velocities between timesteps by first calculating a damping timescale for each individual particle, and then applying the timescale to damp both the eccentricity and inclination of the particle. Note: The timescale of damping should be much greater than a particle's orbital period. The damping force should also be small as compared to the gravitational forces on the particle.
Expand Down Expand Up @@ -62,7 +62,7 @@
#include "reboundx.h"
#include "rebxtools.h"

static struct reb_vec3d rebx_calculate_gas_damping_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* planet, struct reb_particle* star){
static struct reb_vec3d rebx_calculate_gas_damping_timescale(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* planet, struct reb_particle* star){
struct rebx_extras* const rebx = sim->extras;
struct reb_orbit o = reb_orbit_from_particle(sim->G, *planet, *star);

Expand Down Expand Up @@ -134,13 +134,13 @@ static struct reb_vec3d rebx_calculate_gas_damping_forces(struct reb_simulation*
return a;
}

void rebx_gas_damping_forces(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N){
void rebx_gas_damping_timescale(struct reb_simulation* const sim, struct rebx_force* const force, struct reb_particle* const particles, const int N){
int* ptr = rebx_get_param(sim->extras, force->ap, "coordinates");
enum REBX_COORDINATES coordinates = REBX_COORDINATES_JACOBI; // Default
if (ptr != NULL){
coordinates = *ptr;
}
const int back_reactions_inclusive = 1;
const char* reference_name = "primary";
rebx_com_force(sim, force, coordinates, back_reactions_inclusive, reference_name, rebx_calculate_gas_damping_forces, particles, N);
rebx_com_force(sim, force, coordinates, back_reactions_inclusive, reference_name, rebx_calculate_gas_damping_timescale, particles, N);
}

0 comments on commit b2c0d72

Please sign in to comment.