18 template <
typename _Type>
22 double derivative_step)
26 p_RESIDUAL(ptr_to_residual_object) {
27 p_RESIDUAL -> delta() = derivative_step;
28 DELTA = derivative_step;
34 template <
typename _Type>
37 unsigned N = x.
size();
52 p_RESIDUAL -> update(x);
54 oldFn = p_RESIDUAL -> residual();
56 std::cout <<
" DEBUG: starting with |Residuals| = " << oldFn.inf_norm() <<
"\n";
59 if((std::abs(oldFn.inf_norm()) < TOL) || (itn == MAX_STEPS)) {
63 J = p_RESIDUAL -> jacobian();
70 std::cout <<
" DEBUG: Iteration number = " << itn <<
"\n";
71 std::cout <<
" DEBUG: |Newton correction| = " << oldFn.inf_norm() <<
"\n";
79 if(itn == MAX_STEPS) {
81 problem =
" The Newton.iterate method took too many iterations. \n";
82 problem +=
" At the moment, this is set as a failure. \n";
89 problem =
"[ INFO ] : Determinant monitor has changed signs in ODE_BVP.\n";
90 problem +=
"[ INFO ] : Bifurcation detected.\n";
97 template <
typename _Type>
100 if(!
this -> INITIALISED) {
102 problem =
"The Newton.arclength_solve method has been called, but \n";
103 problem +=
" you haven't called the arc_init method first. This means \n";
104 problem +=
" that a starting solution & derivatives thereof are unknown. \n";
105 problem +=
" Please initialise things appropriately! ";
110 std::cout.precision(6);
111 std::cout <<
"[ DEBUG ] : Entering arclength_solve of the Newton class with\n";
112 std::cout <<
"[ DEBUG ] : a parameter of " << *(
this -> p_PARAM) <<
"\n";
116 _Type backup_parameter(*(
this -> p_PARAM));
120 bool step_succeeded(
false);
123 *(
this -> p_PARAM) =
this -> LAST_PARAM +
this -> PARAM_DERIV_S *
this -> DS;
124 x =
this -> LAST_X +
this -> X_DERIV_S *
this -> DS;
127 unsigned N =
this -> p_RESIDUAL -> get_order();
135 this -> p_RESIDUAL -> update(x);
137 J =
this -> p_RESIDUAL -> jacobian();
138 R1 =
this -> p_RESIDUAL -> residual();
140 double E1 =
this -> arclength_residual(x);
142 *(
this -> p_PARAM) +=
this -> DELTA;
143 this -> p_RESIDUAL -> residual_fn(x, R2);
144 double E2 =
this -> arclength_residual(x);
145 *(
this -> p_PARAM) -=
this -> DELTA;
146 dR_dp = (R2 - R1) /
this -> DELTA;
147 _Type dE_dp = (E2 - E1) /
this -> DELTA;
164 J =
this -> p_RESIDUAL -> jacobian();
179 double max_correction = std::max(delta_x.
inf_norm(), std::abs(delta_p));
180 if(max_correction < this -> TOL) {
181 step_succeeded =
true;
186 *(
this -> p_PARAM) += delta_p;
188 if(itn > MAX_STEPS) {
189 step_succeeded =
false;
195 if(!step_succeeded) {
197 std::cout <<
"[ DEBUG ] : REJECTING STEP \n";
201 *(
this -> p_PARAM) = backup_parameter;
203 this -> p_RESIDUAL -> update(x);
205 this -> DS /=
this -> ARCSTEP_MULTIPLIER;
209 if(LAST_DET_SIGN * det_sign < 0) {
210 LAST_DET_SIGN = det_sign;
212 problem =
"[ INFO ] : Determinant monitor has changed signs in the Newton class.\n";
213 problem +=
"[ INFO ] : Bifurcation detected.\n";
216 LAST_DET_SIGN = det_sign;
219 std::cout <<
"[ DEBUG ] : Number of iterations = " << itn <<
"\n";
220 std::cout <<
"[ DEBUG ] : Parameter p = " << *(
this -> p_PARAM)
221 <<
"; arclength DS = " <<
this -> DS <<
"\n";
225 this -> DS /=
this -> ARCSTEP_MULTIPLIER;
227 std::cout <<
"[ DEBUG ] : I decreased DS to " <<
this -> DS <<
"\n";
231 if(std::abs(
this -> DS *
this -> ARCSTEP_MULTIPLIER) <
this -> MAX_DS) {
233 this -> DS *=
this -> ARCSTEP_MULTIPLIER;
235 std::cout <<
"[ DEBUG ] : I increased DS to " <<
this -> DS <<
"\n";
A base class for arclength-capable solvers.
Specification of the linear system class.
The collection of CppNoddy exceptions.
A vector NEWTON iteration class.
A specification of a (double/complex) VECTOR residual class.
A linear system class for vector right-hand sides.
void set_monitor_det(bool flag)
Store the sign of the determinant of the LHS matrix every time a solve is requested on a real system.
int get_det_sign() const
Get the sign of the determinant of the LHS matrix from the linear system just computed.
void solve()
Solve the sparse system.
A matrix class that constructs a DENSE matrix as a row major std::vector of DenseVectors.
An DenseVector class – a dense vector object.
double inf_norm() const
Infinity norm.
std::size_t size() const
A pass-thru definition to get the size of the vector.
An exception to indicate that an error has been detected in an external (LAPACK) routine.
An exception class that is thrown if too many Newton steps are taken in either the scalar or vector N...
A generic runtime exception.
A vector NEWTON iteration class.
void iterate(DenseVector< _Type > &x)
The Newton iteration method.
void arclength_solve(DenseVector< _Type > &x)
Arc-length solve the system.
Newton(Residual< _Type > *ptr_to_residual_object, unsigned max_steps=20, double tolerance=1.e-8, double derivative_step=1.e-8)
Constructor.
A base class to be inherited by objects that define residuals.
_Type dot(const DenseVector< _Type > &X, const DenseVector< _Type > &Y)
Templated dot product.
A collection of OO numerical routines aimed at simple (typical) applied problems in continuum mechani...