ode.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* This file is part of the GNU plotutils package. */
  2. /*
  3. * Copyright (C) 1982-1994, Nicholas B. Tufillaro. All rights reserved.
  4. *
  5. * GNU enhancements Copyright (C) 1996, 1997 Free Software Foundation, Inc.
  6. */
  7. /*
  8. * preprocessor macros and structure declarations for ode.
  9. */
  10. #include <setjmp.h>
  11. #define NAMMAX 32 /* size of identifiers */
  12. #define KMAX 7 /* size of k vector */
  13. #define PASTMAX 7 /* size of history vector */
  14. /*
  15. * symbol table entry
  16. */
  17. struct sym
  18. {
  19. char sy_name[NAMMAX];
  20. double sy_value;
  21. double sy_val[PASTMAX];
  22. double sy_prime;
  23. double sy_pri[PASTMAX];
  24. double sy_predi; /* predictor value */
  25. double sy_sserr; /* relative single step error */
  26. double sy_aberr; /* absolute single step error */
  27. double sy_acerr; /* accumulated error */
  28. double sy_k[KMAX];
  29. int sy_flags;
  30. struct expr *sy_expr;
  31. struct sym *sy_link;
  32. };
  33. /*
  34. * bits in the flags word
  35. * of a symbol table entry
  36. */
  37. #define SF_INIT 1 /* set when the initial value is given */
  38. #define SF_ISEQN 2 /* set when an ODE is given */
  39. #define SF_DEPV (SF_INIT|SF_ISEQN)
  40. /*
  41. * enumeration of printable cells in
  42. * a symbol table entry
  43. */
  44. typedef enum
  45. {
  46. P_VALUE, P_PRIME, P_SSERR, P_ACERR, P_ABERR
  47. } ent_cell;
  48. /*
  49. * the print queue is made
  50. * of these
  51. */
  52. struct prt
  53. {
  54. ent_cell pr_which; /* which cell to print */
  55. struct prt *pr_link;
  56. struct sym *pr_sym;
  57. };
  58. /*
  59. * yylex returns a pointer to this.
  60. * The receiving yacc action must
  61. * free the space when it's done with it.
  62. */
  63. struct lex
  64. {
  65. union
  66. {
  67. double lxu_value;
  68. char lxu_name[NAMMAX];
  69. } lx_u;
  70. int lx_lino;
  71. };
  72. /*
  73. * operation types
  74. */
  75. typedef enum
  76. {
  77. O_NOOP, O_PLUS, O_MINUS, O_MULT, O_DIV, O_POWER, O_SQRT, O_EXP, O_LOG,
  78. O_LOG10, O_SIN, O_COS, O_TAN, O_ASIN, O_ACOS, O_ATAN, O_IDENT, O_CONST,
  79. O_NEG, O_ABS, O_SINH, O_COSH, O_TANH, O_ASINH, O_ACOSH, O_ATANH, O_SQAR,
  80. O_CUBE, O_INV, O_FLOOR, O_CEIL, O_J0, O_J1, O_Y0, O_Y1, O_ERF, O_ERFC,
  81. O_INVERF, O_LGAMMA, O_GAMMA, O_NORM, O_INVNORM, O_IGAMMA, O_IBETA
  82. } op_type;
  83. /*
  84. * an operation in an expression list
  85. */
  86. struct expr
  87. {
  88. op_type ex_oper;
  89. double ex_value;
  90. struct sym *ex_sym;
  91. struct expr *ex_next;
  92. };
  93. /* integration algorithm type */
  94. typedef enum
  95. {
  96. A_EULER, A_ADAMS_MOULTON, A_RUNGE_KUTTA_FEHLBERG
  97. } integration_type;
  98. /*
  99. * misc. consts
  100. */
  101. #define TWO (2.0)
  102. #define HALF (0.5)
  103. #define SCALE (1e-4)
  104. #define HMIN (1e-36) /* Minimum step size */
  105. #define HMAX (0.5) /* Maximum step size */
  106. #define LONGMAX (2147483647) /* 2^31-1 */
  107. #define MESH (2)
  108. #define STOPR (tstep>0 ? \
  109. t-0.0625*tstep>=tstop : t-0.0625*tstep<=tstop )
  110. #define STOPA (tstep>0 ? \
  111. t+0.9375*tstep>=tstop : t+0.9375*tstep<=tstop )