Example #1
0
static int PrepareNextRun(void *cvode_mem, int lmm, int miter, 
                          long int mu, long int ml)
{
  int flag = CV_SUCCESS;
  
  printf("\n\n-------------------------------------------------------------");
  
  printf("\n\nLinear Multistep Method : ");
  if (lmm == CV_ADAMS) {
    printf("ADAMS\n");
  } else {
    printf("BDF\n");
  }
  
  printf("Iteration               : ");
  if (miter == FUNC) {
    printf("FUNCTIONAL\n");
  } else {
    printf("NEWTON\n");
    printf("Linear Solver           : ");
    switch(miter) {
    case DENSE_USER : 
      printf("Dense, User-Supplied Jacobian\n");
      flag = CVDense(cvode_mem, P1_NEQ);
      check_flag(&flag, "CVDense", 1);
      if(flag != CV_SUCCESS) break;
      flag = CVDenseSetJacFn(cvode_mem, Jac1, NULL);
      check_flag(&flag, "CVDenseSetJacFn", 1);
      break;
    case DENSE_DQ   : 
      printf("Dense, Difference Quotient Jacobian\n");
      flag = CVDenseSetJacFn(cvode_mem, NULL, NULL);
      check_flag(&flag, "CVDenseSetJacFn", 1);
      break;
    case DIAG       : 
      printf("Diagonal Jacobian\n");
      flag = CVDiag(cvode_mem);
      check_flag(&flag, "CVDiag", 1);
      break;
    case BAND_USER  : 
      printf("Band, User-Supplied Jacobian\n");
      flag = CVBand(cvode_mem, P2_NEQ, mu, ml);
      check_flag(&flag, "CVBand", 1);
      if(flag != CV_SUCCESS) break;
      flag = CVBandSetJacFn(cvode_mem, Jac2, NULL);
      check_flag(&flag, "CVBandSetJacFn", 1);
      break;
    case BAND_DQ  :   
      printf("Band, Difference Quotient Jacobian\n");
      flag = CVBandSetJacFn(cvode_mem, NULL, NULL);
      check_flag(&flag, "CVBandSetJacFn", 1);
      break;    
    }
  }

  return(flag);
}
Example #2
0
void FCV_BANDSETJAC(int *flag, int *ier)
{
    CVodeMem cv_mem;

    if (*flag == 0) {
        *ier = CVBandSetJacFn(CV_cvodemem, NULL, NULL);
    } else {
        cv_mem = (CVodeMem) CV_cvodemem;
        *ier = CVBandSetJacFn(CV_cvodemem, FCVBandJac, cv_mem->cv_f_data);
    }
}
Example #3
0
int CVBandSetJacFnB(void *cvadj_mem, CVBandJacFnB bjacB, void *jac_dataB)
{
  CVadjMem ca_mem;
  CVBandMemB cvbandB_mem;
  CVodeMem cvB_mem;
  int flag;

  if (cvadj_mem == NULL) {
    CVProcessError(NULL, CVBAND_ADJMEM_NULL, "CVBAND", "CVBandSetJacFnB", MSGB_CAMEM_NULL);
    return(CVBAND_ADJMEM_NULL);
  }
  ca_mem = (CVadjMem) cvadj_mem;

  cvB_mem = ca_mem->cvb_mem;

  if (lmemB == NULL) {
    CVProcessError(cvB_mem, CVBAND_LMEMB_NULL, "CVBAND", "CVBandSetJacFnB", MSGB_LMEMB_NULL);
    return(CVBAND_LMEMB_NULL);
  }
  cvbandB_mem = (CVBandMemB) lmemB;

  bjac_B     = bjacB;
  jac_data_B = jac_dataB;

  flag = CVBandSetJacFn(cvB_mem, CVAbandJac, cvadj_mem);

  return(flag);
}
Example #4
0
int CVBandSetJacFnB(void *cvadj_mem, CVBandJacFnB bjacB, void *jac_dataB)
{
  CVadjMem ca_mem;
  void *cvode_mem;
  int flag;

  if (cvadj_mem == NULL) return(CV_ADJMEM_NULL);
  ca_mem = (CVadjMem) cvadj_mem;

  bjac_B     = bjacB;
  jac_data_B = jac_dataB;

  cvode_mem = (void *) ca_mem->cvb_mem;

  flag = CVBandSetJacFn(cvode_mem, CVAbandJac, cvadj_mem);

  return(flag);
}
void FCV_BANDSETJAC(int *flag, int *ier)
{
  if (*flag == 0) CVBandSetJacFn(CV_cvodemem, NULL, NULL);
  else CVBandSetJacFn(CV_cvodemem, FCVBandJac, NULL);
}
Example #6
0
int main(void)
{
  realtype dx, dy, reltol, abstol, t, tout, umax;
  N_Vector u;
  UserData data;
  void *cvode_mem;
  int iout, flag;
  long int nst;

  u = NULL;
  data = NULL;
  cvode_mem = NULL;

  /* Create a serial vector */

  u = N_VNew_Serial(NEQ);  /* Allocate u vector */
  if(check_flag((void*)u, "N_VNew_Serial", 0)) return(1);

  reltol = ZERO;  /* Set the tolerances */
  abstol = ATOL;

  data = (UserData) malloc(sizeof *data);  /* Allocate data memory */
  if(check_flag((void *)data, "malloc", 2)) return(1);
  dx = data->dx = XMAX/(MX+1);  /* Set grid coefficients in data */
  dy = data->dy = YMAX/(MY+1);
  data->hdcoef = ONE/(dx*dx);
  data->hacoef = HALF/(TWO*dx);
  data->vdcoef = ONE/(dy*dy);

  SetIC(u, data);  /* Initialize u vector */

  /* 
     Call CvodeCreate to create integrator memory 

     CV_BDF     specifies the Backward Differentiation Formula
     CV_NEWTON  specifies a Newton iteration

     A pointer to the integrator problem memory is returned and
     stored in cvode_mem.  
  */

  cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON);
  if(check_flag((void *)cvode_mem, "CVodeCreate", 0)) return(1);

  /* 
     Call CVodeMalloc to initialize the integrator memory: 

     cvode_mem is the pointer to the integrator memory returned by CVodeCreate
     f       is the user's right hand side function in y'=f(t,y)
     T0      is the initial time
     u       is the initial dependent variable vector
     CV_SS   specifies scalar relative and absolute tolerances
     reltol  is the scalar relative tolerance
     &abstol is a pointer to the scalar absolute tolerance
  */

  flag = CVodeMalloc(cvode_mem, f, T0, u, CV_SS, reltol, &abstol);
  if(check_flag(&flag, "CVodeMalloc", 1)) return(1);

  /* Set the pointer to user-defined data */

  flag = CVodeSetFdata(cvode_mem, data);
  if(check_flag(&flag, "CVodeSetFdata", 1)) return(1);

  /* Call CVBand to specify the CVBAND band linear solver */

  flag = CVBand(cvode_mem, NEQ, MY, MY);
  if(check_flag(&flag, "CVBand", 1)) return(1);

  /* Set the user-supplied Jacobian routine Jac and
     the pointer to the user-defined block data. */

  flag = CVBandSetJacFn(cvode_mem, Jac, data);
  if(check_flag(&flag, "CVBandSetJacFn", 1)) return(1);

  /* In loop over output points: call CVode, print results, test for errors */

  umax = N_VMaxNorm(u);
  PrintHeader(reltol, abstol, umax);
  for(iout=1, tout=T1; iout <= NOUT; iout++, tout += DTOUT) {
    flag = CVode(cvode_mem, tout, u, &t, CV_NORMAL);
    if(check_flag(&flag, "CVode", 1)) break;
    umax = N_VMaxNorm(u);
    flag = CVodeGetNumSteps(cvode_mem, &nst);
    check_flag(&flag, "CVodeGetNumSteps", 1);
    PrintOutput(t, umax, nst);
  }

  PrintFinalStats(cvode_mem);  /* Print some final statistics   */

  N_VDestroy_Serial(u);  /* Free the u vector */
  CVodeFree(cvode_mem);  /* Free the integrator memory */
  free(data);            /* Free the user data */

  return(0);
}