G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsStaticNewton.h
Go to the documentation of this file.
1
15#pragma once
16
17
18namespace gismo
19{
20
28template <class T>
30{
31protected:
32
33 typedef gsStaticBase<T> Base;
34
35 typedef typename Base::Residual_t Residual_t;
36 typedef typename Base::ALResidual_t ALResidual_t;
37 typedef typename Base::Jacobian_t Jacobian_t;
38 typedef typename Base::dJacobian_t dJacobian_t;
39
40public:
41
49 const gsVector<T> &force )
50 :
51 m_linear(linear),
52 m_force(force),
53 m_nonlinear(nullptr),
54 m_residualFun(nullptr)
55 {
56 this->_init();
57 }
58
68 const gsVector<T> &force,
69 const Jacobian_t &nonlinear,
70 const Residual_t &residual )
71 :
72 m_linear(linear),
73 m_force(force),
74 m_nonlinear(nonlinear),
75 m_dnonlinear(nullptr),
76 m_residualFun(residual),
77 m_ALresidualFun(nullptr)
78 {
79 m_dnonlinear = [this](gsVector<T> const & x, gsVector<T> const & /*dx*/, gsSparseMatrix<T> & m) -> bool
80 {
81 return m_nonlinear(x,m);
82 };
83
84 this->_init();
85 }
86
96 const gsVector<T> &force,
97 const Jacobian_t &nonlinear,
98 const ALResidual_t &ALResidual )
99 :
100 m_linear(linear),
101 m_force(force),
102 m_nonlinear(nonlinear),
103 m_dnonlinear(nullptr),
104 m_residualFun(nullptr),
105 m_ALresidualFun(ALResidual)
106 {
107 m_L = 1.0;
108 m_residualFun = [this](gsVector<T> const & x, gsVector<T> & result) -> bool
109 {
110 return m_ALresidualFun(x,m_L,result);
111 };
112
113 m_dnonlinear = [this](gsVector<T> const & x, gsVector<T> const & /*dx*/, gsSparseMatrix<T> & m) -> bool
114 {
115 return m_nonlinear(x,m);
116 };
117
118 this->_init();
119 }
120
130 const gsVector<T> &force,
131 const dJacobian_t &dnonlinear,
132 const Residual_t &residual
133 )
134 :
135 m_linear(linear),
136 m_force(force),
137 m_nonlinear(nullptr),
138 m_dnonlinear(dnonlinear),
139 m_residualFun(residual),
140 m_ALresidualFun(nullptr)
141 {
142 this->_init();
143 }
144
145public:
146
148 gsStatus solve() override
149 {
150 if (m_NL)
151 return solveNonlinear();
152 else
153 return solveLinear();
154 }
158 {
159 gsStatus status = this->solveLinear();
160 solution = m_U;
161 return status;
162 }
165 {
167 solution = m_U;
168 return status;
169 }
170 gsStatus solveNonlinear();
171
173 void initOutput() override;
174
176 void stepOutput(index_t k) override;
177
179 void defaultOptions() override;
180
182 void reset() override;
183
185 void getOptions() override;
186
187 using Base::indicator;
188 using Base::stabilityVec;
189
192 {
194 GISMO_ENSURE(m_nonlinear(m_U, m),"Assembly failed");
195 return indicator(m);
196 }
197
200 {
202 GISMO_ENSURE(m_nonlinear(m_U, m),"Assembly failed");
203 return stabilityVec(m);
204 }
205
206protected:
207
212
214
216 void _init();
218 void _start();
220 void _factorizeMatrix(const gsSparseMatrix<T> & jacMat) const;
223
224 gsVector<T> _computeResidual(const gsVector<T> & U);
225
226 gsSparseMatrix<T> _computeJacobian(const gsVector<T> & U, const gsVector<T> & deltaU);
227
228protected:
229
230 const gsSparseMatrix<T> & m_linear;
231 const gsVector<T> & m_force;
232 const Jacobian_t m_nonlinear;
233 dJacobian_t m_dnonlinear;
234 Residual_t m_residualFun;
235 const ALResidual_t m_ALresidualFun;
236
237 using Base::m_R;
238
239 using Base::m_U;
240 using Base::m_DeltaU;
241 using Base::m_deltaU;
242
243 using Base::m_L;
244
245 using Base::m_stabilityVec;
246
247 using Base::m_verbose;
248
249 bool m_NL;
250
251 using Base::m_options;
252
253 using Base::m_tolF;
254 using Base::m_tolU;
255
256 mutable T m_relax;
257
258 using Base::m_maxIterations;
259 using Base::m_numIterations;
260
261 // Residual norms
262 using Base::m_residual;
263 using Base::m_residualIni;
264 using Base::m_residualOld;
265
266 using Base::m_start;
267 using Base::m_headstart;
268
270 using Base::m_solver; // Cholesky by default
271
272 using Base::m_stabilityMethod;
273
275 using Base::m_indicator;
276
277 using Base::m_dofs;
278
279 // Solver status
280 using Base::m_status;
281};
282
283
284} // namespace gismo
285
286
287#ifndef GISMO_BUILD_LIB
288#include GISMO_HPP_HEADER(gsStaticNewton.hpp)
289#endif
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
Base class for static solvers.
Definition gsStaticBase.h:38
virtual gsStatus status() const
Returns the status.
Definition gsStaticBase.h:129
virtual bool _computeStability(const gsSparseMatrix< T > &jacMat, T shift)
Computes the stability of the Jacobian, optionally applying a shift (if provided)
Definition gsStaticBase.h:221
virtual T indicator(const gsSparseMatrix< T > &jacMat, T shift=-1e-2)
Returns the stability indicator.
Definition gsStaticBase.h:146
virtual gsVector< T > solution() const
Access the solution.
Definition gsStaticBase.h:95
virtual gsVector< T > stabilityVec(const gsSparseMatrix< T > &jacMat, T shift=-1e-2)
Returns the stability vector.
Definition gsStaticBase.h:153
Static solver using a newton method.
Definition gsStaticNewton.h:30
gsVector< T > _solveLinear()
Perform a linear solve.
Definition gsStaticNewton.hpp:101
void _start()
Starts the method.
Definition gsStaticNewton.hpp:273
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force)
Constructor.
Definition gsStaticNewton.h:48
void stepOutput(index_t k) override
See gsStaticBase.
Definition gsStaticNewton.hpp:58
gsVector< T > _solveNonlinear()
Perform a nonlinear solve.
Definition gsStaticNewton.hpp:142
gsStatus solveNonlinear(gsVector< T > &solution)
Perform a nonlinearg solve.
Definition gsStaticNewton.h:164
gsVector< T > stabilityVec()
See gsStaticBase.
Definition gsStaticNewton.h:199
T indicator()
See gsStaticBase.
Definition gsStaticNewton.h:191
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const dJacobian_t &dnonlinear, const Residual_t &residual)
{ function_description }
Definition gsStaticNewton.h:129
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const Jacobian_t &nonlinear, const Residual_t &residual)
Constructor.
Definition gsStaticNewton.h:67
void _init()
Initializes the method.
Definition gsStaticNewton.hpp:251
void initOutput() override
See gsStaticBase.
Definition gsStaticNewton.hpp:42
gsVector< T > _solveSystem(const gsVector< T > &F)
Solves the system with RHS F and LHS the Jacobian.
Definition gsStaticNewton.hpp:230
void defaultOptions() override
See gsStaticBase.
Definition gsStaticNewton.hpp:20
void getOptions() override
See gsStaticBase.
Definition gsStaticNewton.hpp:28
gsStatus solve() override
See gsStaticBase.
Definition gsStaticNewton.h:148
void _factorizeMatrix(const gsSparseMatrix< T > &jacMat) const
Factorizes the jacMat.
Definition gsStaticNewton.hpp:215
gsStaticNewton(const gsSparseMatrix< T > &linear, const gsVector< T > &force, const Jacobian_t &nonlinear, const ALResidual_t &ALResidual)
Constructor.
Definition gsStaticNewton.h:95
void reset() override
See gsStaticBase.
Definition gsStaticNewton.hpp:243
gsStatus solveLinear()
Perform a linear solve.
Definition gsStaticNewton.hpp:75
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
#define index_t
Definition gsConfig.h:32
#define GISMO_ENSURE(cond, message)
Definition gsDebug.h:102
Base class for static solvers.
The G+Smo namespace, containing all definitions for the library.
gsStatus
Definition gsStructuralAnalysisTypes.h:21