Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more global time step control #1159

Merged
merged 6 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 46 additions & 11 deletions src/driver/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,25 +205,60 @@ void EvolutionDriver::InitializeBlockTimeSteps() {
// \brief function that loops over all MeshBlocks and find new timestep

void EvolutionDriver::SetGlobalTimeStep() {
// don't allow dt to grow by more than 2x
// consider making this configurable in the input
if (tm.dt < 0.1 * std::numeric_limits<Real>::max()) {
tm.dt *= 2.0;
}
Real big = std::numeric_limits<Real>::max();
for (auto const &pmb : pmesh->block_list) {
tm.dt = std::min(tm.dt, pmb->NewDt());
pmb->SetAllowedDt(big);
// Check if user wants to force the value
if (dt_force > 0.0) {
tm.dt = dt_force;
adamdempsey90 marked this conversation as resolved.
Show resolved Hide resolved
} else {
// Check for special first cycle value
if (tm.ncycle == 0) {
tm.dt = std::min(tm.dt, dt_init);
lroberts36 marked this conversation as resolved.
Show resolved Hide resolved
}
// don't allow dt to grow by more than 2x
// consider making this configurable in the input
if (tm.dt < 0.1 * std::numeric_limits<Real>::max()) {
tm.dt *= 2.0;
adamdempsey90 marked this conversation as resolved.
Show resolved Hide resolved
}
// Allow the meshblocks to vote
Real big = std::numeric_limits<Real>::max();
for (auto const &pmb : pmesh->block_list) {
tm.dt = std::min(tm.dt, pmb->NewDt());
pmb->SetAllowedDt(big);
adamdempsey90 marked this conversation as resolved.
Show resolved Hide resolved
}
// Allow the user to vote
adamdempsey90 marked this conversation as resolved.
Show resolved Hide resolved
tm.dt = std::min(tm.dt, dt_user);
}

#ifdef MPI_PARALLEL
PARTHENON_MPI_CHECK(MPI_Allreduce(MPI_IN_PLACE, &tm.dt, 1, MPI_PARTHENON_REAL, MPI_MIN,
MPI_COMM_WORLD));
#endif

if (tm.time < tm.tlim &&
(tm.tlim - tm.time) < tm.dt) // timestep would take us past desired endpoint
// Check that we have not gone off the rails
if (tm.dt <= dt_min) {
if (++dt_min_count >= dt_min_count_max) {
std::stringstream msg;
msg << "Timesetep has fallen bellow minimum (parthenon/time/dt_min=" << dt_min
<< ") for more than " << dt_min_count_max << " steps";
PARTHENON_FAIL(msg);
}
} else {
dt_min_count = 0;
}
if (tm.dt >= dt_max) {
if (++dt_max_count >= dt_max_count_max) {
std::stringstream msg;
msg << "Timesetep has risen above maximum (parthenon/time/dt_max=" << dt_max
<< ") for more than " << dt_max_count_max << " steps";
PARTHENON_FAIL(msg);
}
adamdempsey90 marked this conversation as resolved.
Show resolved Hide resolved
} else {
dt_max_count = 0;
}

// Limit timestep if it would take us past desired endpoint
if (tm.time < tm.tlim && (tm.tlim - tm.time) < tm.dt) {
tm.dt = tm.tlim - tm.time;
}
}

void EvolutionDriver::DumpInputParameters() {
Expand Down
18 changes: 18 additions & 0 deletions src/driver/driver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,21 @@ class EvolutionDriver : public Driver {
std::numeric_limits<Real>::infinity());
Real dt =
pinput->GetOrAddReal("parthenon/time", "dt", std::numeric_limits<Real>::max());
dt_min = pinput->GetOrAddReal("parthenon/time", "dt_min",
std::numeric_limits<Real>::min());
dt_max = pinput->GetOrAddReal("parthenon/time", "dt_max",
std::numeric_limits<Real>::max());
dt_init = pinput->GetOrAddReal("parthenon/time", "dt_init",
std::numeric_limits<Real>::max());
dt_user = pinput->GetOrAddReal("parthenon/time", "dt_user",
std::numeric_limits<Real>::max());
dt_force = pinput->GetOrAddReal("parthenon/time", "dt_force",
std::numeric_limits<Real>::lowest());
dt_min_count_max =
pinput->GetOrAddInteger("parthenon/time", "dt_min_cycle_limit", 10);
dt_max_count_max = pinput->GetOrAddInteger("parthenon/time", "dt_max_cycle_limit", 1);
dt_min_count = 0;
dt_max_count = 0;
const auto ncycle = pinput->GetOrAddInteger("parthenon/time", "ncycle", 0);
const auto nmax = pinput->GetOrAddInteger("parthenon/time", "nlim", -1);
const auto nout = pinput->GetOrAddInteger("parthenon/time", "ncycle_out", 1);
Expand All @@ -88,6 +103,9 @@ class EvolutionDriver : public Driver {

protected:
void PostExecute(DriverStatus status) override;
Real dt_user, dt_force, dt_init, dt_min, dt_max;
int dt_min_count, dt_max_count;
int dt_min_count_max, dt_max_count_max;

private:
void InitializeBlockTimeSteps();
Expand Down
Loading