From b2c0d72d9a5b14ef64d780abc04ea188ba837f16 Mon Sep 17 00:00:00 2001 From: PhoebeSandhaus Date: Mon, 29 Jul 2024 18:26:36 -0400 Subject: [PATCH] changed function name --- .../Makefile | 0 .../problem.c | 134 +++++++++--------- ...Forces.ipynb => GasDampingTimescale.ipynb} | 14 +- setup.py | 4 +- src/Makefile | 2 +- src/core.c | 4 +- src/core.h | 2 +- ...mping_forces.c => gas_damping_timescale.c} | 12 +- 8 files changed, 86 insertions(+), 86 deletions(-) rename examples/{gas_damping_forces => gas_damping_timescale}/Makefile (100%) rename examples/{gas_damping_forces => gas_damping_timescale}/problem.c (92%) rename ipython_examples/{GasDampingForces.ipynb => GasDampingTimescale.ipynb} (99%) rename src/{gas_damping_forces.c => gas_damping_timescale.c} (89%) diff --git a/examples/gas_damping_forces/Makefile b/examples/gas_damping_timescale/Makefile similarity index 100% rename from examples/gas_damping_forces/Makefile rename to examples/gas_damping_timescale/Makefile diff --git a/examples/gas_damping_forces/problem.c b/examples/gas_damping_timescale/problem.c similarity index 92% rename from examples/gas_damping_forces/problem.c rename to examples/gas_damping_timescale/problem.c index 7855501f..c30ed4c2 100644 --- a/examples/gas_damping_forces/problem.c +++ b/examples/gas_damping_timescale/problem.c @@ -1,67 +1,67 @@ -/** - * Gas Damping Forces Example - * - * This example shows how to add gas damping forces to a REBOUND simulation. - * - */ -#include -#include -#include -#include -#include -#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 +#include +#include +#include +#include +#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); + } +} diff --git a/ipython_examples/GasDampingForces.ipynb b/ipython_examples/GasDampingTimescale.ipynb similarity index 99% rename from ipython_examples/GasDampingForces.ipynb rename to ipython_examples/GasDampingTimescale.ipynb index 39e53a62..eb3dacd0 100644 --- a/ipython_examples/GasDampingForces.ipynb +++ b/ipython_examples/GasDampingTimescale.ipynb @@ -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", @@ -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." ] @@ -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.)" ] @@ -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" @@ -309,7 +309,7 @@ ], "metadata": { "kernelspec": { - "display_name": "virt_env", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -323,7 +323,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.16" + "version": "3.8.8" } }, "nbformat": 4, diff --git a/setup.py b/setup.py index 52a286e6..2f45ad72 100644 --- a/setup.py +++ b/setup.py @@ -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) @@ -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 = ["."], diff --git a/src/Makefile b/src/Makefile index 379bace8..9da7d773 100644 --- a/src/Makefile +++ b/src/Makefile @@ -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 diff --git a/src/core.c b/src/core.c index 93cf06e2..43885c40 100644 --- a/src/core.c +++ b/src/core.c @@ -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){ diff --git a/src/core.h b/src/core.h index ee12e41e..0ff9b580 100644 --- a/src/core.h +++ b/src/core.h @@ -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); diff --git a/src/gas_damping_forces.c b/src/gas_damping_timescale.c similarity index 89% rename from src/gas_damping_forces.c rename to src/gas_damping_timescale.c index 99a0861e..b767c8ea 100644 --- a/src/gas_damping_forces.c +++ b/src/gas_damping_timescale.c @@ -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 * @@ -31,8 +31,8 @@ * Authors Phoebe Sandhaus * Implementation Paper `Sandhaus et al. in prep` * Based on `Dawson et al. 2016 ; Kominami & Ida 2002 `_ - * C Example :ref:`c_example_gas_damping_forces` - * Python Example `GasDampingForces.ipynb `_ + * C Example :ref:`c_example_gas_damping_timescale` + * Python Example `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. @@ -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); @@ -134,7 +134,7 @@ 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){ @@ -142,5 +142,5 @@ void rebx_gas_damping_forces(struct reb_simulation* const sim, struct rebx_force } 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); } \ No newline at end of file