int main() { void *mem; UserData webdata; N_Vector cc, cp, id; int iout, retval; long int mu, ml; realtype rtol, atol, t0, tout, tret; mem = NULL; webdata = NULL; cc = cp = id = NULL; /* Allocate and initialize user data block webdata. */ webdata = (UserData) malloc(sizeof *webdata); webdata->rates = N_VNew_Serial(NEQ); webdata->acoef = newDenseMat(NUM_SPECIES, NUM_SPECIES); InitUserData(webdata); /* Allocate N-vectors and initialize cc, cp, and id. */ cc = N_VNew_Serial(NEQ); if(check_flag((void *)cc, "N_VNew_Serial", 0)) return(1); cp = N_VNew_Serial(NEQ); if(check_flag((void *)cp, "N_VNew_Serial", 0)) return(1); id = N_VNew_Serial(NEQ); if(check_flag((void *)id, "N_VNew_Serial", 0)) return(1); SetInitialProfiles(cc, cp, id, webdata); /* Set remaining inputs to IDAMalloc. */ t0 = ZERO; rtol = RTOL; atol = ATOL; /* Call IDACreate and IDAMalloc to initialize IDA. */ mem = IDACreate(); if(check_flag((void *)mem, "IDACreate", 0)) return(1); retval = IDASetUserData(mem, webdata); if(check_flag(&retval, "IDASetUserData", 1)) return(1); retval = IDASetId(mem, id); if(check_flag(&retval, "IDASetId", 1)) return(1); retval = IDAInit(mem, resweb, t0, cc, cp); if(check_flag(&retval, "IDAInit", 1)) return(1); retval = IDASStolerances(mem, rtol, atol); if(check_flag(&retval, "IDASStolerances", 1)) return(1); /* Call IDABand to specify the IDA linear solver. */ mu = ml = NSMX; retval = IDABand(mem, NEQ, mu, ml); if(check_flag(&retval, "IDABand", 1)) return(1); /* Call IDACalcIC (with default options) to correct the initial values. */ tout = RCONST(0.001); retval = IDACalcIC(mem, IDA_YA_YDP_INIT, tout); if(check_flag(&retval, "IDACalcIC", 1)) return(1); /* Print heading, basic parameters, and initial values. */ PrintHeader(mu, ml, rtol, atol); PrintOutput(mem, cc, ZERO); /* Loop over iout, call IDASolve (normal mode), print selected output. */ for (iout = 1; iout <= NOUT; iout++) { retval = IDASolve(mem, tout, &tret, cc, cp, IDA_NORMAL); if(check_flag(&retval, "IDASolve", 1)) return(retval); PrintOutput(mem, cc, tret); if (iout < 3) tout *= TMULT; else tout += TADD; } /* Print final statistics and free memory. */ PrintFinalStats(mem); /* Free memory */ IDAFree(&mem); N_VDestroy_Serial(cc); N_VDestroy_Serial(cp); N_VDestroy_Serial(id); destroyMat(webdata->acoef); N_VDestroy_Serial(webdata->rates); free(webdata); return(0); }
int main() { void *mem; UserData webdata; N_Vector cc, cp, id; int iout, jx, jy, flag; long int maxl; realtype rtol, atol, t0, tout, tret; mem = NULL; webdata = NULL; cc = cp = id = NULL; /* Allocate and initialize user data block webdata. */ webdata = (UserData) malloc(sizeof *webdata); webdata->rates = N_VNew_Serial(NEQ); webdata->acoef = newDenseMat(NUM_SPECIES, NUM_SPECIES); webdata->ewt = N_VNew_Serial(NEQ); for (jx = 0; jx < MX; jx++) { for (jy = 0; jy < MY; jy++) { (webdata->pivot)[jx][jy] = newLintArray(NUM_SPECIES); (webdata->PP)[jx][jy] = newDenseMat(NUM_SPECIES, NUM_SPECIES); } } InitUserData(webdata); /* Allocate N-vectors and initialize cc, cp, and id. */ cc = N_VNew_Serial(NEQ); if(check_flag((void *)cc, "N_VNew_Serial", 0)) return(1); cp = N_VNew_Serial(NEQ); if(check_flag((void *)cp, "N_VNew_Serial", 0)) return(1); id = N_VNew_Serial(NEQ); if(check_flag((void *)id, "N_VNew_Serial", 0)) return(1); SetInitialProfiles(cc, cp, id, webdata); /* Set remaining inputs to IDAMalloc. */ t0 = ZERO; rtol = RTOL; atol = ATOL; /* Call IDACreate and IDAMalloc to initialize IDA. */ mem = IDACreate(); if(check_flag((void *)mem, "IDACreate", 0)) return(1); flag = IDASetUserData(mem, webdata); if(check_flag(&flag, "IDASetUserData", 1)) return(1); flag = IDASetId(mem, id); if(check_flag(&flag, "IDASetId", 1)) return(1); flag = IDAInit(mem, resweb, t0, cc, cp); if(check_flag(&flag, "IDAInit", 1)) return(1); flag = IDASStolerances(mem, rtol, atol); if(check_flag(&flag, "IDASStolerances", 1)) return(1); webdata->ida_mem = mem; /* Call IDASpgmr to specify the IDA linear solver. */ maxl = 16; /* max dimension of the Krylov subspace */ flag = IDASpgmr(mem, maxl); if(check_flag(&flag, "IDASpgmr", 1)) return(1); flag = IDASpilsSetPreconditioner(mem, Precond, PSolve); if(check_flag(&flag, "IDASpilsSetPreconditioner", 1)) return(1); /* Call IDACalcIC (with default options) to correct the initial values. */ tout = RCONST(0.001); flag = IDACalcIC(mem, IDA_YA_YDP_INIT, tout); if(check_flag(&flag, "IDACalcIC", 1)) return(1); /* Print heading, basic parameters, and initial values. */ PrintHeader(maxl, rtol, atol); PrintOutput(mem, cc, ZERO); /* Loop over iout, call IDASolve (normal mode), print selected output. */ for (iout = 1; iout <= NOUT; iout++) { flag = IDASolve(mem, tout, &tret, cc, cp, IDA_NORMAL); if(check_flag(&flag, "IDASolve", 1)) return(flag); PrintOutput(mem, cc, tret); if (iout < 3) tout *= TMULT; else tout += TADD; } /* Print final statistics and free memory. */ PrintFinalStats(mem); /* Free memory */ IDAFree(&mem); N_VDestroy_Serial(cc); N_VDestroy_Serial(cp); N_VDestroy_Serial(id); destroyMat(webdata->acoef); N_VDestroy_Serial(webdata->rates); N_VDestroy_Serial(webdata->ewt); for (jx = 0; jx < MX; jx++) { for (jy = 0; jy < MY; jy ++) { destroyArray((webdata->pivot)[jx][jy]); destroyMat((webdata->PP)[jx][jy]); } } free(webdata); return(0); }