Skip to content

Commit

Permalink
ODESolvers: Added mechanism for detecting if previous RHSs need to be…
Browse files Browse the repository at this point in the history
… refilled after initialization and regridding
  • Loading branch information
lucass-carneiro committed Jan 9, 2025
1 parent 7f6ad2e commit 3aaa6a7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ODESolvers/interface.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ void FUNCTION CallScheduleGroup(
CCTK_POINTER IN cctkGH,
CCTK_STRING IN groupname)
REQUIRES FUNCTION CallScheduleGroup

CCTK_REAL refill_prev_rhss TYPE=scalar "If true and using hybrid methods, this variable causes the stored prev. RHS to be refilled via regular RK step"
16 changes: 16 additions & 0 deletions ODESolvers/schedule.ccl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ SCHEDULE ODESolvers_Solve AT evol
{
LANG: C
OPTIONS: level
READS: refill_prev_rhss
WRITES: refill_prev_rhss
} "Solve ODEs"

SCHEDULE ODESolvers_SetRefillPrevRHSS AT initial
{
LANG: C
OPTIONS: global
WRITES: refill_prev_rhss
} "Sets refill_prev_rhss to true, thus having previous RHS information recomputed via standard RK methods"

SCHEDULE ODESolvers_SetRefillPrevRHSS AT postregrid
{
LANG: C
OPTIONS: global
WRITES: refill_prev_rhss
} "Sets refill_prev_rhss to true, thus having previous RHS information recomputed via standard RK methods"



# CarpetX scheduled groups:
Expand Down
33 changes: 29 additions & 4 deletions ODESolvers/src/solve.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ void mark_invalid(const std::vector<int> &groups) {
///////////////////////////////////////////////////////////////////////////////

extern "C" void ODESolvers_Solve(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTS_ODESolvers_Solve;
DECLARE_CCTK_ARGUMENTSX_ODESolvers_Solve;
DECLARE_CCTK_PARAMETERS;

static bool did_output = false;
Expand Down Expand Up @@ -1018,7 +1018,13 @@ extern "C" void ODESolvers_Solve(CCTK_ARGUMENTS) {
} else if (CCTK_EQUALS(method, "BMS422")) {

// RK4 Bootstrapping
if (cctkGH->cctk_iteration <= 1) {
if (static_cast<CCTK_INT>(*refill_prev_rhss) != 0) {
if (verbose) {
CCTK_VINFO(" Taking RK4 step to fill prev. RHS");
}

*refill_prev_rhss -= -1;

// k1 = f(y0)
// k2 = f(y0 + h/2 k1)
// k3 = f(y0 + h/2 k2)
Expand Down Expand Up @@ -1052,8 +1058,8 @@ extern "C" void ODESolvers_Solve(CCTK_ARGUMENTS) {
calcrhs(4);
calcupdate(4, dt, 0.0, reals<3>{1.0, dt / 6, dt / 6},
states<3>{&old, &kaccum, &rhs});

} else {

// k0 = f(y(t - h))
// k1 = f(y(t))
// k2 = f(y(t) + h * (a20 * k0 + a21 * k1))
Expand Down Expand Up @@ -1104,7 +1110,13 @@ extern "C" void ODESolvers_Solve(CCTK_ARGUMENTS) {
} else if (CCTK_EQUALS(method, "BMS431")) {

// RK4 Bootstrapping
if (cctkGH->cctk_iteration <= 2) {
if (static_cast<CCTK_INT>(*refill_prev_rhss) != 0) {
if (verbose) {
CCTK_VINFO(" Taking RK4 step to fill prev. RHS");
}

*refill_prev_rhss -= -1;

// k1 = f(y0)
// k2 = f(y0 + h/2 k1)
// k3 = f(y0 + h/2 k2)
Expand Down Expand Up @@ -1484,4 +1496,17 @@ extern "C" void ODESolvers_Solve(CCTK_ARGUMENTS) {
// TODO: Update time here, and not during time level cycling in the driver
}

extern "C" void ODESolvers_SetRefillPrevRHSS(CCTK_ARGUMENTS) {
DECLARE_CCTK_ARGUMENTSX_ODESolvers_SetRefillPrevRHSS;
DECLARE_CCTK_PARAMETERS;

if (CCTK_EQUALS(method, "BMS422")) {
*refill_prev_rhss = 1;
} else if (CCTK_EQUALS(method, "BMS431")) {
*refill_prev_rhss = 2;
} else {
*refill_prev_rhss = 0;
}
}

} // namespace ODESolvers

0 comments on commit 3aaa6a7

Please sign in to comment.