File: NonLinearSolver.h

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (105 lines) | stat: -rw-r--r-- 2,279 bytes parent folder | download | duplicates (2)
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
#ifndef NON_LINEAR_SOLVER_H
#define NON_LINEAR_SOLVER_H

// ATC includes
#include "ATC_TypeDefs.h"
#include "MatrixLibrary.h"
#include "ATC_Error.h"

// other includes
#include <set>
#include <map>

namespace ATC {

/**
 *  @class TangentOperator
 *  @brief an adaptor to allow NonLinearSolver to work with a generic function
 */
class TangentOperator {
 public:
  TangentOperator(){};
  virtual ~TangentOperator(){};
  virtual void function(const VECTOR & /* x */, DENS_VEC & /* f */) {}; // =0;
  virtual void tangent(const VECTOR & x, DENS_VEC & f, MATRIX & dfdx) =0;
  //virtual void function(const VECTOR & x, VECTOR & f) {}; // =0;
  //virtual void tangent(const VECTOR & x, VECTOR & f, MATRIX & dfdx) {}; // =0;
};

/**
 *  @class NonLinearSolver
 *  @brief a class to solve a system of non-linear equations
 *  f(x) = 0
 */


class NonLinearSolver {

 public:
  enum NonLinearSolveType {
    NEWTON_RAPHSON=0,
  };

  /** Constructor */
  NonLinearSolver(
    TangentOperator * f, // provides f and f' at x, pointer for polymorphism
    const BC_SET * bcs = nullptr,
    const int dof = 0,
    bool parallel = false
  );

  /** Destructor */
  virtual ~NonLinearSolver() {};

  /** residual norm */
  double residual_norm(VECTOR & x);

  /** solve */
  bool solve(VECTOR & x); // incoming: initial guess, outgoing: solution

  /** line search */
  bool line_search(VECTOR & x);


  /** access to current state */
  DENS_MAT & tangent()  { return A_;}
  DENS_VEC & residual() { return r_;}


  /** change solver parameters */
  void set_max_iterations(const int maxIter) { maxIterations_=maxIter; }
  void set_residual_tolerance(const double tol) { tol_=tol;}
  void set_solution_tolerance(const double tol) { tolx_=tol;}

 protected:
  /** function & tangent */
  TangentOperator * f_;
  DENS_VEC r_;
  DENS_MAT A_;
  DENS_VEC dx_;

  /** equality constraints */
  const BC_SET * bcs_;

  /** degree of freedom */
  int dof_;

  /** flavors */
  int solverType_;

  /** state */
  double rNorm0_, rNorm0P_, rNorm_, rNormP_;

  /** parameters & tolerances */
  double tol_; // tolerance on f
  double tolx_; // tolerance on dx
  double tol0_; // tolerance on initial f
  int maxIterations_;

  /** run solve in parallel */
  bool parallel_;
};

} // namespace ATC

#endif