deal.II version GIT relicensing-6839-g338455934c 2026-10-02 12:10:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2010 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13
14#include <deal.II/base/config.h>
15
17
20
21#include <string>
22
24
25namespace Algorithms
26{
28 double final,
29 double tolerance,
30 double start_step,
31 double print_step,
32 double max_step)
33 : start_val(start)
34 , final_val(final)
35 , tolerance_val(tolerance)
36 , start_step_val(start_step)
37 , max_step_val(max_step)
38 , min_step_val(0)
39 , current_step_val(start_step)
40 , step_val(start_step)
41 , print_step(print_step)
42 , next_print_val(print_step > 0. ? start_val + print_step : start_val - 1.)
43 {
45
46 // avoid compiler warning
47 (void)min_step_val;
48 }
49
50
51
52 void
54 {
55 param.declare_entry("Start", "0.", Patterns::Double());
56 param.declare_entry("Final", "1.", Patterns::Double());
57 param.declare_entry("First step", "1.e-2", Patterns::Double(0.));
58 param.declare_entry("Max step", "1.", Patterns::Double(0.));
59 param.declare_entry("Tolerance", "1.e-2", Patterns::Double(0.));
60 param.declare_entry("Print step", "-1.", Patterns::Double());
61 }
62
63
64
65 void
67 {
68 start(param.get_double("Start"));
69 start_step(param.get_double("First step"));
70 max_step(param.get_double("Max step"));
71 final(param.get_double("Final"));
72 tolerance(param.get_double("Tolerance"));
73 print_step = param.get_double("Print step");
74 }
75
76
77
78 bool
80 {
81 bool changed = false;
82
83 // Try incrementing time by s
84 double now_trial = now_val + step_val;
86
87 // If we just missed the final time, increase the step size a bit. This way,
88 // we avoid a very small final step. If the step shot over the final time,
89 // adjust it so we hit the final time exactly.
90 double s1 = .01 * step_val;
91 if (now_trial > final_val - s1)
92 {
94 now_trial = final_val;
95 changed = true;
96 }
97
98 now_val = now_trial;
99 return changed;
100 }
101
102
103 bool
105 {
106 if (print_step == 0.)
107 return false;
108 if (print_step < 0.)
109 return true;
110
111 bool result = (now_val >= next_print_val);
112
113 if (result)
114 {
118 }
119 return result;
120 }
121
122} // namespace Algorithms
123
124
void parse_parameters(const ParameterHandler &param)
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 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:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39