static void PrintFinalStats(void *mem) { long int netf, ncfn, ncfl; IDAGetNumErrTestFails(mem, &netf); IDAGetNumNonlinSolvConvFails(mem, &ncfn); IDASpilsGetNumConvFails(mem, &ncfl); printf("\nError test failures = %ld\n", netf); printf("Nonlinear convergence failures = %ld\n", ncfn); printf("Linear convergence failures = %ld\n", ncfl); }
static void PrintFinalStats(void *mem) { long int nst, nre, nreLS, netf, ncfn, nni, ncfl, nli, npe, nps, nge; int flag; flag = IDAGetNumSteps(mem, &nst); check_flag(&flag, "IDAGetNumSteps", 1, 0); flag = IDAGetNumResEvals(mem, &nre); check_flag(&flag, "IDAGetNumResEvals", 1, 0); flag = IDAGetNumErrTestFails(mem, &netf); check_flag(&flag, "IDAGetNumErrTestFails", 1, 0); flag = IDAGetNumNonlinSolvConvFails(mem, &ncfn); check_flag(&flag, "IDAGetNumNonlinSolvConvFails", 1, 0); flag = IDAGetNumNonlinSolvIters(mem, &nni); check_flag(&flag, "IDAGetNumNonlinSolvIters", 1, 0); flag = IDASpilsGetNumConvFails(mem, &ncfl); check_flag(&flag, "IDASpilsGetNumConvFails", 1, 0); flag = IDASpilsGetNumLinIters(mem, &nli); check_flag(&flag, "IDASpilsGetNumLinIters", 1, 0); flag = IDASpilsGetNumPrecEvals(mem, &npe); check_flag(&flag, "IDASpilsGetNumPrecEvals", 1, 0); flag = IDASpilsGetNumPrecSolves(mem, &nps); check_flag(&flag, "IDASpilsGetNumPrecSolves", 1, 0); flag = IDASpilsGetNumResEvals(mem, &nreLS); check_flag(&flag, "IDASpilsGetNumResEvals", 1, 0); flag = IDABBDPrecGetNumGfnEvals(mem, &nge); check_flag(&flag, "IDABBDPrecGetNumGfnEvals", 1, 0); printf("-----------------------------------------------------------\n"); printf("\nFinal statistics: \n\n"); printf("Number of steps = %ld\n", nst); printf("Number of residual evaluations = %ld\n", nre+nreLS); printf("Number of nonlinear iterations = %ld\n", nni); printf("Number of error test failures = %ld\n", netf); printf("Number of nonlinear conv. failures = %ld\n\n", ncfn); printf("Number of linear iterations = %ld\n", nli); printf("Number of linear conv. failures = %ld\n\n", ncfl); printf("Number of preconditioner setups = %ld\n", npe); printf("Number of preconditioner solves = %ld\n", nps); printf("Number of local residual evals. = %ld\n", nge); }
int main() { void *mem; UserData data; N_Vector uu, up, constraints, res; int ier, iout; realtype rtol, atol, t0, t1, tout, tret; long int netf, ncfn, ncfl; mem = NULL; data = NULL; uu = up = constraints = res = NULL; /* Allocate N-vectors and the user data structure. */ uu = N_VNew_Serial(NEQ); if(check_flag((void *)uu, "N_VNew_Serial", 0)) return(1); up = N_VNew_Serial(NEQ); if(check_flag((void *)up, "N_VNew_Serial", 0)) return(1); res = N_VNew_Serial(NEQ); if(check_flag((void *)res, "N_VNew_Serial", 0)) return(1); constraints = N_VNew_Serial(NEQ); if(check_flag((void *)constraints, "N_VNew_Serial", 0)) return(1); data = (UserData) malloc(sizeof *data); data->pp = NULL; if(check_flag((void *)data, "malloc", 2)) return(1); /* Assign parameters in the user data structure. */ data->mm = MGRID; data->dx = ONE/(MGRID-ONE); data->coeff = ONE/(data->dx * data->dx); data->pp = N_VNew_Serial(NEQ); if(check_flag((void *)data->pp, "N_VNew_Serial", 0)) return(1); /* Initialize uu, up. */ SetInitialProfile(data, uu, up, res); /* Set constraints to all 1's for nonnegative solution values. */ N_VConst(ONE, constraints); /* Assign various parameters. */ t0 = ZERO; t1 = RCONST(0.01); rtol = ZERO; atol = RCONST(1.0e-3); /* Call IDACreate and IDAMalloc to initialize solution */ mem = IDACreate(); if(check_flag((void *)mem, "IDACreate", 0)) return(1); ier = IDASetUserData(mem, data); if(check_flag(&ier, "IDASetUserData", 1)) return(1); ier = IDASetConstraints(mem, constraints); if(check_flag(&ier, "IDASetConstraints", 1)) return(1); N_VDestroy_Serial(constraints); ier = IDAInit(mem, resHeat, t0, uu, up); if(check_flag(&ier, "IDAInit", 1)) return(1); ier = IDASStolerances(mem, rtol, atol); if(check_flag(&ier, "IDASStolerances", 1)) return(1); /* Call IDASpgmr to specify the linear solver. */ ier = IDASpgmr(mem, 0); if(check_flag(&ier, "IDASpgmr", 1)) return(1); ier = IDASpilsSetPreconditioner(mem, PsetupHeat, PsolveHeat); if(check_flag(&ier, "IDASpilsSetPreconditioner", 1)) return(1); /* Print output heading. */ PrintHeader(rtol, atol); /* * ------------------------------------------------------------------------- * CASE I * ------------------------------------------------------------------------- */ /* Print case number, output table heading, and initial line of table. */ printf("\n\nCase 1: gsytpe = MODIFIED_GS\n"); printf("\n Output Summary (umax = max-norm of solution) \n\n"); printf(" time umax k nst nni nje nre nreLS h npe nps\n" ); printf("----------------------------------------------------------------------\n"); /* Loop over output times, call IDASolve, and print results. */ for (tout = t1,iout = 1; iout <= NOUT ; iout++, tout *= TWO) { ier = IDASolve(mem, tout, &tret, uu, up, IDA_NORMAL); if(check_flag(&ier, "IDASolve", 1)) return(1); PrintOutput(mem, tret, uu); } /* Print remaining counters. */ ier = IDAGetNumErrTestFails(mem, &netf); check_flag(&ier, "IDAGetNumErrTestFails", 1); ier = IDAGetNumNonlinSolvConvFails(mem, &ncfn); check_flag(&ier, "IDAGetNumNonlinSolvConvFails", 1); ier = IDASpilsGetNumConvFails(mem, &ncfl); check_flag(&ier, "IDASpilsGetNumConvFails", 1); printf("\nError test failures = %ld\n", netf); printf("Nonlinear convergence failures = %ld\n", ncfn); printf("Linear convergence failures = %ld\n", ncfl); /* * ------------------------------------------------------------------------- * CASE II * ------------------------------------------------------------------------- */ /* Re-initialize uu, up. */ SetInitialProfile(data, uu, up, res); /* Re-initialize IDA and IDASPGMR */ ier = IDAReInit(mem, t0, uu, up); if(check_flag(&ier, "IDAReInit", 1)) return(1); ier = IDASpilsSetGSType(mem, CLASSICAL_GS); if(check_flag(&ier, "IDASpilsSetGSType",1)) return(1); /* Print case number, output table heading, and initial line of table. */ printf("\n\nCase 2: gstype = CLASSICAL_GS\n"); printf("\n Output Summary (umax = max-norm of solution) \n\n"); printf(" time umax k nst nni nje nre nreLS h npe nps\n" ); printf("----------------------------------------------------------------------\n"); /* Loop over output times, call IDASolve, and print results. */ for (tout = t1,iout = 1; iout <= NOUT ; iout++, tout *= TWO) { ier = IDASolve(mem, tout, &tret, uu, up, IDA_NORMAL); if(check_flag(&ier, "IDASolve", 1)) return(1); PrintOutput(mem, tret, uu); } /* Print remaining counters. */ ier = IDAGetNumErrTestFails(mem, &netf); check_flag(&ier, "IDAGetNumErrTestFails", 1); ier = IDAGetNumNonlinSolvConvFails(mem, &ncfn); check_flag(&ier, "IDAGetNumNonlinSolvConvFails", 1); ier = IDASpilsGetNumConvFails(mem, &ncfl); check_flag(&ier, "IDASpilsGetNumConvFails", 1); printf("\nError test failures = %ld\n", netf); printf("Nonlinear convergence failures = %ld\n", ncfn); printf("Linear convergence failures = %ld\n", ncfl); /* Free Memory */ IDAFree(&mem); N_VDestroy_Serial(uu); N_VDestroy_Serial(up); N_VDestroy_Serial(res); N_VDestroy_Serial(data->pp); free(data); return(0); }
void FIDA_SOLVE(realtype *tout, realtype *tret, realtype *yret, realtype *ypret, int *itask, int *ier) { int klast, kcur; *ier = 0; /* Attach user data to vectors */ N_VSetArrayPointer(yret, F2C_IDA_vec); N_VSetArrayPointer(ypret, F2C_IDA_ypvec); *ier = IDASolve(IDA_idamem, *tout, tret, F2C_IDA_vec, F2C_IDA_ypvec, *itask); /* Reset data pointers */ N_VSetArrayPointer(NULL, F2C_IDA_vec); N_VSetArrayPointer(NULL, F2C_IDA_ypvec); /* Set optional outputs */ IDAGetWorkSpace(IDA_idamem, &IDA_iout[0], /* LENRW */ &IDA_iout[1]); /* LENIW */ IDAGetIntegratorStats(IDA_idamem, &IDA_iout[2], /* NST */ &IDA_iout[3], /* NRE */ &IDA_iout[7], /* NSETUPS */ &IDA_iout[4], /* NETF */ &klast, /* KLAST */ &kcur, /* KCUR */ &IDA_rout[0], /* HINUSED */ &IDA_rout[1], /* HLAST */ &IDA_rout[2], /* HCUR */ &IDA_rout[3]); /* TCUR */ IDA_iout[8] = (long int) klast; IDA_iout[9] = (long int) kcur; IDAGetNonlinSolvStats(IDA_idamem, &IDA_iout[6], /* NNI */ &IDA_iout[5]); /* NCFN */ IDAGetNumBacktrackOps(IDA_idamem, &IDA_iout[10]); /* NBCKTRK */ IDAGetTolScaleFactor(IDA_idamem, &IDA_rout[4]); /* TOLSFAC */ /* Root finding is on */ if (IDA_nrtfn != 0) IDAGetNumGEvals(IDA_idamem, &IDA_iout[11]); /* NGE */ switch(IDA_ls) { case IDA_LS_DENSE: case IDA_LS_BAND: case IDA_LS_LAPACKDENSE: case IDA_LS_LAPACKBAND: IDADlsGetWorkSpace(IDA_idamem, &IDA_iout[12], &IDA_iout[13]); /* LENRWLS, LENIWLS */ IDADlsGetLastFlag(IDA_idamem, &IDA_iout[14]); /* LSTF */ IDADlsGetNumResEvals(IDA_idamem, &IDA_iout[15]); /* NRE */ IDADlsGetNumJacEvals(IDA_idamem, &IDA_iout[16]); /* NJE */ break; case IDA_LS_KLU: case IDA_LS_SUPERLUMT: IDASlsGetLastFlag(IDA_idamem, &IDA_iout[14]); /* LSTF */ IDASlsGetNumJacEvals(IDA_idamem, &IDA_iout[16]); /* NJE */ break; case IDA_LS_SPGMR: case IDA_LS_SPBCG: case IDA_LS_SPTFQMR: IDASpilsGetWorkSpace(IDA_idamem, &IDA_iout[12], &IDA_iout[13]); /* LENRWLS, LENIWLS */ IDASpilsGetLastFlag(IDA_idamem, &IDA_iout[14]); /* LSTF */ IDASpilsGetNumResEvals(IDA_idamem, &IDA_iout[15]); /* NRE */ IDASpilsGetNumJtimesEvals(IDA_idamem, &IDA_iout[16]); /* NJE */ IDASpilsGetNumPrecEvals(IDA_idamem, &IDA_iout[17]); /* NPE */ IDASpilsGetNumPrecSolves(IDA_idamem, &IDA_iout[18]); /* NPS */ IDASpilsGetNumLinIters(IDA_idamem, &IDA_iout[19]); /* NLI */ IDASpilsGetNumConvFails(IDA_idamem, &IDA_iout[20]); /* NCFL */ break; } return; }