void CVadjFree(void *cvadj_mem) { CVadjMem ca_mem; ca_mem = (CVadjMem) cvadj_mem; /* Delete check points one by one */ while (ca_mem->ck_mem != NULL) { CVAckpntDelete(&(ca_mem->ck_mem)); } /* Free vectors at each data point */ switch (interpType) { case CV_HERMITE: CVAhermiteFree(ca_mem->dt_mem, nsteps); break; } free(ca_mem->dt_mem); /* Free workspace vectors in ca_mem */ CVAfreeVectors(ca_mem); /* Free CVODES memory for backward run */ CVodeFree(ca_mem->cvb_mem); /* Free preconditioner data (the routines below check for non-NULL data) */ CVBandPrecFree(bp_data_B); CVBBDPrecFree(bbd_data_B); /* Free CVODEA memory */ free(ca_mem); }
void FCV_BBDFREE(void) { CVBBDPrecFree(CVBBD_Data); }
int main(int argc, char *argv[]) { UserData data; void *cvode_mem; void *pdata; realtype abstol, reltol, t, tout; N_Vector u; int iout, my_pe, npes, flag, jpre; long int neq, local_N, mudq, mldq, mukeep, mlkeep; MPI_Comm comm; data = NULL; cvode_mem = pdata = NULL; u = NULL; /* Set problem size neq */ neq = NVARS*MX*MY; /* Get processor number and total number of pe's */ MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &npes); MPI_Comm_rank(comm, &my_pe); if (npes != NPEX*NPEY) { if (my_pe == 0) fprintf(stderr, "\nMPI_ERROR(0): npes = %d is not equal to NPEX*NPEY = %d\n\n", npes, NPEX*NPEY); MPI_Finalize(); return(1); } /* Set local length */ local_N = NVARS*MXSUB*MYSUB; /* Allocate and load user data block */ data = (UserData) malloc(sizeof *data); if(check_flag((void *)data, "malloc", 2, my_pe)) MPI_Abort(comm, 1); InitUserData(my_pe, local_N, comm, data); /* Allocate and initialize u, and set tolerances */ u = N_VNew_Parallel(comm, local_N, neq); if(check_flag((void *)u, "N_VNew_Parallel", 0, my_pe)) MPI_Abort(comm, 1); SetInitialProfiles(u, data); abstol = ATOL; reltol = RTOL; /* Call CVodeCreate to create the solver memory: CV_BDF specifies the Backward Differentiation Formula CV_NEWTON specifies a Newton iteration A pointer to the integrator memory is returned and stored in cvode_mem. */ cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON); if(check_flag((void *)cvode_mem, "CVodeCreate", 0, my_pe)) MPI_Abort(comm, 1); /* Set the pointer to user-defined data */ flag = CVodeSetFdata(cvode_mem, data); if(check_flag(&flag, "CVodeSetFdata", 1, my_pe)) MPI_Abort(comm, 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 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, my_pe)) MPI_Abort(comm, 1); /* Allocate preconditioner block */ mudq = mldq = NVARS*MXSUB; mukeep = mlkeep = NVARS; pdata = CVBBDPrecAlloc(cvode_mem, local_N, mudq, mldq, mukeep, mlkeep, ZERO, flocal, NULL); if(check_flag((void *)pdata, "CVBBDPrecAlloc", 0, my_pe)) MPI_Abort(comm, 1); /* Call CVBBDSpgmr to specify the linear solver CVSPGMR using the CVBBDPRE preconditioner, with left preconditioning and the default maximum Krylov dimension maxl */ flag = CVBBDSpgmr(cvode_mem, PREC_LEFT, 0, pdata); if(check_flag(&flag, "CVBBDSpgmr", 1, my_pe)) MPI_Abort(comm, 1); /* Print heading */ if (my_pe == 0) PrintIntro(npes, mudq, mldq, mukeep, mlkeep); /* Loop over jpre (= PREC_LEFT, PREC_RIGHT), and solve the problem */ for (jpre = PREC_LEFT; jpre <= PREC_RIGHT; jpre++) { /* On second run, re-initialize u, the integrator, CVBBDPRE, and CVSPGMR */ if (jpre == PREC_RIGHT) { SetInitialProfiles(u, data); flag = CVodeReInit(cvode_mem, f, T0, u, CV_SS, reltol, &abstol); if(check_flag(&flag, "CVodeReInit", 1, my_pe)) MPI_Abort(comm, 1); flag = CVBBDPrecReInit(pdata, mudq, mldq, ZERO, flocal, NULL); if(check_flag(&flag, "CVBBDPrecReInit", 1, my_pe)) MPI_Abort(comm, 1); flag = CVSpilsSetPrecType(cvode_mem, PREC_RIGHT); check_flag(&flag, "CVSpilsSetPrecType", 1, my_pe); if (my_pe == 0) { printf("\n\n-------------------------------------------------------"); printf("------------\n"); } } if (my_pe == 0) { printf("\n\nPreconditioner type is: jpre = %s\n\n", (jpre == PREC_LEFT) ? "PREC_LEFT" : "PREC_RIGHT"); } /* In loop over output points, call CVode, print results, test for error */ for (iout = 1, tout = TWOHR; iout <= NOUT; iout++, tout += TWOHR) { flag = CVode(cvode_mem, tout, u, &t, CV_NORMAL); if(check_flag(&flag, "CVode", 1, my_pe)) break; PrintOutput(cvode_mem, my_pe, comm, u, t); } /* Print final statistics */ if (my_pe == 0) PrintFinalStats(cvode_mem, pdata); } /* End of jpre loop */ /* Free memory */ N_VDestroy_Parallel(u); CVBBDPrecFree(&pdata); free(data); CVodeFree(&cvode_mem); MPI_Finalize(); return(0); }