From fb6ed6ecf19a9cc5eac66270617115b42a569e3e Mon Sep 17 00:00:00 2001 From: Rahil Makadia Date: Sat, 14 Sep 2024 20:09:21 -0500 Subject: [PATCH] change continuous events to exponential; no longer letting them change timestep --- grss/version.txt | 2 +- include/simulation.h | 7 ++++--- src/force.cpp | 24 ++++++++---------------- src/gr15.cpp | 23 ++++++++--------------- src/grss.cpp | 14 +++++++------- src/simulation.cpp | 17 +++++++++-------- 6 files changed, 37 insertions(+), 50 deletions(-) diff --git a/grss/version.txt b/grss/version.txt index ec87108d..81911389 100644 --- a/grss/version.txt +++ b/grss/version.txt @@ -1 +1 @@ -4.2.3 \ No newline at end of file +4.3.0 \ No newline at end of file diff --git a/include/simulation.h b/include/simulation.h index 44e1cd35..b5404ae9 100644 --- a/include/simulation.h +++ b/include/simulation.h @@ -242,7 +242,8 @@ class Event { real multiplier = 1.0L; // for continuous ejecta events - real dt = 1.0L; + std::vector expAccel0 = {0.0L, 0.0L, 0.0L}; + real tau = 1.0L; bool isContinuous = false; bool isHappening = false; /** @@ -522,8 +523,8 @@ class PropSimulation { /** * @brief Add an ejecta event to the simulation. */ - void add_event(IntegBody body, real tEvent, std::vector deltaV, - real multiplier, real dt); + void add_event(IntegBody body, real tEvent, std::vector expAccel0, + real multiplier, real tau); /** * @brief Set the values of the PropSimulation Constants object. */ diff --git a/src/force.cpp b/src/force.cpp index 87ab2556..7ef4df60 100644 --- a/src/force.cpp +++ b/src/force.cpp @@ -657,24 +657,16 @@ static void force_continuous_event(const real &t, const PropSimulation *propSim, if (propSim->eventMngr.continuousEvents[i].isHappening){ const size_t starti = propSim->eventMngr.continuousEvents[i].xIntegIndex / 2; - const real tPastEvent = - t - propSim->eventMngr.continuousEvents[i].t; - // f = np.sin(np.pi*x/(2*time_for_val)) - // df = np.pi/(2*time_for_val)*np.cos(np.pi*x/(2*time_for_val)) - const real preFac = - PI / (2 * propSim->eventMngr.continuousEvents[i].dt); - real accFac = preFac * cos(preFac * tPastEvent); - if (accFac > preFac || accFac < 0.0) { - accFac = 0.0; - } - accInteg[starti + 0] += accFac * - propSim->eventMngr.continuousEvents[i].deltaV[0] * + const real tPastEvent = t - propSim->eventMngr.continuousEvents[i].t; + const real postFac = exp(-tPastEvent/propSim->eventMngr.continuousEvents[i].tau); + accInteg[starti + 0] += propSim->eventMngr.continuousEvents[i].expAccel0[0] * + postFac * propSim->eventMngr.continuousEvents[i].multiplier * propDir; - accInteg[starti + 1] += accFac * - propSim->eventMngr.continuousEvents[i].deltaV[1] * + accInteg[starti + 1] += propSim->eventMngr.continuousEvents[i].expAccel0[1] * + postFac * propSim->eventMngr.continuousEvents[i].multiplier * propDir; - accInteg[starti + 2] += accFac * - propSim->eventMngr.continuousEvents[i].deltaV[2] * + accInteg[starti + 2] += propSim->eventMngr.continuousEvents[i].expAccel0[2] * + postFac * propSim->eventMngr.continuousEvents[i].multiplier * propDir; } } diff --git a/src/gr15.cpp b/src/gr15.cpp index 61a6dd89..00f4265b 100644 --- a/src/gr15.cpp +++ b/src/gr15.cpp @@ -255,14 +255,12 @@ void check_continuous_events(PropSimulation *propSim, const real &t) { bool allDone = true; bool forwardProp = propSim->integParams.tf > propSim->integParams.t0; for (size_t i = 0; i < propSim->eventMngr.nConEvents; i++) { - // const bool eventStarted = t >= propSim->eventMngr.continuousEvents[i].t; - // const bool eventEnded = t > propSim->eventMngr.continuousEvents[i].t + propSim->eventMngr.continuousEvents[i].dt; bool eventStarted, eventEnded; if (forwardProp) { eventStarted = t >= propSim->eventMngr.continuousEvents[i].t; - eventEnded = t >= (propSim->eventMngr.continuousEvents[i].t + propSim->eventMngr.continuousEvents[i].dt); + eventEnded = t >= propSim->integParams.tf; } else { - eventStarted = t <= (propSim->eventMngr.continuousEvents[i].t + propSim->eventMngr.continuousEvents[i].dt); + eventStarted = t <= propSim->integParams.t0; eventEnded = t < propSim->eventMngr.continuousEvents[i].t; } if (eventStarted && !eventEnded) { @@ -306,17 +304,12 @@ void event_timestep_check(PropSimulation *propSim, real &dt) { } } if (!propSim->eventMngr.allConEventDone) { - for (size_t i = 0; i < propSim->eventMngr.nConEvents; i++) { - if (propSim->eventMngr.continuousEvents[i].isHappening) { - // if any continuous event is happening, set dt to 1/10th of the event duration - // dt is the min of the current dt and the one dictated by the event - dt = fmin(1.0, propSim->eventMngr.continuousEvents[i].dt/10.0L); - dt = forwardProp ? dt : -dt; - } - if (forwardProp && propSim->t < propSim->eventMngr.continuousEvents[i].t) { - tNextEvent = fmin(tNextEvent, propSim->eventMngr.continuousEvents[i].t); - } else if (!forwardProp && propSim->t > propSim->eventMngr.continuousEvents[i].t+propSim->eventMngr.continuousEvents[i].dt) { - tNextEvent = fmax(tNextEvent, propSim->eventMngr.continuousEvents[i].t+propSim->eventMngr.continuousEvents[i].dt); + for (size_t i = 0; i < propSim->eventMngr.nConEvents; i++) { + const real tNextConEvent = propSim->eventMngr.continuousEvents[i].t; + if (forwardProp && propSim->t < tNextConEvent) { + tNextEvent = fmin(tNextEvent, tNextConEvent); + } else if (!forwardProp && propSim->t > tNextConEvent) { + tNextEvent = fmax(tNextEvent, tNextConEvent); } } } diff --git a/src/grss.cpp b/src/grss.cpp index f2bedbe1..a873b3df 100644 --- a/src/grss.cpp +++ b/src/grss.cpp @@ -884,8 +884,8 @@ PYBIND11_MODULE(libgrss, m) { static_cast, real, real)>( &PropSimulation::add_event), - py::arg("bodyName"), py::arg("tEvent"), py::arg("deltaV"), - py::arg("multiplier"), py::arg("dt"), + py::arg("bodyName"), py::arg("tEvent"), py::arg("expAccel0"), + py::arg("multiplier"), py::arg("tau"), R"mydelimiter( Adds an ejecta event to the simulation. @@ -895,12 +895,12 @@ PYBIND11_MODULE(libgrss, m) { Name of the body to apply the delta-V to. tEvent : real MJD Epoch of the event. Must be in TDB. - deltaV : list of real - Delta-V to apply to the body. + expAccel0 : list of real + Initial exponentiallly decaying acceleration. multiplier : real - Multiplier to apply to the delta-V. - dt : real - Time duration for the continuous ejecta event. + Multiplier for the exponential decay. + tau : real + Time constant for the exponentiallly decaying acceleration. )mydelimiter") .def("set_sim_constants", &PropSimulation::set_sim_constants, py::arg("du2m") = 149597870700.0L, py::arg("tu2s") = 86400.0L, diff --git a/src/simulation.cpp b/src/simulation.cpp index 39dcd48c..2c75429c 100644 --- a/src/simulation.cpp +++ b/src/simulation.cpp @@ -1060,7 +1060,7 @@ void PropSimulation::add_event(IntegBody body, real tEvent, event.deltaV = deltaV; event.multiplier = multiplier; - event.dt = 0.0; + event.tau = 0.0; event.isContinuous = false; event.isHappening = false; event_postprocess(this, event); @@ -1070,22 +1070,23 @@ void PropSimulation::add_event(IntegBody body, real tEvent, /** * @param[in] body IntegBody object to apply the EjectaEvent to. * @param[in] tEvent Time at which to apply the EjectaEvent. - * @param[in] deltaV Delta-V for the ejecta. - * @param[in] multiplier Multiplier for the Delta-V. - * @param[in] dt Time duration for the ejecta. + * @param[in] expAccel0 Initial exponentiallly decaying acceleration. + * @param[in] multiplier Multiplier for the exponential decay. + * @param[in] tau Time constant for the exponentiallly decaying acceleration. */ void PropSimulation::add_event(IntegBody body, real tEvent, - std::vector deltaV, real multiplier, - real dt) { + std::vector expAccel0, real multiplier, + real tau) { size_t bodyIndex = event_preprocess(this, body, tEvent); Event event; event.t = tEvent; event.bodyName = body.name; event.bodyIndex = bodyIndex; - event.deltaV = deltaV; + event.deltaV = std::vector(3, 0.0); event.multiplier = multiplier; - event.dt = dt; + event.expAccel0 = expAccel0; + event.tau = tau; event.isContinuous = true; event.isHappening = false; event_postprocess(this, event);