MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
linesearch.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/mbdyn/base/linesearch.cc,v 1.18 2017/01/12 14:46:09 masarati Exp $ */
2 /*
3  * MBDyn (C) is a multibody analysis code.
4  * http://www.mbdyn.org
5  *
6  * Copyright (C) 1996-2017
7  *
8  * Pierangelo Masarati <masarati@aero.polimi.it>
9  * Paolo Mantegazza <mantegazza@aero.polimi.it>
10  *
11  * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
12  * via La Masa, 34 - 20156 Milano, Italy
13  * http://www.aero.polimi.it
14  *
15  * Changing this copyright notice is forbidden.
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation (version 2 of the License).
20  *
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */
31 
32  /*
33  * Portions Copyright (C) 2003-2017
34  * Giuseppe Quaranta <quaranta@aero.polimi.it>
35  *
36  * classi che implementano la risoluzione del sistema nonlineare
37  */
38 
39  /*
40  AUTHOR: Reinhard Resch <r.resch@secop.com>
41  Copyright (C) 2011(-2017) all rights reserved.
42 
43  The copyright of this code is transferred
44  to Pierangelo Masarati and Paolo Mantegazza
45  for use in the software MBDyn as described
46  in the GNU Public License version 2.1
47  */
48 
49 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
50 
51 #include <unistd.h>
52 #include "clock_time.h"
53 #include "solver.h"
54 #include "linesearch.h"
55 #ifdef USE_MPI
56 #include "mbcomm.h"
57 #include "schsolman.h"
58 #endif /* USE_MPI */
59 
60 #include "dofown.h"
61 #include "output.h"
62 
63 #include <cassert>
64 #include <cfloat>
65 #include <cmath>
66 #include <cstdlib>
67 #include <iomanip>
68 #include <limits>
69 
70 //#define DEBUG
71 
72 #ifdef DEBUG
73 #undef ASSERT
74 #define ASSERT(expr) assert(expr)
75 #define TRACE(expr) silent_cerr(__FILE__ << ":" << __LINE__ << ":" << __FUNCTION__ << ":" << expr)
76 #else
77 #define TRACE(expr) static_cast<void>(0)
78 #endif
79 
80 #define TRACE_VAR(varname) TRACE(#varname "=" << (varname) << std::endl)
81 #define TRACE_FLAG(varname, flag) TRACE(#varname "&" #flag "=" << ((varname) & (flag)) << std::endl)
82 
84 : dTolX(1e-7),
85 dTolMin(1e-8),
86 iMaxIterations(200),
87 dMaxStep(100.),
88 dAlpha(1e-4),
89 dLambdaMin(1e-2),
90 dLambdaFactMin(1e-1),
91 dDivergenceCheck(1.),
92 dMinStepScale(1e-3),
93 uFlags(DIVERGENCE_CHECK
94  | ALGORITHM_CUBIC
95  | RELATIVE_LAMBDA_MIN
96  | SCALE_NEWTON_STEP
97  | ABORT_AT_LAMBDA_MIN)
98 {
99  NO_OP;
100 }
101 
104  const struct LineSearchParameters& param)
105 : NonlinearSolver(options),
106 LineSearchParameters(param),
107 pRes(0),
108 pSol(0),
109 pNLP(0),
110 pS(0),
111 pDM(pDM)
112 {
113  TRACE_VAR(dTolX);
114  // TRACE_VAR(dTolF);
118  TRACE_VAR(dAlpha);
124  TRACE_VAR(uFlags);
132 }
133 
135 {
136  NO_OP;
137 }
138 
139 void
141 {
142 #ifdef USE_EXTERNAL
143  SendExternal();
144 #endif /* USE_EXTERNAL */
145 
146  pRes->Reset();
147 
148  try {
149  pNLP->Residual(pRes);
150  }
152  // The Jacobian will be rebuilt anyway
153  }
154 
155  if (outputRes()) {
156  pS->PrintResidual(*pRes, iIterCnt);
157  }
158 
159  f = 0.5 * pRes->Dot();
160 }
161 
162 void
164 {
165  SolutionManager *const pSM = pS->pGetSolutionManager();
166 
167  const integer iMaxIterRebuild = 10;
168 
169  pSM->MatrReset();
170  integer iIter = 0;
171 
172  do {
173  try {
174  pNLP->Jacobian(pSM->pMatHdl());
175  } catch (const MatrixHandler::ErrRebuildMatrix&) {
176  silent_cout("NewtonRaphsonSolver: "
177  "rebuilding matrix..."
178  << std::endl);
179 
180  /* need to rebuild the matrix... */
181  pSM->MatrInitialize();
182  continue;
183  }
184  break;
185  } while (++iIter < iMaxIterRebuild);
186 
187  if (iIter >= iMaxIterRebuild) {
188  silent_cerr("Maximum number of iterations exceeded when rebuilding the Jacobian matrix" << std::endl);
190  }
191 
192  TotJac++;
193 
194 #ifdef USE_MPI
195  if (!bParallel || MBDynComm.Get_rank() == 0)
196 #endif /* USE_MPI */
197  {
198  if (outputJac()) {
199  silent_cout("Jacobian:" << std::endl
200  << *(pSM->pMatHdl()));
201  }
202 
204  silent_cout(" cond=" << pSM->pMatHdl()->ConditionNumber(GetCondMatNorm()) << std::endl);
205  }
206  }
207 }
208 
209 void
211  doublereal& f, bool& check, const integer& iIterCnt)
212 {
213  check = false;
214 
215  if (uFlags & SCALE_NEWTON_STEP) {
216  const doublereal dNormSol = pSol->Norm();
217 
218  if (dNormSol > stpmax) {
219  const doublereal dScale = std::max(dMinStepScale, stpmax / dNormSol);
220  if (uFlags & VERBOSE_MODE) {
221  silent_cerr("line search warning: "
222  "Newton increment is reduced by factor " << dScale
223  << " at time step " << pDM->dGetTime()
224  << " at iteration " << iIterCnt
225  << " The time step is probably too large" << std::endl);
226  }
227  ASSERT(stpmax >= 0);
228  ASSERT(dScale <= 1.);
229  ASSERT(dScale > 0.);
230  *pSol *= dScale;
231  }
232  }
233 
234  p = *pSol; // save the Newton increment
235 
236  doublereal slope = g.InnerProd(p);
237 
238  TRACE_VAR(slope);
239 
240  doublereal dLambdaMinEff = -1.;
241 
242  if (slope >= 0.) {
243  if (uFlags & VERBOSE_MODE) {
244  silent_cerr("line search warning: slope=" << slope << " >= 0"
245  " at time step " << pDM->dGetTime()
246  << " at iteration " << iIterCnt << std::endl
247  << "This could be a roundoff problem" << std::endl);
248  }
249 
251  // It seems to be a numerical problem.
252  // Line search may not work in this situation.
253  // Resort to the ordinary Newton Raphson algorithm
254  slope = 0.;
255  dLambdaMinEff = 1.;
256  } else {
258  }
259  }
260 
261  if (dLambdaMinEff < 0) {
262  // dLambdaMinEff has to be detected
263  if (uFlags & RELATIVE_LAMBDA_MIN) {
264  doublereal test = 0.;
265 
266  for (integer i = 1; i <= Size; ++i) {
267  const doublereal temp = std::abs(p(i)) / std::max(std::max(std::abs((*pDM->GetpXCurr())(i)), std::abs((*pDM->GetpXPCurr())(i))), 1.);
268  if (temp > test) {
269  test = temp;
270  }
271  }
272 
273  dLambdaMinEff = std::max(dLambdaMin, std::min(dTolX / test, 1.));
274  } else {
275  dLambdaMinEff = dLambdaMin;
276  }
277  }
278 
279  doublereal lambda = 1.;
280  doublereal tmplam;
281  doublereal lambda2 = 0; //f2, lambda2 initialized to silence g++ possible uninitialized warning
282  doublereal f2 = 0.;
283 
284 #ifdef DEBUG
285  lambda2 = f2 = NAN;
286 #endif
287 
288  integer iIter = 0;
289 
290  TRACE_VAR(dLambdaMinEff);
291 
292  do {
293  // FIXME: dLambdaMax not defined
294  // ASSERT(lambda <= dLambdaMax);
295 
296  if (iIter > 0) {
297  TRACE("Start new step from Xold, XPold with lambda = " << lambda << " ..." << std::endl);
298  pNLP->Update(&dXneg); // restore the previous state
299 
300  pSol->Reset();
301  pSol->ScalarMul(p, lambda); // scale the Newton increment by lambda
302  }
303 
304  for (integer i = 1; i <= Size; ++i)
305  dXneg(i) = -(*pSol)(i); // save the increment; so we can restore the previous state
306 
307  TRACE("Update the nonlinear problem ... pSol->Norm()=" << pSol->Norm() << std::endl);
308 
309  pNLP->Update(pSol);
310  Residual(f, iIter);
311 
312  ++iIter;
313 
314  TRACE("New value for f:" << f << std::endl);
315 
316  doublereal dErr = 0., dErrDiff = 0.;
317  MakeResTest(pS, pNLP, *pRes, 0., dErr, dErrDiff);
318 
320 #ifdef USE_MPI
321  if (!bParallel || MBDynComm.Get_rank() == 0)
322 #endif /* USE_MPI */
323  {
324  silent_cout("\t\tf(" << iIterCnt << ":" << iIter << ")=" << std::setw(12) << f
325  << "\tErr=" << std::setw(12) << dErr
326  << "\tlambda=" << std::setw(12) << lambda
327  <<"\tslope=" << slope << std::endl);
328  }
329  }
330 
331  pS->CheckTimeStepLimit(dErr, dErrDiff);
332 
333  if (f <= fold + dAlpha * lambda * slope) {
334  TRACE("Sufficient decrease in f: backtrack" << std::endl);
335  return;
336  } else if (lambda <= dLambdaMinEff) {
337  TRACE("Checking for convergence: lambda=" << lambda << " < lambdaMin=" << dLambdaMinEff << std::endl);
338  check = true; // check for convergence
339  return;
340  } else {
341  if (uFlags & ALGORITHM_CUBIC) {
342  TRACE("Calculate new value for alam ..." << std::endl);
343  if (lambda == 1.) {
344  tmplam = -slope / (2 * (f - fold - slope));
345  TRACE_VAR(tmplam);
346  } else {
347  const doublereal rhs1 = f - fold - lambda * slope;
348  const doublereal rhs2 = f2 - fold - lambda2 * slope;
349  const doublereal a = (rhs1 / (lambda * lambda) - rhs2 / (lambda2 * lambda2)) / (lambda - lambda2);
350  const doublereal b = (-lambda2 * rhs1 / (lambda * lambda) + lambda * rhs2 / (lambda2 * lambda2)) / (lambda - lambda2);
351 
352  if (a == 0.) {
353  tmplam = -slope / (2. * b);
354  TRACE_VAR(tmplam);
355  } else {
356  const doublereal disc = b * b - 3. * a * slope;
357 
358  if (disc < 0.) {
359  tmplam = 0.5 * lambda;
360  TRACE_VAR(tmplam);
361  } else if (b <= 0.) {
362  tmplam = (-b + sqrt(disc)) / (3. * a);
363  TRACE_VAR(tmplam);
364  } else {
365  tmplam = -slope / (b + sqrt(disc));
366  TRACE_VAR(tmplam);
367  }
368 
369  if (tmplam > 0.5 * lambda) {
370  tmplam = 0.5 * lambda;
371  TRACE_VAR(tmplam);
372  }
373  }
374  }
375  lambda2 = lambda;
376  f2 = f;
377  TRACE_VAR(tmplam);
378  lambda = std::max(tmplam, dLambdaFactMin * lambda);
379  } else {
380  lambda *= dLambdaFactMin;
381  }
382  }
383 
386  }
387  } while (iIter < iMaxIterations);
388 
389  if (uFlags & VERBOSE_MODE) {
390  silent_cerr("line search warning: Maximum number of line search iterations="
391  << iMaxIterations
392  << " exceeded in line search at time step " << pDM->dGetTime()
393  << " at iteration " << iIterCnt << std::endl);
394  }
395 
397 }
398 
399 void
401  Solver *pS,
402  const integer iMaxIter,
403  const doublereal& Tol,
404  integer& iIterCnt,
405  doublereal& dErr,
406  const doublereal& SolTol,
407  doublereal& dSolErr)
408 {
409  ASSERT(pS != NULL);
410  SolutionManager *const pSM = pS->pGetSolutionManager();
411  this->pS = pS;
412  pNLP = pNonLinProblem;
413  pRes = pSM->pResHdl();
414  pSol = pSM->pSolHdl();
415  Size = pRes->iGetSize();
416 
417  if (g.iGetSize() != Size) {
418  TRACE("Resize temporary vectors ..." << std::endl);
419  g.Resize(Size);
420  p.Resize(Size);
421  dXneg.Resize(Size);
422  }
423 
424  bool check = false;
425  iIterCnt = 0;
426  dSolErr = 0.;
427  dErr = 0.;
428  doublereal dErrDiff = 0.;
429  doublereal f;
430  Residual(f, iIterCnt);
431 
432  TRACE("\t\tf(0) = " << f << std::endl);
433 
434  bool bTest = MakeResTest(pS, pNLP, *pRes, 1e-2 * Tol, dErr, dErrDiff); // use a more stringent test for the first iteration
435  doublereal dPrevErr = std::numeric_limits<doublereal>::max(); // disable error test for the first iteration
436  doublereal dErrFactor = 1.;
437 
438  if (outputIters()) {
439 #ifdef USE_MPI
440  if (!bParallel || MBDynComm.Get_rank() == 0)
441 #endif /* USE_MPI */
442  {
443  silent_cout("\tIteration(" << iIterCnt << ") " << std::setw(12) << dErr);
444 
446  silent_cout(" f=" << std::setw(12) << f);
447  }
448 
449  silent_cout(std::endl);
450  }
451  }
452 
453  pS->CheckTimeStepLimit(dErr, dErrDiff);
454 
455  if (bTest) {
456  return;
457  }
458 
459  const doublereal stpmax = (uFlags & SCALE_NEWTON_STEP)
460  ? dMaxStep * std::max(sqrt(pDM->GetpXPCurr()->Dot() + pDM->GetpXCurr()->Dot()), static_cast<doublereal>(Size))
461  : std::numeric_limits<doublereal>::max();
462 
463  TRACE_VAR(stpmax);
464 
465  doublereal dStartTimeCPU, dEndTimeCPU, dJacobianCPU, dResidualCPU, dLinSolveCPU;
466 
467  while (true) {
468  if (outputCPUTime()) {
469  dStartTimeCPU = mbdyn_clock_time();
470  }
471 
472  Jacobian();
473 
474  ASSERT(pSM->pMatHdl()->iGetNumCols() == Size);
475  ASSERT(pSM->pMatHdl()->iGetNumCols() == pRes->iGetSize());
476  ASSERT(pSM->pMatHdl()->iGetNumRows() == pRes->iGetSize());
477 
478  g.Reset();
479  pSM->pMatHdl()->MatTVecDecMul(g, *pRes); // compute gradient g = \nabla f = fjac^T \, fvec = -Jac^T \, pRes
480 
481  if (outputCPUTime()) {
482  dEndTimeCPU = mbdyn_clock_time();
483  dJacobianCPU = dEndTimeCPU - dStartTimeCPU;
484  AddTimeCPU(dJacobianCPU, CPU_JACOBIAN);
485  dStartTimeCPU = dEndTimeCPU;
486  }
487 
488  const doublereal fold = f;
489 
490  pSM->Solve();
491 
492  if (outputCPUTime()) {
493  dEndTimeCPU = mbdyn_clock_time();
494  dLinSolveCPU = dEndTimeCPU - dStartTimeCPU;
495  AddTimeCPU(dLinSolveCPU, CPU_LINEAR_SOLVER);
496  }
497 
498  if (outputSol()) {
499  pS->PrintSolution(*pSol, iIterCnt);
500  }
501 
502  if (outputCPUTime()) {
503  dStartTimeCPU = mbdyn_clock_time();
504  }
505 
506  LineSearch(stpmax, fold, f, check, iIterCnt);
507 
508  bTest = MakeResTest(pS, pNLP, *pRes, Tol, dErr, dErrDiff);
509 
510  if (outputCPUTime()) {
511  dEndTimeCPU = mbdyn_clock_time();
512  dResidualCPU = dEndTimeCPU - dStartTimeCPU;
513  AddTimeCPU(dResidualCPU, CPU_RESIDUAL);
514  }
515 
516  if (iIterCnt > 0) {
517  dErrFactor *= dErr / dPrevErr;
518  }
519 
520  iIterCnt++;
521 
522 #ifdef USE_MPI
523  if (!bParallel || MBDynComm.Get_rank() == 0)
524 #endif /* USE_MPI */
525  {
527  if (outputIters()) {
528  silent_cout("\tIteration(" << iIterCnt << ") " << std::setw(12) << dErr << " J");
529  }
530 
532  silent_cout(" cond=");
533  doublereal dCond;
534  if (pSM->bGetConditionNumber(dCond)) {
535  silent_cout(dCond);
537  AddCond(dCond);
538  silent_cout(" " << dGetCondMin() << " " << dGetCondMax() << " " << dGetCondAvg());
539  }
540  } else {
541  silent_cout("NA");
542  }
543  }
544 
545  if (outputCPUTime()) {
546  silent_cout(" CPU:" << dResidualCPU << "/" << dGetTimeCPU(CPU_RESIDUAL)
547  << "+" << dJacobianCPU << "/" << dGetTimeCPU(CPU_JACOBIAN)
548  << "+" << dLinSolveCPU << "/" << dGetTimeCPU(CPU_LINEAR_SOLVER));
549  }
550 
552  silent_cout(" f=" << std::setw(12) << f);
553 
554  if (iIterCnt > 1) {
555  silent_cout(" Err(n-1)=" << std::setw(12) << dPrevErr
556  << " Err(n)/Err(n-1)=" << std::setw(12) << dErr / dPrevErr
557  << " Err(n)/Err(1)=" << std::setw(12) << dErrFactor);
558  }
559  }
560 
561  if (outputIters()
563  || (uFlags & PRINT_CONVERGENCE_INFO)) {
564  silent_cout(std::endl);
565  }
566  }
567  }
568 
569  if (bTest) {
570  return;
571  }
572 
573  bTest = MakeSolTest(pS, *pSol, SolTol, dSolErr);
574 
575  if (outputIters()) {
576 #ifdef USE_MPI
577  if (!bParallel || MBDynComm.Get_rank() == 0)
578 #endif /* USE_MPI */
579  {
580  silent_cout("\t\tSolErr "
581  << dSolErr << std::endl);
582  }
583  }
584 
585  if (bTest) {
586  if (uFlags & VERBOSE_MODE) {
587  silent_cerr("line search warning: Convergence on solution "
588  "at time step " << pDM->dGetTime()
589  << "at iteration " << iIterCnt
590  << "\tErr(n)=" << dErr);
591 
592  if (iIterCnt >= 1) {
593  silent_cerr("\tErr(n-1)=" << dPrevErr
594  << "\tErr(n)/Err(n-1)=" << dErr/dPrevErr
595  << "\tErr(n)/Err(1) " << dErrFactor);
596  }
597 
598  silent_cerr(std::endl);
599  }
601  }
602 
603  if (check) { // lambda <= dLambdaMinEff: check for gradient zero
604  doublereal test = 0.;
605  const doublereal den = std::max(f, 0.5 * Size);
606 
607  for (integer i = 1; i <= Size; ++i) {
608  const doublereal absX = std::max(std::abs((*pDM->GetpXCurr())(i)),
609  std::abs((*pDM->GetpXPCurr())(i)));
610  const doublereal temp = std::abs(g(i)) * std::max(absX, 1.) / den;
611  if (temp > test) {
612  test = temp;
613  }
614  }
615 
616  if (test < dTolMin) { // we are at a local minimum of the function f
617  if (uFlags & VERBOSE_MODE) {
618  silent_cerr("line search warning: Zero gradient detected at time step "
619  << pDM->dGetTime() << " at iteration "
620  << iIterCnt << " (spurious convergence) test=" << test
621  << " < tol=" << dTolMin
622  << "\tErr(n)=" << dErr
623  << " > Tol = " << Tol << std::endl);
624  }
625 
627  return;
628  } else {
630  }
631  } else {
632  if (uFlags & VERBOSE_MODE) {
633  silent_cerr("line search warning: lambda min"
634  " has been reached at time step " << pDM->dGetTime()
635  << " at iteration " << iIterCnt
636  << " but the gradient is not zero" << std::endl);
637  }
638 
639  if (uFlags & ABORT_AT_LAMBDA_MIN) {
641  }
642  }
643  } else if (dErr > dPrevErr) { // f <= fold + dAlpha * lambda * slope
644  // We should not get here since f was decreased also Err should be decreased
645  // If not it could be a numerical problem (e.g. the tolerance could be too small)
646  if (uFlags & VERBOSE_MODE) {
647  silent_cerr("line search warning: f has been reduced during line search but the residual could not be reduced at time step "
648  << pDM->dGetTime()
649  << " at iteration " << iIterCnt << std::endl);
650  }
651 
652  // Do not throw an exception here because if we specify for example
653  // tolerance: <<Tol>>, test, minmax;
654  // it could happen that the the norm of the residual vector is decreased
655  // but the maximum residual is not!
656 
657  // In any case we will check for divergence if DIVERGENCE_CHECK is enabled.
658  }
659 
660  if (dErrFactor > dDivergenceCheck) {
661  if (uFlags & DIVERGENCE_CHECK) {
662  if (uFlags & VERBOSE_MODE) {
663  silent_cerr("line search warning: The residual could not be decreased"
664  " at time step " << pDM->dGetTime()
665  << " at iteration " << iIterCnt << std::endl);
666 
667  if (iIterCnt > 1) {
668  silent_cerr("Err(n-1)=" << dPrevErr
669  << "\tErr(n)=" << dErr
670  << "\tErr(n)/Err(n-1)=" << dErr/dPrevErr
671  << "\tErr(n)/Err(1)=" << dErrFactor << std::endl);
672  }
673  }
675  }
676  }
677 
678  if (iIterCnt >= std::abs(iMaxIter)) {
679  if (iMaxIter < 0 && dErrFactor < 1.) {
680  return;
681  }
682  if (outputBailout()) {
683  pS->PrintResidual(*pRes, iIterCnt);
684  }
686  }
687 
688  dPrevErr = dErr;
689  }
690 }
691 
virtual void Reset(void)=0
virtual VectorHandler * pResHdl(void) const =0
void Solve(const NonlinearProblem *pNLP, Solver *pS, const integer iMaxIter, const doublereal &Tol, integer &iIterCnt, doublereal &dErr, const doublereal &SolTol, doublereal &dSolErr)
Definition: linesearch.cc:400
bool outputMatrixConditionNumber(void) const
virtual SolutionManager * pGetSolutionManager(void) const
Definition: solver.h:398
void AddCond(doublereal dCond)
Definition: nonlin.h:331
virtual void Jacobian(MatrixHandler *pJac) const =0
doublereal dGetCondMax() const
Definition: nonlin.h:275
virtual integer iGetNumCols(void) const =0
bool outputIters(void) const
MyVectorHandler p
Definition: linesearch.h:85
integer TotJac
Definition: nonlin.h:252
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
VectorHandler * pRes
Definition: linesearch.h:83
bool outputBailout(void) const
#define TRACE(expr)
Definition: linesearch.cc:77
MatrixHandler::Norm_t GetCondMatNorm(void) const
doublereal dMaxStep
Definition: linesearch.h:60
virtual bool MakeSolTest(Solver *pS, const VectorHandler &Vec, const doublereal &dTol, doublereal &dTest)
Definition: nonlin.cc:497
virtual void PrintResidual(const VectorHandler &Res, integer iIterCnt) const
Definition: solver.cc:5194
virtual bool MakeResTest(Solver *pS, const NonlinearProblem *pNLP, const VectorHandler &Vec, const doublereal &dTol, doublereal &dTest, doublereal &dTestDiff)
Definition: nonlin.cc:474
doublereal dGetTime(void) const
Definition: dataman2.cc:165
double mbdyn_clock_time()
Definition: clock_time.cc:51
virtual VectorHandler & MatTVecDecMul(VectorHandler &out, const VectorHandler &in) const
Definition: mh.cc:368
virtual void CheckTimeStepLimit(doublereal dErr, doublereal dErrDiff) const
Definition: solver.cc:5205
virtual doublereal InnerProd(const VectorHandler &VH) const
Definition: vh.cc:269
MyVectorHandler g
Definition: linesearch.h:86
doublereal dGetCondAvg() const
Definition: nonlin.h:277
doublereal dTolMin
Definition: linesearch.h:58
~LineSearchSolver(void)
Definition: linesearch.cc:134
void LineSearch(doublereal stpmax, doublereal fold, doublereal &f, bool &check, const integer &iIterCnt)
Definition: linesearch.cc:210
bool outputRes(void) const
integer Size
Definition: nonlin.h:251
VectorHandler * pSol
Definition: linesearch.h:84
virtual void Residual(VectorHandler *pRes) const =0
bool outputJac(void) const
#define NO_OP
Definition: myassert.h:74
doublereal dGetCondMin() const
Definition: nonlin.h:276
virtual doublereal Dot(void) const
Definition: vh.cc:244
virtual integer iGetSize(void) const =0
virtual doublereal Norm(void) const
Definition: vh.cc:262
doublereal dGetTimeCPU(CPUTimeType eType) const
Definition: nonlin.h:346
bool outputSolverConditionNumber(void) const
const NonlinearProblem * pNLP
Definition: linesearch.h:88
virtual doublereal ConditionNumber(enum Norm_t eNorm=NORM_1) const
Definition: mh.cc:451
virtual void Resize(integer iSize)
Definition: vh.cc:347
const DataManager *const pDM
Definition: linesearch.h:90
int mbdyn_stop_at_end_of_iteration(void)
Definition: solver.cc:172
doublereal dLambdaMin
Definition: linesearch.h:62
virtual integer iGetSize(void) const
Definition: vh.h:255
doublereal dTolX
Definition: linesearch.h:57
bool outputSol(void) const
doublereal dDivergenceCheck
Definition: linesearch.h:64
void Residual(doublereal &f, integer iIterCnt)
Definition: linesearch.cc:140
virtual MatrixHandler * pMatHdl(void) const =0
#define TRACE_FLAG(varname, flag)
Definition: linesearch.cc:81
const VectorHandler * GetpXPCurr(void) const
Definition: dataman.h:857
virtual VectorHandler & ScalarMul(const VectorHandler &VH, const doublereal &d)
Definition: vh.cc:145
virtual void MatrReset(void)=0
void AddTimeCPU(doublereal dTime, CPUTimeType eType)
Definition: nonlin.h:355
virtual void Solve(void)=0
MyVectorHandler dXneg
Definition: linesearch.h:87
#define ASSERT(expression)
Definition: colamd.c:977
const VectorHandler * GetpXCurr(void) const
Definition: dataman.h:853
GradientExpression< UnaryExpr< FuncSqrt, Expr > > sqrt(const GradientExpression< Expr > &u)
Definition: gradient.h:2974
virtual void MatrInitialize(void)
Definition: solman.cc:72
virtual void Reset(void)
Definition: vh.cc:459
#define TRACE_VAR(varname)
Definition: linesearch.cc:80
doublereal dMinStepScale
Definition: linesearch.h:65
doublereal dAlpha
Definition: linesearch.h:61
struct option options[]
Definition: ann_in.c:46
Definition: solver.h:78
LineSearchSolver(DataManager *pDM, const NonlinearSolverOptions &options, const struct LineSearchParameters &param)
Definition: linesearch.cc:102
integer iMaxIterations
Definition: linesearch.h:59
bool bGetConditionNumber(doublereal &dCond) const
Definition: solman.cc:107
virtual void PrintSolution(const VectorHandler &Sol, integer iIterCnt) const
Definition: solver.cc:5200
bool outputCPUTime(void) const
static const doublereal a
Definition: hfluid_.h:289
doublereal dLambdaFactMin
Definition: linesearch.h:63
virtual VectorHandler * pSolHdl(void) const =0
virtual void Update(const VectorHandler *pSol) const =0
double doublereal
Definition: colamd.c:52
long int integer
Definition: colamd.c:51
bool outputSolverConditionStat(void) const
virtual integer iGetNumRows(void) const =0