23 Base::defaultOptions();
24 m_options.setString(
"Solver",
"CGDiagonal");
25 m_options.addReal(
"Relaxation",
"Relaxation parameter",1);
39 m_relax = m_options.getReal(
"Relaxation");
46 gsInfo<<std::setw(4)<<std::left<<
"It.";
47 gsInfo<<std::setw(17)<<std::left<<
"|R|";
48 gsInfo<<std::setw(17)<<std::left<<
"|R|/|R0|";
49 gsInfo<<std::setw(17)<<std::left<<
"|DU|";
50 gsInfo<<std::setw(17)<<std::left<<
"|dU|";
51 gsInfo<<std::setw(17)<<std::left<<
"|dU|/|DU|";
52 gsInfo<<std::setw(17)<<std::left<<
"|dU|/|U+DU|";
53 gsInfo<<std::setw(17)<<std::left<<
"log(Ri/R0):";
54 gsInfo<<std::setw(17)<<std::left<<
"log(Ri+1/R0)";
62 gsInfo<<std::setw(4)<<std::left<<k;
63 gsInfo<<std::setw(17)<<std::left<<m_residual;
64 gsInfo<<std::setw(17)<<std::left<<m_residual/m_residualIni;
65 gsInfo<<std::setw(17)<<std::left<<m_DeltaU.norm();
66 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm();
67 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm()/m_DeltaU.norm();
68 gsInfo<<std::setw(17)<<std::left<<m_relax * m_deltaU.norm()/(m_U+m_DeltaU).norm();
69 gsInfo<<std::setw(17)<<std::left<<math::log10(m_residualOld/m_residualIni);
70 gsInfo<<std::setw(17)<<std::left<<math::log10(m_residual/m_residualIni);
87 else if (errorCode==2)
89 else if (errorCode==3)
107 gsInfo<<
"Matrix: \n"<<m_linear.toDense()<<
"\n";
108 gsInfo<<
"Vector: \n"<<m_force<<
"\n";
110 _factorizeMatrix( m_linear );
111 m_U = _solveSystem(m_force);
123 catch (
int errorCode)
127 else if (errorCode==2)
129 else if (errorCode==3)
149 if (m_DeltaU.norm()==0 && m_DeltaU.rows()==0)
151 m_deltaU = m_DeltaU = this->_solveLinear();
159 if (m_verbose>0) { initOutput(); }
161 for (m_numIterations = 0; m_numIterations != m_maxIterations; ++m_numIterations)
163 jacMat = this->_computeJacobian(m_U+m_DeltaU,m_deltaU);
166 gsInfo<<
"Matrix: \n"<<jacMat.toDense()<<
"\n";
167 gsInfo<<
"Vector: \n"<<m_R<<
"\n";
170 _factorizeMatrix(jacMat);
171 m_deltaU = _solveSystem(m_R);
172 m_DeltaU += m_relax * m_deltaU;
174 m_R = this->_computeResidual(m_U+m_DeltaU);
175 m_residual = m_R.norm();
177 if (m_verbose>0) { stepOutput(m_numIterations); }
179 m_residualOld = m_residual;
181 if (m_relax * m_deltaU.norm()/m_DeltaU.norm() < m_tolU && m_residual/m_residualIni < m_tolF)
186 else if (m_numIterations+1 == m_maxIterations)
189 gsInfo<<
"Maximum iterations reached. Solution did not converge\n";
200 if (!m_residualFun(U, resVec))
206 gsSparseMatrix<T> gsStaticNewton<T>::_computeJacobian(
const gsVector<T> & U,
const gsVector<T> & deltaU)
210 if (!m_dnonlinear(U,deltaU,m))
218 m_solver->compute(jacMat);
219 if (m_solver->info()!=gsEigen::ComputationInfo::Success)
221 gsInfo<<
"Solver error with code "<<m_solver->info()<<
". See Eigen documentation on ComputationInfo \n"
222 <<gsEigen::ComputationInfo::Success<<
": Success"<<
"\n"
223 <<gsEigen::ComputationInfo::NumericalIssue<<
": NumericalIssue"<<
"\n"
224 <<gsEigen::ComputationInfo::NoConvergence<<
": NoConvergence"<<
"\n"
225 <<gsEigen::ComputationInfo::InvalidInput<<
": InvalidInput"<<
"\n";
235 return m_solver->solve(F);
246 m_dofs = m_force.rows();
255 if( m_dnonlinear==
nullptr || m_residualFun==
nullptr)
260 m_stabilityMethod = 0;
264 gsWarn<<
"The number of degrees of freedom is equal to zero. This can lead to bad initialization.\n";
266 m_residual = m_residualIni = m_residualOld = 0;
284 if (m_dofs==0)
gsWarn<<
"The number of degrees of freedom is equal to zero. This can lead to bad initialization.\n";
285 m_DeltaU.setZero(m_dofs);
287 m_R = this->_computeResidual(m_U);
288 m_residual = m_R.norm();
290 if (m_residual==0) m_residual=1;
292 m_residualIni = m_residualOld = m_residual;
298 m_R = this->_computeResidual(m_U + m_DeltaU);
299 m_residual = m_R.norm();
301 if (m_residual==0) m_residual=1;
303 m_residualOld = m_residual;
305 m_residualIni = this->_computeResidual(m_U).norm();
307 if (m_residualIni==0) m_residualIni=1;
314 m_deltaU.setZero(m_dofs);
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
Assembly problem in step.
Static solver using a newton method.
Definition: gsStaticNewton.h:31
Assembly failed due to an error in the expression (e.g. overflow)
#define index_t
Definition: gsConfig.h:32
gsStatus
Definition: gsStructuralAnalysisTypes.h:20
#define gsWarn
Definition: gsDebug.h:50
gsVector< T > _solveSystem(const gsVector< T > &F)
Solves the system with RHS F and LHS the Jacobian.
Definition: gsStaticNewton.hpp:231
#define gsInfo
Definition: gsDebug.h:43
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
gsStatus solveLinear()
Perform a linear solve.
Definition: gsStaticNewton.hpp:76
gsVector< T > _solveNonlinear()
Perform a nonlinear solve.
Definition: gsStaticNewton.hpp:143
void stepOutput(index_t k) override
See gsStaticBase.
Definition: gsStaticNewton.hpp:59
void defaultOptions() override
See gsStaticBase.
Definition: gsStaticNewton.hpp:21