Reference documentation for deal.II version 9.2.0
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
timestep_control.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
18 
20 
22 
23 using namespace Algorithms;
24 
26  double final,
27  double tolerance,
28  double start_step,
29  double print_step,
30  double max_step)
31  : start_val(start)
32  , final_val(final)
33  , tolerance_val(tolerance)
34  , start_step_val(start_step)
35  , max_step_val(max_step)
36  , min_step_val(0)
37  , current_step_val(start_step)
38  , step_val(start_step)
39  , print_step(print_step)
40  , next_print_val(print_step > 0. ? start_val + print_step : start_val - 1.)
41 {
43 
44  // avoid compiler warning
45  (void)min_step_val;
46 }
47 
48 
49 
50 void
52 {
53  param.declare_entry("Start", "0.", Patterns::Double());
54  param.declare_entry("Final", "1.", Patterns::Double());
55  param.declare_entry("First step", "1.e-2", Patterns::Double(0.));
56  param.declare_entry("Max step", "1.", Patterns::Double(0.));
57  param.declare_entry("Tolerance", "1.e-2", Patterns::Double(0.));
58  param.declare_entry("Print step", "-1.", Patterns::Double());
59 }
60 
61 
62 
63 void
65 {
66  start(param.get_double("Start"));
67  start_step(param.get_double("First step"));
68  max_step(param.get_double("Max step"));
69  final(param.get_double("Final"));
70  tolerance(param.get_double("Tolerance"));
71  print_step = param.get_double("Print step");
72 }
73 
74 
75 
76 bool
78 {
79  bool changed = false;
80 
81  // Try incrementing time by s
82  double now_trial = now_val + step_val;
84 
85  // If we just missed the final time, increase the step size a bit. This way,
86  // we avoid a very small final step. If the step shot over the final time,
87  // adjust it so we hit the final time exactly.
88  double s1 = .01 * step_val;
89  if (now_trial > final_val - s1)
90  {
92  now_trial = final_val;
93  changed = true;
94  }
95 
96  now_val = now_trial;
97  return changed;
98 }
99 
100 
101 bool
103 {
104  if (print_step == 0.)
105  return false;
106  if (print_step < 0.)
107  return true;
108 
109  bool result = (now_val >= next_print_val);
110 
111  if (result)
112  {
116  }
117  return result;
118 }
119 
Algorithms::TimestepControl::advance
bool advance()
Definition: timestep_control.cc:77
ParameterHandler::get_double
double get_double(const std::string &entry_name) const
Definition: parameter_handler.cc:1056
Algorithms::TimestepControl::tolerance
double tolerance() const
Definition: timestep_control.h:253
Algorithms::TimestepControl::min_step_val
double min_step_val
Definition: timestep_control.h:199
Algorithms::TimestepControl::TimestepControl
TimestepControl(double start=0., double final=1., double tolerance=1.e-2, double start_step=1.e-2, double print_step=-1., double max_step=1.)
Definition: timestep_control.cc:25
ParameterHandler::declare_entry
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation="", const bool has_to_be_set=false)
Definition: parameter_handler.cc:784
Algorithms::TimestepControl::next_print_val
double next_print_val
Definition: timestep_control.h:227
Algorithms::TimestepControl::declare_parameters
static void declare_parameters(ParameterHandler &param)
Definition: timestep_control.cc:51
Algorithms::TimestepControl::print
bool print()
Definition: timestep_control.cc:102
Algorithms::TimestepControl::print_step
double print_step
Definition: timestep_control.h:222
Algorithms::TimestepControl::start_val
double start_val
Definition: timestep_control.h:174
Algorithms::TimestepControl::start
double start() const
Definition: timestep_control.h:232
Algorithms::TimestepControl::current_step_val
double current_step_val
Definition: timestep_control.h:205
Algorithms::TimestepControl::start_step
void start_step(const double step)
Definition: timestep_control.h:288
timestep_control.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Algorithms::TimestepControl::max_step
void max_step(double)
Definition: timestep_control.h:295
parameter_handler.h
Algorithms
Definition: newton.h:36
Algorithms::TimestepControl::parse_parameters
void parse_parameters(ParameterHandler &param)
Definition: timestep_control.cc:64
Algorithms::TimestepControl::step_val
double step_val
Definition: timestep_control.h:211
Algorithms::TimestepControl::final_val
double final_val
Definition: timestep_control.h:179
ParameterHandler
Definition: parameter_handler.h:845
Algorithms::TimestepControl::now_val
double now_val
Definition: timestep_control.h:216
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Patterns::Double
Definition: patterns.h:293