/usr/include/deal.II/algorithms/newton.templates.h is in libdeal.ii-dev 8.1.0-6ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | // ---------------------------------------------------------------------
// $Id: newton.templates.h 31349 2013-10-20 19:07:06Z maier $
//
// Copyright (C) 2006 - 2013 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#include <deal.II/algorithms/newton.h>
#include <deal.II/base/parameter_handler.h>
#include <deal.II/base/logstream.h>
#include <deal.II/lac/vector_memory.h>
#include <iomanip>
DEAL_II_NAMESPACE_OPEN
namespace Algorithms
{
template <class VECTOR>
Newton<VECTOR>::Newton(Operator<VECTOR> &residual, Operator<VECTOR> &inverse_derivative)
:
residual(&residual), inverse_derivative(&inverse_derivative),
assemble_now(false),
n_stepsize_iterations(21),
assemble_threshold(0.),
debug_vectors(false),
debug(0)
{}
template <class VECTOR>
void
Newton<VECTOR>::declare_parameters(ParameterHandler ¶m)
{
param.enter_subsection("Newton");
ReductionControl::declare_parameters (param);
param.declare_entry("Assemble threshold", "0.", Patterns::Double());
param.declare_entry("Stepsize iterations", "21", Patterns::Integer());
param.declare_entry("Debug level", "0", Patterns::Integer());
param.declare_entry("Debug vectors", "false", Patterns::Bool());
param.leave_subsection();
}
template <class VECTOR>
void
Newton<VECTOR>::initialize (ParameterHandler ¶m)
{
param.enter_subsection("Newton");
control.parse_parameters (param);
assemble_threshold = param.get_double("Assemble threshold");
n_stepsize_iterations = param.get_integer("Stepsize iterations");
debug_vectors = param.get_bool("Debug vectors");
param.leave_subsection ();
}
template <class VECTOR>
void
Newton<VECTOR>::initialize (OutputOperator<VECTOR> &output)
{
data_out = &output;
}
template <class VECTOR>
void
Newton<VECTOR>::notify(const Event &e)
{
residual->notify(e);
inverse_derivative->notify(e);
}
template <class VECTOR>
void
Newton<VECTOR>::operator() (NamedData<VECTOR *> &out, const NamedData<VECTOR *> &in)
{
Assert (out.size() == 1, ExcNotImplemented());
deallog.push ("Newton");
VECTOR &u = *out(0);
if (debug>2)
deallog << "u: " << u.l2_norm() << std::endl;
GrowingVectorMemory<VECTOR> mem;
typename VectorMemory<VECTOR>::Pointer Du(mem);
typename VectorMemory<VECTOR>::Pointer res(mem);
res->reinit(u);
NamedData<VECTOR *> src1;
NamedData<VECTOR *> src2;
VECTOR *p = &u;
src1.add(p, "Newton iterate");
src1.merge(in);
p = res;
src2.add(p, "Newton residual");
src2.merge(src1);
NamedData<VECTOR *> out1;
out1.add(p, "Residual");
p = Du;
NamedData<VECTOR *> out2;
out2.add(p, "Update");
unsigned int step = 0;
// fill res with (f(u), v)
(*residual)(out1, src1);
double resnorm = res->l2_norm();
double old_residual = resnorm / assemble_threshold + 1;
while (control.check(step++, resnorm) == SolverControl::iterate)
{
// assemble (Df(u), v)
if (resnorm/old_residual >= assemble_threshold)
inverse_derivative->notify (Events::bad_derivative);
Du->reinit(u);
try
{
(*inverse_derivative)(out2, src2);
}
catch (SolverControl::NoConvergence &e)
{
deallog << "Inner iteration failed after "
<< e.last_step << " steps with residual "
<< e.last_residual << std::endl;
}
if (debug_vectors)
{
NamedData<VECTOR *> out;
VECTOR *p = &u;
out.add(p, "solution");
p = Du;
out.add(p, "update");
p = res;
out.add(p, "residual");
*data_out << step;
*data_out << out;
}
u.add(-1., *Du);
old_residual = resnorm;
(*residual)(out1, src1);
resnorm = res->l2_norm();
// Step size control
unsigned int step_size = 0;
while (resnorm >= old_residual)
{
++step_size;
if (step_size > n_stepsize_iterations)
{
deallog << "No smaller stepsize allowed!";
break;
}
if (control.log_history())
deallog << "Trying step size: 1/" << (1<<step_size)
<< " since residual was " << resnorm << std::endl;
u.add(1./(1<<step_size), *Du);
(*residual)(out1, src1);
resnorm = res->l2_norm();
}
}
deallog.pop();
// in case of failure: throw exception
if (control.last_check() != SolverControl::success)
AssertThrow(false, SolverControl::NoConvergence (control.last_step(),
control.last_value()));
// otherwise exit as normal
}
}
DEAL_II_NAMESPACE_CLOSE
|