Reference documentation for deal.II version 9.6.1
\(\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
16
#include <
deal.II/algorithms/timestep_control.h
>
17
18
#include <
deal.II/base/parameter_handler.h
>
19
20
DEAL_II_NAMESPACE_OPEN
21
22
namespace
Algorithms
23
{
24
TimestepControl::TimestepControl
(
double
start
,
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
{
41
now_val
=
start_val
;
42
43
// avoid compiler warning
44
(void)
min_step_val
;
45
}
46
47
48
49
void
50
TimestepControl::declare_parameters
(
ParameterHandler
¶m)
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
63
TimestepControl::parse_parameters
(
const
ParameterHandler
¶m)
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
76
TimestepControl::advance
()
77
{
78
bool
changed =
false
;
79
80
// Try incrementing time by s
81
double
now_trial =
now_val
+
step_val
;
82
current_step_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
{
90
current_step_val
=
final_val
-
now_val
;
91
now_trial =
final_val
;
92
changed =
true
;
93
}
94
95
now_val
= now_trial;
96
return
changed;
97
}
98
99
100
bool
101
TimestepControl::print
()
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
{
112
next_print_val
+=
print_step
;
113
if
(
next_print_val
>
final_val
)
114
next_print_val
=
final_val
;
115
}
116
return
result;
117
}
118
119
}
// namespace Algorithms
120
121
122
DEAL_II_NAMESPACE_CLOSE
Algorithms::TimestepControl::start
double start() const
Definition
timestep_control.h:231
Algorithms::TimestepControl::parse_parameters
void parse_parameters(const ParameterHandler ¶m)
Definition
timestep_control.cc:63
Algorithms::TimestepControl::final
double final() const
Definition
timestep_control.h:238
Algorithms::TimestepControl::current_step_val
double current_step_val
Definition
timestep_control.h:204
Algorithms::TimestepControl::final_val
double final_val
Definition
timestep_control.h:178
Algorithms::TimestepControl::tolerance
double tolerance() const
Definition
timestep_control.h:252
Algorithms::TimestepControl::step_val
double step_val
Definition
timestep_control.h:210
Algorithms::TimestepControl::now_val
double now_val
Definition
timestep_control.h:215
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:24
Algorithms::TimestepControl::max_step_val
double max_step_val
Definition
timestep_control.h:193
Algorithms::TimestepControl::min_step_val
double min_step_val
Definition
timestep_control.h:198
Algorithms::TimestepControl::print
bool print()
Definition
timestep_control.cc:101
Algorithms::TimestepControl::start_step_val
double start_step_val
Definition
timestep_control.h:188
Algorithms::TimestepControl::advance
bool advance()
Definition
timestep_control.cc:76
Algorithms::TimestepControl::start_step
void start_step(const double step)
Definition
timestep_control.h:287
Algorithms::TimestepControl::tolerance_val
double tolerance_val
Definition
timestep_control.h:183
Algorithms::TimestepControl::start_val
double start_val
Definition
timestep_control.h:173
Algorithms::TimestepControl::print_step
double print_step
Definition
timestep_control.h:221
Algorithms::TimestepControl::next_print_val
double next_print_val
Definition
timestep_control.h:226
Algorithms::TimestepControl::max_step
void max_step(double)
Definition
timestep_control.h:294
Algorithms::TimestepControl::declare_parameters
static void declare_parameters(ParameterHandler ¶m)
Definition
timestep_control.cc:50
ParameterHandler
Definition
parameter_handler.h:855
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:846
ParameterHandler::get_double
double get_double(const std::string &entry_name) const
Definition
parameter_handler.cc:1130
Patterns::Double
Definition
patterns.h:291
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition
config.h:501
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition
config.h:502
Algorithms
Definition
newton.h:36
parameter_handler.h
timestep_control.h
source
algorithms
timestep_control.cc
Generated by
1.13.1