deal.II version 9.8.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
source
algorithms
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
16
#include <
deal.II/algorithms/timestep_control.h
>
17
18
#include <
deal.II/base/parameter_handler.h
>
19
#include <
deal.II/base/patterns.h
>
20
21
#include <string>
22
23
DEAL_II_NAMESPACE_OPEN
24
25
namespace
Algorithms
26
{
27
TimestepControl::TimestepControl
(
double
start
,
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
{
44
now_val
=
start_val
;
45
46
// avoid compiler warning
47
(void)
min_step_val
;
48
}
49
50
51
52
void
53
TimestepControl::declare_parameters
(
ParameterHandler
¶m)
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
66
TimestepControl::parse_parameters
(
const
ParameterHandler
¶m)
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
79
TimestepControl::advance
()
80
{
81
bool
changed =
false
;
82
83
// Try incrementing time by s
84
double
now_trial =
now_val
+
step_val
;
85
current_step_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
{
93
current_step_val
=
final_val
-
now_val
;
94
now_trial =
final_val
;
95
changed =
true
;
96
}
97
98
now_val
= now_trial;
99
return
changed;
100
}
101
102
103
bool
104
TimestepControl::print
()
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
{
115
next_print_val
+=
print_step
;
116
if
(
next_print_val
>
final_val
)
117
next_print_val
=
final_val
;
118
}
119
return
result;
120
}
121
122
}
// namespace Algorithms
123
124
125
DEAL_II_NAMESPACE_CLOSE
Algorithms::TimestepControl::start
double start() const
Definition
timestep_control.h:229
Algorithms::TimestepControl::parse_parameters
void parse_parameters(const ParameterHandler ¶m)
Definition
timestep_control.cc:66
Algorithms::TimestepControl::final
double final() const
Definition
timestep_control.h:236
Algorithms::TimestepControl::current_step_val
double current_step_val
Definition
timestep_control.h:202
Algorithms::TimestepControl::final_val
double final_val
Definition
timestep_control.h:176
Algorithms::TimestepControl::tolerance
double tolerance() const
Definition
timestep_control.h:250
Algorithms::TimestepControl::step_val
double step_val
Definition
timestep_control.h:208
Algorithms::TimestepControl::now_val
double now_val
Definition
timestep_control.h:213
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:27
Algorithms::TimestepControl::max_step_val
double max_step_val
Definition
timestep_control.h:191
Algorithms::TimestepControl::min_step_val
double min_step_val
Definition
timestep_control.h:196
Algorithms::TimestepControl::print
bool print()
Definition
timestep_control.cc:104
Algorithms::TimestepControl::start_step_val
double start_step_val
Definition
timestep_control.h:186
Algorithms::TimestepControl::advance
bool advance()
Definition
timestep_control.cc:79
Algorithms::TimestepControl::start_step
void start_step(const double step)
Definition
timestep_control.h:285
Algorithms::TimestepControl::tolerance_val
double tolerance_val
Definition
timestep_control.h:181
Algorithms::TimestepControl::start_val
double start_val
Definition
timestep_control.h:171
Algorithms::TimestepControl::print_step
double print_step
Definition
timestep_control.h:219
Algorithms::TimestepControl::next_print_val
double next_print_val
Definition
timestep_control.h:224
Algorithms::TimestepControl::max_step
void max_step(double)
Definition
timestep_control.h:292
Algorithms::TimestepControl::declare_parameters
static void declare_parameters(ParameterHandler ¶m)
Definition
timestep_control.cc:53
ParameterHandler
Definition
parameter_handler.h:854
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:889
ParameterHandler::get_double
double get_double(const std::string &entry_name) const
Definition
parameter_handler.cc:1203
Patterns::Double
Definition
patterns.h:295
config.h
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition
config.h:38
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition
config.h:39
Algorithms
Definition
newton.h:35
parameter_handler.h
patterns.h
timestep_control.h
Generated by
1.16.1