G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsALMBase.h
Go to the documentation of this file.
1
17#pragma once
19
20#ifdef gsSpectra_ENABLED
21#include <gsSpectra/gsSpectra.h>
22#endif
23#include <gsIO/gsOptionList.h>
25
26namespace gismo
27{
28
36template <class T>
38{
39protected:
40
41 typedef typename gsStructuralAnalysisOps<T>::ALResidual_t ALResidual_t;
42 typedef typename gsStructuralAnalysisOps<T>::Jacobian_t Jacobian_t;
43 typedef typename gsStructuralAnalysisOps<T>::dJacobian_t dJacobian_t;
44
45public:
46
47 virtual ~gsALMBase() {};
48
50 gsALMBase( const Jacobian_t & Jacobian,
51 const ALResidual_t & ALResidual,
52 const gsVector<T> & Force )
53 : m_residualFun(ALResidual),
54 m_forcing(Force)
55 {
56 m_jacobian = Jacobian;
57 m_djacobian = [this](gsVector<T> const & x, gsVector<T> const & /*dx*/, gsSparseMatrix<T> & m) -> bool
58 {
59 return m_jacobian(x,m);
60 };
61
62 // initialize variables
64 this->defaultOptions();
65 this->setLength(1e-2);
66 m_converged = false;
67
68 // initialize errors
69 m_basisResidualF = 0.0;
70 m_basisResidualU = 0.0;
71
72 m_status = gsStatus::NotStarted;
73 }
74
76 gsALMBase( const dJacobian_t & dJacobian,
77 const ALResidual_t & Residual,
78 const gsVector<T> & Force )
79 : m_residualFun(Residual),
80 m_forcing(Force)
81 {
82 m_djacobian = dJacobian;
83
84 // initialize variables
86 this->defaultOptions();
87 this->setLength(1e-2);
88 m_converged = false;
89
90 // initialize errors
91 m_basisResidualF = 0.0;
92 m_basisResidualU = 0.0;
93 }
94
95// General functions
96public:
97
98 virtual gsStatus status() { return m_status; }
99
100 // Returns the number of DoFs
101 virtual index_t numDofs() {return m_forcing.size();}
102
103 // Returns the current length
104 virtual T getLength() {return m_arcLength; }
105
107 virtual gsStatus step();
108
110 virtual void initialize(bool stability = true)
111 {
112 m_initialized = true;
113 this -> initMethods();
114 this -> init(stability);
115 }
116
118 virtual void setLength(T length)
119 {
120 m_options.setReal("Length",length);
121 m_arcLength = m_arcLength_prev = m_arcLength_ori = m_options.getReal("Length");
122 }
123
125 virtual void setLength(T length, bool adaptive)
126 {
127 this->setLength(length);
128 m_adaptiveLength = adaptive;
129 m_desiredIterations = 10; // number of desired iterations defaults to 10
130 }
131
133 virtual void setLength(T length, bool adaptive, index_t iterations)
134 {
135 this->setLength(length);
136 m_adaptiveLength = adaptive;
137 m_desiredIterations = iterations;
138 }
140 virtual void setLength(T length, index_t iterations)
141 {
142 this->setLength(length);
143 m_adaptiveLength = true;
144 m_desiredIterations = iterations;
145 }
146
147 // Output
149 virtual bool converged() const {return m_converged;}
150
152 virtual index_t numIterations() const { return m_numIterations;}
153
155 virtual T tolerance() const {return m_tolerance;}
156
158 virtual T residue() const {return m_residue;}
159
161 virtual T indicator() const {return m_indicator;}
162 virtual void setIndicator(T indicator) {m_indicator = indicator; m_stability = this->stability();}
163
165 virtual const gsVector<T> & solutionU() const {return m_U;}
166 virtual const gsVector<T> & solutionDU() const {return m_DeltaU;}
167 virtual T solutionL() const {return m_L;}
168 virtual T solutionDL() const {return m_DeltaL;}
169 virtual const gsVector<T> & solutionV() const {return m_V;}
170
172 virtual bool isStable() const {return m_stability;}
173
174 // /// Returns the value of the deterimant of the jacobian
175 // virtual T determinant() const
176 // {
177 // return m_jacobian(m_U).toDense().determinant();
178 // }
179
181 virtual void resetStep() {m_DeltaUold.setZero(); m_DeltaLold = 0;}
182
183 // Set initial guess for solution
184 virtual void setInitialGuess(const gsVector<T> & Uguess, const T & Lguess) {m_Uguess = Uguess; m_Lguess = Lguess;}
185 virtual void setPrevious(const gsVector<T> & Uprev, const T & Lprev)
186 {
187 m_Uprev = Uprev;
188 m_Lprev = Lprev;
189 m_DeltaUold = m_U - m_Uprev;
190 m_DeltaLold = m_L - m_Lprev;
191 }
192
194 virtual void setSolution(const gsVector<T> & U, const T & L) {m_L = L; m_U = U; }// m_DeltaUold.setZero(); m_DeltaLold = 0;}
195
197 virtual void setSolutionStep(const gsVector<T> & DU, const T & DL) {m_DeltaUold = DU; m_DeltaLold = DL;}// m_DeltaUold.setZero(); m_DeltaLold = 0;}
198
200 virtual gsOptionList & options() {return m_options;};
201
203 virtual void setOptions(gsOptionList options) {m_options.update(options,gsOptionList::addIfUnknown); this->getOptions(); };
204
206 virtual void options_into(gsOptionList options) {options = m_options;};
207
209 virtual void applyOptions() {this->getOptions(); }
210
211 virtual T distance(const gsVector<T>& /*DeltaU*/, const T /*DeltaL*/) const
212 {
214 }
215
216// ------------------------------------------------------------------------------------------------------------
217// ---------------------------------------Singular point methods-----------------------------------------------
218// ------------------------------------------------------------------------------------------------------------
219public:
220
221
234 virtual gsStatus computeSingularPoint(const gsVector<T> & U, const T & L, bool switchBranch=false, bool jacobian=false, bool testPoint=true);
235
237 virtual bool isBifurcation(bool jacobian = false);
238
240 virtual bool stabilityChange() const;
241
251 virtual gsStatus computeStability(bool jacobian=true, T shift = -1e2);
252
254 virtual index_t stability() const;
255
257 virtual void switchBranch();
258
260 virtual T reduceLength(T fac = 0.5);
261
263 virtual T resetLength();
264
265protected:
266
268 virtual void _computeStability(const gsVector<T> & x, bool jacobian=true, T shift = -1e2);
269
271 virtual void _computeSingularPoint(const gsVector<T> & U, const T & L, bool switchBranch=false, bool jacobian=false, bool testPoint=true);
272
280 virtual bool _testSingularPoint(bool jacobian=false);
281
283 virtual void _extendedSystemIteration();
284
286 virtual index_t _bisectionObjectiveFunction(const gsVector<T> & x, bool jacobian=true);
288 virtual T _bisectionTerminationFunction(const gsVector<T> & x, bool jacobian=true);
289
291 virtual bool _extendedSystemSolve(const gsVector<T> & U, const T L, const T tol);
292
294 virtual bool _bisectionSolve(const gsVector<T> & U, const T L, const T tol);
295
297 virtual void _initOutputExtended();
298
300 virtual void _stepOutputExtended();
301
302// ------------------------------------------------------------------------------------------------------------
303// ---------------------------------------Computations---------------------------------------------------------
304// ------------------------------------------------------------------------------------------------------------
305protected:
307 virtual void _step();
308
310 virtual void defaultOptions();
311
313 virtual void getOptions();
314
316 virtual void init(bool stability);
317
319 virtual void factorizeMatrix(const gsSparseMatrix<T> & M);
320
322 virtual gsVector<T> solveSystem(const gsVector<T> & F);
323
325 virtual gsVector<T> computeResidual(const gsVector<T> & U, const T & L);
326 virtual void computeResidual();
327
329 virtual void computeResidualNorms();
330
332 virtual gsSparseMatrix<T> _computeJacobian(const gsVector<T> & U, const gsVector<T> & dU);
333 virtual gsSparseMatrix<T> computeJacobian(const gsVector<T> & U, const gsVector<T> & dU);
334 virtual gsSparseMatrix<T> computeJacobian(const gsVector<T> & U);
335 virtual gsSparseMatrix<T> computeJacobian();
336
338 virtual void computeLength();
339
341 virtual void computeUt();
343 virtual void computeUbar();
344
345// Purely virtual functions
346protected:
348 virtual void initMethods() = 0;
350 virtual void initiateStep() = 0;
352 virtual void iterationFinish() = 0;
353
355 virtual void quasiNewtonPredictor() = 0;
357 virtual void quasiNewtonIteration() = 0;
358
360 virtual void predictor() = 0;
361 virtual void predictorGuess() = 0;
363 virtual void iteration() = 0;
364
366 virtual void initOutput() = 0;
368 virtual void stepOutput() = 0;
369
370protected:
371
372 // Number of degrees of freedom
373 index_t m_numDof;
374
375 Jacobian_t m_jacobian;
376 dJacobian_t m_djacobian;
377 const ALResidual_t m_residualFun;
378 const gsVector<T> m_forcing;
379
380 mutable typename gsSparseSolver<T>::uPtr m_solver; // Cholesky by default
381
382public:
383
384
385 struct bifmethod
386 {
387 enum type
388 {
389 Nothing = -1,
390 Determinant = 0,
391 Eigenvalue = 1,
392 };
393 };
394
395 struct solver
396 {
397 enum type
398 {
399 LDLT = 0,
400 CG = 1, // The CG solver is robust for membrane models, where zero-blocks in the matrix might occur.
401 };
402 };
403
404 struct SPfail
405 {
406 enum type
407 {
408 Without = 0,
409 With = 1,
410 };
411 };
412
413 protected:
414 mutable gsOptionList m_options;
415
416
419
422
425
428 T m_arcLength_prev;
429 T m_arcLength_ori;
430 bool m_adaptiveLength;
431
434
437
440
441 bool m_verbose;
442 bool m_initialized;
443
444 bool m_quasiNewton;
445 index_t m_quasiNewtonInterval;
446
447 std::string m_note;
448
449 gsStatus m_status;
450
451protected:
452
455
458
461 T m_basisResidualF;
462
465 T m_basisResidualU;
466
469
472 T m_basisResidualKTPhi;
473
476 index_t m_negatives;
477
480
481protected:
482
483 // Previous update
484 gsVector<T> m_DeltaUold;
485 real_t m_DeltaLold;
487 gsVector<T> m_U, m_Uprev;
496
498 T m_L, m_Lprev;
505
506 gsVector<T> m_Uguess;
507 T m_Lguess;
508
511 T m_detKT;
512
515
516 // eigenvector
517 gsVector<T> m_V;
518 // step eigenvector
519 gsVector<T> m_deltaV;
520 gsVector<T> m_deltaVbar;
521 gsVector<T> m_deltaVt;
522 gsVector<T> m_DeltaV;
523
524 // Stability indicator
525 gsVector<T> m_stabilityVec;
526
527 // Integer if point is unstable (-1) or not (+1)
528 index_t m_stabilityPrev; //previous step
529 index_t m_stability; //current step
530 // Method to check if a point is a bifurcation point
531 index_t m_bifurcationMethod;
532
533 // What to do after computeSingularPoint fails?
534 index_t m_SPfail;
535
536 // Number of iterations and the tolerance for the singular point test
537 index_t m_SPTestIt;
538 T m_SPTestTol;
539
540 // Singular point computation tolerances
541 T m_SPCompTolE; // extended iterations
542 T m_SPCompTolB; // bisection method
543
544 // Branch switch parameter
545 T m_tau;
546};
547
548
549} // namespace gismo
550
551#ifndef GISMO_BUILD_LIB
552#include GISMO_HPP_HEADER(gsALMBase.hpp)
553#endif
Performs the arc length method to solve a nonlinear system of equations.
Definition gsALMBase.h:38
virtual void setSolutionStep(const gsVector< T > &DU, const T &DL)
Sets the solution step.
Definition gsALMBase.h:197
virtual void predictor()=0
Step predictor.
bool m_converged
Convergence result.
Definition gsALMBase.h:454
gsALMBase(const Jacobian_t &Jacobian, const ALResidual_t &ALResidual, const gsVector< T > &Force)
Constructor.
Definition gsALMBase.h:50
virtual void initMethods()=0
Initialize the ALM.
virtual void initiateStep()=0
Initiate the first iteration.
gsVector< T > m_deltaLs
Vector with lambda updates.
Definition gsALMBase.h:504
virtual void computeLength()
Compute the adaptive arc-length.
Definition gsALMBase.hpp:106
gsVector< T > m_deltaUt
u_t
Definition gsALMBase.h:493
virtual gsVector< T > solveSystem(const gsVector< T > &F)
Solve the system with right-hand side F.
Definition gsALMBase.hpp:201
virtual void _computeStability(const gsVector< T > &x, bool jacobian=true, T shift=-1e2)
See computeStability.
Definition gsALMBase.hpp:547
virtual T indicator() const
Returns the value of the Determinant or other indicator.
Definition gsALMBase.h:161
virtual void _initOutputExtended()
Initialize the output for extended iterations.
Definition gsALMBase.hpp:863
virtual void defaultOptions()
Set default options.
Definition gsALMBase.hpp:23
gsVector< T > m_DeltaU
Update of displacement vector.
Definition gsALMBase.h:489
virtual bool stabilityChange() const
Checks if the stability of the system changed since the previously known solution.
Definition gsALMBase.hpp:624
virtual void _computeSingularPoint(const gsVector< T > &U, const T &L, bool switchBranch=false, bool jacobian=false, bool testPoint=true)
See computeSingularPoint.
Definition gsALMBase.hpp:422
virtual void setLength(T length, bool adaptive)
Set arc length to length, enables adaptive steps.
Definition gsALMBase.h:125
gsVector< T > m_deltaU
Update of update of displacement vector.
Definition gsALMBase.h:495
virtual bool converged() const
True if the Arc Length method converged.
Definition gsALMBase.h:149
virtual T residue() const
Returns the error after solving the nonlinear system.
Definition gsALMBase.h:158
virtual void _extendedSystemIteration()
Perform an extended system iteration.
Definition gsALMBase.hpp:706
virtual void quasiNewtonPredictor()=0
Provide a specialized predictor when using quasi newton methods.
virtual bool _extendedSystemSolve(const gsVector< T > &U, const T L, const T tol)
Perform an extended system solve to find a singular point.
Definition gsALMBase.hpp:631
virtual void quasiNewtonIteration()=0
Perform iteration using quasi-newton method.
virtual T tolerance() const
Returns the tolerance value used.
Definition gsALMBase.h:155
index_t m_numIterations
Number of Arc Length iterations performed.
Definition gsALMBase.h:418
virtual void stepOutput()=0
Provide step-wise output.
T m_relax
Relaxation factor.
Definition gsALMBase.h:479
virtual index_t numIterations() const
Returns the number of Newton iterations performed.
Definition gsALMBase.h:152
virtual void setLength(T length)
Set arc length to length.
Definition gsALMBase.h:118
virtual void initialize(bool stability=true)
Initialize the arc-length method, computes the stability of the initial configuration if stability is...
Definition gsALMBase.h:110
virtual void init(bool stability)
Initialize the solver.
Definition gsALMBase.hpp:96
virtual gsSparseMatrix< T > _computeJacobian(const gsVector< T > &U, const gsVector< T > &dU)
Compute the jacobian matrix.
Definition gsALMBase.hpp:214
virtual gsStatus step()
Perform one arc-length step.
Definition gsALMBase.hpp:328
virtual void setLength(T length, index_t iterations)
Set arc length to length, enables adaptive steps aiming for iterations number of iterations per step.
Definition gsALMBase.h:140
T m_toleranceF
Tolerance value to decide convergence - Force criterion.
Definition gsALMBase.h:436
virtual const gsVector< T > & solutionU() const
Return the solution vector and factor.
Definition gsALMBase.h:165
virtual void resetStep()
Resets the step.
Definition gsALMBase.h:181
virtual T _bisectionTerminationFunction(const gsVector< T > &x, bool jacobian=true)
Returns the termination function for the bisection method given solution x.
Definition gsALMBase.hpp:746
gsVector< T > m_U
Displacement vector (present, at previously converged point)
Definition gsALMBase.h:487
virtual void computeResidualNorms()
Compute the residual error norms.
Definition gsALMBase.hpp:151
virtual void setLength(T length, bool adaptive, index_t iterations)
Set arc length to length, enables adaptive steps aiming for iterations number of iterations per step.
Definition gsALMBase.h:133
virtual void iterationFinish()=0
Finish the iterations.
virtual void setSolution(const gsVector< T > &U, const T &L)
Sets the solution.
Definition gsALMBase.h:194
virtual void setOptions(gsOptionList options)
Set the options to options.
Definition gsALMBase.h:203
T m_residueF
Force residuum.
Definition gsALMBase.h:460
virtual void applyOptions()
Apply the options.
Definition gsALMBase.h:209
index_t m_maxIterations
Maximum number of Arc Length iterations allowed.
Definition gsALMBase.h:421
T m_L
Lambda (present, at previously converged point)
Definition gsALMBase.h:498
T m_DeltaL
Update of lambdaGeneralizedSelfAdjointEigenSolver.
Definition gsALMBase.h:500
gsALMBase(const dJacobian_t &dJacobian, const ALResidual_t &Residual, const gsVector< T > &Force)
Constructor using the jacobian that takes the solution and the solution step.
Definition gsALMBase.h:76
virtual void computeUt()
Compute .
Definition gsALMBase.hpp:255
virtual bool _testSingularPoint(bool jacobian=false)
Tests if a point is a bifurcation point.
Definition gsALMBase.hpp:475
T m_residueKTPhi
Singular point.
Definition gsALMBase.h:471
virtual T resetLength()
Reset the length.
Definition gsALMBase.hpp:127
virtual void _step()
Implementation of step.
Definition gsALMBase.hpp:354
T m_residue
Force residuum.
Definition gsALMBase.h:457
virtual void initOutput()=0
Initialize the output.
index_t m_desiredIterations
Number of desired iterations.
Definition gsALMBase.h:424
virtual void iteration()=0
A single iteration.
T m_arcLength
Length of the step in the u,f plane.
Definition gsALMBase.h:427
virtual gsStatus computeStability(bool jacobian=true, T shift=-1e2)
Calculates the stability of the solution x.
Definition gsALMBase.hpp:521
gsVector< T > m_resVec
Value of residual function.
Definition gsALMBase.h:514
virtual index_t _bisectionObjectiveFunction(const gsVector< T > &x, bool jacobian=true)
Returns the objective function for the bisection method given solution x.
Definition gsALMBase.hpp:738
virtual gsStatus computeSingularPoint(const gsVector< T > &U, const T &L, bool switchBranch=false, bool jacobian=false, bool testPoint=true)
Calculates the singular point.
Definition gsALMBase.hpp:450
gsSparseMatrix< T > m_jacMat
Jacobian matrix.
Definition gsALMBase.h:510
T m_tolerance
Tolerance value to decide convergence.
Definition gsALMBase.h:433
virtual T reduceLength(T fac=0.5)
Reduce the length by multiplication with a factor fac.
Definition gsALMBase.hpp:120
virtual void _stepOutputExtended()
Step output for extended iterations.
Definition gsALMBase.hpp:888
virtual gsOptionList & options()
Access the options.
Definition gsALMBase.h:200
T m_deltaL
Update of update of lambda.
Definition gsALMBase.h:502
virtual void computeUbar()
Compute .
Definition gsALMBase.hpp:249
T m_residueL
Load residuum.
Definition gsALMBase.h:468
T m_residueU
Displacement residuum.
Definition gsALMBase.h:464
gsVector< T > m_deltaUbar
u_bar
Definition gsALMBase.h:491
virtual void factorizeMatrix(const gsSparseMatrix< T > &M)
Factorize the matrix M.
Definition gsALMBase.hpp:186
T m_toleranceU
Tolerance value to decide convergence - Displacement criterion.
Definition gsALMBase.h:439
T m_indicator
Indicator for bifurcation.
Definition gsALMBase.h:475
virtual void switchBranch()
Switches branches.
Definition gsALMBase.hpp:843
virtual bool _bisectionSolve(const gsVector< T > &U, const T L, const T tol)
Perform a bisection system solve to find a singular point.
Definition gsALMBase.hpp:754
virtual void options_into(gsOptionList options)
Return the options into options.
Definition gsALMBase.h:206
virtual index_t stability() const
Computes the stability: -1 if unstable, +1 if stable.
Definition gsALMBase.hpp:618
virtual void getOptions()
Apply options.
Definition gsALMBase.hpp:57
virtual bool isBifurcation(bool jacobian=false)
Returns true if the point is a bifurcation.
Definition gsALMBase.hpp:514
virtual bool isStable() const
Returns if solution passed a bifurcation point.
Definition gsALMBase.h:172
Class which holds a list of parameters/options, and provides easy access to them.
Definition gsOptionList.h:33
void update(const gsOptionList &other, updateType type=ignoreIfUnknown)
Updates the object using the data from other.
Definition gsOptionList.cpp:253
void setReal(const std::string &label, const Real &value)
Sets an existing option label to be equal to value.
Definition gsOptionList.cpp:166
Real getReal(const std::string &label) const
Reads value for option label from options.
Definition gsOptionList.cpp:44
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
A vector with arbitrary coefficient type and fixed or dynamic size.
Definition gsVector.h:37
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
This is the main header file that collects wrappers of Eigen for linear algebra.
Provides a list of labeled parameters/options that can be set and accessed easily.
Header file for using Spectra extension.
Provides a status object and typedefs.
The G+Smo namespace, containing all definitions for the library.
gsStatus
Definition gsStructuralAnalysisTypes.h:21
@ NotStarted
ALM has not started yet.
std::function< bool(gsVector< T > const &, gsVector< T > const &, gsSparseMatrix< T > &) > dJacobian_t
Jacobian with solution update as argument.
Definition gsStructuralAnalysisTypes.h:90
std::function< bool(gsVector< T > const &, const T, gsVector< T > &)> ALResidual_t
Arc-Length Residual, Fint-lambda*Fext.
Definition gsStructuralAnalysisTypes.h:70
std::function< bool(gsVector< T > const &, gsSparseMatrix< T > &) > Jacobian_t
Jacobian.
Definition gsStructuralAnalysisTypes.h:86