From: Reza Rastak Date: Sat, 27 Jun 2020 22:48:31 +0000 (-0700) Subject: DiscreteTime::set_next_step_size() added X-Git-Tag: v9.3.0-rc1~1268^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5e0f91a9839fa3f95f0d6930d63d9499cb231296;p=dealii.git DiscreteTime::set_next_step_size() added --- diff --git a/doc/news/changes/minor/20200627RezaRastak b/doc/news/changes/minor/20200627RezaRastak new file mode 100644 index 0000000000..c951c0b639 --- /dev/null +++ b/doc/news/changes/minor/20200627RezaRastak @@ -0,0 +1,3 @@ +New: The member function DiscreteTime::set_next_step_size() is added. +
+(Reza Rastak, 2020/06/27) diff --git a/include/deal.II/base/discrete_time.h b/include/deal.II/base/discrete_time.h index a656f77138..51c81f85f2 100644 --- a/include/deal.II/base/discrete_time.h +++ b/include/deal.II/base/discrete_time.h @@ -349,6 +349,22 @@ public: void set_desired_next_step_size(const double time_step_size); + /** + * Set the *actual* value of the next time step size. By calling this + * method, we are indicating the next time advance_time() is called, + * @p time_step_size is to be used to advance the simulation time. + * + * @note The difference between set_next_step_size() and + * set_desired_next_step_size() is that the former uses the provided $dt$ + * exactly without any adjustment, but produces an + * error (in debug mode) if $dt$ is not in the acceptable range. + * Generally, set_desired_next_step_size() is the preferred method because + * it can adjust the $dt$ intelligently, based on $T_{\text{end}}$. + * @pre $0 < dt \le T_{\text{end}} - t$. + */ + void + set_next_step_size(const double time_step_size); + /** * Advance the current time based on the value of the current step. * If you want to adjust the next time step size, call the method diff --git a/source/base/discrete_time.cc b/source/base/discrete_time.cc index 1ce499e1a5..28636a7d54 100644 --- a/source/base/discrete_time.cc +++ b/source/base/discrete_time.cc @@ -66,6 +66,20 @@ DiscreteTime::set_desired_next_step_size(const double next_step_size) +void +DiscreteTime::set_next_step_size(const double next_step_size) +{ + Assert(next_step_size > 0, + ExcMessage("Only positive time step size is allowed.")); + next_time = current_time + next_step_size; + Assert( + next_time <= end_time, + ExcMessage( + "Time step size is too large. The next time cannot exceed the end time.")); +} + + + void DiscreteTime::advance_time() { diff --git a/tests/base/discrete_time_1.cc b/tests/base/discrete_time_1.cc index e5461cf198..b37ee917d4 100644 --- a/tests/base/discrete_time_1.cc +++ b/tests/base/discrete_time_1.cc @@ -69,7 +69,7 @@ test_adjust_time_step_size() print_time(time); time.advance_time(); print_time(time); - time.set_desired_next_step_size(0.36); + time.set_next_step_size(0.36); time.advance_time(); print_time(time); time.advance_time();