Skip to content

Commit

Permalink
change continuous events to exponential; no longer letting them chang…
Browse files Browse the repository at this point in the history
…e timestep
  • Loading branch information
rahil-makadia committed Sep 15, 2024
1 parent bffa7ac commit fb6ed6e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 50 deletions.
2 changes: 1 addition & 1 deletion grss/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.3
4.3.0
7 changes: 4 additions & 3 deletions include/simulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ class Event {
real multiplier = 1.0L;

// for continuous ejecta events
real dt = 1.0L;
std::vector<real> expAccel0 = {0.0L, 0.0L, 0.0L};
real tau = 1.0L;
bool isContinuous = false;
bool isHappening = false;
/**
Expand Down Expand Up @@ -522,8 +523,8 @@ class PropSimulation {
/**
* @brief Add an ejecta event to the simulation.
*/
void add_event(IntegBody body, real tEvent, std::vector<real> deltaV,
real multiplier, real dt);
void add_event(IntegBody body, real tEvent, std::vector<real> expAccel0,
real multiplier, real tau);
/**
* @brief Set the values of the PropSimulation Constants object.
*/
Expand Down
24 changes: 8 additions & 16 deletions src/force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
23 changes: 8 additions & 15 deletions src/gr15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/grss.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ PYBIND11_MODULE(libgrss, m) {
static_cast<void (PropSimulation::*)(
IntegBody, real, std::vector<real>, 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.
Expand All @@ -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,
Expand Down
17 changes: 9 additions & 8 deletions src/simulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<real> deltaV, real multiplier,
real dt) {
std::vector<real> 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<real>(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);
Expand Down

0 comments on commit fb6ed6e

Please sign in to comment.