static void PrintOutput(void *cvode_mem, realtype t, N_Vector u) { long int nst; int qu, flag; realtype hu; flag = CVodeGetNumSteps(cvode_mem, &nst); check_flag(&flag, "CVodeGetNumSteps", 1); flag = CVodeGetLastOrder(cvode_mem, &qu); check_flag(&flag, "CVodeGetLastOrder", 1); flag = CVodeGetLastStep(cvode_mem, &hu); check_flag(&flag, "CVodeGetLastStep", 1); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%8.3Le %2d %8.3Le %5ld\n", t, qu, hu ,nst); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%8.3le %2d %8.3le %5ld\n", t, qu, hu ,nst); #else printf("%8.3e %2d %8.3e %5ld\n", t, qu, hu ,nst); #endif printf(" Solution "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", N_VMaxNorm(u)); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4le \n", N_VMaxNorm(u)); #else printf("%12.4e \n", N_VMaxNorm(u)); #endif }
static void PrintOutputS(int my_pe, N_Vector *uS) { realtype smax; smax = N_VMaxNorm(uS[0]); if (my_pe == 0) { printf(" Sensitivity 1 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", smax); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4le \n", smax); #else printf("%12.4e \n", smax); #endif } smax = N_VMaxNorm(uS[1]); if (my_pe == 0) { printf(" Sensitivity 2 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", smax); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4le \n", smax); #else printf("%12.4e \n", smax); #endif } }
int main(void) { realtype dx, dy, reltol, abstol, t, tout, umax; N_Vector u, up; UserData data; void *cvode_mem; int iout, flag; long int nst; u = NULL; data = NULL; cvode_mem = NULL; u = N_VNew_Serial(NEQ); up = N_VNew_Serial(NEQ); reltol = ZERO; abstol = ATOL; data = (UserData) malloc(sizeof *data); dx = data->dx = XMAX/(MX+1); dy = data->dy = YMAX/(MY+1); data->hdcoef = ONE/(dx*dx); data->hacoef = HALF/(TWO*dx); data->vdcoef = ONE/(dy*dy); SetIC(u, data); cvode_mem = CPodeCreate(CP_EXPL, CP_BDF, CP_NEWTON); flag = CPodeInit(cvode_mem, (void *)f, data, T0, u, NULL, CP_SS, reltol, &abstol); flag = CPLapackBand(cvode_mem, NEQ, MY, MY); flag = CPDlsSetJacFn(cvode_mem, (void *)Jac, data); /* In loop over output points: call CPode, print results, test for errors */ umax = N_VMaxNorm(u); PrintHeader(reltol, abstol, umax); for(iout=1, tout=T1; iout <= NOUT; iout++, tout += DTOUT) { flag = CPode(cvode_mem, tout, &t, u, up, CP_NORMAL); umax = N_VMaxNorm(u); flag = CPodeGetNumSteps(cvode_mem, &nst); PrintOutput(t, umax, nst); } PrintFinalStats(cvode_mem); N_VDestroy_Serial(u); CPodeFree(&cvode_mem); free(data); return(0); }
static void PrintOutput(void *mem, realtype t, N_Vector uu) { int ier; realtype umax, hused; long int nst, nni, nje, nre; int kused; umax = N_VMaxNorm(uu); ier = IDAGetLastOrder(mem, &kused); check_flag(&ier, "IDAGetLastOrder", 1); ier = IDAGetNumSteps(mem, &nst); check_flag(&ier, "IDAGetNumSteps", 1); ier = IDAGetNumNonlinSolvIters(mem, &nni); check_flag(&ier, "IDAGetNumNonlinSolvIters", 1); ier = IDAGetNumResEvals(mem, &nre); check_flag(&ier, "IDAGetNumResEvals", 1); ier = IDAGetLastStep(mem, &hused); check_flag(&ier, "IDAGetLastStep", 1); ier = IDASlsGetNumJacEvals(mem, &nje); check_flag(&ier, "IDASlsGetNumJacEvals", 1); #if defined(SUNDIALS_EXTENDED_PRECISION) printf(" %5.2Lf %13.5Le %d %3ld %3ld %3ld %4ld %9.2Le \n", t, umax, kused, nst, nni, nje, nre, hused); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf(" %5.2f %13.5e %d %3ld %3ld %3ld %4ld %9.2e \n", t, umax, kused, nst, nni, nje, nre, hused); #else printf(" %5.2f %13.5e %d %3ld %3ld %3ld %4ld %9.2e \n", t, umax, kused, nst, nni, nje, nre, hused); #endif }
int IDASetConstraints(void *ida_mem, N_Vector constraints) { IDAMem IDA_mem; realtype temptest; if (ida_mem==NULL) { IDAProcessError(NULL, IDA_MEM_NULL, "IDA", "IDASetConstraints", MSG_NO_MEM); return(IDA_MEM_NULL); } IDA_mem = (IDAMem) ida_mem; if (constraints == NULL) { if (IDA_mem->ida_constraintsMallocDone) { N_VDestroy(IDA_mem->ida_constraints); lrw -= lrw1; liw -= liw1; } IDA_mem->ida_constraintsMallocDone = FALSE; IDA_mem->ida_constraintsSet = FALSE; return(IDA_SUCCESS); } /* Test if required vector ops. are defined */ if (constraints->ops->nvdiv == NULL || constraints->ops->nvmaxnorm == NULL || constraints->ops->nvcompare == NULL || constraints->ops->nvconstrmask == NULL || constraints->ops->nvminquotient == NULL) { IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASetConstraints", MSG_BAD_NVECTOR); return(IDA_ILL_INPUT); } /* Check the constraints vector */ temptest = N_VMaxNorm(constraints); if((temptest > TWOPT5) || (temptest < HALF)){ IDAProcessError(IDA_mem, IDA_ILL_INPUT, "IDA", "IDASetConstraints", MSG_BAD_CONSTR); return(IDA_ILL_INPUT); } if ( !(IDA_mem->ida_constraintsMallocDone) ) { IDA_mem->ida_constraints = NULL; IDA_mem->ida_constraints = N_VClone(constraints); lrw += lrw1; liw += liw1; IDA_mem->ida_constraintsMallocDone = TRUE; } /* Load the constraints vector */ N_VScale(ONE, constraints, IDA_mem->ida_constraints); IDA_mem->ida_constraintsSet = TRUE; return(IDA_SUCCESS); }
static real KINScSteplength(KINMem kin_mem, N_Vector ucur, N_Vector ss, N_Vector usc) { N_VInv(usc, vtemp1); N_VAbs(ucur, vtemp2); N_VLinearSum(ONE, vtemp1, ONE, vtemp2, vtemp1); N_VDiv(ss, vtemp1, vtemp1); return(N_VMaxNorm(vtemp1)); }
int CVodeSetConstraints(void *cvode_mem, N_Vector constraints) { CVodeMem cv_mem; realtype temptest; if (cvode_mem==NULL) { cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVodeSetConstraints", MSGCV_NO_MEM); return(CV_MEM_NULL); } cv_mem = (CVodeMem) cvode_mem; /* If there are no constraints, destroy data structures */ if (constraints == NULL) { if (cv_mem->cv_constraintsMallocDone) { N_VDestroy(cv_mem->cv_constraints); cv_mem->cv_lrw -= cv_mem->cv_lrw1; cv_mem->cv_liw -= cv_mem->cv_liw1; } cv_mem->cv_constraintsMallocDone = SUNFALSE; cv_mem->cv_constraintsSet = SUNFALSE; return(CV_SUCCESS); } /* Test if required vector ops. are defined */ if (constraints->ops->nvdiv == NULL || constraints->ops->nvmaxnorm == NULL || constraints->ops->nvcompare == NULL || constraints->ops->nvconstrmask == NULL || constraints->ops->nvminquotient == NULL) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetConstraints", MSGCV_BAD_NVECTOR); return(CV_ILL_INPUT); } /* Check the constraints vector */ temptest = N_VMaxNorm(constraints); if ((temptest > TWOPT5) || (temptest < HALF)) { cvProcessError(cv_mem, CV_ILL_INPUT, "CVODE", "CVodeSetConstraints", MSGCV_BAD_CONSTR); return(CV_ILL_INPUT); } if ( !(cv_mem->cv_constraintsMallocDone) ) { cv_mem->cv_constraints = N_VClone(constraints); cv_mem->cv_lrw += cv_mem->cv_lrw1; cv_mem->cv_liw += cv_mem->cv_liw1; cv_mem->cv_constraintsMallocDone = SUNTRUE; } /* Load the constraints vector */ N_VScale(ONE, constraints, cv_mem->cv_constraints); cv_mem->cv_constraintsSet = SUNTRUE; return(CV_SUCCESS); }
realtype N_VMaxNorm_SensWrapper(N_Vector x) { int i; realtype max, tmp; max = ZERO; for (i=0; i < NV_NVECS_SW(x); i++) { tmp = N_VMaxNorm(NV_VEC_SW(x,i)); if (tmp > max) max = tmp; } return(max); }
int KINSetConstraints(void *kinmem, N_Vector constraints) { KINMem kin_mem; realtype temptest; if (kinmem == NULL) { KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetConstraints", MSG_NO_MEM); return(KIN_MEM_NULL); } kin_mem = (KINMem) kinmem; if (constraints == NULL) { if (kin_mem->kin_constraintsSet) { N_VDestroy(kin_mem->kin_constraints); lrw -= lrw1; liw -= liw1; } kin_mem->kin_constraintsSet = FALSE; return(KIN_SUCCESS); } /* Check the constraints vector */ temptest = N_VMaxNorm(constraints); if (temptest > TWOPT5){ KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetConstraints", MSG_BAD_CONSTRAINTS); return(KIN_ILL_INPUT); } if (!kin_mem->kin_constraintsSet) { kin_mem->kin_constraints = NULL; kin_mem->kin_constraints = N_VClone(constraints); lrw += lrw1; liw += liw1; kin_mem->kin_constraintsSet = TRUE; } /* Load the constraint vector */ N_VScale(ONE, constraints, kin_mem->kin_constraints); return(KIN_SUCCESS); }
static void PrintOutput(int id, void *mem, realtype t, N_Vector uu) { realtype umax, hused; int kused, ier; long int nst, nni, nre, nli, npe, nps, nreLS, nge; umax = N_VMaxNorm(uu); if (id == 0) { ier = IDAGetLastOrder(mem, &kused); check_flag(&ier, "IDAGetLastOrder", 1, id); ier = IDAGetNumSteps(mem, &nst); check_flag(&ier, "IDAGetNumSteps", 1, id); ier = IDAGetNumNonlinSolvIters(mem, &nni); check_flag(&ier, "IDAGetNumNonlinSolvIters", 1, id); ier = IDAGetNumResEvals(mem, &nre); check_flag(&ier, "IDAGetNumResEvals", 1, id); ier = IDAGetLastStep(mem, &hused); check_flag(&ier, "IDAGetLastStep", 1, id); ier = IDASpilsGetNumLinIters(mem, &nli); check_flag(&ier, "IDASpilsGetNumLinIters", 1, id); ier = IDASpilsGetNumResEvals(mem, &nreLS); check_flag(&ier, "IDASpilsGetNumResEvals", 1, id); ier = IDABBDPrecGetNumGfnEvals(mem, &nge); check_flag(&ier, "IDABBDPrecGetNumGfnEvals", 1, id); ier = IDASpilsGetNumPrecEvals(mem, &npe); check_flag(&ier, "IDASpilsGetPrecEvals", 1, id); ier = IDASpilsGetNumPrecSolves(mem, &nps); check_flag(&ier, "IDASpilsGetNumPrecSolves", 1, id); #if defined(SUNDIALS_EXTENDED_PRECISION) printf(" %5.2Lf %13.5Le %d %3ld %3ld %3ld %4ld %4ld %4ld %9.2Le %3ld %3ld\n", t, umax, kused, nst, nni, nli, nre, nreLS, nge, hused, npe, nps); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf(" %5.2f %13.5e %d %3ld %3ld %3ld %4ld %4ld %4ld %9.2e %3ld %3ld\n", t, umax, kused, nst, nni, nli, nre, nreLS, nge, hused, npe, nps); #else printf(" %5.2f %13.5e %d %3ld %3ld %3ld %4ld %4ld %4ld %9.2e %3ld %3ld\n", t, umax, kused, nst, nni, nli, nre, nreLS, nge, hused, npe, nps); #endif } }
static void PrintOutput(void *mem, realtype t, N_Vector uu) { realtype hused, umax; long int nst, nni, nje, nre, nreS, nli, npe, nps; int kused, ier; umax = N_VMaxNorm(uu); ier = IDAGetLastOrder(mem, &kused); check_flag(&ier, "IDAGetLastOrder", 1); ier = IDAGetNumSteps(mem, &nst); check_flag(&ier, "IDAGetNumSteps", 1); ier = IDAGetNumNonlinSolvIters(mem, &nni); check_flag(&ier, "IDAGetNumNonlinSolvIters", 1); ier = IDAGetNumResEvals(mem, &nre); check_flag(&ier, "IDAGetNumResEvals", 1); ier = IDAGetLastStep(mem, &hused); check_flag(&ier, "IDAGetLastStep", 1); ier = IDASpgmrGetNumJtimesEvals(mem, &nje); check_flag(&ier, "IDASpgmrGetNumJtimesEvals", 1); ier = IDASpgmrGetNumLinIters(mem, &nli); check_flag(&ier, "IDASpgmrGetNumLinIters", 1); ier = IDASpgmrGetNumResEvals(mem, &nreS); check_flag(&ier, "IDASpgmrGetNumResEvals", 1); ier = IDASpgmrGetNumPrecEvals(mem, &npe); check_flag(&ier, "IDASpgmrGetPrecEvals", 1); ier = IDASpgmrGetNumPrecSolves(mem, &nps); check_flag(&ier, "IDASpgmrGetNumPrecSolves", 1); #if defined(SUNDIALS_EXTENDED_PRECISION) printf(" %5.2Lf %13.5Le %d %3ld %3ld %3ld %4ld %4ld %9.2Le %3ld %3ld\n", t, umax, kused, nst, nni, nje, nre, nreS, hused, npe, nps); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf(" %5.2f %13.5le %d %3ld %3ld %3ld %4ld %4ld %9.2le %3ld %3ld\n", t, umax, kused, nst, nni, nje, nre, nreS, hused, npe, nps); #else printf(" %5.2f %13.5e %d %3ld %3ld %3ld %4ld %4ld %9.2e %3ld %3ld\n", t, umax, kused, nst, nni, nje, nre, nreS, hused, npe, nps); #endif }
static void PrintOutput(void *cvode_mem, int my_pe, realtype t, N_Vector u) { long int nst; int qu, retval; realtype hu, umax; retval = CVodeGetNumSteps(cvode_mem, &nst); check_retval(&retval, "CVodeGetNumSteps", 1, my_pe); retval = CVodeGetLastOrder(cvode_mem, &qu); check_retval(&retval, "CVodeGetLastOrder", 1, my_pe); retval = CVodeGetLastStep(cvode_mem, &hu); check_retval(&retval, "CVodeGetLastStep", 1, my_pe); umax = N_VMaxNorm(u); if (my_pe == 0) { #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%8.3Le %2d %8.3Le %5ld\n", t,qu,hu,nst); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%8.3e %2d %8.3e %5ld\n", t,qu,hu,nst); #else printf("%8.3e %2d %8.3e %5ld\n", t,qu,hu,nst); #endif printf(" Solution "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", umax); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4e \n", umax); #else printf("%12.4e \n", umax); #endif } }
static int KINConstraint(KINMem kin_mem) { real mxchange; N_VLinearSum(ONE, uu, ONE, pp, vtemp1); /* this vector.c routine returns TRUE if all products v1[i]*v2[i] are * positive (with the proviso that all products which would result from * v1[i]=0. are ignored) , and FALSE otherwise (e.g. at least one such * product is negative) */ if (N_VConstrProdPos(constraints, vtemp1)) return(0); N_VDiv(pp, uu, vtemp2); mxchange = N_VMaxNorm(vtemp2); if (mxchange >= relu) { stepl = POINT9 * relu / mxchange; return(1); } return(0); }
static void PrintOutputS(N_Vector *uS) { printf(" Sensitivity 1 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", N_VMaxNorm(uS[0])); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4le \n", N_VMaxNorm(uS[0])); #else printf("%12.4e \n", N_VMaxNorm(uS[0])); #endif printf(" Sensitivity 2 "); #if defined(SUNDIALS_EXTENDED_PRECISION) printf("%12.4Le \n", N_VMaxNorm(uS[1])); #elif defined(SUNDIALS_DOUBLE_PRECISION) printf("%12.4le \n", N_VMaxNorm(uS[1])); #else printf("%12.4e \n", N_VMaxNorm(uS[1])); #endif }
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 the solver memory and specify the * Backward Differentiation Formula and the use of a Newton iteration */ cvode_mem = CVodeCreate(CV_BDF, CV_NEWTON); if(check_flag((void *)cvode_mem, "CVodeCreate", 0)) return(1); /* Call CVodeInit to initialize the integrator memory and specify the * user's right hand side function in u'=f(t,u), the inital time T0, and * the initial dependent variable vector u. */ flag = CVodeInit(cvode_mem, f, T0, u); if(check_flag(&flag, "CVodeInit", 1)) return(1); /* Call CVodeSStolerances to specify the scalar relative tolerance * and scalar absolute tolerance */ flag = CVodeSStolerances(cvode_mem, reltol, abstol); if (check_flag(&flag, "CVodeSStolerances", 1)) return(1); /* Set the pointer to user-defined data */ flag = CVodeSetUserData(cvode_mem, data); if(check_flag(&flag, "CVodeSetUserData", 1)) return(1); /* Call CVLapackBand to specify the CVBAND band linear solver */ flag = CVLapackBand(cvode_mem, NEQ, MY, MY); if(check_flag(&flag, "CVLapackBand", 1)) return(1); /* Set the user-supplied Jacobian routine Jac */ flag = CVDlsSetBandJacFn(cvode_mem, Jac); if(check_flag(&flag, "CVDlsSetBandJacFn", 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); }
int main(int argc, char *argv[]) { realtype dx, reltol, abstol, t, tout, umax; N_Vector u; UserData data; void *cvode_mem; int iout, retval, my_pe, npes; sunindextype local_N, nperpe, nrem, my_base; long int nst; MPI_Comm comm; u = NULL; data = NULL; cvode_mem = NULL; /* Get processor number, total number of pe's, and my_pe. */ MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &npes); MPI_Comm_rank(comm, &my_pe); /* Set local vector length. */ nperpe = NEQ/npes; nrem = NEQ - npes*nperpe; local_N = (my_pe < nrem) ? nperpe+1 : nperpe; my_base = (my_pe < nrem) ? my_pe*local_N : my_pe*nperpe + nrem; data = (UserData) malloc(sizeof *data); /* Allocate data memory */ if(check_retval((void *)data, "malloc", 2, my_pe)) MPI_Abort(comm, 1); data->comm = comm; data->npes = npes; data->my_pe = my_pe; u = N_VNew_Parallel(comm, local_N, NEQ); /* Allocate u vector */ if(check_retval((void *)u, "N_VNew", 0, my_pe)) MPI_Abort(comm, 1); reltol = ZERO; /* Set the tolerances */ abstol = ATOL; dx = data->dx = XMAX/((realtype)(MX+1)); /* Set grid coefficients in data */ data->hdcoef = RCONST(1.0)/(dx*dx); data->hacoef = RCONST(0.5)/(RCONST(2.0)*dx); SetIC(u, dx, local_N, my_base); /* Initialize u vector */ /* Call CVodeCreate to create the solver memory and specify the * Adams-Moulton LMM */ cvode_mem = CVodeCreate(CV_ADAMS); if(check_retval((void *)cvode_mem, "CVodeCreate", 0, my_pe)) MPI_Abort(comm, 1); retval = CVodeSetUserData(cvode_mem, data); if(check_retval(&retval, "CVodeSetUserData", 1, my_pe)) MPI_Abort(comm, 1); /* Call CVodeInit to initialize the integrator memory and specify the * user's right hand side function in u'=f(t,u), the inital time T0, and * the initial dependent variable vector u. */ retval = CVodeInit(cvode_mem, f, T0, u); if(check_retval(&retval, "CVodeInit", 1, my_pe)) return(1); /* Call CVodeSStolerances to specify the scalar relative tolerance * and scalar absolute tolerances */ retval = CVodeSStolerances(cvode_mem, reltol, abstol); if (check_retval(&retval, "CVodeSStolerances", 1, my_pe)) return(1); /* Call CVDiag to create and attach CVODE-specific diagonal linear solver */ retval = CVDiag(cvode_mem); if(check_retval(&retval, "CVDiag", 1, my_pe)) return(1); if (my_pe == 0) PrintIntro(npes); umax = N_VMaxNorm(u); if (my_pe == 0) { t = T0; PrintData(t, umax, 0); } /* In loop over output points, call CVode, print results, test for error */ for (iout=1, tout=T1; iout <= NOUT; iout++, tout += DTOUT) { retval = CVode(cvode_mem, tout, u, &t, CV_NORMAL); if(check_retval(&retval, "CVode", 1, my_pe)) break; umax = N_VMaxNorm(u); retval = CVodeGetNumSteps(cvode_mem, &nst); check_retval(&retval, "CVodeGetNumSteps", 1, my_pe); if (my_pe == 0) PrintData(t, umax, nst); } if (my_pe == 0) PrintFinalStats(cvode_mem); /* Print some final statistics */ N_VDestroy_Parallel(u); /* Free the u vector */ CVodeFree(&cvode_mem); /* Free the integrator memory */ free(data); /* Free user data */ MPI_Finalize(); return(0); }
int main(int argc, char *argv[]) { realtype dx, reltol, abstol, t, tout, umax; N_Vector u; UserData data; void *cvode_mem; int iout, flag, my_pe, npes; long int local_N, nperpe, nrem, my_base, nst; MPI_Comm comm; u = NULL; data = NULL; cvode_mem = NULL; /* Get processor number, total number of pe's, and my_pe. */ MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &npes); MPI_Comm_rank(comm, &my_pe); /* Set local vector length. */ nperpe = NEQ/npes; nrem = NEQ - npes*nperpe; local_N = (my_pe < nrem) ? nperpe+1 : nperpe; my_base = (my_pe < nrem) ? my_pe*local_N : my_pe*nperpe + nrem; data = (UserData) malloc(sizeof *data); /* Allocate data memory */ if(check_flag((void *)data, "malloc", 2, my_pe)) MPI_Abort(comm, 1); data->comm = comm; data->npes = npes; data->my_pe = my_pe; u = N_VNew_Parallel(comm, local_N, NEQ); /* Allocate u vector */ if(check_flag((void *)u, "N_VNew", 0, my_pe)) MPI_Abort(comm, 1); reltol = ZERO; /* Set the tolerances */ abstol = ATOL; dx = data->dx = XMAX/((realtype)(MX+1)); /* Set grid coefficients in data */ data->hdcoef = RCONST(1.0)/(dx*dx); data->hacoef = RCONST(0.5)/(RCONST(2.0)*dx); SetIC(u, dx, local_N, my_base); /* Initialize u vector */ /* Call CVodeCreate to create the solver memory: CV_ADAMS specifies the Adams Method CV_FUNCTIONAL specifies functional iteration A pointer to the integrator memory is returned and stored in cvode_mem. */ cvode_mem = CVodeCreate(CV_ADAMS, CV_FUNCTIONAL); if(check_flag((void *)cvode_mem, "CVodeCreate", 0, my_pe)) MPI_Abort(comm, 1); 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); if (my_pe == 0) PrintIntro(npes); umax = N_VMaxNorm(u); if (my_pe == 0) { t = T0; PrintData(t, umax, 0); } /* In loop over output points, call CVode, print results, test for error */ 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, my_pe)) break; umax = N_VMaxNorm(u); flag = CVodeGetNumSteps(cvode_mem, &nst); check_flag(&flag, "CVodeGetNumSteps", 1, my_pe); if (my_pe == 0) PrintData(t, umax, nst); } if (my_pe == 0) PrintFinalStats(cvode_mem); /* Print some final statistics */ N_VDestroy_Parallel(u); /* Free the u vector */ CVodeFree(&cvode_mem); /* Free the integrator memory */ free(data); /* Free user data */ MPI_Finalize(); return(0); }
int main(int argc, char *argv[]) { realtype dx, reltol, abstol, t, tout, umax; N_Vector u; UserData data; void *cvode_mem; int iout, flag, my_pe, npes; long int nst; HYPRE_Int local_N, nperpe, nrem, my_base; HYPRE_ParVector Upar; /* Declare HYPRE parallel vector */ HYPRE_IJVector Uij; /* Declare "IJ" interface to HYPRE vector */ MPI_Comm comm; u = NULL; data = NULL; cvode_mem = NULL; /* Get processor number, total number of pe's, and my_pe. */ MPI_Init(&argc, &argv); comm = MPI_COMM_WORLD; MPI_Comm_size(comm, &npes); MPI_Comm_rank(comm, &my_pe); /* Set partitioning. */ nperpe = NEQ/npes; nrem = NEQ - npes*nperpe; local_N = (my_pe < nrem) ? nperpe+1 : nperpe; my_base = (my_pe < nrem) ? my_pe*local_N : my_pe*nperpe + nrem; /* Allocate hypre vector */ HYPRE_IJVectorCreate(comm, my_base, my_base + local_N - 1, &Uij); HYPRE_IJVectorSetObjectType(Uij, HYPRE_PARCSR); HYPRE_IJVectorInitialize(Uij); /* Allocate user defined data */ data = (UserData) malloc(sizeof *data); /* Allocate data memory */ if(check_flag((void *)data, "malloc", 2, my_pe)) MPI_Abort(comm, 1); data->comm = comm; data->npes = npes; data->my_pe = my_pe; reltol = ZERO; /* Set the tolerances */ abstol = ATOL; dx = data->dx = XMAX/((realtype)(MX+1)); /* Set grid coefficients in data */ data->hdcoef = RCONST(1.0)/(dx*dx); data->hacoef = RCONST(0.5)/(RCONST(2.0)*dx); /* Initialize solutin vector. */ SetIC(Uij, dx, local_N, my_base); HYPRE_IJVectorAssemble(Uij); HYPRE_IJVectorGetObject(Uij, (void**) &Upar); u = N_VMake_ParHyp(Upar); /* Create wrapper u around hypre vector */ if(check_flag((void *)u, "N_VNew", 0, my_pe)) MPI_Abort(comm, 1); /* Call CVodeCreate to create the solver memory and specify the * Adams-Moulton LMM and the use of a functional iteration */ cvode_mem = CVodeCreate(CV_ADAMS, CV_FUNCTIONAL); if(check_flag((void *)cvode_mem, "CVodeCreate", 0, my_pe)) MPI_Abort(comm, 1); flag = CVodeSetUserData(cvode_mem, data); if(check_flag(&flag, "CVodeSetUserData", 1, my_pe)) MPI_Abort(comm, 1); /* Call CVodeInit to initialize the integrator memory and specify the * user's right hand side function in u'=f(t,u), the inital time T0, and * the initial dependent variable vector u. */ flag = CVodeInit(cvode_mem, f, T0, u); if(check_flag(&flag, "CVodeInit", 1, my_pe)) return(1); /* Call CVodeSStolerances to specify the scalar relative tolerance * and scalar absolute tolerances */ flag = CVodeSStolerances(cvode_mem, reltol, abstol); if (check_flag(&flag, "CVodeSStolerances", 1, my_pe)) return(1); if (my_pe == 0) PrintIntro(npes); umax = N_VMaxNorm(u); if (my_pe == 0) { t = T0; PrintData(t, umax, 0); } /* In loop over output points, call CVode, print results, test for error */ 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, my_pe)) break; umax = N_VMaxNorm(u); flag = CVodeGetNumSteps(cvode_mem, &nst); check_flag(&flag, "CVodeGetNumSteps", 1, my_pe); if (my_pe == 0) PrintData(t, umax, nst); } if (my_pe == 0) PrintFinalStats(cvode_mem); /* Print some final statistics */ N_VDestroy(u); /* Free hypre vector wrapper */ HYPRE_IJVectorDestroy(Uij); /* Free the underlying hypre vector */ CVodeFree(&cvode_mem); /* Free the integrator memory */ free(data); /* Free user data */ MPI_Finalize(); return(0); }
static real KINScFNorm(N_Vector vv, N_Vector scale, N_Vector wrkv) { N_VAbs(vv, wrkv); N_VProd(scale, wrkv, wrkv); return(N_VMaxNorm(wrkv)); }