18 #include <deal.II/algorithms/newton.h>
20 #include <deal.II/base/parameter_handler.h>
21 #include <deal.II/base/logstream.h>
22 #include <deal.II/lac/vector_memory.h>
27 DEAL_II_NAMESPACE_OPEN
31 template <
class VECTOR>
34 residual(&residual), inverse_derivative(&inverse_derivative),
36 n_stepsize_iterations(21),
37 assemble_threshold(0.),
43 template <
class VECTOR>
56 template <
class VECTOR>
61 control.parse_parameters (param);
62 assemble_threshold = param.
get_double(
"Assemble threshold");
63 n_stepsize_iterations = param.
get_integer(
"Stepsize iterations");
64 debug_vectors = param.
get_bool(
"Debug vectors");
68 template <
class VECTOR>
75 template <
class VECTOR>
80 inverse_derivative->notify(e);
84 template <
class VECTOR>
89 deallog.
push (
"Newton");
94 deallog <<
"u: " << u.l2_norm() << std::endl;
104 src1.
add(p,
"Newton iterate");
107 src2.
add(p,
"Newton residual");
110 out1.
add(p,
"Residual");
113 out2.
add(p,
"Update");
115 unsigned int step = 0;
117 (*residual)(out1, src1);
118 double resnorm = res->l2_norm();
119 double old_residual = resnorm / assemble_threshold + 1;
124 if (resnorm/old_residual >= assemble_threshold)
130 (*inverse_derivative)(out2, src2);
134 deallog <<
"Inner iteration failed after "
135 << e.
last_step <<
" steps with residual "
143 out.
add(p,
"solution");
145 out.
add(p,
"update");
147 out.
add(p,
"residual");
153 old_residual = resnorm;
154 (*residual)(out1, src1);
155 resnorm = res->l2_norm();
158 unsigned int step_size = 0;
159 while (resnorm >= old_residual)
162 if (step_size > n_stepsize_iterations)
164 deallog <<
"No smaller stepsize allowed!";
167 if (control.log_history())
168 deallog <<
"Trying step size: 1/" << (1<<step_size)
169 <<
" since residual was " << resnorm << std::endl;
170 u.add(1./(1<<step_size), *Du);
171 (*residual)(out1, src1);
172 resnorm = res->l2_norm();
180 control.last_value()));
186 DEAL_II_NAMESPACE_CLOSE
const double last_residual
static void declare_parameters(ParameterHandler ¶m)
void add(DATA &v, const std::string &name)
void initialize(ParameterHandler ¶m)
#define AssertThrow(cond, exc)
virtual void operator()(NamedData< VECTOR * > &out, const NamedData< VECTOR * > &in)
void enter_subsection(const std::string &subsection)
Newton(Operator< VECTOR > &residual, Operator< VECTOR > &inverse_derivative)
const unsigned int last_step
Stop iteration, goal reached.
#define Assert(cond, exc)
const Event bad_derivative
unsigned int size() const
Number of stored data objects.
void declare_parameters(ParameterHandler ¶m)
void merge(NamedData< DATA2 > &)
bool get_bool(const std::string &entry_name) const
void push(const std::string &text)
virtual void notify(const Event &)
double get_double(const std::string &entry_name) const
void declare_entry(const std::string &entry, const std::string &default_value, const Patterns::PatternBase &pattern=Patterns::Anything(), const std::string &documentation=std::string())
::ExceptionBase & ExcNotImplemented()
long int get_integer(const std::string &entry_string) const