iMSTK
Interactive Medical Simulation Toolkit
imstkNewtonSolver.h
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #pragma once
8 
9 #include "imstkNonLinearSolver.h"
10 #include "imstkLinearSolver.h"
11 
12 namespace imstk
13 {
23 template<typename SystemMatrix>
24 class NewtonSolver : public NonLinearSolver<SystemMatrix>
25 {
26 public:
28 
29  NewtonSolver();
30  ~NewtonSolver() override = default;
31 
35  NewtonSolver(const NewtonSolver& other) = delete;
36  NewtonSolver(const NewtonSolver&& other) = delete;
37  NewtonSolver& operator=(const NewtonSolver& other) = delete;
38  NewtonSolver& operator=(const NewtonSolver&& other) = delete;
39 
45  void solveGivenState(Vectord& x) override;
46  void solve() override;
47 
56  void updateForcingTerm(const double ratio,
57  const double stopTolerance,
58  const double fnorm);
59 
65  void setLinearSolver(std::shared_ptr<LinearSolverType> newLinearSolver)
66  {
67  m_linearSolver = newLinearSolver;
68  }
69 
73  // std::shared_ptr<LinearSolverType> getLinearSolver() const;
74  auto getLinearSolver() const->std::shared_ptr<LinearSolverType>;
75 
81  double updateJacobian(const Vectord& x);
82 
86  //SystemMatrix& getJacobianMatrix();
87 
93  void setAbsoluteTolerance(const double aTolerance);
94 
98  double getAbsoluteTolerance() const;
99 
105  void setRelativeTolerance(const double newRelativeTolerance)
106  {
107  m_relativeTolerance = newRelativeTolerance;
108  }
109 
113  double getRelativeTolerance() const { return m_relativeTolerance; }
114 
120  void setGamma(const double newGamma) { m_gamma = newGamma; }
121 
125  double getGamma() const { return m_gamma; }
126 
135  void setEtaMax(const double newEtaMax)
136  {
137  m_etaMax = newEtaMax;
138  }
139 
143  double getEtaMax() const { return m_etaMax; }
144 
148  void setMaxIterations(const size_t newMaxIterations)
149  {
150  m_maxIterations = newMaxIterations;
151  }
152 
156  size_t getMaxIterations() const { return m_maxIterations; }
157 
162  void setUseArmijo(const bool value)
163  {
164  m_useArmijo = value;
165  (value) ? this->m_armijoMax = 30 : this->m_armijoMax = 0;
166  }
167 
171  bool getUseArmijo() const { return m_useArmijo; }
172 
177  void setForcingTerm(const double value) { m_forcingTerm = value; }
178 
182  double getForcingTerm() const { return m_forcingTerm; }
183 
187  void setToFullyImplicit() override
188  {
189  this->m_isSemiImplicit = false;
190  }
191 
195  void setToSemiImplicit() override
196  {
197  this->m_isSemiImplicit = true;
198  m_maxIterations = 1;
199  }
200 
201 private:
202  std::shared_ptr<LinearSolverType> m_linearSolver;
203  double m_forcingTerm;
204  double m_absoluteTolerance;
205  double m_relativeTolerance;
206  double m_gamma;
207  double m_etaMax;
208  size_t m_maxIterations;
209  bool m_useArmijo;
210  std::vector<double> m_fnorms;
211 };
212 } // namespace imstk
auto getLinearSolver() const -> std::shared_ptr< LinearSolverType >
Get LinearSolver.
void solveGivenState(Vectord &x) override
Solve the non linear system of equations G(x)=0 using Newton&#39;s method.
bool m_isSemiImplicit
Semi-Implicit solver.
size_t m_armijoMax
Maximum number of step length reductions.
double getRelativeTolerance() const
Get RelativeTolerance. Returns current relative tolerance value.
void setAbsoluteTolerance(const double aTolerance)
Get JacobianMatrix. Returns jacobian matrix.
Compound Geometry.
void setForcingTerm(const double value)
Set the useArmijo flag. If useArmijo is true a line search is performed using the Armijo-Goldstein co...
double getGamma() const
Get Gamma. Returns current gamma value.
bool getUseArmijo() const
Get MaxIterations. Returns current maximum nonlinear iterations.
void setEtaMax(const double newEtaMax)
Set EtaMax. Maximum error tolerance for residual in inner iteration. The inner iteration terminates w...
void setUseArmijo(const bool value)
Set the useArmijo flag. If useArmijo is true a line search is performed using the Armijo-Goldstein co...
double getForcingTerm() const
Get MaxIterations. Returns current maximum nonlinear iterations.
void updateForcingTerm(const double ratio, const double stopTolerance, const double fnorm)
Update forcing term according to Eisenstat-Walker criteria.
void setMaxIterations(const size_t newMaxIterations)
Set MaxIterations. The maximum number of nonlinear iterations.
void setGamma(const double newGamma)
Set Gamma. Sets the gamma parameter used to update the forcing term.
void setToSemiImplicit() override
Set the Newton solver to be fully implicit.
void setLinearSolver(std::shared_ptr< LinearSolverType > newLinearSolver)
Set LinearSolver.
void setRelativeTolerance(const double newRelativeTolerance)
Set RelativeTolerance.
Base class for non-linear solvers.
double updateJacobian(const Vectord &x)
Update jacobians.
Base class for linear solvers.
double getAbsoluteTolerance() const
Get AbsoluteTolerance. Returns current tolerance value.
Newton method. This version of the newton method is based on the work by Tim Kelly and others at NC S...
double getEtaMax() const
Get EtaMax. Returns current etaMax value.
size_t getMaxIterations() const
Get MaxIterations. Returns current maximum nonlinear iterations.
void setToFullyImplicit() override
Set the Newton solver to be fully implicit.