MCPcopy Create free account
hub / github.com/boutproject/BOUT-dev / CVNewtonIteration

Function CVNewtonIteration

externalpackages/PVODE/source/cvode.cpp:1968–2030  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1966*********************************************************************/
1967
1968static int CVNewtonIteration(CVodeMem cv_mem)
1969{
1970 int m, ret;
1971 real del, delp, dcon;
1972 N_Vector b;
1973
1974
1975 mnewt = m = 0;
1976
1977 /* Looping point for Newton iteration */
1978 loop {
1979
1980 /* Evaluate the residual of the nonlinear system*/
1981 N_VLinearSum(rl1, zn[1], ONE, acor, tempv);
1982 N_VLinearSum(gamma, ftemp, -ONE, tempv, tempv);
1983
1984 /* Call the lsolve function */
1985 b = tempv;
1986 ret = lsolve(cv_mem, b, y, ftemp);
1987 nni++;
1988
1989 if (ret < 0) return(SOLVE_FAIL_UNREC);
1990
1991 /* If lsolve had a recoverable failure and Jacobian data is
1992 not current, signal to try the solution again */
1993 if (ret > 0) {
1994 if ((!jcur) && (setupNonNull)) return(TRY_AGAIN);
1995 return(CONV_FAIL);
1996 }
1997/* *************** */
1998 /* Get WRMS norm of correction; add correction to acor and y */
1999 del = N_VWrmsNorm(b, ewt);
2000 N_VLinearSum(ONE, acor, ONE, b, acor);
2001 N_VLinearSum(ONE, zn[0], ONE, acor, y);
2002
2003 /* Test for convergence. If m > 0, an estimate of the convergence
2004 rate constant is stored in crate, and used in the test. */
2005 if (m > 0) {
2006 crate = MAX(CRDOWN * crate, del/delp);
2007 }
2008 dcon = del * MIN(ONE, crate) / tq[4];
2009
2010 if (dcon <= ONE) {
2011 acnrm = (m==0) ? del : N_VWrmsNorm(acor, ewt);
2012 jcur = FALSE;
2013 return(SOLVED); /* Nonlinear system was solved successfully */
2014 }
2015
2016 mnewt = ++m;
2017
2018 /* Stop at maxcor iterations or if iter. seems to be diverging.
2019 If still not converged and Jacobian data is not current,
2020 signal to try the solution again */
2021 if ((m == maxcor) || ((m >= 2) && (del > RDIV*delp))) {
2022 if ((!jcur) && (setupNonNull)) return(TRY_AGAIN);
2023 return(CONV_FAIL);
2024 }
2025

Callers 1

CVnlsNewtonFunction · 0.85

Calls 3

N_VLinearSumFunction · 0.85
N_VWrmsNormFunction · 0.85
fFunction · 0.85

Tested by

no test coverage detected