Exemplo n.º 1
0
/* 
 * Get and print some final statistics
 */
void PrintFinalStats(struct Integrator* integrator)
{
  void* cvode_mem = integrator->cvode_mem;
  long int lenrw = -1, leniw = -1, nst = -1, nfe = -1, nsetups = -1, nni = -1, ncfn = -1, netf = -1;
  long int lenrwLS = -1, leniwLS = -1, nje = -1, nfeLS = -1,npe = -1,nps = -1,ncfl = -1,nli = -1;
  int flag;

  flag = CVodeGetWorkSpace(cvode_mem, &lenrw, &leniw);
  check_flag(&flag, "CVodeGetWorkSpace", 1);
  flag = CVodeGetNumSteps(cvode_mem, &nst);
  check_flag(&flag, "CVodeGetNumSteps", 1);
  flag = CVodeGetNumRhsEvals(cvode_mem, &nfe);
  check_flag(&flag, "CVodeGetNumRhsEvals", 1);
  flag = CVodeGetNumLinSolvSetups(cvode_mem, &nsetups);
  check_flag(&flag, "CVodeGetNumLinSolvSetups", 1);
  flag = CVodeGetNumErrTestFails(cvode_mem, &netf);
  check_flag(&flag, "CVodeGetNumErrTestFails", 1);
  flag = CVodeGetNumNonlinSolvIters(cvode_mem, &nni);
  check_flag(&flag, "CVodeGetNumNonlinSolvIters", 1);
  flag = CVodeGetNumNonlinSolvConvFails(cvode_mem, &ncfn);
  check_flag(&flag, "CVodeGetNumNonlinSolvConvFails", 1);

  printf("\n Final integrator statistics for this run:\n");
  printf(" (MM: %s; IM: %s; LS: %s; max-step: %0.4le)\n",
    multistepMethodToString(
      simulationGetMultistepMethod(integrator->simulation)),
    iterationMethodToString(
      simulationGetIterationMethod(integrator->simulation)),
    linearSolverToString(simulationGetLinearSolver(integrator->simulation)),
    simulationGetBvarMaxStep(integrator->simulation));
  printf(" CVode real workspace length              = %4ld \n", lenrw);
  printf(" CVode integer workspace length           = %4ld \n", leniw);
  printf(" Number of steps                          = %4ld \n",  nst);
  printf(" Number of f-s                            = %4ld \n",  nfe);
  printf(" Number of setups                         = %4ld \n",  nsetups);
  printf(" Number of nonlinear iterations           = %4ld \n",  nni);
  printf(" Number of nonlinear convergence failures = %4ld \n",  ncfn);
  printf(" Number of error test failures            = %4ld \n\n",netf);

  if (simulationGetIterationMethod(integrator->simulation) == NEWTON)
  {
    enum LinearSolver solver =
      simulationGetLinearSolver(integrator->simulation);
    switch(solver)
    {
      case DENSE:
      {
        //flag = CVDenseGetNumJacEvals(cvode_mem, &nje);
        //check_flag(&flag, "CVDenseGetNumJacEvals", 1);
        //flag = CVDenseGetNumRhsEvals(cvode_mem, &nfeLS);
        //check_flag(&flag, "CVDenseGetNumRhsEvals", 1);
        //flag = CVDenseGetWorkSpace(cvode_mem, &lenrwLS, &leniwLS);
        //check_flag(&flag, "CVDenseGetWorkSpace", 1);
      } break;
      case BAND:
      {
        //flag = CVBandGetNumJacEvals(cvode_mem, &nje);
        //check_flag(&flag, "CVBandGetNumJacEvals", 1);
        //flag = CVBandGetNumRhsEvals(cvode_mem, &nfeLS);
        //check_flag(&flag, "CVBandGetNumRhsEvals", 1);
        //flag = CVBandGetWorkSpace(cvode_mem, &lenrwLS, &leniwLS);
        //check_flag(&flag, "CVBandGetWorkSpace", 1);
      } break;
      case DIAG:
      {
        nje = nsetups;
        flag = CVDiagGetNumRhsEvals(cvode_mem, &nfeLS);
        check_flag(&flag, "CVDiagGetNumRhsEvals", 1);
        flag = CVDiagGetWorkSpace(cvode_mem, &lenrwLS, &leniwLS);
        check_flag(&flag, "CVDiagGetWorkSpace", 1);
      } break;
      case SPGMR:
      case SPBCG:
      case SPTFQMR:
      {
        nje = nsetups;
        flag = CVSpilsGetWorkSpace(cvode_mem,&lenrwLS,&leniwLS);
        check_flag(&flag, "CVSpilsGetWorkSpace", 1);
        flag = CVSpilsGetNumRhsEvals(cvode_mem, &nfeLS);
        check_flag(&flag, "CVSpilsGetNumRhsEvals", 1);
        
        flag = CVSpilsGetNumLinIters(cvode_mem, &nli);
        check_flag(&flag, "CVSpilsGetNumLinIters", 1);
        flag = CVSpilsGetNumPrecEvals(cvode_mem, &npe);
        check_flag(&flag, "CVSpilsGetNumPrecEvals", 1);
        flag = CVSpilsGetNumPrecSolves(cvode_mem, &nps);
        check_flag(&flag, "CVSpilsGetNumPrecSolves", 1);
        flag = CVSpilsGetNumConvFails(cvode_mem, &ncfl);
        check_flag(&flag, "CVSpilsGetNumConvFails", 1);
      } break;
      default:
      {
        nje = -1;
        nfeLS = -1;
        lenrwLS = -1;
        leniwLS = -1;
      }
      break;
    }
    printf(" Linear solver real workspace length      = %4ld \n", lenrwLS);
    printf(" Linear solver integer workspace length   = %4ld \n", leniwLS);
    printf(" Number of Jacobian evaluations           = %4ld \n", nje);
    printf(" Number of f evals. in linear solver      = %4ld \n", nfeLS);
    if ((solver == SPGMR) || (solver == SPBCG) ||
      (solver == SPTFQMR))
    {
      printf(" Number of linear iterations              = %4ld \n",nli);
      printf(" Number of preconditioner evaluations     = %4ld \n",npe);
      printf(" Number of preconditioner solves          = %4ld \n",nps);
      printf(" Number of convergence failures           = %4ld \n",ncfl);
    }
    printf("\n");
  }
}
Exemplo n.º 2
0
void FCV_CVODE(realtype *tout, realtype *t, realtype *y, int *itask, int *ier)
{
  realtype h0u;
  int qu, qcur;

  /* 
     tout      is the t value where output is desired
     F2C_vec   is the N_Vector containing the solution on return
     t         is the returned independent variable value
     itask     is the task indicator (1 = CV_NORMAL, 2 = CV_ONE_STEP, 
                                      3 = CV_NORMAL_TSTOP, 4 = CV_ONE_STEP_TSTOP) 
  */

  *ier = CVode(CV_cvodemem, *tout, F2C_vec, t, *itask);

  y = N_VGetArrayPointer(F2C_vec);

  /* Load optional outputs in iopt & ropt */
  if ( (CV_iopt != NULL) && (CV_ropt != NULL) ) {

    CVodeGetIntegratorStats(CV_cvodemem, 
                            &CV_iopt[3],  /* NST */
                            &CV_iopt[4],  /* NFE */ 
                            &CV_iopt[5],  /* NSETUPS */ 
                            &CV_iopt[8],  /* NETF */ 
                            &qu,
                            &qcur,
                            &h0u,
                            &CV_ropt[3],  /* HU */ 
                            &CV_ropt[4],  /* HCUR */ 
                            &CV_ropt[5]);  /* TCUR */ 
    CV_iopt[9]  = (long int)qu;  /* QU */ 
    CV_iopt[10] = (long int)qcur;  /* QCUR */ 
    CVodeGetTolScaleFactor(CV_cvodemem, &CV_ropt[6]);
    CVodeGetNonlinSolvStats(CV_cvodemem,
                            &CV_iopt[6],  /* NNI */
                            &CV_iopt[7]);  /* NCFN */
    CVodeGetWorkSpace(CV_cvodemem,
                      &CV_iopt[11],  /* LENRW */
                      &CV_iopt[12]);  /* LENIW */
    if (CV_optin && (CV_iopt[13] > 0))
      CVodeGetNumStabLimOrderReds(CV_cvodemem, &CV_iopt[14]);  /* NOR */

    /* Root finding is on */
    if (CV_nrtfn != 0)
      CVodeGetNumGEvals(CV_cvodemem, &CV_iopt[24]);

    switch(CV_ls) {
    case 1:
      CVDenseGetWorkSpace(CV_cvodemem, &CV_iopt[15], &CV_iopt[16]);  /* LRW and LIW */
      CVDenseGetNumJacEvals(CV_cvodemem, &CV_iopt[17]);  /* NJE */
      CVDenseGetLastFlag(CV_cvodemem, (int *) &CV_iopt[25]);  /* last linear solver flag */
      break;
    case 2:
      CVBandGetWorkSpace(CV_cvodemem, &CV_iopt[15], &CV_iopt[16]);  /* LRW and LIW */
      CVBandGetNumJacEvals(CV_cvodemem, &CV_iopt[17]);  /* NJE */
      CVBandGetLastFlag(CV_cvodemem, (int *) &CV_iopt[25]);  /* last linear solver flag */
      break;
    case 3:
      CVDiagGetWorkSpace(CV_cvodemem, &CV_iopt[15], &CV_iopt[16]);  /* LRW and LIW */
      CVDiagGetLastFlag(CV_cvodemem, (int *) &CV_iopt[25]);  /* last linear solver flag */
      break;
    case 4:
      CVSpgmrGetWorkSpace(CV_cvodemem, &CV_iopt[15], &CV_iopt[16]);  /* LRW and LIW */
      CVSpgmrGetNumPrecEvals(CV_cvodemem, &CV_iopt[17]);  /* NPE */
      CVSpgmrGetNumLinIters(CV_cvodemem, &CV_iopt[18]);  /* NLI */
      CVSpgmrGetNumPrecSolves(CV_cvodemem, &CV_iopt[19]);  /* NPS */
      CVSpgmrGetNumConvFails(CV_cvodemem, &CV_iopt[20]);  /* NCFL */
      CVSpgmrGetLastFlag(CV_cvodemem, (int *) &CV_iopt[25]);  /* last linear solver flag */
      break;
    }
  }
}
Exemplo n.º 3
0
static void PrintFinalStats(void *cvode_mem, int miter, realtype ero)
{
  long int lenrw, leniw, nst, nfe, nsetups, nni, ncfn, netf;
  long int lenrwL, leniwL, nje, nfeL;
  int flag;

  flag = CVodeGetWorkSpace(cvode_mem, &lenrw, &leniw);
  check_flag(&flag, "CVodeGetWorkSpace", 1);
  flag = CVodeGetNumSteps(cvode_mem, &nst);
  check_flag(&flag, "CVodeGetNumSteps", 1);
  flag = CVodeGetNumRhsEvals(cvode_mem, &nfe);
  check_flag(&flag, "CVodeGetNumRhsEvals", 1);
  flag = CVodeGetNumLinSolvSetups(cvode_mem, &nsetups);
  check_flag(&flag, "CVodeGetNumLinSolvSetups", 1);
  flag = CVodeGetNumErrTestFails(cvode_mem, &netf);
  check_flag(&flag, "CVodeGetNumErrTestFails", 1);
  flag = CVodeGetNumNonlinSolvIters(cvode_mem, &nni);
  check_flag(&flag, "CVodeGetNumNonlinSolvIters", 1);
  flag = CVodeGetNumNonlinSolvConvFails(cvode_mem, &ncfn);
  check_flag(&flag, "CVodeGetNumNonlinSolvConvFails", 1);

  printf("\n Final statistics for this run:\n\n");
  printf(" CVode real workspace length              = %4ld \n", lenrw);
  printf(" CVode integer workspace length           = %4ld \n", leniw);
  printf(" Number of steps                          = %4ld \n",  nst);
  printf(" Number of f-s                            = %4ld \n",  nfe);
  printf(" Number of setups                         = %4ld \n",  nsetups);
  printf(" Number of nonlinear iterations           = %4ld \n",  nni);
  printf(" Number of nonlinear convergence failures = %4ld \n",  ncfn);
  printf(" Number of error test failures            = %4ld \n\n",netf);
  
  if (miter != FUNC) {
    switch(miter) {
    case DENSE_USER :
    case DENSE_DQ   :
      flag = CVDenseGetNumJacEvals(cvode_mem, &nje);
      check_flag(&flag, "CVDenseGetNumJacEvals", 1);
      flag = CVDenseGetNumRhsEvals(cvode_mem, &nfeL);
      check_flag(&flag, "CVDenseGetNumRhsEvals", 1);
      flag = CVDenseGetWorkSpace(cvode_mem, &lenrwL, &leniwL);
      check_flag(&flag, "CVDenseGetWorkSpace", 1);
      break;
    case BAND_USER  :
    case BAND_DQ    :
      flag = CVBandGetNumJacEvals(cvode_mem, &nje);
      check_flag(&flag, "CVBandGetNumJacEvals", 1);
      flag = CVBandGetNumRhsEvals(cvode_mem, &nfeL);
      check_flag(&flag, "CVBandGetNumRhsEvals", 1);
      flag = CVBandGetWorkSpace(cvode_mem, &lenrwL, &leniwL);
      check_flag(&flag, "CVBandGetWorkSpace", 1);
      break;  
    case DIAG       :
      nje = nsetups;
      flag = CVDiagGetNumRhsEvals(cvode_mem, &nfeL);
      check_flag(&flag, "CVDiagGetNumRhsEvals", 1);
      flag = CVDiagGetWorkSpace(cvode_mem, &lenrwL, &leniwL);
      check_flag(&flag, "CVDiagGetWorkSpace", 1);
      break;
    }
    printf(" Linear solver real workspace length      = %4ld \n", lenrwL);
    printf(" Linear solver integer workspace length   = %4ld \n", leniwL);
    printf(" Number of Jacobian evaluations           = %4ld  \n", nje);
    printf(" Number of f-s evaluations                = %4ld \n\n", nfeL);
  }
  
#if defined(SUNDIALS_EXTENDED_PRECISION)
  printf(" Error overrun = %.3Lf \n", ero);
#else
  printf(" Error overrun = %.3f \n", ero);
#endif
}
Exemplo n.º 4
0
void FCV_CVODE(realtype *tout, realtype *t, realtype *y, int *itask, int *ier)
{
  /* 
     tout          is the t value where output is desired
     F2C_CVODE_vec is the N_Vector containing the solution on return
     t             is the returned independent variable value
     itask         is the task indicator (1 = CV_NORMAL, 2 = CV_ONE_STEP, 
                                          3 = CV_NORMAL_TSTOP, 4 = CV_ONE_STEP_TSTOP) 
  */

  int qu, qcur;

  N_VSetArrayPointer(y, F2C_CVODE_vec);

  *ier = CVode(CV_cvodemem, *tout, F2C_CVODE_vec, t, *itask);

  N_VSetArrayPointer(NULL, F2C_CVODE_vec);

  /* Load optional outputs in iout & rout */
  CVodeGetWorkSpace(CV_cvodemem,
                    &CV_iout[0],                          /* LENRW   */
                    &CV_iout[1]);                         /* LENIW   */
  CVodeGetIntegratorStats(CV_cvodemem, 
                          &CV_iout[2],                    /* NST     */
                          &CV_iout[3],                    /* NFE     */ 
                          &CV_iout[7],                    /* NSETUPS */ 
                          &CV_iout[4],                    /* NETF    */ 
                          &qu,                            /* QU      */
                          &qcur,                          /* QCUR    */
                          &CV_rout[0],                    /* H0U     */
                          &CV_rout[1],                    /* HU      */ 
                          &CV_rout[2],                    /* HCUR    */ 
                          &CV_rout[3]);                   /* TCUR    */ 
  CV_iout[8] = (long int) qu;
  CV_iout[9] = (long int) qcur;
  CVodeGetTolScaleFactor(CV_cvodemem, 
                         &CV_rout[4]);                    /* TOLSFAC */
  CVodeGetNonlinSolvStats(CV_cvodemem,
                          &CV_iout[6],                    /* NNI     */
                          &CV_iout[5]);                   /* NCFN    */
  CVodeGetNumStabLimOrderReds(CV_cvodemem, &CV_iout[10]); /* NOR     */
  
  /* Root finding is on */
  if (CV_nrtfn != 0)
    CVodeGetNumGEvals(CV_cvodemem, &CV_iout[11]);         /* NGE     */
  
  switch(CV_ls) {
  case CV_LS_STD:
    CVodeGetLinWorkSpace(CV_cvodemem, &CV_iout[12], &CV_iout[13]);   /* LENRWLS,LENIWLS */
    CVodeGetLastLinFlag(CV_cvodemem, &CV_iout[14]);                  /* LSTF */
    CVodeGetNumLinRhsEvals(CV_cvodemem, &CV_iout[15]);               /* NFELS */
    CVodeGetNumJacEvals(CV_cvodemem, &CV_iout[16]);                  /* NJE */
    CVodeGetNumJTSetupEvals(CV_cvodemem, &CV_iout[17]);              /* NJTS */
    CVodeGetNumJtimesEvals(CV_cvodemem, &CV_iout[18]);               /* NJTV */
    CVodeGetNumPrecEvals(CV_cvodemem, &CV_iout[19]);                 /* NPE */
    CVodeGetNumPrecSolves(CV_cvodemem, &CV_iout[20]);                /* NPS */
    CVodeGetNumLinIters(CV_cvodemem, &CV_iout[21]);                  /* NLI */
    CVodeGetNumLinConvFails(CV_cvodemem, &CV_iout[22]);              /* NCFL */
    break;
  case CV_LS_DIAG:
    CVDiagGetWorkSpace(CV_cvodemem, &CV_iout[12], &CV_iout[13]);  /* LENRWLS,LENIWLS */
    CVDiagGetLastFlag(CV_cvodemem, &CV_iout[14]);                 /* LSTF */
    CVDiagGetNumRhsEvals(CV_cvodemem, &CV_iout[15]);              /* NFELS */
  }
}