Reference documentation for deal.II version 9.5.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\}}\)
Loading...
Searching...
No Matches
timestep_control.cc
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2006 - 2022 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
23namespace 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
120} // namespace Algorithms
121
122
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.)
void parse_parameters(ParameterHandler &param)
void start_step(const double step)
static void declare_parameters(ParameterHandler &param)
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)
double get_double(const std::string &entry_name) const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473