/[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 941 by johnpye, Wed Nov 22 13:09:09 2006 UTC revision 942 by johnpye, Sat Nov 25 05:26:47 2006 UTC
# Line 39  Line 39 
39  #include <utilities/error.h>  #include <utilities/error.h>
40  #include <utilities/ascConfig.h>  #include <utilities/ascConfig.h>
41  #include <utilities/ascSignal.h>  #include <utilities/ascSignal.h>
42    #include <utilities/ascPanic.h>
43  #include <compiler/instance_enum.h>  #include <compiler/instance_enum.h>
44  #include "var.h"  #include "var.h"
45  #include "rel.h"  #include "rel.h"
# Line 121  void integrator_ida_create(IntegratorSys Line 122  void integrator_ida_create(IntegratorSys
122      enginedata->varlist = NULL;      enginedata->varlist = NULL;
123      enginedata->safeeval = 1;      enginedata->safeeval = 1;
124      blsys->enginedata = (void *)enginedata;      blsys->enginedata = (void *)enginedata;
125        integrator_ida_params_default(blsys);
126  }  }
127    
128  void integrator_ida_free(void *enginedata){  void integrator_ida_free(void *enginedata){
# Line 141  IntegratorIdaData *integrator_ida_engine Line 143  IntegratorIdaData *integrator_ida_engine
143  }  }
144    
145  /*-------------------------------------------------------------  /*-------------------------------------------------------------
146      PARAMETERS FOR IDA
147    */
148    
149    enum ida_parameters{
150        IDA_PARAM_AUTODIFF
151        ,IDA_PARAMS_SIZE
152    };
153    
154    /**
155        Here the full set of parameters is defined, along with upper/lower bounds,
156        etc. The values are stuck into the blsys->params structure.
157    
158        @return 0 on success
159    */
160    int integrator_ida_params_default(IntegratorSystem *blsys){
161        asc_assert(blsys!=NULL);
162        asc_assert(blsys->engine==INTEG_IDA);
163        slv_parameters_t *p;
164        p = &(blsys->params);
165    
166        slv_destroy_parms(p);
167    
168        if(p->parms==NULL){
169            CONSOLE_DEBUG("params NULL");
170            p->parms = ASC_NEW_ARRAY(struct slv_parameter, IDA_PARAMS_SIZE);
171            if(p->parms==NULL)return -1;
172            p->dynamic_parms = 1;
173        }else{
174            CONSOLE_DEBUG("params not NULL");
175        }
176    
177        /* reset the number of parameters to zero so that we can check it at the end */
178        p->num_parms = 0;
179    
180        slv_param_bool(p,IDA_PARAM_AUTODIFF
181                ,(SlvParameterInitBool){{"autodiff"
182                ,"Use auto-diff?",1
183                ,"Use automatic differentiation of expressions (1) or use numerical derivatives (0)"
184            }, TRUE}
185        );
186    
187        asc_assert(p->num_parms == IDA_PARAMS_SIZE);
188    
189        CONSOLE_DEBUG("Created %d params", p->num_parms);
190    
191        return 0;
192    }
193    
194    /*-------------------------------------------------------------
195    MAIN IDA SOLVER ROUTINE, see IDA manual, sec 5.4, p. 27 ff.    MAIN IDA SOLVER ROUTINE, see IDA manual, sec 5.4, p. 27 ff.
196  */  */
197    
# Line 234  int integrator_ida_solve( Line 285  int integrator_ida_solve(
285      }/* else success */      }/* else success */
286    
287      /* assign the J*v function */      /* assign the J*v function */
288  #if 0      if(SLV_PARAM_BOOL(&(blsys->params),IDA_PARAM_AUTODIFF)){
289      flag = IDASpilsSetJacTimesVecFn(ida_mem, &integrator_ida_jvex, (void *)blsys);          CONSOLE_DEBUG("USING AUTODIFF");
290      if(flag==IDASPILS_MEM_NULL){          flag = IDASpilsSetJacTimesVecFn(ida_mem, &integrator_ida_jvex, (void *)blsys);
291          ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");          if(flag==IDASPILS_MEM_NULL){
292          return 0;              ERROR_REPORTER_HERE(ASC_PROG_ERR,"ida_mem is NULL");
293      }else if(flag==IDASPILS_LMEM_NULL){              return 0;
294          ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDASPILS linear solver has not been initialized");          }else if(flag==IDASPILS_LMEM_NULL){
295          return 0;              ERROR_REPORTER_HERE(ASC_PROG_ERR,"IDASPILS linear solver has not been initialized");
296      }/* else success */              return 0;
297  #endif          }/* else success */
298        }else{
299            CONSOLE_DEBUG("USING NUMERICAL DIFF");
300        }      
301    
302      /* set linear solver optional inputs...      /* set linear solver optional inputs...
303    
# Line 287  int integrator_ida_solve( Line 341  int integrator_ida_solve(
341      for(t_index=start_index+1;t_index <= finish_index;++t_index, ++blsys->currentstep){      for(t_index=start_index+1;t_index <= finish_index;++t_index, ++blsys->currentstep){
342          t = samplelist_get(blsys->samples, t_index);          t = samplelist_get(blsys->samples, t_index);
343    
344          CONSOLE_DEBUG("SOLVING UP TO t = %f", t);          /* CONSOLE_DEBUG("SOLVING UP TO t = %f", t); */
345            
346          flag = IDASolve(ida_mem, t, &tret, yret, ypret, IDA_NORMAL);          flag = IDASolve(ida_mem, t, &tret, yret, ypret, IDA_NORMAL);
347    

Legend:
Removed from v.941  
changed lines
  Added in v.942

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