/[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 1143 by johnpye, Mon Jan 15 06:46:44 2007 UTC revision 1144 by johnpye, Mon Jan 15 10:42:11 2007 UTC
# Line 51  Line 51 
51      Last in CVS $Revision: 1.29 $ $Date: 2000/01/25 02:26:31 $ $Author: ballan $      Last in CVS $Revision: 1.29 $ $Date: 2000/01/25 02:26:31 $ $Author: ballan $
52  */  */
53    
54    #include <time.h>
55    #ifndef CLOCKS_PER_SEC
56    # error "Where is CLOCKS_PER_SEC?"
57    #endif
58    
59  #include <utilities/config.h>  #include <utilities/config.h>
60    
61  #ifdef ASC_SIGNAL_TRAPS  #ifdef ASC_SIGNAL_TRAPS
62  # include <signal.h>  # include <signal.h>
63  # include <general/except.h>  # include <general/except.h>
# Line 143  const IntegratorInternals integrator_lso Line 149  const IntegratorInternals integrator_lso
149  #define GETCOMMON GET_LSODE_COMMON  #define GETCOMMON GET_LSODE_COMMON
150  #endif  #endif
151    
152  #define DOTIME FALSE  #define TIMING_DEBUG
153    #define ASC_CLOCK_CHECK_PERIOD 1 /* number of FEX or JEX cycled between GUI updates */
154    #define ASC_CLOCK_MAX_GUI_WAIT (0.5*CLOCKS_PER_SEC) /* max number of clock ticks between GUI updates */
155  /* definitions of lsode supported children of atoms, etc */  /* definitions of lsode supported children of atoms, etc */
156  /********************************************************************/  /********************************************************************/
157  /* solver_var children expected for state variables */  /* solver_var children expected for state variables */
# Line 201  typedef struct IntegratorLsodeDataStruct Line 208  typedef struct IntegratorLsodeDataStruct
208      char stop;                             /* stop requested? */      char stop;                             /* stop requested? */
209      int partitioned;                       /* partioned func evals or not */      int partitioned;                       /* partioned func evals or not */
210        
211        clock_t lastwrite;                     /* time of last call to the reporter 'write' function */
212  } IntegratorLsodeData;  } IntegratorLsodeData;
213    
214  /**<  /**<
# Line 727  error: Line 735  error:
735      function calls.  This code below attempts to handle these cases.      function calls.  This code below attempts to handle these cases.
736  */  */
737  static void LSODE_FEX( int *n_eq ,double *t ,double *y ,double *ydot){  static void LSODE_FEX( int *n_eq ,double *t ,double *y ,double *ydot){
738        static short clockcheck = 0;
739    slv_status_t status;    slv_status_t status;
740    LSODEDATA_GET(lsodedata);    LSODEDATA_GET(lsodedata);
741    
# Line 734  static void LSODE_FEX( int *n_eq ,double Line 743  static void LSODE_FEX( int *n_eq ,double
743    /* int i; */    /* int i; */
744    unsigned long res;    unsigned long res;
745    
746  #if DOTIME  #ifdef TIMING_DEBUG
747    double time1,time2;    clock_t time1,time2;
748  #endif  #endif
749    
750    /* CONSOLE_DEBUG("Calling for a function evaluation"); */    /* CONSOLE_DEBUG("Calling for a function evaluation"); */
751    
752  #if DOTIME  #ifdef TIMING_DEBUG
753    CONSOLE_DEBUG("Calling for a function evaluation");    CONSOLE_DEBUG("Calling for a function evaluation");
754    time1 = tm_cpu_time();    time1 = clock();
755  #endif  #endif
756    
757    /*    /*
# Line 751  static void LSODE_FEX( int *n_eq ,double Line 760  static void LSODE_FEX( int *n_eq ,double
760    integrator_set_t(l_lsode_blsys, t[0]);    integrator_set_t(l_lsode_blsys, t[0]);
761    integrator_set_y(l_lsode_blsys, y);    integrator_set_y(l_lsode_blsys, y);
762    
763  #if DOTIME  #ifdef TIMING_DEBUG
764    time2 = tm_cpu_time();    time2 = clock();
765  #endif  #endif
766    
767    switch(lsodedata->lastcall) {    switch(lsodedata->lastcall) {
# Line 784  static void LSODE_FEX( int *n_eq ,double Line 793  static void LSODE_FEX( int *n_eq ,double
793    /* pass the solver status to the integrator */    /* pass the solver status to the integrator */
794    res = integrator_checkstatus(status);    res = integrator_checkstatus(status);
795    
796  #if DOTIME      /* Do we need to do clock check? */
797    time2 = tm_cpu_time() - time2;      if((++clockcheck % ASC_CLOCK_CHECK_PERIOD)==0){
798            if((clock() - lsodedata->lastwrite) > ASC_CLOCK_MAX_GUI_WAIT){
799                integrator_output_write(l_lsode_blsys);
800                lsodedata->lastwrite = clock(); /* don't count the update time, or we might never get anything done */
801            }
802        }          
803            
804    #ifdef TIMING_DEBUG
805      time2 = clock() - time2;
806  #endif  #endif
807    
808    if(res){    if(res){
# Line 810  static void LSODE_FEX( int *n_eq ,double Line 827  static void LSODE_FEX( int *n_eq ,double
827    integrator_get_ydot(l_lsode_blsys, ydot);    integrator_get_ydot(l_lsode_blsys, ydot);
828    
829    lsodedata->lastcall = lsode_function;    lsodedata->lastcall = lsode_function;
830  #if DOTIME  #ifdef TIMING_DEBUG
831    time1 = tm_cpu_time() - time1;    time1 = clock() - time1;
832    CONSOLE_DEBUG("Function evalulation has been completed in time %g. True function call  time = %g",time1,time2);    CONSOLE_DEBUG("Function evalulation has been completed in %ld ticks. True function call time = %ld ticks",time1,time2);
833  #endif  #endif
834  }  }
835    
# Line 822  static void LSODE_FEX( int *n_eq ,double Line 839  static void LSODE_FEX( int *n_eq ,double
839  static void LSODE_JEX(int *neq ,double *t, double *y  static void LSODE_JEX(int *neq ,double *t, double *y
840          , int *ml ,int *mu ,double *pd, int *nrpd          , int *ml ,int *mu ,double *pd, int *nrpd
841  ){  ){
842        static short clockcheck = 0;
843    int nok = 0;    int nok = 0;
844    int i,j;    int i,j;
845    
# Line 833  static void LSODE_JEX(int *neq ,double * Line 851  static void LSODE_JEX(int *neq ,double *
851    UNUSED_PARAMETER(mu);    UNUSED_PARAMETER(mu);
852    
853    /* CONSOLE_DEBUG("Calling for a gradient evaluation"); */    /* CONSOLE_DEBUG("Calling for a gradient evaluation"); */
854  #if DOTIME  #ifdef TIMING_DEBUG
855    double time1;    clock_t time1;
856    
857    CONSOLE_DEBUG("Calling for a gradient evaluation");    CONSOLE_DEBUG("Calling for a gradient evaluation");
858    time1 = tm_cpu_time();    time1 = clock();
859  #endif  #endif
860    /*    /*
861     * Make the real call.     * Make the real call.
# Line 858  static void LSODE_JEX(int *neq ,double * Line 876  static void LSODE_JEX(int *neq ,double *
876      lsodedata->status = lsode_ok;      lsodedata->status = lsode_ok;
877      lsodedata->lastcall = lsode_derivative;      lsodedata->lastcall = lsode_derivative;
878    }    }
879    
880        /* Do we need to do clock check? */
881        if((++clockcheck % ASC_CLOCK_CHECK_PERIOD)==0){
882            /* do we need to update the GUI? */
883            CONSOLE_DEBUG("CLOCK = %ld", clock());
884            if((clock() - lsodedata->lastwrite) > ASC_CLOCK_MAX_GUI_WAIT){
885                integrator_output_write(l_lsode_blsys);
886                lsodedata->lastwrite = clock(); /* don't count the update time, or we might never get anything done */
887            }
888        }
889    
890    /*    /*
891      Map data from C based matrix to Fortan matrix.      Map data from C based matrix to Fortan matrix.
892      We will send in a column major ordering vector for pd.      We will send in a column major ordering vector for pd.
# Line 871  static void LSODE_JEX(int *neq ,double * Line 900  static void LSODE_JEX(int *neq ,double *
900      }      }
901    }    }
902    
903  #if DOTIME  #ifdef TIMING_DEBUG
904    time1 = tm_cpu_time() - time1;    time1 = clock() - time1;
905    CONSOLE_DEBUG("Time to do gradient evaluation %g",time1);    CONSOLE_DEBUG("Time to do gradient evaluation %ld ticks",time1);
906  #endif  #endif
907    
908    return;    return;
# Line 1093  int integrator_lsode_solve(IntegratorSys Line 1122  int integrator_lsode_solve(IntegratorSys
1122        }        }
1123        */        */
1124    
1125                d->lastwrite = clock();
1126    
1127        /* provides some rudimentary locking to prevent reentrance*/        /* provides some rudimentary locking to prevent reentrance*/
1128        LSODEDATA_SET(blsys);        LSODEDATA_SET(blsys);
1129    
# Line 1277  void XASCWV( char *msg, /* pointer to st Line 1308  void XASCWV( char *msg, /* pointer to st
1308          case 201:          case 201:
1309              if(*nr==0 && *ni==0)return;              if(*nr==0 && *ni==0)return;
1310              if(*nr==1 && *ni==1){              if(*nr==1 && *ni==1){
1311                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"At current t=%f, mxstep=%f steps taken on this call before reaching tout.",*r1,*i1);                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"At current t=%f, mxstep=%d steps taken on this call before reaching tout.",*r1,*i1);
1312                  return;                  return;
1313              } break;              } break;
1314          case 204:          case 204:

Legend:
Removed from v.1143  
changed lines
  Added in v.1144

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