G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsStaticNewton.h
Go to the documentation of this file.
1 
14 #include <typeinfo>
15 
17 #pragma once
18 
19 
20 namespace gismo
21 {
22 
30 template <class T>
31 class gsStaticNewton : public gsStaticBase<T>
32 {
33 protected:
34 
35  typedef gsStaticBase<T> Base;
36 
37  typedef typename Base::Residual_t Residual_t;
38  typedef typename Base::ALResidual_t ALResidual_t;
39  typedef typename Base::Jacobian_t Jacobian_t;
40  typedef typename Base::dJacobian_t dJacobian_t;
41 
42 public:
43 
51  const gsVector<T> &force )
52  :
53  m_linear(linear),
54  m_force(force),
55  m_nonlinear(nullptr),
56  m_residualFun(nullptr)
57  {
58  this->_init();
59  }
60 
70  const gsVector<T> &force,
71  const Jacobian_t &nonlinear,
72  const Residual_t &residual )
73  :
74  m_linear(linear),
75  m_force(force),
76  m_nonlinear(nonlinear),
77  m_dnonlinear(nullptr),
78  m_residualFun(residual),
79  m_ALresidualFun(nullptr)
80  {
81  m_dnonlinear = [this](gsVector<T> const & x, gsVector<T> const & dx, gsSparseMatrix<T> & m) -> bool
82  {
83  return m_nonlinear(x,m);
84  };
85 
86  this->_init();
87  }
88 
98  const gsVector<T> &force,
99  const Jacobian_t &nonlinear,
100  const ALResidual_t &ALResidual )
101  :
102  m_linear(linear),
103  m_force(force),
104  m_nonlinear(nonlinear),
105  m_dnonlinear(nullptr),
106  m_residualFun(nullptr),
107  m_ALresidualFun(ALResidual)
108  {
109  m_L = 1.0;
110  m_residualFun = [this](gsVector<T> const & x, gsVector<T> & result) -> bool
111  {
112  return m_ALresidualFun(x,m_L,result);
113  };
114 
115  m_dnonlinear = [this](gsVector<T> const & x, gsVector<T> const & dx, gsSparseMatrix<T> & m) -> bool
116  {
117  return m_nonlinear(x,m);
118  };
119 
120  this->_init();
121  }
122 
132  const gsVector<T> &force,
133  const dJacobian_t &dnonlinear,
134  const Residual_t &residual
135  )
136  :
137  m_linear(linear),
138  m_force(force),
139  m_nonlinear(nullptr),
140  m_dnonlinear(dnonlinear),
141  m_residualFun(residual),
142  m_ALresidualFun(nullptr)
143  {
144  this->_init();
145  }
146 
147 public:
148 
150  gsStatus solve() override
151  {
152  if (m_NL)
153  return solveNonlinear();
154  else
155  return solveLinear();
156  }
160  {
161  gsStatus status = this->solveLinear();
162  solution = m_U;
163  return status;
164  }
167  {
168  gsStatus status = this->solveNonlinear();
169  solution = m_U;
170  return status;
171  }
172  gsStatus solveNonlinear();
173 
175  void initOutput() override;
176 
178  void stepOutput(index_t k) override;
179 
181  void defaultOptions() override;
182 
184  void reset() override;
185 
187  void getOptions() override;
188 
189  using Base::indicator;
190  using Base::stabilityVec;
191 
194  {
196  GISMO_ENSURE(m_nonlinear(m_U, m),"Assembly failed");
197  return indicator(m);
198  }
199 
202  {
204  GISMO_ENSURE(m_nonlinear(m_U, m),"Assembly failed");
205  return stabilityVec(m);
206  }
207 
208 protected:
209 
214 
216 
218  void _init();
220  void _start();
222  void _factorizeMatrix(const gsSparseMatrix<T> & jacMat) const;
225 
226  gsVector<T> _computeResidual(const gsVector<T> & U);
227 
228  gsSparseMatrix<T> _computeJacobian(const gsVector<T> & U, const gsVector<T> & deltaU);
229 
230 protected:
231 
232  const gsSparseMatrix<T> & m_linear;
233  const gsVector<T> & m_force;
234  const Jacobian_t m_nonlinear;
235  dJacobian_t m_dnonlinear;
236  Residual_t m_residualFun;
237  const ALResidual_t m_ALresidualFun;
238 
239  using Base::m_R;
240 
241  using Base::m_U;
242  using Base::m_DeltaU;
243  using Base::m_deltaU;
244 
245  using Base::m_L;
246 
247  using Base::m_stabilityVec;
248 
249  using Base::m_verbose;
250 
251  bool m_NL;
252 
253  using Base::m_options;
254 
255  using Base::m_tolF;
256  using Base::m_tolU;
257 
258  mutable T m_relax;
259 
260  using Base::m_maxIterations;
261  using Base::m_numIterations;
262 
263  // Residual norms
264  using Base::m_residual;
265  using Base::m_residualIni;
266  using Base::m_residualOld;
267 
268  using Base::m_start;
269  using Base::m_headstart;
270 
272  using Base::m_solver; // Cholesky by default
273 
274  using Base::m_stabilityMethod;
275 
277  using Base::m_indicator;
278 
279  using Base::m_dofs;
280 
281  // Solver status
282  using Base::m_status;
283 };
284 
285 
286 } // namespace gismo
287 
288 
289 #ifndef GISMO_BUILD_LIB
290 #include GISMO_HPP_HEADER(gsStaticNewton.hpp)
291 #endif
Base class for static solvers.
void _factorizeMatrix(const gsSparseMatrix< T > &jacMat) const
Factorizes the jacMat.
Definition: gsStaticNewton.hpp:216
void getOptions() override
See gsStaticBase.
Definition: gsStaticNewton.hpp:29
void _start()
Starts the method.
Definition: gsStaticNewton.hpp:274
gsVector< T > _solveLinear()
Perform a linear solve.
Definition: gsStaticNewton.hpp:102
virtual gsVector< T > solution() const
Access the solution.
Definition: gsStaticBase.h:95
T indicator()
See gsStaticBase.
Definition: gsStaticNewton.h:193
Static solver using a newton method.
Definition: gsStaticNewton.h:31
#define index_t
Definition: gsConfig.h:32
gsStatus
Definition: gsStructuralAnalysisTypes.h:20
#define GISMO_ENSURE(cond, message)
Definition: gsDebug.h:102
virtual T indicator(const gsSparseMatrix< T > &jacMat, T shift=-1e-2)
Returns the stability indicator.
Definition: gsStaticBase.h:146
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const Jacobian_t &nonlinear, const ALResidual_t &ALResidual)
Constructor.
Definition: gsStaticNewton.h:97
gsVector< T > _solveSystem(const gsVector< T > &F)
Solves the system with RHS F and LHS the Jacobian.
Definition: gsStaticNewton.hpp:231
gsVector< T > stabilityVec()
See gsStaticBase.
Definition: gsStaticNewton.h:201
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const Jacobian_t &nonlinear, const Residual_t &residual)
Constructor.
Definition: gsStaticNewton.h:69
gsStatus solveNonlinear(gsVector< T > &solution)
Perform a nonlinearg solve.
Definition: gsStaticNewton.h:166
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const dJacobian_t &dnonlinear, const Residual_t &residual)
{ function_description }
Definition: gsStaticNewton.h:131
void initOutput() override
See gsStaticBase.
Definition: gsStaticNewton.hpp:43
void _init()
Initializes the method.
Definition: gsStaticNewton.hpp:252
void reset() override
See gsStaticBase.
Definition: gsStaticNewton.hpp:244
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force)
Constructor.
Definition: gsStaticNewton.h:50
gsStatus solveLinear()
Perform a linear solve.
Definition: gsStaticNewton.hpp:76
gsVector< T > _solveNonlinear()
Perform a nonlinear solve.
Definition: gsStaticNewton.hpp:143
virtual gsVector< T > stabilityVec(const gsSparseMatrix< T > &jacMat, T shift=-1e-2)
Returns the stability vector.
Definition: gsStaticBase.h:153
gsStatus solve() override
See gsStaticBase.
Definition: gsStaticNewton.h:150
void stepOutput(index_t k) override
See gsStaticBase.
Definition: gsStaticNewton.hpp:59
virtual bool _computeStability(const gsSparseMatrix< T > &jacMat, T shift)
Computes the stability of the Jacobian, optionally applying a shift (if provided) ...
Definition: gsStaticBase.h:220
virtual gsStatus status() const
Returns the status.
Definition: gsStaticBase.h:129
void defaultOptions() override
See gsStaticBase.
Definition: gsStaticNewton.hpp:21
Base class for static solvers.
Definition: gsStaticBase.h:37