int IDABBDSpbcg(void *ida_mem, int maxl, void *bbd_data)
{
  IDAMem IDA_mem;
  int flag;

  flag = IDASpbcg(ida_mem, maxl);
  if(flag != IDASPILS_SUCCESS) return(flag);

  IDA_mem = (IDAMem) ida_mem;

  if (bbd_data == NULL) {
    IDAProcessError(IDA_mem, IDABBDPRE_PDATA_NULL, "IDABBDPRE", "IDABBDSpbcg", MSGBBD_PDATA_NULL);
    return(IDABBDPRE_PDATA_NULL);
  }

  flag = IDASpilsSetPreconditioner(ida_mem, IDABBDPrecSetup, IDABBDPrecSolve, bbd_data);
  if(flag != IDASPILS_SUCCESS) return(flag);

  return(IDASPILS_SUCCESS);
}
Beispiel #2
0
void FIDA_SPBCG(int *maxl, realtype *eplifac, realtype *dqincfac, int *ier)
{

  *ier = 0;

  *ier = IDASpbcg(IDA_idamem, *maxl);
  if (*ier != IDASPILS_SUCCESS) return;

  if (*eplifac != ZERO) {
    *ier = IDASpilsSetEpsLin(IDA_idamem, *eplifac);
    if (*ier != IDASPILS_SUCCESS) return;
  }

  if (*dqincfac != ZERO) {
    *ier = IDASpilsSetIncrementFactor(IDA_idamem, *dqincfac);
    if (*ier != IDASPILS_SUCCESS) return;
  }

  IDA_ls = IDA_LS_SPBCG;

  return;
}
Beispiel #3
0
int IDASpbcgB(void *ida_mem, int which, int maxlB)
{
  IDAMem IDA_mem;
  IDAadjMem IDAADJ_mem;
  IDABMem IDAB_mem;
  IDASpilsMemB idaspilsB_mem;
  void *ida_memB;
  int flag;
  
  /* Check if ida_mem is allright. */
  if (ida_mem == NULL) {
    IDAProcessError(NULL, IDASPILS_MEM_NULL, "IDASPBCG", "IDASpbcgB", MSGS_IDAMEM_NULL);
    return(IDASPILS_MEM_NULL);
  }
  IDA_mem = (IDAMem) ida_mem;

  /* Is ASA initialized? */
  if (IDA_mem->ida_adjMallocDone == FALSE) {
    IDAProcessError(IDA_mem, IDASPILS_NO_ADJ, "IDASPBCG", "IDASpbcgB",  MSGS_NO_ADJ);
    return(IDASPILS_NO_ADJ);
  }
  IDAADJ_mem = IDA_mem->ida_adj_mem;

  /* Check the value of which */
  if ( which >= IDAADJ_mem->ia_nbckpbs ) {
    IDAProcessError(IDA_mem, IDASPILS_ILL_INPUT, "IDASPBCG", "IDASpbcgB", MSGS_BAD_WHICH);
    return(IDASPILS_ILL_INPUT);
  }

  /* Find the IDABMem entry in the linked list corresponding to 'which'. */
  IDAB_mem = IDAADJ_mem->IDAB_mem;
  while (IDAB_mem != NULL) {
    if( which == IDAB_mem->ida_index ) break;
    /* advance */
    IDAB_mem = IDAB_mem->ida_next;
  }
  /* ida_mem corresponding to 'which' problem. */
  ida_memB = (void *) IDAB_mem->IDA_mem;

  
  /* Get memory for IDASpilsMemRecB */
  idaspilsB_mem = NULL;
  idaspilsB_mem = (IDASpilsMemB) malloc(sizeof(struct IDASpilsMemRecB));
  if (idaspilsB_mem == NULL) {
    IDAProcessError(IDA_mem, IDASPILS_MEM_FAIL, "IDASPBCG", "IDASpbcgB", MSGS_MEM_FAIL);
    return(IDASPILS_MEM_FAIL);
  }

  idaspilsB_mem->s_psetB = NULL;
  idaspilsB_mem->s_psolveB = NULL;
  idaspilsB_mem->s_P_dataB = NULL;

  /* initialize Jacobian function */
  idaspilsB_mem->s_jtimesB = NULL;

  /* attach lmem and lfree */
  IDAB_mem->ida_lmem = idaspilsB_mem;
  IDAB_mem->ida_lfree = IDASpbcgFreeB;

  flag = IDASpbcg(IDAB_mem->IDA_mem, maxlB);

  if (flag != IDASPILS_SUCCESS) {
    free(idaspilsB_mem);
    idaspilsB_mem = NULL;
  }

  return(flag);
}
CAMLprim value sundials_ml_ida_spbcg(value ida_solver, value maxl) {
  CAMLparam2(ida_solver, maxl);
  const int ret = IDASpbcg(IDA_MEM(ida_solver), Int_val(maxl));
  CAMLreturn(Val_int(ret));
}
Beispiel #5
0
void SundialsIda::initialize()
{
    sundialsMem = IDACreate();
    if (check_flag((void *)sundialsMem, "IDACreate", 0)) {
        throw DebugException("SundialsIda::initialize: error in IDACreate");
    }

    IDASetUserData(sundialsMem, theDAE);

    int flag;
    if (calcIC)    {
        // Pick an appropriate initial condition for ydot and algebraic components of y
        flag = IDASetId(sundialsMem, componentId.forSundials());
    }

    flag = IDAInit(sundialsMem, f, t0, y.forSundials(), ydot.forSundials());
    if (check_flag(&flag, "IDAMalloc", 1)) {
        throw DebugException("SundialsIda::initialize: error in IDAInit");
    }

    IDASVtolerances(sundialsMem, reltol, abstol.forSundials());

    if (findRoots) {
        rootsFound.resize(nRoots);
        // Call IDARootInit to specify the root function g with nRoots components
        flag = IDARootInit(sundialsMem, nRoots, g);
        if (check_flag(&flag, "IDARootInit", 1)) {
            throw DebugException("SundialsIda::initialize: error in IDARootInit");
        }
    }

    // Call IDASpbcg to specify the IDASpbcg dense linear solver
    flag = IDASpbcg(sundialsMem, 0);
    if (check_flag(&flag, "IDASpbcg", 1)) {
        throw DebugException("SundialsIda::initialize: error in IDASpbcg");
    }

    if (imposeConstraints) {
        flag = IDASetConstraints(sundialsMem, constraints.forSundials());
        if (check_flag(&flag, "IDASetConstraints", 1)) {
            throw DebugException("SundialsIda::initialize: error in IDASetConstraints");
        }
    }

    // this seems to work better using the default J-v function rather than specifying our own...
    //flag = IDASpilsSetJacTimesVecFn(sundialsMem, JvProd, theDAE);
    //if (check_flag(&flag, "IDASpilsSetJacTimesVecFn", 1)) {
    //    throw myException("SundialsIda::initialize: error in IDASpilsSetJacTimesVecFn");
    //}

    flag = IDASpilsSetPreconditioner(sundialsMem, preconditionerSetup, preconditionerSolve);
    if (check_flag(&flag, "IDASpilsSetPreconditioner", 1)) {
        throw DebugException("SundialsIda::initialize: error in IDASpilsSetPreconditioner");
    }

    if (calcIC) {
        flag = IDACalcIC(sundialsMem, IDA_YA_YDP_INIT, t0+1e-4);
        if (check_flag(&flag, "IDACalcIC", 1)) {
            logFile.write("IDACalcIC Error");
            throw DebugException("SundialsIda::initialize: error in IDACalcIC");
        }

        flag = IDAGetConsistentIC(sundialsMem, y0.forSundials(), ydot0.forSundials());
        if (check_flag(&flag, "IDAGetConsistentIC", 1)) {
            throw DebugException("SundialsIda::initialize: error in IDAGetConsistentIC");
        }
    }

}