22 Base::defaultOptions();
23 m_options.setString(
"Solver",
"CGDiagonal");
24 m_options.addReal(
"Relaxation",
"Relaxation parameter",1);
38 m_relax = m_options.getReal(
"Relaxation");
45 gsInfo<<std::setw(4)<<std::left<<
"It.";
46 gsInfo<<std::setw(17)<<std::left<<
"|R|";
47 gsInfo<<std::setw(17)<<std::left<<
"|R|/|R0|";
48 gsInfo<<std::setw(17)<<std::left<<
"|DU|";
49 gsInfo<<std::setw(17)<<std::left<<
"|dU|";
50 gsInfo<<std::setw(17)<<std::left<<
"|dU|/|DU|";
51 gsInfo<<std::setw(17)<<std::left<<
"|dU|/|U+DU|";
52 gsInfo<<std::setw(17)<<std::left<<
"log(Ri/R0):";
53 gsInfo<<std::setw(17)<<std::left<<
"log(Ri+1/R0)";
61 gsInfo<<std::setw(4)<<std::left<<k;
62 gsInfo<<std::setw(17)<<std::left<<m_residual;
63 gsInfo<<std::setw(17)<<std::left<<m_residual/m_residualIni;
64 gsInfo<<std::setw(17)<<std::left<<m_DeltaU.norm();
65 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm();
66 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm()/m_DeltaU.norm();
67 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm()/(m_U+m_DeltaU).norm();
68 gsInfo<<std::setw(17)<<std::left<<math::log10(m_residualOld/m_residualIni);
69 gsInfo<<std::setw(17)<<std::left<<math::log10(m_residual/m_residualIni);
86 else if (errorCode==2)
88 else if (errorCode==3)
106 gsInfo<<
"Matrix: \n"<<m_linear.toDense()<<
"\n";
107 gsInfo<<
"Vector: \n"<<m_force<<
"\n";
109 _factorizeMatrix( m_linear );
110 m_U = _solveSystem(m_force);
122 catch (
int errorCode)
126 else if (errorCode==2)
128 else if (errorCode==3)
148 if (m_DeltaU.norm()==0 && m_DeltaU.rows()==0)
150 m_deltaU = m_DeltaU = this->_solveLinear();
158 if (m_verbose>0) { initOutput(); }
160 for (m_numIterations = 0; m_numIterations != m_maxIterations; ++m_numIterations)
162 jacMat = this->_computeJacobian(m_U+m_DeltaU,m_deltaU);
165 gsInfo<<
"Matrix: \n"<<jacMat.toDense()<<
"\n";
166 gsInfo<<
"Vector: \n"<<m_R<<
"\n";
169 _factorizeMatrix(jacMat);
170 m_deltaU = _solveSystem(m_R);
171 m_DeltaU += m_relax * m_deltaU;
173 m_R = this->_computeResidual(m_U+m_DeltaU);
174 m_residual = m_R.norm();
176 if (m_verbose>0) { stepOutput(m_numIterations); }
178 m_residualOld = m_residual;
180 if (m_relax * m_deltaU.norm()/m_DeltaU.norm() < m_tolU && m_residual/m_residualIni < m_tolF)
185 else if (m_numIterations+1 == m_maxIterations)
188 gsInfo<<
"Maximum iterations reached. Solution did not converge\n";
199 if (!m_residualFun(U, resVec))
205gsSparseMatrix<T> gsStaticNewton<T>::_computeJacobian(
const gsVector<T> & U,
const gsVector<T> & deltaU)
209 if (!m_dnonlinear(U,deltaU,m))
217 m_solver->compute(jacMat);
218 if (m_solver->info()!=gsEigen::ComputationInfo::Success)
220 gsInfo<<
"Solver error with code "<<m_solver->info()<<
". See Eigen documentation on ComputationInfo \n"
221 <<gsEigen::ComputationInfo::Success<<
": Success"<<
"\n"
222 <<gsEigen::ComputationInfo::NumericalIssue<<
": NumericalIssue"<<
"\n"
223 <<gsEigen::ComputationInfo::NoConvergence<<
": NoConvergence"<<
"\n"
224 <<gsEigen::ComputationInfo::InvalidInput<<
": InvalidInput"<<
"\n";
234 return m_solver->solve(F);
245 m_dofs = m_force.rows();
254 if( m_dnonlinear==
nullptr || m_residualFun==
nullptr)
259 m_stabilityMethod = 0;
263 gsWarn<<
"The number of degrees of freedom is equal to zero. This can lead to bad initialization.\n";
265 m_residual = m_residualIni = m_residualOld = 0;
283 if (m_dofs==0)
gsWarn<<
"The number of degrees of freedom is equal to zero. This can lead to bad initialization.\n";
284 m_DeltaU.setZero(m_dofs);
286 m_R = this->_computeResidual(m_U);
287 m_residual = m_R.norm();
289 if (m_residual==0) m_residual=1;
291 m_residualIni = m_residualOld = m_residual;
297 m_R = this->_computeResidual(m_U + m_DeltaU);
298 m_residual = m_R.norm();
300 if (m_residual==0) m_residual=1;
302 m_residualOld = m_residual;
304 m_residualIni = this->_computeResidual(m_U).norm();
306 if (m_residualIni==0) m_residualIni=1;
313 m_deltaU.setZero(m_dofs);
Sparse matrix class, based on gsEigen::SparseMatrix.
Definition gsSparseMatrix.h:139
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
void stepOutput(index_t k) override
See gsStaticBase.
Definition gsStaticNewton.hpp:58
gsVector< T > _solveNonlinear()
Perform a nonlinear solve.
Definition gsStaticNewton.hpp:142
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
void _factorizeMatrix(const gsSparseMatrix< T > &jacMat) const
Factorizes the jacMat.
Definition gsStaticNewton.hpp:215
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 gsWarn
Definition gsDebug.h:50
#define gsInfo
Definition gsDebug.h:43
The G+Smo namespace, containing all definitions for the library.
gsStatus
Definition gsStructuralAnalysisTypes.h:21
@ SolverError
Assembly problem in step.
@ AssemblyError
Assembly problem in step.
@ NotConverged
Step did not converge.
@ NotStarted
ALM has not started yet.