/[ascend]/trunk/base/generic/integrator/idaanalyse.c
ViewVC logotype

Diff of /trunk/base/generic/integrator/idaanalyse.c

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

revision 1270 by johnpye, Sun Feb 4 01:01:18 2007 UTC revision 1271 by johnpye, Sun Feb 4 02:00:01 2007 UTC
# Line 10  Line 10 
10  #include <solver/slvDOF.h>  #include <solver/slvDOF.h>
11  #endif  #endif
12    
13  #define ANALYSE_DEBUG  /* #define ANALYSE_DEBUG */
14    
15  #define VARMSG(MSG) \  #define VARMSG(MSG) \
16      varname = var_make_name(sys->system,v); \      varname = var_make_name(sys->system,v); \
# Line 61  static int integrator_ida_check_vars(Int Line 61  static int integrator_ida_check_vars(Int
61      SolverDiffVarSequence seq;      SolverDiffVarSequence seq;
62      int vok;      int vok;
63    
64    #ifdef ANALYSE_DEBUG
65      CONSOLE_DEBUG("BEFORE CHECKING VARS");      CONSOLE_DEBUG("BEFORE CHECKING VARS");
66      integrator_ida_analyse_debug(sys,stderr);      integrator_ida_analyse_debug(sys,stderr);
67    #endif
68    
69      /* we shouldn't have allocated these yet: just be sure */      /* we shouldn't have allocated these yet: just be sure */
70      asc_assert(sys->y==NULL);      asc_assert(sys->y==NULL);
# Line 76  static int integrator_ida_check_vars(Int Line 78  static int integrator_ida_check_vars(Int
78          return 1;          return 1;
79      }      }
80    
81    #ifdef ANALYSE_DEBUG
82      system_var_list_debug(sys->system);      system_var_list_debug(sys->system);
83    #endif
84            
85      /* add the variables from the derivative chains */      /* add the variables from the derivative chains */
86      for(i=0; i<diffvars->nseqs; ++i){      for(i=0; i<diffvars->nseqs; ++i){
# Line 148  static int integrator_ida_check_vars(Int Line 152  static int integrator_ida_check_vars(Int
152      /* we assert that all vars in y meet the integrator_ida_nonderiv filter */      /* we assert that all vars in y meet the integrator_ida_nonderiv filter */
153      /* we assert that all vars in ydot meet the integrator_ida_deriv filter */      /* we assert that all vars in ydot meet the integrator_ida_deriv filter */
154    
155    #ifdef ANALYSE_DEBUG
156      CONSOLE_DEBUG("Found %d good non-derivative vars", n_y);      CONSOLE_DEBUG("Found %d good non-derivative vars", n_y);
157    #endif
158      sys->n_y = n_y;      sys->n_y = n_y;
159    
160      return 0;      return 0;
# Line 163  static int integrator_ida_sort_rels_and_ Line 169  static int integrator_ida_sort_rels_and_
169      int ny1, nydot, nr;      int ny1, nydot, nr;
170    
171    
172    #ifdef ANALYSE_DEBUG
173      CONSOLE_DEBUG("BEFORE SORTING RELS AND VARS");      CONSOLE_DEBUG("BEFORE SORTING RELS AND VARS");
174      integrator_ida_analyse_debug(sys,stderr);      integrator_ida_analyse_debug(sys,stderr);
175    #endif
176    
177      /* we should not have allocated y or ydot yet */      /* we should not have allocated y or ydot yet */
178      asc_assert(sys->y==NULL && sys->ydot==NULL);      asc_assert(sys->y==NULL && sys->ydot==NULL);
# Line 177  static int integrator_ida_sort_rels_and_ Line 185  static int integrator_ida_sort_rels_and_
185          return 1;          return 1;
186      }      }
187    
188    #ifdef ANALYSE_DEBUG
189      CONSOLE_DEBUG("cut_vars: ny1 = %d, sys->n_y = %d",ny1,sys->n_y);      CONSOLE_DEBUG("cut_vars: ny1 = %d, sys->n_y = %d",ny1,sys->n_y);
190    #endif
191      asc_assert(ny1 == sys->n_y);      asc_assert(ny1 == sys->n_y);
192    
193      if(system_cut_vars(sys->system, ny1, &integrator_ida_deriv, &nydot)){      if(system_cut_vars(sys->system, ny1, &integrator_ida_deriv, &nydot)){
# Line 217  static int integrator_ida_create_lists(I Line 227  static int integrator_ida_create_lists(I
227      const SolverDiffVarCollection *diffvars;      const SolverDiffVarCollection *diffvars;
228      int i, j;      int i, j;
229      struct var_variable *v;      struct var_variable *v;
230    #ifdef ANALYSE_DEBUG
231      char *varname;      char *varname;
232    #endif
233    
234      SolverDiffVarSequence seq;      SolverDiffVarSequence seq;
235    
# Line 240  static int integrator_ida_create_lists(I Line 252  static int integrator_ida_create_lists(I
252          asc_assert(sys->ydot[i] == 0);          asc_assert(sys->ydot[i] == 0);
253      }      }
254    
255    #ifdef ANALYSE_DEBUG
256      CONSOLE_DEBUG("Passing through chains...");      CONSOLE_DEBUG("Passing through chains...");
257    #endif
258      /* create the lists y and ydot, ignoring 'bad' vars */      /* create the lists y and ydot, ignoring 'bad' vars */
259      for(i=0; i<diffvars->nseqs; ++i){      for(i=0; i<diffvars->nseqs; ++i){
260          /* CONSOLE_DEBUG("i = %d",i); */          /* CONSOLE_DEBUG("i = %d",i); */
# Line 271  static int integrator_ida_create_lists(I Line 284  static int integrator_ida_create_lists(I
284          }          }
285      }      }
286    
287    #ifdef ANALYSE_DEBUG
288      CONSOLE_DEBUG("Found %d good non-derivs",j);      CONSOLE_DEBUG("Found %d good non-derivs",j);
289    #endif
290      /* create the list y_id by looking at non-NULLs from ydot */      /* create the list y_id by looking at non-NULLs from ydot */
291      sys->y_id = ASC_NEW_ARRAY(int,sys->n_ydot);      sys->y_id = ASC_NEW_ARRAY(int,sys->n_ydot);
292      for(i=0,j=0; i <  sys->n_y; ++i){      for(i=0,j=0; i <  sys->n_y; ++i){
# Line 309  static int integrator_ida_create_lists(I Line 323  static int integrator_ida_create_lists(I
323  int integrator_ida_analyse(IntegratorSystem *sys){  int integrator_ida_analyse(IntegratorSystem *sys){
324      int res;      int res;
325      const SolverDiffVarCollection *diffvars;      const SolverDiffVarCollection *diffvars;
     char *varname;  
326      int i;      int i;
327    #ifdef ANALYSE_DEBUG
328        char *varname;
329    #endif
330    
331      asc_assert(sys->engine==INTEG_IDA);      asc_assert(sys->engine==INTEG_IDA);
332    
# Line 336  int integrator_ida_analyse(IntegratorSys Line 352  int integrator_ida_analyse(IntegratorSys
352    
353  #ifdef ANALYSE_DEBUG  #ifdef ANALYSE_DEBUG
354      CONSOLE_DEBUG("Creating lists");      CONSOLE_DEBUG("Creating lists");
 #endif  
355    
356      CONSOLE_DEBUG("BEFORE MAKING LISTS");      CONSOLE_DEBUG("BEFORE MAKING LISTS");
357      integrator_ida_debug(sys,stderr);      integrator_ida_debug(sys,stderr);
358    #endif
359    
360      res = integrator_ida_create_lists(sys);      res = integrator_ida_create_lists(sys);
361      if(res){      if(res){
# Line 349  int integrator_ida_analyse(IntegratorSys Line 365  int integrator_ida_analyse(IntegratorSys
365    
366  #ifdef ANALYSE_DEBUG  #ifdef ANALYSE_DEBUG
367      CONSOLE_DEBUG("Checking lists");      CONSOLE_DEBUG("Checking lists");
 #endif  
368    
369      asc_assert(sys->y);      asc_assert(sys->y);
370      asc_assert(sys->ydot);      asc_assert(sys->ydot);
371      asc_assert(sys->y_id);      asc_assert(sys->y_id);
372    
373      integrator_ida_debug(sys,stderr);      integrator_ida_debug(sys,stderr);
374    #endif
375    
376      if(integrator_ida_check_diffindex(sys)){      if(integrator_ida_check_diffindex(sys)){
377          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Error with diffindex");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"Error with diffindex");
# Line 428  int integrator_ida_analyse(IntegratorSys Line 444  int integrator_ida_analyse(IntegratorSys
444      for(i=0;i<sys->n_obs;++i){      for(i=0;i<sys->n_obs;++i){
445          /* we get them all, regardless of flags etc */          /* we get them all, regardless of flags etc */
446          sys->obs[i] = diffvars->obs[i];          sys->obs[i] = diffvars->obs[i];
447    #ifdef ANALYSE_DEBUG
448          varname = var_make_name(sys->system,sys->obs[i]);          varname = var_make_name(sys->system,sys->obs[i]);
449          CONSOLE_DEBUG("'%s' is observation",varname);          CONSOLE_DEBUG("'%s' is observation",varname);
450          ASC_FREE(varname);          ASC_FREE(varname);
451    #endif
452      }      }
453    
454      return 0;      return 0;
# Line 454  static int integrator_ida_check_partitio Line 472  static int integrator_ida_check_partitio
472          if(!var_apply_filter(v,&vf))continue;          if(!var_apply_filter(v,&vf))continue;
473          varname = var_make_name(sys->system,v);          varname = var_make_name(sys->system,v);
474          if(!var_deriv(v)){          if(!var_deriv(v)){
475    #ifdef ANALYSE_DEBUG
476              fprintf(stderr,"vlist[%ld] = '%s' (nonderiv)\n",i,varname);              fprintf(stderr,"vlist[%ld] = '%s' (nonderiv)\n",i,varname);
477    #endif
478              if(i>=sys->n_y){              if(i>=sys->n_y){
479                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"non-deriv var '%s' is not at the start",varname);                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"non-deriv var '%s' is not at the start",varname);
480                  err++;                  err++;
481              }              }
482          }else{          }else{
483    #ifdef ANALYSE_DEBUG
484              fprintf(stderr,"vlist[%ld] = '%s' (derivative)\n",i,varname);              fprintf(stderr,"vlist[%ld] = '%s' (derivative)\n",i,varname);
485    #endif
486              if(i<sys->n_y){              if(i<sys->n_y){
487                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"deriv var '%s' is not at the end (n_y = %d, i = %d)"                  ERROR_REPORTER_HERE(ASC_PROG_ERR,"deriv var '%s' is not at the end (n_y = %d, i = %d)"
488                      ,varname, sys->n_y, i                      ,varname, sys->n_y, i
# Line 544  int integrator_ida_block_check(Integrato Line 566  int integrator_ida_block_check(Integrato
566  static int check_dups(IntegratorSystem *sys, struct var_variable **list,int n,int allownull){  static int check_dups(IntegratorSystem *sys, struct var_variable **list,int n,int allownull){
567      int i,j;      int i,j;
568      struct var_variable *v;      struct var_variable *v;
569    #ifdef ANALYSE_DEBUG
570      char *varname;      char *varname;
571    #endif
572      for(i=0; i< n; ++i){      for(i=0; i< n; ++i){
573          v=list[i];          v=list[i];
574          if(v==NULL){          if(v==NULL){
575              if(allownull)continue;              if(allownull)continue;
576              else return 2;              else return 2;
577          }          }
578          asc_assert(v!=0x31);          asc_assert(v!=(void *)0x31);
579          for(j=0; j<i-1;++j){          for(j=0; j<i-1;++j){
580              if(list[j]==NULL)continue;              if(list[j]==NULL)continue;
581              if(v==list[j]){              if(v==list[j]){
582    #ifdef ANALYSE_DEBUG
583                  varname = var_make_name(sys->system,v);                  varname = var_make_name(sys->system,v);
584                  if(varname){                  if(varname){
585                      CONSOLE_DEBUG("Duplicate of '%s' found",varname);                      CONSOLE_DEBUG("Duplicate of '%s' found",varname);
# Line 563  static int check_dups(IntegratorSystem * Line 588  static int check_dups(IntegratorSystem *
588                      CONSOLE_DEBUG("Duplicate found (couldn't retrieve name)");                      CONSOLE_DEBUG("Duplicate found (couldn't retrieve name)");
589                  }                  }
590                  ASC_FREE(varname);                  ASC_FREE(varname);
591    #endif
592                  return 1;                  return 1;
593              }              }
594          }          }
# Line 595  static int integrator_ida_check_diffinde Line 621  static int integrator_ida_check_diffinde
621      int diffindex;      int diffindex;
622      const char *msg;      const char *msg;
623    
624    #ifdef ANALYSE_DEBUG
625      CONSOLE_DEBUG("Checking diffindex vector");      CONSOLE_DEBUG("Checking diffindex vector");
626    #endif
627    
628      if(sys->y_id == NULL || sys->y == NULL || sys->ydot == NULL){      if(sys->y_id == NULL || sys->y == NULL || sys->ydot == NULL){
629          ERROR_REPORTER_HERE(ASC_PROG_ERR,"list(s) NULL");          ERROR_REPORTER_HERE(ASC_PROG_ERR,"list(s) NULL");

Legend:
Removed from v.1270  
changed lines
  Added in v.1271

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