Exemple #1
0
void PVBBDFree(PVBBDData pdata)
{
  BandFreeMat(pdata->savedJ);
  BandFreeMat(pdata->savedP);
  BandFreePiv(pdata->pivots);
  free(pdata);
}
static void CVBandFree(CVodeMem cv_mem)
{
  CVBandMem cvband_mem;

  cvband_mem = (CVBandMem) lmem;

  BandFreeMat(M);
  BandFreeMat(savedJ);
  BandFreePiv(pivots);
  free(cvband_mem); cvband_mem = NULL;
}
void CVBBDPrecFree(void *bbd_data)
{
  CVBBDPrecData pdata;
  
  if ( bbd_data != NULL ) {
    pdata = (CVBBDPrecData) bbd_data;
    BandFreeMat(pdata->savedJ);
    BandFreeMat(pdata->savedP);
    BandFreePiv(pdata->pivots);
    free(pdata);
  }
}
Exemple #4
0
static int IDABandFree(IDAMem IDA_mem)
{
  IDABandMem idaband_mem;

  idaband_mem = (IDABandMem) lmem;
  
  BandFreeMat(JJ);
  BandFreePiv(pivots);
  free(lmem);

  return(0);

}
void IDABBDPrecFree(void **bbd_data)
{
  IBBDPrecData pdata;
  
  if (*bbd_data == NULL) return;

  pdata = (IBBDPrecData) (*bbd_data);
  BandFreeMat(pdata->PP);
  BandFreePiv(pdata->pivots);
  N_VDestroy(pdata->tempv4);

  free(*bbd_data);
  *bbd_data = NULL;

}
void CVBandPrecFree(void **bp_data)
{
    CVBandPrecData pdata;

    if (*bp_data == NULL) return;

    pdata = (CVBandPrecData) (*bp_data);
    BandFreeMat(pdata->savedJ);
    BandFreeMat(pdata->savedP);
    BandFreePiv(pdata->pivots);

    free(*bp_data);
    *bp_data = NULL;

}
void KINBBDPrecFree(void **p_data)
{
  KBBDPrecData pdata;

  if (*p_data == NULL) return;

  pdata = (KBBDPrecData) (*p_data);
  N_VDestroy(pdata->vtemp3);
  BandFreeMat(pdata->PP);
  BandFreePiv(pdata->pivots);

  free(*p_data);
  *p_data = NULL;

}
void *IDABBDPrecAlloc(void *ida_mem, long int Nlocal, 
		      long int mudq, long int mldq, 
		      long int mukeep, long int mlkeep, 
		      realtype dq_rel_yy, 
		      IDABBDLocalFn Gres, IDABBDCommFn Gcomm)
{
  IDAMem IDA_mem;
  IBBDPrecData pdata;
  N_Vector tempv4;
  long int muk, mlk, storage_mu;

  if (ida_mem == NULL) {
    IDAProcessError(NULL, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_IDAMEM_NULL);
    return(NULL);
  }

  IDA_mem = (IDAMem) ida_mem;

  /* Test if the NVECTOR package is compatible with BLOCK BAND preconditioner */
  if(vec_tmpl->ops->nvgetarraypointer == NULL) {
    IDAProcessError(IDA_mem, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_BAD_NVECTOR);
    return(NULL);
  }

  /* Allocate data memory. */
  pdata = NULL;
  pdata = (IBBDPrecData) malloc(sizeof *pdata);
  if (pdata == NULL) {
    IDAProcessError(IDA_mem, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_MEM_FAIL);
    return(NULL);
  }

  /* Set pointers to glocal and gcomm; load half-bandwidths. */
  pdata->ida_mem = IDA_mem;
  pdata->glocal = Gres;
  pdata->gcomm = Gcomm;
  pdata->mudq = MIN(Nlocal-1, MAX(0, mudq));
  pdata->mldq = MIN(Nlocal-1, MAX(0, mldq));
  muk = MIN(Nlocal-1, MAX(0, mukeep));
  mlk = MIN(Nlocal-1, MAX(0, mlkeep));
  pdata->mukeep = muk;
  pdata->mlkeep = mlk;

  /* Set extended upper half-bandwidth for PP (required for pivoting). */
  storage_mu = MIN(Nlocal-1, muk+mlk);

  /* Allocate memory for preconditioner matrix. */
  pdata->PP = NULL;
  pdata->PP = BandAllocMat(Nlocal, muk, mlk, storage_mu);
  if (pdata->PP == NULL) { 
    free(pdata); pdata = NULL;
    IDAProcessError(IDA_mem, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_MEM_FAIL);
    return(NULL); 
  }

  /* Allocate memory for pivots. */
  pdata->pivots = NULL;
  pdata->pivots = BandAllocPiv(Nlocal);
  if (pdata->PP == NULL) {
    BandFreeMat(pdata->PP);
    free(pdata); pdata = NULL;
    IDAProcessError(IDA_mem, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_MEM_FAIL);
    return(NULL);
  }

  /* Allocate tempv4 for use by IBBDDQJac */
  tempv4 = NULL;
  tempv4 = N_VClone(vec_tmpl); 
  if (tempv4 == NULL){
    BandFreeMat(pdata->PP);
    BandFreePiv(pdata->pivots);
    free(pdata); pdata = NULL;
    IDAProcessError(IDA_mem, 0, "IDABBDPRE", "IDABBDPrecAlloc", MSGBBD_MEM_FAIL);
    return(NULL);
  }
  pdata->tempv4 = tempv4;
  
  /* Set rel_yy based on input value dq_rel_yy (0 implies default). */
  pdata->rel_yy = (dq_rel_yy > ZERO) ? dq_rel_yy : RSqrt(uround); 

  /* Store Nlocal to be used in IDABBDPrecSetup */
  pdata->n_local = Nlocal;
  
  /* Set work space sizes and initialize nge. */
  pdata->rpwsize = Nlocal*(mlk + storage_mu + 1);
  pdata->ipwsize = Nlocal;
  pdata->nge = 0;

  return((void *)pdata);
}
void *KINBBDPrecAlloc(void *kinmem, long int Nlocal, 
		      long int mudq, long int mldq,
		      long int mukeep, long int mlkeep,
		      realtype dq_rel_uu, 
		      KINLocalFn gloc, KINCommFn gcomm)
{
  KBBDPrecData pdata;
  KINMem kin_mem;
  N_Vector vtemp3;
  long int muk, mlk, storage_mu;

  pdata = NULL;

  if (kinmem == NULL) {
    KINProcessError(NULL, 0, "KINBBDPRE", "KINBBDPrecAlloc", MSGBBD_KINMEM_NULL);
    return(NULL);
  }
  kin_mem = (KINMem) kinmem;

  /* test if the NVECTOR package is compatible with BLOCK BAND preconditioner */

  /* Note: do NOT need to check for N_VScale since it is required by KINSOL and
     so has already been checked for (see KINMalloc) */

  if (vec_tmpl->ops->nvgetarraypointer == NULL) {
    KINProcessError(kin_mem, 0, "KINBBDPRE", "KINBBDPrecAlloc", MSGBBD_BAD_NVECTOR);
    return(NULL);
  }

  pdata = NULL;
  pdata = (KBBDPrecData) malloc(sizeof *pdata);  /* allocate data memory */
  if (pdata == NULL) {
    KINProcessError(kin_mem, 0, "KINBBDPRE", "KINBBDPrecAlloc", MSGBBD_MEM_FAIL);
    return(NULL);
  }

  /* set pointers to gloc and gcomm and load half-bandwiths */

  pdata->kin_mem = kinmem;
  pdata->gloc = gloc;
  pdata->gcomm = gcomm;
  pdata->mudq = MIN(Nlocal-1, MAX(0, mudq));
  pdata->mldq = MIN(Nlocal-1, MAX(0, mldq));
  muk = MIN(Nlocal-1, MAX(0,mukeep));
  mlk = MIN(Nlocal-1, MAX(0,mlkeep));
  pdata->mukeep = muk;
  pdata->mlkeep = mlk;

  /* allocate memory for preconditioner matrix */

  storage_mu = MIN(Nlocal-1, muk+mlk);
  pdata->PP = NULL;
  pdata->PP = BandAllocMat(Nlocal, muk, mlk, storage_mu);
  if (pdata->PP == NULL) {
    free(pdata); pdata = NULL;
    return(NULL);
  }

  /* allocate memory for pivots */

  pdata->pivots = NULL;
  pdata->pivots = BandAllocPiv(Nlocal);
  if (pdata->pivots == NULL) {
    BandFreeMat(pdata->PP);
    free(pdata); pdata = NULL;
    return(NULL);
  }

  /* allocate vtemp3 for use by KBBDDQJac routine */

  vtemp3 = NULL;
  vtemp3 = N_VClone(kin_mem->kin_vtemp1);
  if (vtemp3 == NULL) {
    BandFreePiv(pdata->pivots);
    BandFreeMat(pdata->PP);
    free(pdata); pdata = NULL;
    return(NULL);
  }
  pdata->vtemp3 = vtemp3;

  /* set rel_uu based on input value dq_rel_uu */

  if (dq_rel_uu > ZERO) pdata->rel_uu = dq_rel_uu;
  else pdata->rel_uu = RSqrt(uround);  /* using dq_rel_uu = 0.0 means use default */

  /* store Nlocal to be used by the preconditioner routines */

  pdata->n_local = Nlocal;

  /* set work space sizes and initialize nge */

  pdata->rpwsize = Nlocal * (storage_mu*mlk + 1) + 1;
  pdata->ipwsize = Nlocal + 1;
  pdata->nge = 0;

  return((void *) pdata);
}