reacteqn.txt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. REDUCE Support for Reaction Equation Systems
  2. Herbert Melenk
  3. Konrad-Zuse-Zentrum Berlin
  4. January 1991
  5. The REDUCE package REACTEQN allows one to transform chemical reaction
  6. systems into ordinary differential equation systems (ode)
  7. corresponding to the laws of pure mass action.
  8. A single reaction equation is an expression of the form
  9. <n1><s1> + <n2><s2> + ... -> <n3><s3> + <n4><s4> + ...
  10. or
  11. <n1><s1> + <n2><s2> + ... <> <n3><s3> + <n4><s4> + ...
  12. where the <si> are arbitrary names of species (REDUCE symbols)
  13. and the <ni> are positive integer numbers. The number 1
  14. can be omitted. The connector -> describes a one way reaction,
  15. while <> describes a forward and backward reaction.
  16. A reaction system is a list of reaction equations, each of them
  17. optionally followed by one or two expressions for the rate
  18. constants. A rate constant can a number, a symbol or an
  19. arbitrary REDUCE expression. If a rate constant is missing,
  20. an automatic constant of the form RATE(n) (where n is an
  21. integer counter) is generated. For double reactions the
  22. first constant is used for the forward direction, the second
  23. one for the backward direction.
  24. The names of the species are collected in a list bound to
  25. the REDUCE variable SPECIES. This list is automatically filled
  26. during the processing of a reaction system. The species enter
  27. in an order corresponding to their appearance in the reaction
  28. system and the resulting ode's will be ordered in the same manner.
  29. If a list of species is preassigned to the variable
  30. SPECIES either explicitly or from previous operations, the
  31. given order will be maintained and will dominate the formatting
  32. process. So the ordering of the result can be easily influenced
  33. by the user.
  34. Syntax:
  35. reac2ode { <reaction> [,<rate> [,<rate>]]
  36. [,<reaction> [,<rate> [,<rate>]]]
  37. ....
  38. };
  39. where two rates are applicable only for <> reactions.
  40. Result is a system of explicit ordinary differential
  41. equations with polynomial righthand sides. As side
  42. effect the following variables are set:
  43. lists:
  44. rates: list of the rates in the system
  45. species: list of the species in the system
  46. matrices:
  47. inputmat: matrix of the input coefficients
  48. outputmat: matrix of the output coefficients
  49. In the matrices the row number corresponds to the input reaction
  50. number, while the column number corresponds to the species index.
  51. Note: if the rates are numerical values, it will be in most cases
  52. appropriate to select a REDUCE evaluation mode for floating
  53. point numbers. That is
  54. REDUCE 3.3: on float,numval;
  55. REDUCE 3.4: on rounded;
  56. Inputmat and outputmat can be used for linear algebra type
  57. investigations of the reaction system. The classical reaction
  58. matrix is the difference of these matrices; however, the two
  59. matrices contain more information than their differences because
  60. the appearance of a species on both sides is not reflected by
  61. the reaction matrix.
  62. EXAMPLES:
  63. % Example taken from Feinberg (Chemical Engineering):
  64. species := {A1,A2,A3,A4,A5};
  65. reac2ode { A1 + A4 <> 2A1, rho, beta,
  66. A1 + A2 <> A3, gamma, epsilon,
  67. A3 <> A2 + A5, theta, mue};
  68. 2
  69. {DF(A1,T)=RHO*A1*A4 - BETA*A1 - GAMMA*A1*A2 + EPSILON*A3,
  70. DF(A2,T)= - GAMMA*A1*A2 + EPSILON*A3 + THETA*A3 - MUE*A2*A5,
  71. DF(A3,T)=GAMMA*A1*A2 - EPSILON*A3 - THETA*A3 + MUE*A2*A5,
  72. 2
  73. DF(A4,T)= - RHO*A1*A4 + BETA*A1 ,
  74. DF(A5,T)=THETA*A3 - MUE*A2*A5}
  75. % the corresponding matrices:
  76. inputmat;
  77. [1 0 0 1 0]
  78. [ ]
  79. [1 1 0 0 0]
  80. [ ]
  81. [0 0 1 0 0]
  82. outputmat;
  83. [2 0 0 0 0]
  84. [ ]
  85. [0 0 1 0 0]
  86. [ ]
  87. [0 1 0 0 1]
  88. % computation of the classical reaction matrix as difference
  89. % of output and input matrix:
  90. reactmat := outputmat-inputmat;
  91. [1 0 0 -1 0]
  92. [ ]
  93. REACTMAT := [-1 -1 1 0 0]
  94. [ ]
  95. [0 1 -1 0 1]
  96. % Example with automatic generation of rate constants
  97. % and automatic extraction of species
  98. species := {};
  99. reac2ode { A1 + A4 <> 2A1,
  100. A1 + A2 <> A3,
  101. a3 <> A2 + A5};
  102. new species: A1
  103. new species: A4
  104. new species: A3
  105. new species: A2
  106. new species: A5
  107. 2
  108. {DF(A1,T)= - A1 *RATE(2) + A1*A4*RATE(1) - A1*A2*RATE(3) +
  109. A3*RATE(4),
  110. 2
  111. DF(A4,T)=A1 *RATE(2) - A1*A4*RATE(1),
  112. DF(A2,T)= - A1*A2*RATE(3) - A2*A5*RATE(6) + A3*RATE(5) + A3*RATE(4),
  113. DF(A3,T)=A1*A2*RATE(3) + A2*A5*RATE(6) - A3*RATE(5) - A3*RATE(4),
  114. DF(A5,T)= - A2*A5*RATE(6) + A3*RATE(5)}
  115. % Example with rates computed from numerical expressions
  116. species := {};
  117. reac2ode { A1 + A4 <> 2A1, 17.3* 22.4^1.5,
  118. 0.04* 22.4^1.5 };
  119. new species: A1
  120. new species: A4
  121. 2
  122. {DF(A1,T)= - 4.24065*A1 + 1834.08*A1*A4,
  123. 2
  124. DF(A4,T)=4.24065*A1 - 1834.08*A1*A4}
  125. Herbert Melenk
  126. Konrad-Zuse-Zentrum fuer Informationstechnik
  127. Heilbronner Str 10
  128. D 1000 Berlin 31
  129. Germany
  130. Phone: (49) 30 89604 195
  131. FAX: (49) 30 89604 125
  132. E-mail: melenk@zib.de