23 #include "pism/icemodel/IceModel.hh"
24 #include "pism/util/Grid.hh"
25 #include "pism/util/ConfigInterface.hh"
26 #include "pism/util/Time.hh"
27 #include "pism/util/MaxTimestep.hh"
28 #include "pism/stressbalance/StressBalance.hh"
29 #include "pism/util/Component.hh"
31 #include "pism/frontretreat/calving/EigenCalving.hh"
32 #include "pism/frontretreat/calving/HayhurstCalving.hh"
33 #include "pism/frontretreat/calving/vonMisesCalving.hh"
34 #include "pism/frontretreat/FrontRetreat.hh"
36 #include "pism/coupler/FrontalMelt.hh"
54 adaptive_timestepping_ratio =
m_config->get_number(
"time_stepping.adaptive_ratio");
61 return std::min(dt_diffusivity, dt_max);
77 if (not
m_config->get_flag(
"time_stepping.skip.enabled")) {
81 const int skip_max =
static_cast<int>(
m_config->get_number(
"time_stepping.skip.max"));
83 if (dt_diffusivity > 0.0) {
84 const double conservative_factor = 0.95;
85 const double counter = floor(conservative_factor * (
dt / dt_diffusivity));
86 return std::min(
static_cast<int>(counter), skip_max);
103 const double current_time =
m_time->current();
105 std::vector<MaxTimestep> restrictions;
109 restrictions.push_back(m.second->max_timestep(current_time));
115 if (front_retreat and
m_config->get_flag(
"geometry.front_retreat.use_cfl")) {
120 retreat_rate.
set(0.0);
140 restrictions.push_back(
144 const char *end =
"end of the run";
145 const char *
max =
"max";
154 const double time_to_end =
m_time->end() - current_time;
155 if (time_to_end > 0.0) {
156 restrictions.push_back(
MaxTimestep(time_to_end, end));
167 if (
m_config->get_flag(
"geometry.update.enabled")) {
170 restrictions.push_back(
MaxTimestep(cfl.dt_max.value(),
"2D CFL"));
175 std::sort(restrictions.begin(), restrictions.end());
179 assert(restrictions.size() >= 2);
180 auto dt_max = restrictions[0];
181 auto dt_other = restrictions[1];
184 result.
dt = dt_max.value();
185 result.
reason = (dt_max.description() +
" (overrides " + dt_other.description() +
")");
188 double resolution =
m_config->get_number(
"time_stepping.resolution",
"seconds");
192 int year_increment =
static_cast<int>(
m_config->get_number(
"time_stepping.hit_multiples"));
193 if (year_increment > 0) {
197 if (std::fabs(current_time - next_time) < resolution) {
200 next_time =
m_time->increment_date(current_time, year_increment);
203 auto dt = next_time - current_time;
204 assert(
dt > resolution);
206 if (
dt < result.
dt) {
209 year_increment, dt_max.description().c_str());
216 if (dt_max.description() ==
"diffusivity" and counter == 0) {
225 if (
member(dt_max.description(), {max, end}) and counter > 1) {
230 if (resolution > 0.0) {
231 double dt = std::floor(result.
dt * resolution) / resolution;
235 if (
dt >= resolution) {
array::CellType2 cell_type
std::map< std::string, const Component * > m_submodels
the list of sub-models, for writing model states and obtaining diagnostics
MaxTimestep extras_max_timestep(double my_t)
Computes the maximum time-step we can take and still hit all -extra_times.
std::shared_ptr< stressbalance::StressBalance > m_stress_balance
const Config::Ptr m_config
Configuration flags and parameters.
const Time::Ptr m_time
Time manager.
double m_timestep_hit_multiples_last_time
std::shared_ptr< frontalmelt::FrontalMelt > m_frontal_melt
virtual unsigned int skip_counter(double input_dt, double input_dt_diffusivity)
Compute the skip counter using "long" (usually determined using the CFL stability criterion) and "sho...
virtual MaxTimestep max_timestep_diffusivity()
Compute the maximum time step allowed by the diffusive SIA.
MaxTimestep ts_max_timestep(double my_t)
Computes the maximum time-step we can take and still hit all -ts_times.
std::shared_ptr< calving::EigenCalving > m_eigen_calving
std::vector< std::shared_ptr< array::Scalar2 > > m_work2d
std::shared_ptr< calving::HayhurstCalving > m_hayhurst_calving
array::Scalar1 m_ice_thickness_bc_mask
Mask prescribing locations where ice thickness is held constant.
MaxTimestep save_max_timestep(double my_t)
Computes the maximum time-step we can take and still hit all -save_times.
std::shared_ptr< calving::vonMisesCalving > m_vonmises_calving
const std::shared_ptr< Grid > m_grid
Computational grid.
virtual TimesteppingInfo max_timestep(unsigned int counter)
Use various stability criteria to determine the time step for an evolution run.
std::shared_ptr< FrontRetreat > m_front_retreat
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
void add(double alpha, const Array2D< T > &x)
void set(double c)
Result: v[j] <- c for all j.
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
double min(const array::Scalar &input)
Finds minimum over all the values in an array::Scalar object. Ignores ghosts.
std::string printf(const char *format,...)
bool member(const std::string &string, const std::set< std::string > &set)
MaxTimestep max_timestep_diffusivity(double D_max, double dx, double dy, double adaptive_timestepping_ratio)
unsigned int skip_counter