7 #ifndef __darcy_checkerboard_constrained_newton_h 8 #define __darcy_checkerboard_constrained_newton_h 10 #include <deal.II/algorithms/newton.h> 12 #include <deal.II/base/logstream.h> 13 #include <deal.II/lac/vector_memory.h> 17 namespace Checkerboard
29 template <
class VECTOR>
34 virtual void operator()(AnyData& out,
const AnyData& in);
36 bool constraint_violation(
const VECTOR& u);
39 SmartPointer<OperatorBase, Newton<VECTOR>>
residual;
46 template <
class VECTOR>
48 OperatorBase& inverse_derivative)
49 : Newton<VECTOR>(residual, inverse_derivative)
51 , inverse_derivative(&inverse_derivative)
52 , n_stepsize_iterations(21)
56 template <
class VECTOR>
60 Assert(out.size() == 1, ExcNotImplemented());
61 deallog.push(
"Newton");
63 VECTOR& u = *out.entry<VECTOR*>(0);
65 GrowingVectorMemory<VECTOR> mem;
66 typename VectorMemory<VECTOR>::Pointer Du(mem);
67 typename VectorMemory<VECTOR>::Pointer res(mem);
72 src1.add<
const VECTOR*>(&u,
"Newton iterate");
74 src2.add<
const VECTOR*>(res,
"Newton residual");
77 out1.add<VECTOR*>(res,
"Residual");
79 out2.add<VECTOR*>(Du,
"Update");
81 unsigned int step = 0;
83 (*residual)(out1, src1);
84 double resnorm = res->l2_norm();
87 while (this->control.check(step++, resnorm) == SolverControl::iterate)
92 (*inverse_derivative)(out2, src2);
94 catch (SolverControl::NoConvergence& e)
96 deallog <<
"Inner iteration failed after " << e.last_step <<
" steps with residual " 97 << e.last_residual << std::endl;
101 old_residual = resnorm;
102 (*residual)(out1, src1);
103 resnorm = res->l2_norm();
106 unsigned int step_size = 0;
112 deallog <<
"No smaller stepsize allowed!";
115 if (this->control.log_history())
116 deallog <<
"Trying step size: 1/" << (1 << step_size) <<
" since residual was " << resnorm
118 u.add(1. / (1 << step_size), *Du);
119 (*residual)(out1, src1);
120 resnorm = res->l2_norm();
126 if (this->control.last_check() != SolverControl::success)
128 false, SolverControl::NoConvergence(this->control.last_step(), this->control.last_value()));
132 template <
class VECTOR>
139 if (!(0.0 < gamma && gamma < 2))
143 if (!(std::max(0.0, numbers::PI * gamma - numbers::PI) < 2 * rho * gamma &&
144 2 * rho * gamma < std::min(numbers::PI * gamma, numbers::PI)))
148 if (!(std::max(0.0, numbers::PI - numbers::PI * gamma) < -2 * sigma * gamma &&
149 -2 * sigma * gamma < std::min(numbers::PI, 2 * numbers::PI - numbers::PI * gamma)))
bool constraint_violation(const VECTOR &u)
Definition: constrained_newton.h:134
virtual void operator()(AnyData &out, const AnyData &in)
Definition: constrained_newton.h:58
SmartPointer< OperatorBase, Newton< VECTOR > > inverse_derivative
Definition: constrained_newton.h:41
const unsigned int n_stepsize_iterations
Definition: constrained_newton.h:43
Definition: constrained_newton.h:30
Definition: constrained_newton.h:15
ConstrainedNewton(OperatorBase &residual, OperatorBase &inverse_derivative)
Definition: constrained_newton.h:47
SmartPointer< OperatorBase, Newton< VECTOR > > residual
Definition: constrained_newton.h:39