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

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

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

revision 962 by johnpye, Mon Dec 11 14:43:02 2006 UTC revision 963 by johnpye, Tue Dec 12 13:36:52 2006 UTC
# Line 272  void integrator_lsode_free(void *engined Line 272  void integrator_lsode_free(void *engined
272    
273  enum ida_parameters{  enum ida_parameters{
274      LSODE_PARAM_TIMING      LSODE_PARAM_TIMING
275      ,LSODE_PARAM_RTOLDEF      ,LSODE_PARAM_RTOLVECT
276      ,LSODE_PARAM_ATOLDEF      ,LSODE_PARAM_RTOL
277        ,LSODE_PARAM_ATOLVECT
278        ,LSODE_PARAM_ATOL
279      ,LSODE_PARAMS_SIZE      ,LSODE_PARAMS_SIZE
280  };  };
281    
# Line 311  int integrator_lsode_params_default(Inte Line 313  int integrator_lsode_params_default(Inte
313          }, TRUE}          }, TRUE}
314      );      );
315    
316      slv_param_real(p,LSODE_PARAM_ATOLDEF      slv_param_bool(p,LSODE_PARAM_ATOLVECT
317              ,(SlvParameterInitReal){{"atoldef"              ,(SlvParameterInitBool){{"atolvect"
318                ,"Use 'ode_atol' values as specified for each var?",1
319                ,"If TRUE, values of 'ode_atol' are taken from your model and used "
320                " in the integration. If FALSE, a scalar absolute tolerance (atol)"
321                " is shared by all variables."
322            }, TRUE }
323        );
324    
325        slv_param_real(p,LSODE_PARAM_ATOL
326                ,(SlvParameterInitReal){{"atol"
327              ,"Scalar absolute error tolerance",1              ,"Scalar absolute error tolerance",1
328              ,"Default value of the scalar absolute error tolerance (for cases"              ,"Default value of the scalar absolute error tolerance (for cases"
329              " where not specified in oda_atol var property. See 'lsode.f' for"              " where not specified in oda_atol var property. See 'lsode.f' for"
# Line 320  int integrator_lsode_params_default(Inte Line 331  int integrator_lsode_params_default(Inte
331          }, 1e-6, DBL_MIN, DBL_MAX }          }, 1e-6, DBL_MIN, DBL_MAX }
332      );      );
333    
334      slv_param_real(p,LSODE_PARAM_RTOLDEF      slv_param_bool(p,LSODE_PARAM_RTOLVECT
335              ,(SlvParameterInitReal){{"rtoldef"              ,(SlvParameterInitBool){{"rtolvect"
336                ,"Use 'ode_rtol' values as specified for each var?",1
337                ,"If TRUE, values of 'ode_atol' are taken from your model and used "
338                " in the integration. If FALSE, a scalar absolute tolerance (rtol)"
339                " is shared by all variables."
340            }, TRUE }
341        );
342    
343        slv_param_real(p,LSODE_PARAM_RTOL
344                ,(SlvParameterInitReal){{"rtol"
345              ,"Scalar relative error tolerance",1              ,"Scalar relative error tolerance",1
346              ,"Default value of the scalar relative error tolerance (for cases"              ,"Default value of the scalar relative error tolerance (for cases"
347              " where not specified in oda_rtol var property. See 'lsode.f' for"              " where not specified in oda_rtol var property. See 'lsode.f' for"
# Line 425  int integrator_lsode_setup_diffs(Integra Line 445  int integrator_lsode_setup_diffs(Integra
445  /**  /**
446      allocates, fills, and returns the atol vector based on LSODE      allocates, fills, and returns the atol vector based on LSODE
447    
448      State variables missing child ode_rtol will be defaulted to ATOLDEF      State variables missing child ode_rtol will be defaulted to ATOL
449  */  */
450  static double *lsode_get_atol( IntegratorSystem *blsys) {  static double *lsode_get_atol( IntegratorSystem *blsys) {
451    
452    struct Instance *tol;    struct Instance *tol;
453    double *atoli;    double *atoli;
454    int i,len;    int i,len;
455      double atol;
456    
457    len = blsys->n_y;    len = blsys->n_y;
458    atoli = ASC_NEW_ARRAY(double, blsys->n_y+1);    atoli = ASC_NEW_ARRAY(double, blsys->n_y); /* changed, this was n_y+1 before, dunnowi -- JP */
459    if (atoli == NULL) {    if (atoli == NULL) {
460      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Insufficient memory");      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Insufficient memory");
461      return atoli;      return atoli;
462    }    }
463    InitTolNames();  
464    for (i=0; i<len; i++) {    if(!SLV_PARAM_BOOL(&(blsys->params),LSODE_PARAM_ATOLVECT)){
465      tol = ChildByChar(var_instance(blsys->y[i]),STATEATOL);      atol = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_ATOL);
466      if (tol == NULL || !AtomAssigned(tol) ) {      CONSOLE_DEBUG("Using ATOL = %f for all vars", atol);
467        atoli[i] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_ATOLDEF);      for(i=0; i<len; ++i){
468        ERROR_REPORTER_HERE(ASC_PROG_WARNING,"Assuming atol = %3g"        atoli[i] = atol;
469          "for ode_atol child undefined for state variable %ld."      }
470          ,atoli[i], blsys->y_id[i]    }else{
471        );      InitTolNames();
472      } else {      for (i=0; i<len; i++) {
473        atoli[i] = RealAtomValue(tol);        
474        CONSOLE_DEBUG("Using tolerance %3g for state variable %ld.",atoli[i], blsys->y_id[i]);        tol = ChildByChar(var_instance(blsys->y[i]),STATEATOL);
475          if (tol == NULL || !AtomAssigned(tol) ) {
476            atoli[i] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_ATOL);
477            ERROR_REPORTER_HERE(ASC_PROG_WARNING,"Assuming atol = %3g"
478              "for ode_atol child undefined for state variable %ld."
479                ,atoli[i], blsys->y_id[i]
480            );
481          } else {
482            atoli[i] = RealAtomValue(tol);
483            CONSOLE_DEBUG("Using atol %3g for state variable %ld.",atoli[i], blsys->y_id[i]);
484          }
485      }      }
486    }    }
   atoli[len] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_ATOLDEF); /* not sure why this one...? */  
487    return atoli;    return atoli;
488  }  }
489    
490  /**  /**
491      Allocates, fills, and returns the rtol vector based on LSODE      Allocates, fills, and returns the rtol vector based on LSODE
492    
493      State variables missing child ode_rtol will be defaulted to RTOLDEF      State variables missing child ode_rtol will be defaulted to RTOL
494  */  */
495  static double *lsode_get_rtol( IntegratorSystem *blsys) {  static double *lsode_get_rtol( IntegratorSystem *blsys) {
496    
497    struct Instance *tol;    struct Instance *tol;
498    double *rtoli;    double rtol, *rtoli;
499    int i,len;    int i,len;
500    
501    len = blsys->n_y;    len = blsys->n_y;
# Line 474  static double *lsode_get_rtol( Integrato Line 504  static double *lsode_get_rtol( Integrato
504      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Insufficient memory");      ERROR_REPORTER_HERE(ASC_PROG_ERR,"Insufficient memory");
505      return rtoli;      return rtoli;
506    }    }
507    InitTolNames();    if(!SLV_PARAM_BOOL(&(blsys->params),LSODE_PARAM_RTOLVECT)){
508    for (i=0; i<len; i++) {      rtol = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_RTOL);
509      tol = ChildByChar(var_instance(blsys->y[i]),STATERTOL);      CONSOLE_DEBUG("Using RTOL = %f for all vars", rtol);
510      if (tol == NULL || !AtomAssigned(tol) ) {      for(i=0; i<len; ++i){
511        rtoli[i] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_RTOLDEF);        rtoli[i] = rtol;
512        }
513        ERROR_REPORTER_HERE(ASC_PROG_WARNING,"Assuming rtol = %3g"    }else{
514          "for ode_rtol child undefined for state variable %ld."      InitTolNames();
515          ,rtoli[i], blsys->y_id[i]      for (i=0; i<len; i++) {
516        );        tol = ChildByChar(var_instance(blsys->y[i]),STATERTOL);
517          if (tol == NULL || !AtomAssigned(tol) ) {
518      } else {          rtoli[i] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_RTOL);
519        rtoli[i] = RealAtomValue(tol);  
520            ERROR_REPORTER_HERE(ASC_PROG_WARNING,"Assuming rtol = %3g"
521                "for ode_rtol child undefined for state variable %ld."
522                ,rtoli[i], blsys->y_id[i]
523            );
524      
525          } else {
526            rtoli[i] = RealAtomValue(tol);
527          }
528      }      }
529    }    }
530    rtoli[len] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_RTOLDEF);    rtoli[len] = SLV_PARAM_REAL(&(blsys->params),LSODE_PARAM_RTOL);
531    return rtoli;    return rtoli;
532  }  }
533    

Legend:
Removed from v.962  
changed lines
  Added in v.963

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