/[ascend]/trunk/base/generic/solver/ida.c
ViewVC logotype

Diff of /trunk/base/generic/solver/ida.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1048 by johnpye, Wed Jan 3 09:13:44 2007 UTC revision 1049 by johnpye, Fri Jan 5 13:45:13 2007 UTC
# Line 424  static double div1(double a, double b){ Line 424  static double div1(double a, double b){
424  typedef int IdaFlagFn(void *,int *);  typedef int IdaFlagFn(void *,int *);
425  typedef char *IdaFlagNameFn(int);  typedef char *IdaFlagNameFn(int);
426    
427  /* return 1 on success */  /* return 0 on success */
428  int integrator_ida_solve(  int integrator_ida_solve(
429          IntegratorSystem *blsys          IntegratorSystem *blsys
430          , unsigned long start_index          , unsigned long start_index
# Line 465  int integrator_ida_solve( Line 465  int integrator_ida_solve(
465    
466      if(enginedata->nrels!=size){      if(enginedata->nrels!=size){
467          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Integration problem is not square (%d rels, %d vars)", enginedata->nrels, size);          ERROR_REPORTER_HERE(ASC_USER_ERROR,"Integration problem is not square (%d rels, %d vars)", enginedata->nrels, size);
468          return 0; /* failure */          return 1; /* failure */
469      }      }
470    
471      /* retrieve initial values from the system */      /* retrieve initial values from the system */
# Line 517  int integrator_ida_solve( Line 517  int integrator_ida_solve(
517    
518      if(flag==IDA_MEM_NULL){      if(flag==IDA_MEM_NULL){
519          ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");
520          return 0;          return 2;
521      }else if(flag==IDA_MEM_FAIL){      }else if(flag==IDA_MEM_FAIL){
522          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to allocate memory (IDAMalloc)");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to allocate memory (IDAMalloc)");
523          return 0;          return 3;
524      }else if(flag==IDA_ILL_INPUT){      }else if(flag==IDA_ILL_INPUT){
525          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Invalid input to IDAMalloc");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Invalid input to IDAMalloc");
526          return 0;          return 4;
527      }/* else success */      }/* else success */
528    
529      /* set optional inputs... */      /* set optional inputs... */
# Line 559  int integrator_ida_solve( Line 559  int integrator_ida_solve(
559          flag = IDADense(ida_mem, size);          flag = IDADense(ida_mem, size);
560          switch(flag){          switch(flag){
561              case IDADENSE_SUCCESS: break;              case IDADENSE_SUCCESS: break;
562              case IDADENSE_MEM_NULL: ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL"); return 0;              case IDADENSE_MEM_NULL: ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL"); return 5;
563              case IDADENSE_ILL_INPUT: ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDADENSE is not compatible with current nvector module"); return 0;              case IDADENSE_ILL_INPUT: ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDADENSE is not compatible with current nvector module"); return 5;
564              case IDADENSE_MEM_FAIL: ERROR_REPORTER_HERE(ASC_PROG_ERR,"Memory allocation failed for IDADENSE"); return 0;              case IDADENSE_MEM_FAIL: ERROR_REPORTER_HERE(ASC_PROG_ERR,"Memory allocation failed for IDADENSE"); return 5;
565              default: ERROR_REPORTER_HERE(ASC_PROG_ERR,"bad return"); return 0;              default: ERROR_REPORTER_HERE(ASC_PROG_ERR,"bad return"); return 5;
566          }          }
567    
568          if(SLV_PARAM_BOOL(&(blsys->params),IDA_PARAM_AUTODIFF)){          if(SLV_PARAM_BOOL(&(blsys->params),IDA_PARAM_AUTODIFF)){
# Line 570  int integrator_ida_solve( Line 570  int integrator_ida_solve(
570              flag = IDADenseSetJacFn(ida_mem, &integrator_ida_djex, (void *)blsys);              flag = IDADenseSetJacFn(ida_mem, &integrator_ida_djex, (void *)blsys);
571              switch(flag){              switch(flag){
572                  case IDADENSE_SUCCESS: break;                  case IDADENSE_SUCCESS: break;
573                  default: ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed IDADenseSetJacFn"); return 0;                  default: ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed IDADenseSetJacFn"); return 6;
574              }              }
575          }else{          }else{
576              CONSOLE_DEBUG("USING NUMERICAL DIFF");              CONSOLE_DEBUG("USING NUMERICAL DIFF");
# Line 594  int integrator_ida_solve( Line 594  int integrator_ida_solve(
594              prec = &prec_jacobi;              prec = &prec_jacobi;
595          }else{          }else{
596              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Invalid preconditioner choice '%s'",pname);              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Invalid preconditioner choice '%s'",pname);
597              return 0;              return 7;
598          }          }
599    
600          /* which SPILS linear solver? */          /* which SPILS linear solver? */
# Line 609  int integrator_ida_solve( Line 609  int integrator_ida_solve(
609              flag = IDASptfqmr(ida_mem,maxl);              flag = IDASptfqmr(ida_mem,maxl);
610          }else{          }else{
611              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unknown IDA linear solver choice '%s'",linsolver);              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unknown IDA linear solver choice '%s'",linsolver);
612              return 0;              return 8;
613          }          }
614    
615          if(prec){          if(prec){
# Line 627  int integrator_ida_solve( Line 627  int integrator_ida_solve(
627    
628          if(flag==IDASPILS_MEM_NULL){          if(flag==IDASPILS_MEM_NULL){
629              ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");              ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");
630              return 0;              return 9;
631          }else if(flag==IDASPILS_MEM_FAIL){          }else if(flag==IDASPILS_MEM_FAIL){
632              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to allocate memory (IDASpgmr)");              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to allocate memory (IDASpgmr)");
633              return 0;              return 9;
634          }/* else success */          }/* else success */
635    
636          /* assign the J*v function */          /* assign the J*v function */
# Line 639  int integrator_ida_solve( Line 639  int integrator_ida_solve(
639              flag = IDASpilsSetJacTimesVecFn(ida_mem, &integrator_ida_jvex, (void *)blsys);              flag = IDASpilsSetJacTimesVecFn(ida_mem, &integrator_ida_jvex, (void *)blsys);
640              if(flag==IDASPILS_MEM_NULL){              if(flag==IDASPILS_MEM_NULL){
641                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");
642                  return 0;                  return 10;
643              }else if(flag==IDASPILS_LMEM_NULL){              }else if(flag==IDASPILS_LMEM_NULL){
644                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDASPILS linear solver has not been initialized");                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDASPILS linear solver has not been initialized");
645                  return 0;                  return 10;
646              }/* else success */              }/* else success */
647          }else{          }else{
648              CONSOLE_DEBUG("USING NUMERICAL DIFF");              CONSOLE_DEBUG("USING NUMERICAL DIFF");
# Line 655  int integrator_ida_solve( Line 655  int integrator_ida_solve(
655                  flag = IDASpilsSetGSType(ida_mem,MODIFIED_GS);                  flag = IDASpilsSetGSType(ida_mem,MODIFIED_GS);
656                  if(flag!=IDASPILS_SUCCESS){                  if(flag!=IDASPILS_SUCCESS){
657                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to set GS_MODIFIED");                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to set GS_MODIFIED");
658                      return 0;                      return 11;
659                  }                  }
660              }else{              }else{
661                  CONSOLE_DEBUG("USING CLASSICAL GS");                  CONSOLE_DEBUG("USING CLASSICAL GS");
662                  flag = IDASpilsSetGSType(ida_mem,CLASSICAL_GS);                  flag = IDASpilsSetGSType(ida_mem,CLASSICAL_GS);
663                  if(flag!=IDASPILS_SUCCESS){                  if(flag!=IDASPILS_SUCCESS){
664                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to set GS_MODIFIED");                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to set GS_MODIFIED");
665                      return 0;                      return 11;
666                  }                  }
667              }              }
668          }          }
# Line 744  int integrator_ida_solve( Line 744  int integrator_ida_solve(
744                      flag = (flagfn)(ida_mem,&flag1);                      flag = (flagfn)(ida_mem,&flag1);
745                      if(flag){                      if(flag){
746                          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to retrieve error code from %s (err %d)",flagfntype,flag);                          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Unable to retrieve error code from %s (err %d)",flagfntype,flag);
747                          return 0;                          return 12;
748                      }                      }
749                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s returned flag '%s' (value = %d)",flagfntype,(flagnamefn)(flag1),flag1);                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"%s returned flag '%s' (value = %d)",flagfntype,(flagnamefn)(flag1),flag1);
750                      return 0;                      return 12;
751    
752                  default:                  default:
753                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to solve initial condition (IDACalcIC)");                      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Failed to solve initial condition (IDACalcIC)");
754                      return 0;                      return 12;
755              }              }
756          }else{          }else{
757              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Floating point error while solving initial conditions");              ERROR_REPORTER_HERE(ASC_PROG_ERR,"Floating point error while solving initial conditions");
758              return 0;              return 13;
759          }          }
760    
761          if(enginedata->safeeval){          if(enginedata->safeeval){
# Line 831  int integrator_ida_solve( Line 831  int integrator_ida_solve(
831    
832      if(flag < 0){      if(flag < 0){
833          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Solving aborted while attempting t = %f", t);          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Solving aborted while attempting t = %f", t);
834          return 0;          return 14;
835      }      }
836    
837      /* all done, success */      /* all done, success */
838      return 1;      return 0;
839  }  }
840    
841  /*--------------------------------------------------  /*--------------------------------------------------

Legend:
Removed from v.1048  
changed lines
  Added in v.1049

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22