home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / modellib / generic_choose_algorithm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-16  |  1.8 KB  |  80 lines

  1. /*
  2. Determines which algorithm to use to compute orbits
  3. depending on model and parameters and returns the value of algorithm
  4.  
  5. int_driver=0,1:
  6. int_algorithm: 0=Euler, 1=Explicit symplectic, 2=Implicit symplectic,
  7.     3= Runge-Kutta (4th order),4= user algorithm
  8. int_driver=2:
  9. iint_algorithm: 0=Runge-Kutta QC (5), 1= Bulirsch-Stoer (5)
  10. -------------------------------------------------------------------
  11. NOTE:    (1) can block the use of wrong algorithms here
  12.     (for example, symplectic algorithm can be used only for Hamitonian
  13.     vector field)
  14.     (2) any model-specific testing or error handling should be done here 
  15.     since it is read immediatedly before every new orbit is computed
  16.     (3) Do not touch this subroutine to select algorithm from the panel
  17. ---------------------------------------------------------------
  18.  
  19. /*
  20. Example 1 (default) - always use panel selection
  21. */
  22. int choose_algorithm()
  23. {
  24.     extern int int_algorithm;
  25.     return(int_algorithm);
  26. }
  27.  
  28. /*
  29. Example 2
  30. When model=0, always use the 4th order Runge-Kutta.
  31. When model=1, always use the explicit symplectic algorithm.
  32. Otherwise, use the panel selection
  33. */
  34. int choose_algorithm()
  35. {
  36.     extern int model,int_algorithm;
  37.     extern double *param;
  38.     
  39.     switch(model){
  40.         case 0:
  41.             return(3);
  42.             break;
  43.         case 1:
  44.             return(1);
  45.             break;
  46.         default:
  47.             return(int_algorithm);
  48.             break;
  49.     }
  50. }
  51.  
  52. /*
  53. Example 3
  54. When model=1 and parameters are right, use the explicit symplectic algorithm.
  55. When model=2 and algorithm=1, complain and stop
  56. Otherwise, use the panel selection
  57. */
  58. int choose_algorithm()
  59. {
  60.     extern int model,int_algorithm;
  61.     extern double *param;
  62.     
  63.     switch(model){
  64.         case 1:
  65.             if(param[0] == 0 && param[1] == 0)
  66.                 return(1);
  67.             else
  68.                 return(int_algorithm);
  69.             break;
  70.         case 2:
  71.             if(int_algorithm==1){
  72.                 system_mess_proc(1,"Wrong algorithm!");
  73.                 return(-1);
  74.             }
  75.         default:
  76.             return(int_algorithm);
  77.             break;
  78.     }
  79. }
  80.