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