-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathNewton.h
103 lines (90 loc) · 2.63 KB
/
Newton.h
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
#ifndef NEWTON_H
#define NEWTON_H
#include <fstream>
#include "Definitions.h"
#include "NonlinearSolver.h"
#include "Utilities.h"
#include "LinearSolver.h"
#include "Jacobian.h"
#include "VectorNorm.h"
#include "DataCollector.h"
#include "Vec.h"
#include "VecOperators.h"
#include "VecBlas.h"
namespace Daetk
{
class Newton : public NonlinearSolver
{
public:
enum LineSearchType { poorMansLS, cubicLS, armijoLS };
void setConvergenceFactor(const real&){}
void recomputeConvergenceRate(){}
Newton();
Newton(LinearSolver& linearSolverIn, Jacobian& jacIn,VectorNorm& W,
DataCollector& dataIn, int neq, real lTol=0.005*0.33,
real nlTol=0.33, int maxit=4,
LineSearchType lsType = poorMansLS);
void testResidual(real tol);
void testConvergenceRate(bool flag=true);
void linearSolverIsInexact();
virtual ~Newton();
bool solve(Vec& correction,VectorFunction& F);
void computeRate();
bool converged(VectorFunction& F);
virtual void useLineSearch(int nls=10);
virtual void usePicardHybrid(){USE_PICARD_HYBRID=true;}
virtual void setLineSearchFact(real lsRedIn);
virtual void setLineSearchMethod(LineSearchType lsType);
bool logSteps(bool yesNo=true){LOG_STEPS=yesNo; return false;}
//mwf added for NonIterative time integrators
virtual void setMaxIterations(const int& maxItIn)
{ maxIterations = maxItIn; }
virtual int getMaxIterations()
{ return maxIterations; }
protected:
bool USE_LINE_SEARCH,LOG_STEPS,USE_PICARD_HYBRID;
LineSearchType lineSearchMethod;
int nLineSearches;
real lsRedFact;
//
bool INEXACT_LINEAR_SOLVER,
TEST_RESIDUAL,
TEST_RATE,
evalError;
int iterations,
maxIterations,
lin_it;
real s,
rate,
normOfInitialGuess,
norm2OfInitialGuess,
normOfLastCorrection,
normOfCorrection,
nonlinearTolerance,
roundOffTolerance,
r0,
resTol,
linearTolerance,FnNew,FnOld;
Vec p,pLS,p0,tmpArg,tmpF,argPrev,funPrev,
residual;
VectorNorm* weightedNorm;
DataCollector* data;
LinearSolver* linearSolver;
std::ofstream mnout;
//go through and perform switch to see which linesearch to use
bool lineSearch(Vec& yp,Vec& ppLS, const Vec& pp,Vec& Fp,Vec& Fnew,
bool& evalFailed,
VectorFunction& F);
bool cubicLineSearch(Vec& yp,Vec& ppLS, const Vec& pp,Vec& Fp,Vec& Fnew,
bool& evalFailed,
VectorFunction& F);
bool poorMansLineSearch(Vec& yp,Vec& ppLS, const Vec& pp,Vec& Fp,Vec& Fnew,
bool& evalFailed,
VectorFunction& F);
bool armijoLineSearch(Vec& yp,Vec& ppLS, const Vec& pp,Vec& Fp,Vec& Fnew,
bool& evalFailed,
VectorFunction& F);
Jacobian* jac;
};
}//Daetk
#endif