static void KINSpbcgFree(KINMem kin_mem) { KINSpilsMem kinspils_mem; SpbcgMem spbcg_mem; kinspils_mem = (KINSpilsMem) lmem; spbcg_mem = (SpbcgMem) spils_mem; SpbcgFree(spbcg_mem); free(lmem); lmem = NULL; }
static void CVSpbcgFree(CVodeMem cv_mem) { CVSpilsMem cvspils_mem; SpbcgMem spbcg_mem; cvspils_mem = (CVSpilsMem) lmem; spbcg_mem = (SpbcgMem) spils_mem; N_VDestroy(ytemp); N_VDestroy(x); SpbcgFree(spbcg_mem); free(cvspils_mem); cvspils_mem = NULL; }
static void KINSpbcgFree(KINMem kin_mem) { KINSpilsMem kinspils_mem; SpbcgMem spbcg_mem; kinspils_mem = (KINSpilsMem) lmem; spbcg_mem = (SpbcgMem) spils_mem; SpbcgFree(spbcg_mem); if (kinspils_mem->s_pfree != NULL) (kinspils_mem->s_pfree)(kin_mem); free(kinspils_mem); kinspils_mem = NULL; }
static void cpSpbcgFree(CPodeMem cp_mem) { CPSpilsMem cpspils_mem; SpbcgMem spbcg_mem; cpspils_mem = (CPSpilsMem) lmem; spbcg_mem = (SpbcgMem) spils_mem; SpbcgFree(spbcg_mem); N_VDestroy(x); N_VDestroy(ytemp); if (ode_type == CP_EXPL) N_VDestroy(yptemp); free(cpspils_mem); cpspils_mem = NULL; }
/*--------------------------------------------------------------- ARKMassSpbcgFree: This routine frees memory specific to the Spbcg mass matrix solver. ---------------------------------------------------------------*/ static void ARKMassSpbcgFree(ARKodeMem ark_mem) { ARKSpilsMassMem arkspils_mem; SpbcgMem spbcg_mem; arkspils_mem = (ARKSpilsMassMem) ark_mem->ark_mass_mem; N_VDestroy(arkspils_mem->s_ytemp); N_VDestroy(arkspils_mem->s_x); spbcg_mem = (SpbcgMem) arkspils_mem->s_spils_mem; SpbcgFree(spbcg_mem); if (arkspils_mem->s_pfree != NULL) (arkspils_mem->s_pfree)(ark_mem); free(arkspils_mem); ark_mem->ark_mass_mem = NULL; }
static int IDASpbcgFree(IDAMem IDA_mem) { IDASpilsMem idaspils_mem; SpbcgMem spbcg_mem; idaspils_mem = (IDASpilsMem) lmem; N_VDestroy(ytemp); N_VDestroy(yptemp); N_VDestroy(xx); spbcg_mem = (SpbcgMem)spils_mem; SpbcgFree(spbcg_mem); if (idaspils_mem->s_pfree != NULL) (idaspils_mem->s_pfree)(IDA_mem); free(idaspils_mem); idaspils_mem = NULL; return(0); }
static int CVSpbcgFree(CVodeMem cv_mem) { CVSpilsMem cvspils_mem; SpbcgMem spbcg_mem; cvspils_mem = (CVSpilsMem) lmem; N_VDestroy(ytemp); N_VDestroy(x); spbcg_mem = (SpbcgMem) spils_mem; SpbcgFree(spbcg_mem); if (cvspils_mem->s_pfree != NULL) (cvspils_mem->s_pfree)(cv_mem); free(cvspils_mem); cv_mem->cv_lmem = NULL; return(0); }
int CPSpbcg(void *cpode_mem, int pretype, int maxl) { CPodeMem cp_mem; CPSpilsMem cpspils_mem; SpbcgMem spbcg_mem; int mxl; /* Return immediately if cpode_mem is NULL */ if (cpode_mem == NULL) { cpProcessError(NULL, CPSPILS_MEM_NULL, "CPSPBCG", "CPSpbcg", MSGS_CPMEM_NULL); return(CPSPILS_MEM_NULL); } cp_mem = (CPodeMem) cpode_mem; /* Check if N_VDotProd is present */ if (vec_tmpl->ops->nvdotprod == NULL) { cpProcessError(cp_mem, CPSPILS_ILL_INPUT, "CPSPBCG", "CPSpbcg", MSGS_BAD_NVECTOR); return(CPSPILS_ILL_INPUT); } if (lfree != NULL) lfree(cp_mem); /* Set four main function fields in cp_mem */ linit = cpSpbcgInit; lsetup = cpSpbcgSetup; lsolve = cpSpbcgSolve; lfree = cpSpbcgFree; /* Get memory for CPSpilsMemRec */ cpspils_mem = NULL; cpspils_mem = (CPSpilsMem) malloc(sizeof(CPSpilsMemRec)); if (cpspils_mem == NULL) { cpProcessError(cp_mem, CPSPILS_MEM_FAIL, "CPSPBCG", "CPSpbcg", MSGS_MEM_FAIL); return(CPSPILS_MEM_FAIL); } /* Set ILS type */ cpspils_mem->s_type = SPILS_SPBCG; /* Set Spbcg parameters that have been passed in call sequence */ cpspils_mem->s_pretype = pretype; mxl = cpspils_mem->s_maxl = (maxl <= 0) ? CPSPILS_MAXL : maxl; /* Set default values for the rest of the Spbcg parameters */ cpspils_mem->s_delt = CPSPILS_DELT; cpspils_mem->s_psetE = NULL; cpspils_mem->s_psetI = NULL; cpspils_mem->s_pslvE = NULL; cpspils_mem->s_pslvI = NULL; cpspils_mem->s_jtvE = NULL; cpspils_mem->s_jtvI = NULL; cpspils_mem->s_P_data = NULL; cpspils_mem->s_j_data = NULL; cpspils_mem->s_last_flag = CPSPILS_SUCCESS; lsetup_exists = FALSE; /* Check for legal pretype */ if ((pretype != PREC_NONE) && (pretype != PREC_LEFT) && (pretype != PREC_RIGHT) && (pretype != PREC_BOTH)) { cpProcessError(cp_mem, CPSPILS_ILL_INPUT, "CPSPBCG", "CPSpbcg", MSGS_BAD_PRETYPE); return(CPSPILS_ILL_INPUT); } /* Alocate memory */ spbcg_mem = NULL; ytemp = NULL; yptemp = NULL; x = NULL; /* Call SpbcgMalloc to allocate workspace for Spbcg */ spbcg_mem = SpbcgMalloc(mxl, vec_tmpl); if (spbcg_mem == NULL) { cpProcessError(cp_mem, CPSPILS_MEM_FAIL, "CPSPBCG", "CPSpbcg", MSGS_MEM_FAIL); free(cpspils_mem); return(CPSPILS_MEM_FAIL); } /* Allocate memory for x, ytemp and (if needed) yptemp */ x = N_VClone(vec_tmpl); if (x == NULL) { cpProcessError(cp_mem, CPSPILS_MEM_FAIL, "CPSPBCG", "CPSpbcg", MSGS_MEM_FAIL); SpbcgFree(spbcg_mem); free(cpspils_mem); return(CPSPILS_MEM_FAIL); } ytemp = N_VClone(vec_tmpl); if (ytemp == NULL) { cpProcessError(cp_mem, CPSPILS_MEM_FAIL, "CPSPBCG", "CPSpbcg", MSGS_MEM_FAIL); SpbcgFree(spbcg_mem); N_VDestroy(x); free(cpspils_mem); return(CPSPILS_MEM_FAIL); } if (ode_type == CP_IMPL) { yptemp = N_VClone(vec_tmpl); if (yptemp == NULL) { cpProcessError(cp_mem, CPSPILS_MEM_FAIL, "CPSPBCG", "CPSpbcg", MSGS_MEM_FAIL); SpbcgFree(spbcg_mem); N_VDestroy(x); N_VDestroy(ytemp); free(cpspils_mem); return(CPSPILS_MEM_FAIL); } } /* Compute sqrtN from a dot product */ N_VConst(ONE, ytemp); sqrtN = RSqrt(N_VDotProd(ytemp, ytemp)); /* Attach SPBCG memory to spils memory structure */ spils_mem = (void *) spbcg_mem; /* Attach linear solver memory to integrator memory */ lmem = cpspils_mem; return(CPSPILS_SUCCESS); }