pyEQL 1.4.0rc9__cp313-cp313-macosx_10_13_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (491) hide show
  1. pyEQL/__init__.py +50 -0
  2. pyEQL/_phreeqc.cpython-313-darwin.so +0 -0
  3. pyEQL/activity_correction.py +879 -0
  4. pyEQL/database/geothermal.dat +5693 -0
  5. pyEQL/database/llnl.dat +19305 -0
  6. pyEQL/database/phreeqc_license.txt +54 -0
  7. pyEQL/database/pyeql_db.json +35607 -0
  8. pyEQL/engines.py +1153 -0
  9. pyEQL/equilibrium.py +227 -0
  10. pyEQL/functions.py +281 -0
  11. pyEQL/phreeqc/__init__.py +5 -0
  12. pyEQL/phreeqc/bindings.cpp +84 -0
  13. pyEQL/phreeqc/core.py +239 -0
  14. pyEQL/phreeqc/database/Amm.dat +1968 -0
  15. pyEQL/phreeqc/database/CMakeLists.txt +32 -0
  16. pyEQL/phreeqc/database/ColdChem.dat +267 -0
  17. pyEQL/phreeqc/database/Concrete_PHR.dat +158 -0
  18. pyEQL/phreeqc/database/Concrete_PZ.dat +195 -0
  19. pyEQL/phreeqc/database/Kinec.v2.dat +12039 -0
  20. pyEQL/phreeqc/database/Kinec_v3.dat +12159 -0
  21. pyEQL/phreeqc/database/Makefile.am +28 -0
  22. pyEQL/phreeqc/database/Makefile.in +530 -0
  23. pyEQL/phreeqc/database/PHREEQC_ThermoddemV1.10_15Dec2020.dat +12965 -0
  24. pyEQL/phreeqc/database/Tipping_Hurley.dat +4137 -0
  25. pyEQL/phreeqc/database/__init__.py +0 -0
  26. pyEQL/phreeqc/database/core10.dat +6824 -0
  27. pyEQL/phreeqc/database/frezchem.dat +634 -0
  28. pyEQL/phreeqc/database/iso.dat +7235 -0
  29. pyEQL/phreeqc/database/llnl.dat +19310 -0
  30. pyEQL/phreeqc/database/minteq.dat +5654 -0
  31. pyEQL/phreeqc/database/minteq.v4.dat +13212 -0
  32. pyEQL/phreeqc/database/phreeqc.dat +1972 -0
  33. pyEQL/phreeqc/database/phreeqc_rates.dat +3158 -0
  34. pyEQL/phreeqc/database/pitzer.dat +1044 -0
  35. pyEQL/phreeqc/database/sit.dat +14348 -0
  36. pyEQL/phreeqc/database/wateq4f.dat +4036 -0
  37. pyEQL/phreeqc/ext/README.md +10 -0
  38. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/CMakeLists.txt +476 -0
  39. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/INSTALL +302 -0
  40. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/IPhreeqc.rc +61 -0
  41. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/IPhreeqcConfig.cmake.in +4 -0
  42. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/Makefile.am +8 -0
  43. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/Makefile.in +816 -0
  44. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/aclocal.m4 +1217 -0
  45. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/CTestScript.cmake +167 -0
  46. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/CSelectedOutput.cpp.o +0 -0
  47. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/IPhreeqc.cpp.o +0 -0
  48. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/IPhreeqcLib.cpp.o +0 -0
  49. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/IPhreeqc_interface_F.cpp.o +0 -0
  50. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/Var.c.o +0 -0
  51. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Dictionary.cpp.o +0 -0
  52. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/ExchComp.cxx.o +0 -0
  53. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Exchange.cxx.o +0 -0
  54. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/GasComp.cxx.o +0 -0
  55. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/GasPhase.cxx.o +0 -0
  56. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/ISolution.cxx.o +0 -0
  57. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/ISolutionComp.cxx.o +0 -0
  58. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/KineticsComp.cxx.o +0 -0
  59. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/NameDouble.cxx.o +0 -0
  60. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/NumKeyword.cxx.o +0 -0
  61. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/PBasic.cpp.o +0 -0
  62. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/PHRQ_io_output.cpp.o +0 -0
  63. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/PPassemblage.cxx.o +0 -0
  64. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/PPassemblageComp.cxx.o +0 -0
  65. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Phreeqc.cpp.o +0 -0
  66. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/PhreeqcKeywords/Keywords.cpp.o +0 -0
  67. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Pressure.cxx.o +0 -0
  68. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Reaction.cxx.o +0 -0
  69. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/ReadClass.cxx.o +0 -0
  70. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SS.cxx.o +0 -0
  71. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SSassemblage.cxx.o +0 -0
  72. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SScomp.cxx.o +0 -0
  73. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SelectedOutput.cpp.o +0 -0
  74. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Serializer.cxx.o +0 -0
  75. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Solution.cxx.o +0 -0
  76. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SolutionIsotope.cxx.o +0 -0
  77. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/StorageBin.cxx.o +0 -0
  78. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/StorageBinList.cpp.o +0 -0
  79. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Surface.cxx.o +0 -0
  80. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SurfaceCharge.cxx.o +0 -0
  81. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/SurfaceComp.cxx.o +0 -0
  82. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/System.cxx.o +0 -0
  83. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Temperature.cxx.o +0 -0
  84. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/Use.cpp.o +0 -0
  85. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/UserPunch.cpp.o +0 -0
  86. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/advection.cpp.o +0 -0
  87. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/basicsubs.cpp.o +0 -0
  88. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/cl1.cpp.o +0 -0
  89. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/common/PHRQ_base.cxx.o +0 -0
  90. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/common/PHRQ_io.cpp.o +0 -0
  91. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/common/Parser.cxx.o +0 -0
  92. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/common/Utils.cxx.o +0 -0
  93. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/cvdense.cpp.o +0 -0
  94. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/cvode.cpp.o +0 -0
  95. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/cxxKinetics.cxx.o +0 -0
  96. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/cxxMix.cxx.o +0 -0
  97. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/dense.cpp.o +0 -0
  98. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/dumper.cpp.o +0 -0
  99. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/gases.cpp.o +0 -0
  100. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/input.cpp.o +0 -0
  101. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/integrate.cpp.o +0 -0
  102. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/inverse.cpp.o +0 -0
  103. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/isotopes.cpp.o +0 -0
  104. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/kinetics.cpp.o +0 -0
  105. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/mainsubs.cpp.o +0 -0
  106. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/model.cpp.o +0 -0
  107. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/nvector.cpp.o +0 -0
  108. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/nvector_serial.cpp.o +0 -0
  109. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/parse.cpp.o +0 -0
  110. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/phqalloc.cpp.o +0 -0
  111. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/pitzer.cpp.o +0 -0
  112. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/pitzer_structures.cpp.o +0 -0
  113. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/prep.cpp.o +0 -0
  114. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/print.cpp.o +0 -0
  115. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/read.cpp.o +0 -0
  116. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/readtr.cpp.o +0 -0
  117. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/runner.cpp.o +0 -0
  118. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/sit.cpp.o +0 -0
  119. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/smalldense.cpp.o +0 -0
  120. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/spread.cpp.o +0 -0
  121. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/step.cpp.o +0 -0
  122. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/structures.cpp.o +0 -0
  123. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/sundialsmath.cpp.o +0 -0
  124. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/tally.cpp.o +0 -0
  125. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/tidy.cpp.o +0 -0
  126. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/transport.cpp.o +0 -0
  127. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CMakeFiles/IPhreeqc.dir/src/phreeqcpp/utilities.cpp.o +0 -0
  128. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/CTestTestfile.cmake +6 -0
  129. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/DartConfiguration.tcl +109 -0
  130. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/cmake_install.cmake +45 -0
  131. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/build/libIPhreeqc.a +0 -0
  132. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/ar-lib +270 -0
  133. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/compile +347 -0
  134. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/config.guess +1441 -0
  135. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/config.sub +1813 -0
  136. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/depcomp +791 -0
  137. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/install-sh +508 -0
  138. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/ltmain.sh +11156 -0
  139. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/missing +215 -0
  140. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/config/test-driver +148 -0
  141. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/configure +23867 -0
  142. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/configure.ac +136 -0
  143. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Amm.dat +1968 -0
  144. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/CMakeLists.txt +32 -0
  145. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/ColdChem.dat +267 -0
  146. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Concrete_PHR.dat +158 -0
  147. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Concrete_PZ.dat +195 -0
  148. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Kinec.v2.dat +12039 -0
  149. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Kinec_v3.dat +12159 -0
  150. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Makefile.am +28 -0
  151. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Makefile.in +530 -0
  152. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/PHREEQC_ThermoddemV1.10_15Dec2020.dat +12965 -0
  153. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/Tipping_Hurley.dat +4137 -0
  154. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/core10.dat +6824 -0
  155. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/frezchem.dat +634 -0
  156. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/iso.dat +7235 -0
  157. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/llnl.dat +19310 -0
  158. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/minteq.dat +5654 -0
  159. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/minteq.v4.dat +13212 -0
  160. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/phreeqc.dat +1972 -0
  161. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/phreeqc_rates.dat +3158 -0
  162. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/pitzer.dat +1044 -0
  163. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/sit.dat +14348 -0
  164. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/database/wateq4f.dat +4036 -0
  165. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/CMakeLists.txt +35 -0
  166. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/IPhreeqc.pdf +0 -0
  167. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/Makefile.am +24 -0
  168. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/Makefile.in +545 -0
  169. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/NOTICE +51 -0
  170. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/Phreeqc_2_1999_manual.pdf +0 -0
  171. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/Phreeqc_3_2013_manual.pdf +0 -0
  172. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/README +428 -0
  173. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/RELEASE +7294 -0
  174. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/IPhreeqc_8h.html +5096 -0
  175. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/IPhreeqc_8h_source.html +389 -0
  176. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/IPhreeqc_8hpp.html +83 -0
  177. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/IPhreeqc_8hpp_source.html +478 -0
  178. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/Var_8h.html +318 -0
  179. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/Var_8h_source.html +200 -0
  180. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/bc_s.png +0 -0
  181. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/bdwn.png +0 -0
  182. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/classIPhreeqc.html +2274 -0
  183. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/classIPhreeqc.png +0 -0
  184. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/classIPhreeqcStop.html +69 -0
  185. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/classIPhreeqcStop.png +0 -0
  186. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/closed.png +0 -0
  187. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html +68 -0
  188. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/doxygen.css +1440 -0
  189. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/doxygen.png +0 -0
  190. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/dynsections.js +97 -0
  191. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2blank.png +0 -0
  192. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2doc.png +0 -0
  193. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2folderclosed.png +0 -0
  194. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2folderopen.png +0 -0
  195. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2lastnode.png +0 -0
  196. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2link.png +0 -0
  197. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2mlastnode.png +0 -0
  198. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2mnode.png +0 -0
  199. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2node.png +0 -0
  200. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2plastnode.png +0 -0
  201. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2pnode.png +0 -0
  202. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2splitbar.png +0 -0
  203. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/ftv2vertline.png +0 -0
  204. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/index.html +58 -0
  205. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/jquery.js +31 -0
  206. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/nav_f.png +0 -0
  207. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/nav_g.png +0 -0
  208. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/nav_h.png +0 -0
  209. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/open.png +0 -0
  210. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/structVAR.html +143 -0
  211. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/sync_off.png +0 -0
  212. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/sync_on.png +0 -0
  213. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/tab_a.png +0 -0
  214. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/tab_b.png +0 -0
  215. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/tab_h.png +0 -0
  216. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/tab_s.png +0 -0
  217. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/html/tabs.css +60 -0
  218. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/doc/phreeqc3.chm +0 -0
  219. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/CMakeLists.txt +11 -0
  220. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/Makefile.am +88 -0
  221. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/Makefile.in +696 -0
  222. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/CMakeLists.txt +1 -0
  223. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/CMakeLists.txt +35 -0
  224. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/CMakeLists.txt.in +21 -0
  225. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/README.txt +44 -0
  226. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/advect.c +101 -0
  227. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/ic +17 -0
  228. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/c/advect/phreeqc.dat +1579 -0
  229. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/CMakeLists.txt +10 -0
  230. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/README.txt +3 -0
  231. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/excel/CMakeLists.txt +9 -0
  232. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/excel/phreeqc.dat +1582 -0
  233. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/excel/runphreeqc.xls +0 -0
  234. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/excel/withcallback.xls +0 -0
  235. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/CMakeLists.txt +11 -0
  236. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/Gypsum.py +52 -0
  237. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/parallel_advect.py +465 -0
  238. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/phreeqc.dat +1582 -0
  239. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/pitzer.dat +790 -0
  240. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/com/python/wateq4f.dat +3846 -0
  241. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/CMakeLists.txt +1 -0
  242. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/CMakeLists.txt +35 -0
  243. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/CMakeLists.txt.in +20 -0
  244. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/README.txt +45 -0
  245. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/advect.cpp +110 -0
  246. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/ic +17 -0
  247. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/cpp/advect/phreeqc.dat +1579 -0
  248. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/CMakeLists.txt +1 -0
  249. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/CMakeLists.txt +44 -0
  250. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/CMakeLists.txt.in +24 -0
  251. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/README.txt +45 -0
  252. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/advect.F90 +102 -0
  253. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/ic +17 -0
  254. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/fortran/advect/phreeqc.dat +1579 -0
  255. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/CMakeLists.txt +26 -0
  256. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/CMakeLists.txt.in +20 -0
  257. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/README.txt +37 -0
  258. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/ex2 +26 -0
  259. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/main.cpp +20 -0
  260. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/phreeqc.dat +1837 -0
  261. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/examples/using-cmake/post-install.cmake.in +7 -0
  262. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/CMakeLists.txt +185 -0
  263. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/FileTest.cpp +171 -0
  264. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/FileTest.h +34 -0
  265. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/Makefile.am +18 -0
  266. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/Makefile.in +466 -0
  267. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/TestCVar.cpp +9 -0
  268. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/TestIPhreeqc.cpp +4901 -0
  269. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/TestIPhreeqcLib.cpp +4644 -0
  270. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/TestSelectedOutput.cpp +669 -0
  271. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/TestVar.cpp +10 -0
  272. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/conv_fail.in +11 -0
  273. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/dump +42 -0
  274. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/iso.dat +7231 -0
  275. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/kinn20140218 +349 -0
  276. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/missing_e.dat +1556 -0
  277. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/multi_punch +105 -0
  278. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/multi_punch_no_set +102 -0
  279. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/phreeqc.dat.90a6449 +1935 -0
  280. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/gtest/phreeqc.dat.old +1556 -0
  281. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/m4/libtool.m4 +8388 -0
  282. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/m4/ltoptions.m4 +437 -0
  283. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/m4/ltsugar.m4 +124 -0
  284. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/m4/ltversion.m4 +23 -0
  285. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/m4/lt~obsolete.m4 +99 -0
  286. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/resource.h +14 -0
  287. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/CSelectedOutput.cpp +401 -0
  288. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/CSelectedOutput.hxx +77 -0
  289. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/CVar.hxx +162 -0
  290. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Debug.h +12 -0
  291. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/ErrorReporter.hxx +70 -0
  292. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc.cpp +1889 -0
  293. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc.f.inc +91 -0
  294. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc.f90.inc +603 -0
  295. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc.h +2182 -0
  296. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc.hpp +1027 -0
  297. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqcCallbacks.h +19 -0
  298. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqcF.f +653 -0
  299. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqcLib.cpp +1098 -0
  300. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc_interface.F90 +1283 -0
  301. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc_interface_F.cpp +535 -0
  302. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/IPhreeqc_interface_F.h +162 -0
  303. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Makefile.am +210 -0
  304. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Makefile.in +1294 -0
  305. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/README.Fortran +17 -0
  306. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Var.c +84 -0
  307. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Var.h +152 -0
  308. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/Version.h +36 -0
  309. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fimpl.h +282 -0
  310. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap.cpp +646 -0
  311. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap.h +163 -0
  312. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap1.cpp +24 -0
  313. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap2.cpp +24 -0
  314. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap3.cpp +24 -0
  315. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap4.cpp +24 -0
  316. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap5.cpp +24 -0
  317. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap6.cpp +25 -0
  318. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap7.cpp +25 -0
  319. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/fwrap8.cpp +24 -0
  320. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ChartHandler.cpp +225 -0
  321. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ChartHandler.h +59 -0
  322. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ChartObject.cpp +1382 -0
  323. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ChartObject.h +444 -0
  324. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/CurveObject.cpp +42 -0
  325. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/CurveObject.h +79 -0
  326. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Dictionary.cpp +41 -0
  327. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Dictionary.h +28 -0
  328. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ExchComp.cxx +398 -0
  329. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ExchComp.h +117 -0
  330. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Exchange.cxx +466 -0
  331. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Exchange.h +74 -0
  332. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Form1.h +1184 -0
  333. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Form1.resX +36 -0
  334. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/GasComp.cxx +265 -0
  335. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/GasComp.h +59 -0
  336. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/GasPhase.cxx +659 -0
  337. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/GasPhase.h +103 -0
  338. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ISolution.cxx +40 -0
  339. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ISolution.h +53 -0
  340. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ISolutionComp.cxx +202 -0
  341. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ISolutionComp.h +138 -0
  342. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/KineticsComp.cxx +318 -0
  343. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/KineticsComp.h +81 -0
  344. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/NA.h +1 -0
  345. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/NameDouble.cxx +537 -0
  346. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/NameDouble.h +66 -0
  347. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/NumKeyword.cxx +190 -0
  348. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/NumKeyword.h +67 -0
  349. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PBasic.cpp +8350 -0
  350. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PBasic.h +572 -0
  351. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PHRQ_io_output.cpp +411 -0
  352. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PPassemblage.cxx +375 -0
  353. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PPassemblage.h +70 -0
  354. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PPassemblageComp.cxx +441 -0
  355. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PPassemblageComp.h +83 -0
  356. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Phreeqc.cpp +2087 -0
  357. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Phreeqc.h +2164 -0
  358. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PhreeqcKeywords/Keywords.cpp +242 -0
  359. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/PhreeqcKeywords/Keywords.h +104 -0
  360. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Pressure.cxx +417 -0
  361. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Pressure.h +43 -0
  362. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Reaction.cxx +284 -0
  363. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Reaction.h +57 -0
  364. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ReadClass.cxx +1150 -0
  365. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SS.cxx +609 -0
  366. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SS.h +128 -0
  367. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SSassemblage.cxx +317 -0
  368. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SSassemblage.h +59 -0
  369. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SScomp.cxx +297 -0
  370. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SScomp.h +66 -0
  371. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SelectedOutput.cpp +115 -0
  372. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SelectedOutput.h +209 -0
  373. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Serializer.cxx +213 -0
  374. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Serializer.h +42 -0
  375. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Solution.cxx +1795 -0
  376. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Solution.h +154 -0
  377. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SolutionIsotope.cxx +333 -0
  378. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SolutionIsotope.h +85 -0
  379. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/StorageBin.cxx +1507 -0
  380. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/StorageBin.h +141 -0
  381. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/StorageBinList.cpp +358 -0
  382. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/StorageBinList.h +81 -0
  383. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Surface.cxx +837 -0
  384. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Surface.h +108 -0
  385. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SurfaceCharge.cxx +617 -0
  386. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SurfaceCharge.h +137 -0
  387. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SurfaceComp.cxx +509 -0
  388. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/SurfaceComp.h +70 -0
  389. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/System.cxx +103 -0
  390. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/System.h +89 -0
  391. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Temperature.cxx +423 -0
  392. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Temperature.h +42 -0
  393. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Use.cpp +78 -0
  394. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/Use.h +159 -0
  395. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/UserPunch.cpp +32 -0
  396. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/UserPunch.h +39 -0
  397. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/ZedGraph.dll +0 -0
  398. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/advection.cpp +140 -0
  399. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/basicsubs.cpp +4333 -0
  400. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cl1.cpp +881 -0
  401. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/PHRQ_base.cxx +117 -0
  402. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/PHRQ_base.h +48 -0
  403. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/PHRQ_exports.h +20 -0
  404. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/PHRQ_io.cpp +914 -0
  405. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/PHRQ_io.h +207 -0
  406. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/Parser.cxx +1331 -0
  407. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/Parser.h +310 -0
  408. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/Utils.cxx +263 -0
  409. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/Utils.h +29 -0
  410. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/common/phrqtype.h +18 -0
  411. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cvdense.cpp +566 -0
  412. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cvdense.h +267 -0
  413. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cvode.cpp +3939 -0
  414. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cvode.h +940 -0
  415. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cxxKinetics.cxx +617 -0
  416. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cxxKinetics.h +78 -0
  417. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cxxMix.cxx +154 -0
  418. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/cxxMix.h +58 -0
  419. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/dense.cpp +175 -0
  420. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/dense.h +341 -0
  421. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/dumper.cpp +277 -0
  422. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/dumper.h +60 -0
  423. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/gases.cpp +748 -0
  424. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/global_structures.h +1672 -0
  425. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/input.cpp +133 -0
  426. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/integrate.cpp +1219 -0
  427. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/inverse.cpp +5135 -0
  428. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/isotopes.cpp +1813 -0
  429. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/kinetics.cpp +3180 -0
  430. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/mainsubs.cpp +2320 -0
  431. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/model.cpp +5843 -0
  432. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/nvector.cpp +272 -0
  433. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/nvector.h +485 -0
  434. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/nvector_serial.cpp +1032 -0
  435. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/nvector_serial.h +369 -0
  436. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/parse.cpp +1044 -0
  437. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/phqalloc.cpp +316 -0
  438. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/phqalloc.h +47 -0
  439. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/pitzer.cpp +2709 -0
  440. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/pitzer_structures.cpp +225 -0
  441. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/prep.cpp +6267 -0
  442. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/print.cpp +3673 -0
  443. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/read.cpp +10245 -0
  444. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/readtr.cpp +1495 -0
  445. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/runner.cpp +158 -0
  446. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/runner.h +33 -0
  447. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/sit.cpp +1684 -0
  448. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/smalldense.cpp +324 -0
  449. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/smalldense.h +261 -0
  450. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/spread.cpp +1309 -0
  451. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/step.cpp +1566 -0
  452. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/structures.cpp +3381 -0
  453. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/sundialsmath.cpp +133 -0
  454. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/sundialsmath.h +162 -0
  455. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/sundialstypes.h +183 -0
  456. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/tally.cpp +1288 -0
  457. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/tidy.cpp +5600 -0
  458. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/transport.cpp +6403 -0
  459. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/phreeqcpp/utilities.cpp +1339 -0
  460. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/src/thread.h +64 -0
  461. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/CMakeLists.txt +133 -0
  462. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/Makefile.am +45 -0
  463. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/Makefile.in +1128 -0
  464. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/ex2.in +26 -0
  465. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/main.f90 +31 -0
  466. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/main77.f +6 -0
  467. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/main_fortran.cxx +8 -0
  468. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/phreeqc.dat.in +1556 -0
  469. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/test_c.c +148 -0
  470. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/test_cxx.cxx +152 -0
  471. pyEQL/phreeqc/ext/iphreeqc-3.8.6-17100/tests/test_f90.F90 +328 -0
  472. pyEQL/phreeqc/iphreeqc_wrapper.cpp +75 -0
  473. pyEQL/phreeqc/solution.py +74 -0
  474. pyEQL/phreeqc/var.py +50 -0
  475. pyEQL/presets/Ringers lactate.yaml +20 -0
  476. pyEQL/presets/__init__.py +17 -0
  477. pyEQL/presets/normal saline.yaml +17 -0
  478. pyEQL/presets/rainwater.yaml +17 -0
  479. pyEQL/presets/seawater.yaml +29 -0
  480. pyEQL/presets/urine.yaml +26 -0
  481. pyEQL/presets/wastewater.yaml +21 -0
  482. pyEQL/py.typed +0 -0
  483. pyEQL/salt_ion_match.py +112 -0
  484. pyEQL/solute.py +163 -0
  485. pyEQL/solution.py +2714 -0
  486. pyEQL/utils.py +237 -0
  487. pyeql-1.4.0rc9.dist-info/METADATA +130 -0
  488. pyeql-1.4.0rc9.dist-info/RECORD +491 -0
  489. pyeql-1.4.0rc9.dist-info/WHEEL +6 -0
  490. pyeql-1.4.0rc9.dist-info/licenses/AUTHORS.md +21 -0
  491. pyeql-1.4.0rc9.dist-info/licenses/LICENSE.txt +20 -0
@@ -0,0 +1,3939 @@
1
+ /*#define DEBUG_CVODE*/
2
+ /**************************************************************************
3
+ * *
4
+ * File : cvode.c *
5
+ * Programmers : Scott D. Cohen, Alan C. Hindmarsh, Radu Serban, *
6
+ * and Dan Shumaker @ LLNL *
7
+ * Version of : 24 July 2002 *
8
+ *------------------------------------------------------------------------*
9
+ * Copyright (c) 2002, The Regents of the University of California *
10
+ * Produced at the Lawrence Livermore National Laboratory *
11
+ * All rights reserved *
12
+ * For details, see LICENSE below *
13
+ *------------------------------------------------------------------------*
14
+ * This is the implementation file for the main CVODE integrator. *
15
+ * It is independent of the CVODE linear solver in use. *
16
+ * *
17
+ *------------------------------------------------------------------------*
18
+ * LICENSE *
19
+ *------------------------------------------------------------------------*
20
+ * Copyright (c) 2002, The Regents of the University of California. *
21
+ * Produced at the Lawrence Livermore National Laboratory. *
22
+ * Written by S.D. Cohen, A.C. Hindmarsh, R. Serban, *
23
+ * D. Shumaker, and A.G. Taylor. *
24
+ * UCRL-CODE-155951 (CVODE) *
25
+ * UCRL-CODE-155950 (CVODES) *
26
+ * UCRL-CODE-155952 (IDA) *
27
+ * UCRL-CODE-237203 (IDAS) *
28
+ * UCRL-CODE-155953 (KINSOL) *
29
+ * All rights reserved. *
30
+ * *
31
+ * This file is part of SUNDIALS. *
32
+ * *
33
+ * Redistribution and use in source and binary forms, with or without *
34
+ * modification, are permitted provided that the following conditions *
35
+ * are met: *
36
+ * *
37
+ * 1. Redistributions of source code must retain the above copyright *
38
+ * notice, this list of conditions and the disclaimer below. *
39
+ * *
40
+ * 2. Redistributions in binary form must reproduce the above copyright *
41
+ * notice, this list of conditions and the disclaimer (as noted below) *
42
+ * in the documentation and/or other materials provided with the *
43
+ * distribution. *
44
+ * *
45
+ * 3. Neither the name of the UC/LLNL nor the names of its contributors *
46
+ * may be used to endorse or promote products derived from this software *
47
+ * without specific prior written permission. *
48
+ * *
49
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
50
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
51
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *
52
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *
53
+ * REGENTS OF THE UNIVERSITY OF CALIFORNIA, THE U.S. DEPARTMENT OF ENERGY *
54
+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
55
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
56
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
57
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
58
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
59
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
60
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
61
+ **************************************************************************/
62
+ #include "Phreeqc.h"
63
+ #include "nvector_serial.h"
64
+ #define Ith(v,i) NV_Ith_S(v,i-1)
65
+ /************************************************************/
66
+ /******************* BEGIN Imports **************************/
67
+ /************************************************************/
68
+ #include <stdio.h>
69
+ #include <stdlib.h>
70
+ #include "cvode.h"
71
+ #include "sundialstypes.h"
72
+ #include "nvector.h"
73
+ #include "sundialsmath.h"
74
+
75
+
76
+ #if !defined(WIN32_MEMORY_DEBUG)
77
+ #define malloc MACHENV_MALLOC PHRQ_malloc
78
+ #endif
79
+ #define MACHENV machEnv->phreeqc_ptr->
80
+ #define CVMEM cv_mem->cv_machenv->phreeqc_ptr->
81
+ #define MACHENV_MALLOC MACHENV
82
+ #define CVMEM_MALLOC CVMEM
83
+
84
+ #include "phqalloc.h"
85
+ /* WARNING don`t include any headers below here */
86
+
87
+
88
+ /************************************************************/
89
+ /******************** END Imports ***************************/
90
+ /************************************************************/
91
+
92
+
93
+ /***************************************************************/
94
+ /*********************** BEGIN Macros **************************/
95
+ /***************************************************************/
96
+
97
+ /* Macro: loop */
98
+
99
+ #define loop for(;;)
100
+
101
+ /***************************************************************/
102
+ /************************ END Macros ***************************/
103
+ /***************************************************************/
104
+
105
+
106
+
107
+ /************************************************************/
108
+ /************** BEGIN CVODE Private Constants ***************/
109
+ /*****************************************
110
+ *******************/
111
+
112
+ #define FOURTH RCONST(0.25) /* real 0.25 */
113
+ #define THREE RCONST(3.0) /* real 3.0 */
114
+ #define FOUR RCONST(4.0) /* real 4.0 */
115
+ #define HUN RCONST(100.0) /* real 100.0 */
116
+ #define TINY RCONST(1.0e-10) /* small number */
117
+ #define HALF RCONST(0.5) /* real 0.5 */
118
+ #define ZERO RCONST(0.0) /* real 0.0 */
119
+ #define ONE RCONST(1.0) /* real 1.0 */
120
+ #define TWO RCONST(2.0) /* real 2.0 */
121
+ #define TWELVE RCONST(12.0) /* real 12.0 */
122
+
123
+ /***************************************************************/
124
+ /************** BEGIN Default Constants ************************/
125
+ /***************************************************************/
126
+
127
+ #define HMIN_DEFAULT ZERO /* hmin default value */
128
+ #define HMAX_INV_DEFAULT ZERO /* hmax_inv default value */
129
+ #define MXHNIL_DEFAULT 10 /* mxhnil default value */
130
+ #define MXSTEP_DEFAULT 1000 /* mxstep default value */
131
+
132
+
133
+ /***************************************************************/
134
+ /*************** END Default Constants *************************/
135
+ /***************************************************************/
136
+
137
+
138
+ /***************************************************************/
139
+ /************ BEGIN Routine-Specific Constants *****************/
140
+ /***************************************************************/
141
+
142
+ /* CVodeDky */
143
+
144
+ #define FUZZ_FACTOR RCONST(100.0)
145
+
146
+ /* CVHin */
147
+
148
+ #define HLB_FACTOR RCONST(100.0)
149
+ #define HUB_FACTOR RCONST(0.1)
150
+ #define H_BIAS HALF
151
+ #define MAX_ITERS 40
152
+
153
+ /* CVSet */
154
+
155
+ #define CORTES RCONST(0.1)
156
+
157
+ /* CVStep return values */
158
+
159
+ #define SUCCESS_STEP 0
160
+ #define REP_ERR_FAIL -1
161
+ #define REP_CONV_FAIL -2
162
+ #define SETUP_FAILED -3
163
+ #define SOLVE_FAILED -4
164
+
165
+ /* CVStep control constants */
166
+
167
+ #define PREDICT_AGAIN -5
168
+ #define DO_ERROR_TEST 1
169
+
170
+ /* CVStep */
171
+
172
+ #define THRESH RCONST(1.5)
173
+ #define ETAMX1 RCONST(10000.0)
174
+ #define ETAMX2 RCONST(10.0)
175
+ #define ETAMX3 RCONST(10.0)
176
+ #define ETAMXF RCONST(0.2)
177
+ #define ETAMIN RCONST(0.1)
178
+ #define ETACF RCONST(0.25)
179
+ #define ADDON RCONST(0.000001)
180
+ #define BIAS1 RCONST(6.0)
181
+ #define BIAS2 RCONST(6.0)
182
+ #define BIAS3 RCONST(10.0)
183
+ #define ONEPSM RCONST(1.000001)
184
+
185
+ #define SMALL_NST 10 /* nst > SMALL_NST => use ETAMX3 */
186
+ #define MXNCF 10 /* max no. of convergence failures during */
187
+ /* one step try */
188
+ #define MXNEF 7 /* max no. of error test failures during */
189
+ /* one step try */
190
+ #define MXNEF1 3 /* max no. of error test failures before */
191
+ /* forcing a reduction of order */
192
+ #define SMALL_NEF 2 /* if an error failure occurs and */
193
+ /* SMALL_NEF <= nef <= MXNEF1, then */
194
+ /* reset eta = MIN(eta, ETAMXF) */
195
+ #define LONG_WAIT 10 /* number of steps to wait before */
196
+ /* considering an order change when */
197
+ /* q==1 and MXNEF1 error test failures */
198
+ /* have occurred */
199
+
200
+ /* CVnls return values */
201
+
202
+ #define SOLVED 0
203
+ #define CONV_FAIL -1
204
+ #define SETUP_FAIL_UNREC -2
205
+ #define SOLVE_FAIL_UNREC -3
206
+
207
+ /* CVnls input flags */
208
+
209
+ #define FIRST_CALL 0
210
+ #define PREV_CONV_FAIL -1
211
+ #define PREV_ERR_FAIL -2
212
+
213
+ /* CVnls other constants */
214
+
215
+ #define FUNC_MAXCOR 3 /* maximum no. of corrector iterations */
216
+ /* for iter == FUNCTIONAL */
217
+ #define NEWT_MAXCOR 3 /* maximum no. of corrector iterations */
218
+ /* for iter == NEWTON */
219
+
220
+ #define CRDOWN RCONST(0.3) /* constant used in the estimation of the */
221
+ /* convergence rate (crate) of the */
222
+ /* iterates for the nonlinear equation */
223
+ #define DGMAX RCONST(0.3) /* iter == NEWTON, |gamma/gammap-1| > DGMAX */
224
+ /* => call lsetup */
225
+
226
+ #define RDIV TWO /* declare divergence if ratio del/delp > RDIV */
227
+ #define MSBP 20 /* max no. of steps between lsetup calls */
228
+
229
+ #define TRY_AGAIN_CVODE 99 /* control constant for CVnlsNewton - should be */
230
+ /* distinct from CVnls return values */
231
+
232
+
233
+ /***************************************************************/
234
+ /*************** END Routine-Specific Constants ***************/
235
+ /***************************************************************/
236
+
237
+
238
+ /***************************************************************/
239
+ /***************** BEGIN Error Messages ************************/
240
+ /***************************************************************/
241
+
242
+ /* CVodeMalloc/CVReInit Error Messages */
243
+
244
+ #define CVM "CVodeMalloc/CVReInit-- "
245
+
246
+ #define MSG_Y0_NULL CVM "y0=NULL illegal.\n\n"
247
+
248
+ #define MSG_BAD_N CVM "N=%ld < 1 illegal.\n\n"
249
+
250
+ #define MSG_BAD_LMM_1 CVM "lmm=%d illegal.\n"
251
+ #define MSG_BAD_LMM_2 "The legal values are ADAMS=%d and BDF=%d.\n\n"
252
+ #define MSG_BAD_LMM MSG_BAD_LMM_1 MSG_BAD_LMM_2
253
+
254
+ #define MSG_BAD_ITER_1 CVM "iter=%d illegal.\n"
255
+ #define MSG_BAD_ITER_2 "The legal values are FUNCTIONAL=%d "
256
+ #define MSG_BAD_ITER_3 "and NEWTON=%d.\n\n"
257
+ #define MSG_BAD_ITER MSG_BAD_ITER_1 MSG_BAD_ITER_2 MSG_BAD_ITER_3
258
+
259
+ #define MSG_BAD_ITOL_1 CVM "itol=%d illegal.\n"
260
+ #define MSG_BAD_ITOL_2 "The legal values are SS=%d and SV=%d.\n\n"
261
+ #define MSG_BAD_ITOL MSG_BAD_ITOL_1 MSG_BAD_ITOL_2
262
+
263
+ #define MSG_F_NULL CVM "f=NULL illegal.\n\n"
264
+
265
+ #define MSG_RELTOL_NULL CVM "reltol=NULL illegal.\n\n"
266
+
267
+ #define MSG_BAD_RELTOL CVM "*reltol=%g < 0 illegal.\n\n"
268
+
269
+ #define MSG_ABSTOL_NULL CVM "abstol=NULL illegal.\n\n"
270
+
271
+ #define MSG_BAD_ABSTOL CVM "Some abstol component < 0.0 illegal.\n\n"
272
+
273
+ #define MSG_BAD_OPTIN_1 CVM "optIn=%d illegal.\n"
274
+ #define MSG_BAD_OPTIN_2 "The legal values are FALSE=%d and TRUE=%d.\n\n"
275
+ #define MSG_BAD_OPTIN MSG_BAD_OPTIN_1 MSG_BAD_OPTIN_2
276
+
277
+ #define MSG_BAD_OPT CVM "optIn=TRUE, but iopt=ropt=NULL.\n\n"
278
+
279
+ #define MSG_MEM_FAIL CVM "A memory request failed.\n\n"
280
+
281
+ #define MSG_BAD_EWT CVM "Some initial ewt component = 0.0 illegal.\n\n"
282
+
283
+ #define MSG_REI_NO_MEM "CVReInit-- cvode_mem = NULL illegal.\n\n"
284
+
285
+ #define MSG_REI_MAXORD1 "CVReInit-- Illegal attempt to increase "
286
+ #define MSG_REI_MAXORD2 "maximum method order from %d to %d.\n\n"
287
+ #define MSG_REI_MAXORD MSG_REI_MAXORD1 MSG_REI_MAXORD2
288
+
289
+
290
+ /* CVode error messages */
291
+
292
+ #define CVODE "CVode-- "
293
+
294
+ #define NO_MEM "cvode_mem=NULL illegal.\n\n"
295
+
296
+ #define MSG_CVODE_NO_MEM CVODE NO_MEM
297
+
298
+ #define MSG_LINIT_NULL CVODE "The linear solver's init routine is NULL.\n\n"
299
+
300
+ #define MSG_LSETUP_NULL CVODE "The linear solver's setup routine is NULL.\n\n"
301
+
302
+ #define MSG_LSOLVE_NULL CVODE "The linear solver's solve routine is NULL.\n\n"
303
+
304
+ #define MSG_LFREE_NULL CVODE "The linear solver's free routine is NULL.\n\n"
305
+
306
+ #define MSG_LINIT_FAIL CVODE "The linear solver's init routine failed.\n\n"
307
+
308
+ #define MSG_YOUT_NULL CVODE "yout=NULL illegal.\n\n"
309
+
310
+ #define MSG_T_NULL CVODE "t=NULL illegal.\n\n"
311
+
312
+ #define MSG_BAD_ITASK_1 CVODE "itask=%d illegal.\nThe legal values are"
313
+ #define MSG_BAD_ITASK_2 " NORMAL=%d and ONE_STEP=%d.\n\n"
314
+ #define MSG_BAD_ITASK MSG_BAD_ITASK_1 MSG_BAD_ITASK_2
315
+
316
+ #define MSG_BAD_HMIN_HMAX_1 CVODE "Inconsistent step size limits:\n"
317
+ #define MSG_BAD_HMIN_HMAX_2 "ropt[HMIN]=%g > ropt[HMAX]=%g.\n\n"
318
+ #define MSG_BAD_HMIN_HMAX MSG_BAD_HMIN_HMAX_1 MSG_BAD_HMIN_HMAX_2
319
+
320
+ #define MSG_BAD_H0 CVODE "h0=%g and tout-t0=%g inconsistent.\n\n"
321
+
322
+ #define MSG_BAD_TOUT_1 CVODE "Trouble interpolating at tout = %g.\n"
323
+ #define MSG_BAD_TOUT_2 "tout too far back in direction of integration.\n\n"
324
+ #define MSG_BAD_TOUT MSG_BAD_TOUT_1 MSG_BAD_TOUT_2
325
+
326
+ #define MSG_MAX_STEPS_1 CVODE "At t=%g, mxstep=%d steps taken on "
327
+ #define MSG_MAX_STEPS_2 "this call before\nreaching tout=%g.\n\n"
328
+ #define MSG_MAX_STEPS MSG_MAX_STEPS_1 MSG_MAX_STEPS_2
329
+
330
+ #define MSG_EWT_NOW_BAD_1 CVODE "At t=%g, "
331
+ #define MSG_EWT_NOW_BAD_2 "some ewt component has become <= 0.0.\n\n"
332
+ #define MSG_EWT_NOW_BAD MSG_EWT_NOW_BAD_1 MSG_EWT_NOW_BAD_2
333
+
334
+ #define MSG_TOO_MUCH_ACC CVODE "At t=%g, too much accuracy requested.\n\n"
335
+
336
+ #define MSG_HNIL_1 CVODE "Warning.. internal t=%g and step size h=%g\n"
337
+ #define MSG_HNIL_2 "are such that t + h == t on the next step.\n"
338
+ #define MSG_HNIL_3 "The solver will continue anyway.\n\n"
339
+ #define MSG_HNIL MSG_HNIL_1 MSG_HNIL_2 MSG_HNIL_3
340
+
341
+ #define MSG_HNIL_DONE_1 CVODE "The above warning has been issued %d times "
342
+ #define MSG_HNIL_DONE_2 "and will not be\nissued again for this problem.\n\n"
343
+ #define MSG_HNIL_DONE MSG_HNIL_DONE_1 MSG_HNIL_DONE_2
344
+
345
+ #define MSG_ERR_FAILS_1 CVODE "At t=%g and step size h=%g, the error test\n"
346
+ #define MSG_ERR_FAILS_2 "failed repeatedly or with |h| = hmin.\n\n"
347
+ #define MSG_ERR_FAILS MSG_ERR_FAILS_1 MSG_ERR_FAILS_2
348
+
349
+ #define MSG_CONV_FAILS_1 CVODE "At t=%g and step size h=%g, the corrector\n"
350
+ #define MSG_CONV_FAILS_2 "convergence failed repeatedly or "
351
+ #define MSG_CONV_FAILS_3 "with |h| = hmin.\n\n"
352
+ #define MSG_CONV_FAILS MSG_CONV_FAILS_1 MSG_CONV_FAILS_2 MSG_CONV_FAILS_3
353
+
354
+ #define MSG_SETUP_FAILED_1 CVODE "At t=%g, the setup routine failed in an "
355
+ #define MSG_SETUP_FAILED_2 "unrecoverable manner.\n\n"
356
+ #define MSG_SETUP_FAILED MSG_SETUP_FAILED_1 MSG_SETUP_FAILED_2
357
+
358
+ #define MSG_SOLVE_FAILED_1 CVODE "At t=%g, the solve routine failed in an "
359
+ #define MSG_SOLVE_FAILED_2 "unrecoverable manner.\n\n"
360
+ #define MSG_SOLVE_FAILED MSG_SOLVE_FAILED_1 MSG_SOLVE_FAILED_2
361
+
362
+ #define MSG_TOO_CLOSE_1 CVODE "tout=%g too close to t0=%g to start"
363
+ #define MSG_TOO_CLOSE_2 " integration.\n\n"
364
+ #define MSG_TOO_CLOSE MSG_TOO_CLOSE_1 MSG_TOO_CLOSE_2
365
+
366
+
367
+ /* CVodeDky Error Messages */
368
+
369
+ #define DKY "CVodeDky-- "
370
+
371
+ #define MSG_DKY_NO_MEM DKY NO_MEM
372
+
373
+ #define MSG_BAD_K DKY "k=%d illegal.\n\n"
374
+
375
+ #define MSG_BAD_T_1 DKY "t=%g illegal.\n"
376
+ #define MSG_BAD_T_2 "t not in interval tcur-hu=%g to tcur=%g.\n\n"
377
+ #define MSG_BAD_T MSG_BAD_T_1 MSG_BAD_T_2
378
+
379
+ #define MSG_BAD_DKY DKY "dky=NULL illegal.\n\n"
380
+
381
+ /***************************************************************/
382
+ /****************** END Error Messages *************************/
383
+ /***************************************************************/
384
+
385
+
386
+ /************************************************************/
387
+ /*************** END CVODE Private Constants ****************/
388
+ /************************************************************/
389
+
390
+
391
+ /**************************************************************/
392
+ /********* BEGIN Private Helper Functions Prototypes **********/
393
+ /**************************************************************/
394
+
395
+ static booleantype CVAllocVectors(CVodeMem cv_mem, integertype neq,
396
+ int maxord, M_Env machEnv);
397
+ static void CVFreeVectors(CVodeMem cv_mem, int maxord);
398
+
399
+ static booleantype CVEwtSet(CVodeMem cv_mem, N_Vector ycur);
400
+ static booleantype CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur);
401
+ static booleantype CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur);
402
+
403
+ static booleantype CVHin(CVodeMem cv_mem, realtype tout);
404
+ static realtype CVUpperBoundH0(CVodeMem cv_mem, realtype tdist);
405
+ static realtype CVYddNorm(CVodeMem cv_mem, realtype hg);
406
+
407
+ static int CVStep(CVodeMem cv_mem);
408
+
409
+ #ifdef ORIGINAL_CVBDFStab
410
+ static int CVsldet(CVodeMem cv_mem);
411
+ #endif
412
+ static void CVAdjustParams(CVodeMem cv_mem);
413
+ static void CVAdjustOrder(CVodeMem cv_mem, int deltaq);
414
+ static void CVAdjustAdams(CVodeMem cv_mem, int deltaq);
415
+ static void CVAdjustBDF(CVodeMem cv_mem, int deltaq);
416
+ static void CVIncreaseBDF(CVodeMem cv_mem);
417
+ static void CVDecreaseBDF(CVodeMem cv_mem);
418
+
419
+ static void CVRescale(CVodeMem cv_mem);
420
+
421
+ static void CVPredict(CVodeMem cv_mem);
422
+
423
+ static void CVSet(CVodeMem cv_mem);
424
+ static void CVSetAdams(CVodeMem cv_mem);
425
+ static realtype CVAdamsStart(CVodeMem cv_mem, realtype m[]);
426
+ static void CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[],
427
+ realtype hsum);
428
+ static realtype CVAltSum(int iend, realtype a[], int k);
429
+ static void CVSetBDF(CVodeMem cv_mem);
430
+ static void CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0,
431
+ realtype alpha0_hat, realtype xi_inv,
432
+ realtype xistar_inv);
433
+
434
+ static int CVnls(CVodeMem cv_mem, int nflag);
435
+ static int CVnlsFunctional(CVodeMem cv_mem);
436
+ static int CVnlsNewton(CVodeMem cv_mem, int nflag);
437
+ static int CVNewtonIteration(CVodeMem cv_mem);
438
+
439
+ static int CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t,
440
+ int *ncfPtr);
441
+
442
+ static void CVRestore(CVodeMem cv_mem, realtype saved_t);
443
+
444
+ static booleantype CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr,
445
+ int *kflagPtr, realtype saved_t,
446
+ int *nefPtr, realtype * dsmPtr);
447
+
448
+ static void CVCompleteStep(CVodeMem cv_mem);
449
+
450
+ static void CVPrepareNextStep(CVodeMem cv_mem, realtype dsm);
451
+ static void CVSetEta(CVodeMem cv_mem);
452
+ static realtype CVComputeEtaqm1(CVodeMem cv_mem);
453
+ static realtype CVComputeEtaqp1(CVodeMem cv_mem);
454
+ static void CVChooseEta(CVodeMem cv_mem);
455
+ static void CVBDFStab(CVodeMem cv_mem);
456
+
457
+ static int CVHandleFailure(CVodeMem cv_mem, int kflag);
458
+
459
+
460
+ /**************************************************************/
461
+ /********** END Private Helper Functions Prototypes ***********/
462
+ /**************************************************************/
463
+
464
+
465
+ /**************************************************************/
466
+ /**************** BEGIN Readability Constants *****************/
467
+ /**************************************************************/
468
+
469
+
470
+ #define uround (cv_mem->cv_uround)
471
+ #define zn (cv_mem->cv_zn)
472
+ #define ewt (cv_mem->cv_ewt)
473
+ #define y (cv_mem->cv_y)
474
+ #define acor (cv_mem->cv_acor)
475
+ #define tempv (cv_mem->cv_tempv)
476
+ #define ftemp (cv_mem->cv_ftemp)
477
+ #define q (cv_mem->cv_q)
478
+ #define qprime (cv_mem->cv_qprime)
479
+ #define qwait (cv_mem->cv_qwait)
480
+ #define L (cv_mem->cv_L)
481
+ #define h (cv_mem->cv_h)
482
+ #define hprime (cv_mem->cv_hprime)
483
+ #define eta (cv_mem-> cv_eta)
484
+ #define etaqm1 (cv_mem-> cv_etaqm1)
485
+ #define etaq (cv_mem-> cv_etaq)
486
+ #define etaqp1 (cv_mem-> cv_etaqp1)
487
+ #define nscon (cv_mem->cv_nscon)
488
+ #define ssdat (cv_mem->cv_ssdat)
489
+ #define hscale (cv_mem->cv_hscale)
490
+ #define tn (cv_mem->cv_tn)
491
+ #define tau (cv_mem->cv_tau)
492
+ #define tq (cv_mem->cv_tq)
493
+ #define l (cv_mem->cv_l)
494
+ #define rl1 (cv_mem->cv_rl1)
495
+ #define gamma (cv_mem->cv_gamma)
496
+ #define gammap (cv_mem->cv_gammap)
497
+ #define gamrat (cv_mem->cv_gamrat)
498
+ #define crate (cv_mem->cv_crate)
499
+ #define acnrm (cv_mem->cv_acnrm)
500
+ #define mnewt (cv_mem->cv_mnewt)
501
+ #define qmax (cv_mem->cv_qmax)
502
+ #define mxstep (cv_mem->cv_mxstep)
503
+ #define maxcor (cv_mem->cv_maxcor)
504
+ #define mxhnil (cv_mem->cv_mxhnil)
505
+ #define hmin (cv_mem->cv_hmin)
506
+ #define hmax_inv (cv_mem->cv_hmax_inv)
507
+ #define etamax (cv_mem->cv_etamax)
508
+ #define nst (cv_mem->cv_nst)
509
+ #define nfe (cv_mem->cv_nfe)
510
+ #define ncfn (cv_mem->cv_ncfn)
511
+ #define netf (cv_mem->cv_netf)
512
+ #define nni (cv_mem-> cv_nni)
513
+ #define nsetups (cv_mem->cv_nsetups)
514
+ #define nhnil (cv_mem->cv_nhnil)
515
+ #define lrw (cv_mem->cv_lrw)
516
+ #define liw (cv_mem->cv_liw)
517
+ #define linit (cv_mem->cv_linit)
518
+ #define lsetup (cv_mem->cv_lsetup)
519
+ #define lsolve (cv_mem->cv_lsolve)
520
+ #define lfree (cv_mem->cv_lfree)
521
+ #define lmem (cv_mem->cv_lmem)
522
+ #define qu (cv_mem->cv_qu)
523
+ #define nstlp (cv_mem->cv_nstlp)
524
+ #define hu (cv_mem->cv_hu)
525
+ #define saved_tq5 (cv_mem->cv_saved_tq5)
526
+ #define jcur (cv_mem->cv_jcur)
527
+ #define tolsf (cv_mem->cv_tolsf)
528
+ #define setupNonNull (cv_mem->cv_setupNonNull)
529
+ #define machenv (cv_mem->cv_machenv)
530
+ #define sldeton (cv_mem->cv_sldeton)
531
+
532
+ /**************************************************************/
533
+ /***************** END Readability Constants ******************/
534
+ /**************************************************************/
535
+
536
+
537
+ /***************************************************************/
538
+ /************* BEGIN CVODE Implementation **********************/
539
+ /***************************************************************/
540
+
541
+
542
+ /***************************************************************/
543
+ /********* BEGIN Exported Functions Implementation *************/
544
+ /***************************************************************/
545
+
546
+ #if defined(PHREEQCI_GUI)
547
+ #ifdef _DEBUG
548
+ #define new DEBUG_NEW
549
+ #undef THIS_FILE
550
+ static char THIS_FILE[] = __FILE__;
551
+ #endif
552
+ #endif
553
+
554
+ /******************** CVodeMalloc *******************************
555
+
556
+ CVodeMalloc allocates and initializes memory for a problem. All
557
+ problem specification inputs are checked for errors. If any
558
+ error occurs during initialization, it is reported to the file
559
+ whose file pointer is errfp and NULL is returned. Otherwise, the
560
+ pointer to successfully initialized problem memory is returned.
561
+
562
+ *****************************************************************/
563
+
564
+ void *
565
+ CVodeMalloc(integertype N, RhsFn f, realtype t0, N_Vector y0,
566
+ int lmm, int iter, int itol,
567
+ realtype * reltol, void *abstol,
568
+ void *f_data, FILE * errfp, booleantype optIn,
569
+ long int iopt[], realtype ropt[], M_Env machEnv)
570
+ {
571
+ booleantype allocOK, ioptExists, roptExists, neg_abstol, ewtsetOK;
572
+ int maxord;
573
+ CVodeMem cv_mem;
574
+ #if !defined(R_SO)
575
+ FILE *fp;
576
+ #endif
577
+ int i, k;
578
+
579
+ /* Check for legal input parameters */
580
+
581
+ #if !defined(R_SO)
582
+ fp = (errfp == NULL) ? stdout : errfp;
583
+ #endif
584
+
585
+ if (y0 == NULL)
586
+ {
587
+ MACHENV warning_msg( MSG_Y0_NULL);
588
+ return (NULL);
589
+ }
590
+
591
+ if (N <= 0)
592
+ {
593
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_N, N));
594
+ return (NULL);
595
+ }
596
+
597
+ if ((lmm != ADAMS) && (lmm != BDF))
598
+ {
599
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_LMM, lmm, ADAMS, BDF));
600
+ return (NULL);
601
+ }
602
+
603
+ if ((iter != FUNCTIONAL) && (iter != NEWTON))
604
+ {
605
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON));
606
+ return (NULL);
607
+ }
608
+
609
+ if ((itol != SS) && (itol != SV))
610
+ {
611
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITOL, itol, SS, SV));
612
+ return (NULL);
613
+ }
614
+
615
+ if (f == NULL)
616
+ {
617
+ MACHENV warning_msg(MSG_F_NULL);
618
+ return (NULL);
619
+ }
620
+
621
+ if (reltol == NULL)
622
+ {
623
+ MACHENV warning_msg(MSG_RELTOL_NULL);
624
+ return (NULL);
625
+ }
626
+
627
+ if (*reltol < ZERO)
628
+ {
629
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_RELTOL, (double) *reltol));
630
+ return (NULL);
631
+ }
632
+
633
+ if (abstol == NULL)
634
+ {
635
+ MACHENV warning_msg(MSG_ABSTOL_NULL);
636
+ return (NULL);
637
+ }
638
+
639
+ if (itol == SS)
640
+ {
641
+ neg_abstol = (*((realtype *) abstol) < ZERO);
642
+ }
643
+ else
644
+ {
645
+ neg_abstol = (N_VMin((N_Vector) abstol) < ZERO);
646
+ }
647
+ if (neg_abstol)
648
+ {
649
+ MACHENV warning_msg(MSG_BAD_ABSTOL);
650
+ return (NULL);
651
+ }
652
+
653
+ if ((optIn != FALSE) && (optIn != TRUE))
654
+ {
655
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_OPTIN, optIn, FALSE, TRUE));
656
+ return (NULL);
657
+ }
658
+
659
+ if ((optIn) && (iopt == NULL) && (ropt == NULL))
660
+ {
661
+ MACHENV warning_msg(MSG_BAD_OPT);
662
+ return (NULL);
663
+ }
664
+
665
+ ioptExists = (iopt != NULL);
666
+ roptExists = (ropt != NULL);
667
+
668
+ /* Compute maxord */
669
+
670
+ maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX;
671
+
672
+ if (optIn && ioptExists)
673
+ {
674
+ if (iopt[MAXORD] > 0)
675
+ maxord = MIN(maxord, iopt[MAXORD]);
676
+ }
677
+
678
+ cv_mem = (CVodeMem) malloc(sizeof(struct CVodeMemRec));
679
+ if (cv_mem == NULL)
680
+ {
681
+ MACHENV warning_msg(MSG_MEM_FAIL);
682
+ return (NULL);
683
+ }
684
+
685
+ /* Allocate the vectors */
686
+
687
+ allocOK = CVAllocVectors(cv_mem, N, maxord, machEnv);
688
+ if (!allocOK)
689
+ {
690
+ MACHENV warning_msg(MSG_MEM_FAIL);
691
+ MACHENV_MALLOC PHRQ_free(cv_mem);
692
+ return (NULL);
693
+ }
694
+
695
+ /* Copy tolerances into memory, and set the ewt vector */
696
+
697
+ cv_mem->cv_itol = itol;
698
+ cv_mem->cv_reltol = reltol;
699
+ cv_mem->cv_abstol = abstol;
700
+ ewtsetOK = CVEwtSet(cv_mem, y0);
701
+ if (!ewtsetOK)
702
+ {
703
+ MACHENV warning_msg(MSG_BAD_EWT);
704
+ CVFreeVectors(cv_mem, maxord);
705
+ MACHENV_MALLOC PHRQ_free(cv_mem);
706
+ return (NULL);
707
+ }
708
+
709
+ /* All error checking is complete at this point */
710
+
711
+ /* Copy the remaining input parameters into CVODE memory */
712
+
713
+ cv_mem->cv_N = N;
714
+ cv_mem->cv_f = f;
715
+ cv_mem->cv_f_data = f_data;
716
+ cv_mem->cv_lmm = lmm;
717
+ cv_mem->cv_iter = iter;
718
+ cv_mem->cv_optIn = optIn;
719
+ cv_mem->cv_iopt = iopt;
720
+ cv_mem->cv_ropt = ropt;
721
+ #if !defined(R_SO)
722
+ cv_mem->cv_errfp = fp;
723
+ #endif
724
+ tn = t0;
725
+ machenv = machEnv;
726
+
727
+ /* Set step parameters */
728
+
729
+ q = 1;
730
+ L = 2;
731
+ qwait = L;
732
+ qmax = maxord;
733
+ etamax = ETAMX1;
734
+
735
+ /* Set uround */
736
+
737
+ uround = UnitRoundoff();
738
+
739
+ /* Set the linear solver addresses to NULL.
740
+ (We check != NULL later, in CVode, if using NEWTON.) */
741
+
742
+ linit = NULL;
743
+ lsetup = NULL;
744
+ lsolve = NULL;
745
+ lfree = NULL;
746
+ lmem = NULL;
747
+
748
+ /* Initialize zn[0] in the history array */
749
+
750
+ N_VScale(ONE, y0, zn[0]);
751
+
752
+ /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */
753
+
754
+ hmax_inv = HMAX_INV_DEFAULT;
755
+ hmin = HMIN_DEFAULT;
756
+ if (optIn && roptExists)
757
+ {
758
+ if (ropt[HMIN] > ZERO)
759
+ hmin = ropt[HMIN];
760
+ }
761
+
762
+ mxhnil = MXHNIL_DEFAULT;
763
+ mxstep = MXSTEP_DEFAULT;
764
+ if (optIn && ioptExists)
765
+ {
766
+ if (iopt[MXHNIL] != 0)
767
+ mxhnil = iopt[MXHNIL];
768
+ if (iopt[MXSTEP] > 0)
769
+ mxstep = iopt[MXSTEP];
770
+ }
771
+
772
+ if ((!optIn) && roptExists)
773
+ ropt[H0] = ZERO;
774
+
775
+ /* Set maxcor */
776
+
777
+ maxcor = (iter == NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR;
778
+
779
+ /* Initialize all the counters */
780
+
781
+ nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0;
782
+
783
+ /* Initialize all other variables corresponding to optional outputs */
784
+
785
+ qu = 0;
786
+ hu = ZERO;
787
+ tolsf = ONE;
788
+
789
+ /* Initialize optional output locations in iopt, ropt */
790
+ /* and Stablilty Limit Detection data. */
791
+
792
+ nscon = 0;
793
+ sldeton = FALSE;
794
+ if (ioptExists)
795
+ {
796
+ iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0;
797
+ iopt[NCFN] = iopt[NETF] = 0;
798
+ iopt[QU] = qu;
799
+ iopt[QCUR] = 0;
800
+ iopt[LENRW] = lrw;
801
+ iopt[LENIW] = liw;
802
+ if (optIn && iopt[SLDET] && (lmm == BDF))
803
+ {
804
+ sldeton = TRUE;
805
+ iopt[NOR] = 0;
806
+ for (i = 1; i <= 5; i++)
807
+ {
808
+ for (k = 1; k <= 3; k++)
809
+ ssdat[i - 1][k - 1] = ZERO;
810
+ }
811
+ }
812
+ }
813
+
814
+ if (roptExists)
815
+ {
816
+ ropt[HU] = hu;
817
+ ropt[HCUR] = ZERO;
818
+ ropt[TCUR] = t0;
819
+ ropt[TOLSF] = tolsf;
820
+ }
821
+
822
+
823
+ /* Problem has been successfully initialized */
824
+
825
+ return ((void *) cv_mem);
826
+ }
827
+
828
+
829
+ /******************** CVReInit **********************************
830
+
831
+ CVReInit re-initializes CVODE's memory for a problem, assuming
832
+ it has already been allocated in a prior CVodeMalloc call.
833
+ All problem specification inputs are checked for errors.
834
+ The problem size N is assumed to be unchanged since the call to
835
+ CVodeMalloc, and the maximum order maxord must not be larger.
836
+ If any error occurs during initialization, it is reported to the
837
+ file whose file pointer is errfp.
838
+ The return value is SUCCESS = 0 if no errors occurred, or
839
+ a negative value otherwise.
840
+
841
+ *****************************************************************/
842
+
843
+ int
844
+ CVReInit(void *cvode_mem, RhsFn f, realtype t0, N_Vector y0,
845
+ int lmm, int iter, int itol,
846
+ realtype * reltol, void *abstol,
847
+ void *f_data, FILE * errfp, booleantype optIn,
848
+ long int iopt[], realtype ropt[], M_Env machEnv)
849
+ {
850
+ booleantype ioptExists, roptExists, neg_abstol, ewtsetOK;
851
+ int maxord, i, k;
852
+ CVodeMem cv_mem;
853
+ #if !defined(R_SO)
854
+ FILE *fp;
855
+ #endif
856
+ /* Check for legal input parameters */
857
+
858
+ #if !defined(R_SO)
859
+ fp = (errfp == NULL) ? stdout : errfp;
860
+ #endif
861
+
862
+ if (cvode_mem == NULL)
863
+ {
864
+ MACHENV warning_msg(MSG_REI_NO_MEM);
865
+ return (CVREI_NO_MEM);
866
+ }
867
+ cv_mem = (CVodeMem) cvode_mem;
868
+
869
+ if (y0 == NULL)
870
+ {
871
+ MACHENV warning_msg(MSG_Y0_NULL);
872
+ return (CVREI_ILL_INPUT);
873
+ }
874
+
875
+ if ((lmm != ADAMS) && (lmm != BDF))
876
+ {
877
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_LMM, lmm, ADAMS, BDF));
878
+ return (CVREI_ILL_INPUT);
879
+ }
880
+
881
+ if ((iter != FUNCTIONAL) && (iter != NEWTON))
882
+ {
883
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITER, iter, FUNCTIONAL, NEWTON));
884
+ return (CVREI_ILL_INPUT);
885
+ }
886
+
887
+ if ((itol != SS) && (itol != SV))
888
+ {
889
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_ITOL, itol, SS, SV));
890
+ return (CVREI_ILL_INPUT);
891
+ }
892
+
893
+ if (f == NULL)
894
+ {
895
+ MACHENV warning_msg(MSG_F_NULL);
896
+ return (CVREI_ILL_INPUT);
897
+ }
898
+
899
+ if (reltol == NULL)
900
+ {
901
+ MACHENV warning_msg(MSG_RELTOL_NULL);
902
+ return (CVREI_ILL_INPUT);
903
+ }
904
+
905
+ if (*reltol < ZERO)
906
+ {
907
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_RELTOL, (double) *reltol));
908
+ return (CVREI_ILL_INPUT);
909
+ }
910
+
911
+ if (abstol == NULL)
912
+ {
913
+ MACHENV warning_msg(MSG_ABSTOL_NULL);
914
+ return (CVREI_ILL_INPUT);
915
+ }
916
+
917
+ if (itol == SS)
918
+ {
919
+ neg_abstol = (*((realtype *) abstol) < ZERO);
920
+ }
921
+ else
922
+ {
923
+ neg_abstol = (N_VMin((N_Vector) abstol) < ZERO);
924
+ }
925
+ if (neg_abstol)
926
+ {
927
+ MACHENV warning_msg(MSG_BAD_ABSTOL);
928
+ return (CVREI_ILL_INPUT);
929
+ }
930
+
931
+ if ((optIn != FALSE) && (optIn != TRUE))
932
+ {
933
+ MACHENV warning_msg(MACHENV sformatf(MSG_BAD_OPTIN, optIn, FALSE, TRUE));
934
+ return (CVREI_ILL_INPUT);
935
+ }
936
+
937
+ if ((optIn) && (iopt == NULL) && (ropt == NULL))
938
+ {
939
+ MACHENV warning_msg(MSG_BAD_OPT);
940
+ return (CVREI_ILL_INPUT);
941
+ }
942
+
943
+ ioptExists = (iopt != NULL);
944
+ roptExists = (ropt != NULL);
945
+
946
+ /* Compute new maxord and check against old value */
947
+
948
+ maxord = (lmm == ADAMS) ? ADAMS_Q_MAX : BDF_Q_MAX;
949
+ if (optIn && ioptExists)
950
+ {
951
+ if (iopt[MAXORD] > 0)
952
+ maxord = MIN(maxord, iopt[MAXORD]);
953
+ }
954
+ if (maxord > qmax)
955
+ {
956
+ MACHENV warning_msg(MACHENV sformatf(MSG_REI_MAXORD, qmax, maxord));
957
+ return (CVREI_ILL_INPUT);
958
+ }
959
+
960
+ /* Copy tolerances into memory, and set the ewt vector */
961
+
962
+ cv_mem->cv_itol = itol;
963
+ cv_mem->cv_reltol = reltol;
964
+ cv_mem->cv_abstol = abstol;
965
+ ewtsetOK = CVEwtSet(cv_mem, y0);
966
+ if (!ewtsetOK)
967
+ {
968
+ MACHENV warning_msg(MSG_BAD_EWT);
969
+ return (CVREI_ILL_INPUT);
970
+ }
971
+
972
+ /* All error checking is complete at this point */
973
+
974
+ /* Copy the remaining input parameters into CVODE memory */
975
+
976
+ cv_mem->cv_f = f;
977
+ cv_mem->cv_f_data = f_data;
978
+ cv_mem->cv_lmm = lmm;
979
+ cv_mem->cv_iter = iter;
980
+ cv_mem->cv_optIn = optIn;
981
+ cv_mem->cv_iopt = iopt;
982
+ cv_mem->cv_ropt = ropt;
983
+ #if !defined(R_SO)
984
+ cv_mem->cv_errfp = fp;
985
+ #endif
986
+ tn = t0;
987
+ machenv = machEnv;
988
+
989
+ /* Set step parameters */
990
+
991
+ q = 1;
992
+ L = 2;
993
+ qwait = L;
994
+ qmax = maxord;
995
+ etamax = ETAMX1;
996
+
997
+ /* Set uround */
998
+
999
+ uround = UnitRoundoff();
1000
+
1001
+ /* Initialize zn[0] in the history array */
1002
+
1003
+ N_VScale(ONE, y0, zn[0]);
1004
+
1005
+ /* Handle the remaining optional inputs (CVode checks ropt[HMAX]) */
1006
+
1007
+ hmax_inv = HMAX_INV_DEFAULT;
1008
+ hmin = HMIN_DEFAULT;
1009
+ if (optIn && roptExists)
1010
+ {
1011
+ if (ropt[HMIN] > ZERO)
1012
+ hmin = ropt[HMIN];
1013
+ }
1014
+
1015
+ mxhnil = MXHNIL_DEFAULT;
1016
+ mxstep = MXSTEP_DEFAULT;
1017
+ if (optIn && ioptExists)
1018
+ {
1019
+ if (iopt[MXHNIL] != 0)
1020
+ mxhnil = iopt[MXHNIL];
1021
+ if (iopt[MXSTEP] > 0)
1022
+ mxstep = iopt[MXSTEP];
1023
+ }
1024
+
1025
+ if ((!optIn) && roptExists)
1026
+ ropt[H0] = ZERO;
1027
+
1028
+ /* Set maxcor */
1029
+
1030
+ maxcor = (iter == NEWTON) ? NEWT_MAXCOR : FUNC_MAXCOR;
1031
+
1032
+ /* Initialize all the counters */
1033
+
1034
+ nst = nfe = ncfn = netf = nni = nsetups = nhnil = nstlp = 0;
1035
+
1036
+ /* Initialize all other vars corresponding to optional outputs */
1037
+
1038
+ qu = 0;
1039
+ hu = ZERO;
1040
+ tolsf = ONE;
1041
+
1042
+ /* Initialize optional output locations in iopt, ropt */
1043
+ /* and Stablilty Limit Detection data. */
1044
+
1045
+ nscon = 0;
1046
+ sldeton = FALSE;
1047
+ if (ioptExists)
1048
+ {
1049
+ iopt[NST] = iopt[NFE] = iopt[NSETUPS] = iopt[NNI] = 0;
1050
+ iopt[NCFN] = iopt[NETF] = 0;
1051
+ iopt[QU] = qu;
1052
+ iopt[QCUR] = 0;
1053
+ iopt[LENRW] = lrw;
1054
+ iopt[LENIW] = liw;
1055
+ if (optIn && iopt[SLDET] && (lmm == BDF))
1056
+ {
1057
+ sldeton = TRUE;
1058
+ iopt[NOR] = 0;
1059
+ for (i = 1; i <= 5; i++)
1060
+ {
1061
+ for (k = 1; k <= 3; k++)
1062
+ ssdat[i - 1][k - 1] = ZERO;
1063
+ }
1064
+ }
1065
+ }
1066
+
1067
+ if (roptExists)
1068
+ {
1069
+ ropt[HU] = hu;
1070
+ ropt[HCUR] = ZERO;
1071
+ ropt[TCUR] = t0;
1072
+ ropt[TOLSF] = tolsf;
1073
+ }
1074
+
1075
+ /* Problem has been successfully re-initialized */
1076
+
1077
+ return (SUCCESS);
1078
+ }
1079
+
1080
+
1081
+ /**************************************************************/
1082
+ /************** BEGIN More Readability Constants **************/
1083
+ /**************************************************************/
1084
+
1085
+ #define N (cv_mem->cv_N)
1086
+ #define f (cv_mem->cv_f)
1087
+ #define f_data (cv_mem->cv_f_data)
1088
+ #define lmm (cv_mem->cv_lmm)
1089
+ #define iter (cv_mem->cv_iter)
1090
+ #define itol (cv_mem->cv_itol)
1091
+ #define reltol (cv_mem->cv_reltol)
1092
+ #define abstol (cv_mem->cv_abstol)
1093
+ #define optIn (cv_mem->cv_optIn)
1094
+ #define iopt (cv_mem->cv_iopt)
1095
+ #define ropt (cv_mem->cv_ropt)
1096
+ #define errfp (cv_mem->cv_errfp)
1097
+
1098
+ /**************************************************************/
1099
+ /*************** END More Readability Constants ***************/
1100
+ /**************************************************************/
1101
+
1102
+
1103
+ /********************* CVode ****************************************
1104
+
1105
+ This routine is the main driver of the CVODE package.
1106
+
1107
+ It integrates over a time interval defined by the user, by calling
1108
+ CVStep to do internal time steps.
1109
+
1110
+ The first time that CVode is called for a successfully initialized
1111
+ problem, it computes a tentative initial step size h.
1112
+
1113
+ CVode supports two modes, specified by itask: NORMAL and ONE_STEP.
1114
+ In the NORMAL mode, the solver steps until it reaches or passes tout
1115
+ and then interpolates to obtain y(tout).
1116
+ In the ONE_STEP mode, it takes one internal step and returns.
1117
+
1118
+ ********************************************************************/
1119
+
1120
+ int
1121
+ CVode(void *cvode_mem, realtype tout, N_Vector yout, realtype * t, int itask)
1122
+ {
1123
+ int nstloc, kflag, istate, next_q, ier;
1124
+ realtype rh, next_h;
1125
+ booleantype hOK, ewtsetOK;
1126
+ CVodeMem cv_mem;
1127
+ realtype t0;
1128
+
1129
+ /* Check for legal inputs in all cases */
1130
+
1131
+ cv_mem = (CVodeMem) cvode_mem;
1132
+ if (cvode_mem == NULL)
1133
+ {
1134
+ CVMEM warning_msg(MSG_CVODE_NO_MEM);
1135
+ return (CVODE_NO_MEM);
1136
+ }
1137
+
1138
+ if ((y = yout) == NULL)
1139
+ {
1140
+ CVMEM warning_msg(MSG_YOUT_NULL);
1141
+ return (ILL_INPUT);
1142
+ }
1143
+
1144
+ if (t == NULL)
1145
+ {
1146
+ CVMEM warning_msg(MSG_T_NULL);
1147
+ return (ILL_INPUT);
1148
+ }
1149
+ t0 = tn;
1150
+ *t = tn;
1151
+
1152
+ if ((itask != NORMAL) && (itask != ONE_STEP))
1153
+ {
1154
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_ITASK, itask, NORMAL, ONE_STEP));
1155
+ return (ILL_INPUT);
1156
+ }
1157
+
1158
+ /* Set hmax_inv from ropt[HMAX] and test for hmin > hmax */
1159
+
1160
+ if (optIn && ropt != NULL)
1161
+ {
1162
+ if (ropt[HMAX] > ZERO)
1163
+ hmax_inv = ONE / ropt[HMAX];
1164
+ if (hmin * hmax_inv > ONE)
1165
+ {
1166
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_HMIN_HMAX, (double) hmin,
1167
+ (double) ropt[HMAX]));
1168
+ return (ILL_INPUT);
1169
+ }
1170
+ }
1171
+
1172
+ /* On first call, check solver functions and call linit function */
1173
+
1174
+ if (nst == 0)
1175
+ {
1176
+ if (iter == NEWTON)
1177
+ {
1178
+ if (linit == NULL)
1179
+ {
1180
+ CVMEM warning_msg(MSG_LINIT_NULL);
1181
+ return (ILL_INPUT);
1182
+ }
1183
+ if (lsetup == NULL)
1184
+ {
1185
+ CVMEM warning_msg(MSG_LSETUP_NULL);
1186
+ return (ILL_INPUT);
1187
+ }
1188
+ if (lsolve == NULL)
1189
+ {
1190
+ CVMEM warning_msg(MSG_LSOLVE_NULL);
1191
+ return (ILL_INPUT);
1192
+ }
1193
+ if (lfree == NULL)
1194
+ {
1195
+ CVMEM warning_msg(MSG_LFREE_NULL);
1196
+ return (ILL_INPUT);
1197
+ }
1198
+ ier = linit(cv_mem);
1199
+ if (ier != LINIT_OK)
1200
+ {
1201
+ CVMEM warning_msg(MSG_LINIT_FAIL);
1202
+ return (ILL_INPUT);
1203
+ }
1204
+ }
1205
+
1206
+ /* On the first call, call f at (t0,y0), set zn[1] = y'(t0),
1207
+ set initial h (from H0 or CVHin), and scale zn[1] by h */
1208
+ CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tn;
1209
+ CVMEM cvode_step_fraction = 0;
1210
+
1211
+ f(N, tn, zn[0], zn[1], f_data);
1212
+ nfe = 1;
1213
+ h = ZERO;
1214
+ if (ropt != NULL)
1215
+ h = ropt[H0];
1216
+ if ((h != ZERO) && ((tout - tn) * h < ZERO))
1217
+ {
1218
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_H0, (double) h,
1219
+ (double) (tout - tn)));
1220
+ return (ILL_INPUT);
1221
+ }
1222
+ if (h == ZERO)
1223
+ {
1224
+ hOK = CVHin(cv_mem, tout);
1225
+ if (!hOK)
1226
+ {
1227
+ CVMEM warning_msg(CVMEM sformatf(MSG_TOO_CLOSE, (double) tout,
1228
+ (double) tn));
1229
+ return (ILL_INPUT);
1230
+ }
1231
+ }
1232
+ rh = ABS(h) * hmax_inv;
1233
+ if (rh > ONE)
1234
+ h /= rh;
1235
+ if (ABS(h) < hmin)
1236
+ h *= hmin / ABS(h);
1237
+ hscale = h;
1238
+ N_VScale(h, zn[1], zn[1]);
1239
+
1240
+ } /* end of first call block */
1241
+
1242
+ /* If not the first call, check if tout already reached */
1243
+
1244
+ if ((itask == NORMAL) && (nst > 0) && ((tn - tout) * h >= ZERO))
1245
+ {
1246
+ *t = tout;
1247
+ ier = CVodeDky(cv_mem, tout, 0, yout);
1248
+ if (ier != OKAY)
1249
+ { /* ier must be == BAD_T */
1250
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_TOUT, (double) tout));
1251
+ return (ILL_INPUT);
1252
+ }
1253
+ return (SUCCESS);
1254
+ }
1255
+
1256
+ /* Looping point for internal steps */
1257
+
1258
+ nstloc = 0;
1259
+ loop
1260
+ {
1261
+
1262
+ next_h = h;
1263
+ next_q = q;
1264
+
1265
+ /* Reset and check ewt */
1266
+
1267
+ if (nst > 0)
1268
+ {
1269
+ ewtsetOK = CVEwtSet(cv_mem, zn[0]);
1270
+ if (!ewtsetOK)
1271
+ {
1272
+ CVMEM warning_msg(CVMEM sformatf(MSG_EWT_NOW_BAD, (double) tn));
1273
+ istate = ILL_INPUT;
1274
+ *t = tn;
1275
+ N_VScale(ONE, zn[0], yout);
1276
+ break;
1277
+ }
1278
+ }
1279
+
1280
+ /* Check for too many steps */
1281
+
1282
+ if (nstloc >= mxstep)
1283
+ {
1284
+ istate = TOO_MUCH_WORK;
1285
+ *t = tn;
1286
+ N_VScale(ONE, zn[0], yout);
1287
+ break;
1288
+ }
1289
+
1290
+ /* Check for too much accuracy requested */
1291
+
1292
+ if ((tolsf = uround * N_VWrmsNorm(zn[0], ewt)) > ONE)
1293
+ {
1294
+ CVMEM warning_msg(CVMEM sformatf(MSG_TOO_MUCH_ACC, (double) tn));
1295
+ istate = TOO_MUCH_ACC;
1296
+ *t = tn;
1297
+ N_VScale(ONE, zn[0], yout);
1298
+ tolsf *= TWO;
1299
+ break;
1300
+ }
1301
+
1302
+ /* Check for h below roundoff level in tn */
1303
+
1304
+ if (tn + h == tn)
1305
+ {
1306
+ nhnil++;
1307
+ if (nhnil <= mxhnil)
1308
+ CVMEM warning_msg(CVMEM sformatf(MSG_HNIL, (double) tn, (double) h));
1309
+ if (nhnil == mxhnil)
1310
+ CVMEM warning_msg(CVMEM sformatf(MSG_HNIL_DONE, mxhnil));
1311
+ }
1312
+
1313
+ /* Call CVStep to take a step */
1314
+
1315
+ kflag = CVStep(cv_mem);
1316
+ #ifdef DEBUG_CVODE
1317
+ cvode_test = TRUE;
1318
+ f(N, tn, y, ftemp, f_data);
1319
+ cvode_test = FALSE;
1320
+ if (cvode_error == TRUE)
1321
+ {
1322
+ CVMEM warning_msg("After CVStep, y Fail\n");
1323
+ }
1324
+ else
1325
+ {
1326
+ CVMEM warning_msg("After CVStep, y OK\n");
1327
+ }
1328
+ cvode_test = TRUE;
1329
+ f(N, tn, zn[0], ftemp, f_data);
1330
+ cvode_test = FALSE;
1331
+ if (cvode_error == TRUE)
1332
+ {
1333
+ CCVMEM warning_msg("After CVStep, zn Fail\n");
1334
+ }
1335
+ else
1336
+ {
1337
+ CVMEM warning_msg("After CVStep, zn OK\n");
1338
+ }
1339
+ #endif
1340
+ /* Process failed step cases, and exit loop */
1341
+
1342
+ if (kflag != SUCCESS_STEP)
1343
+ {
1344
+ istate = CVHandleFailure(cv_mem, kflag);
1345
+ *t = tn;
1346
+ N_VScale(ONE, zn[0], yout);
1347
+ break;
1348
+ }
1349
+
1350
+ nstloc++;
1351
+
1352
+ /* Check if in one-step mode, and if so copy y and exit loop */
1353
+
1354
+ if (itask == ONE_STEP)
1355
+ {
1356
+ istate = SUCCESS;
1357
+ *t = tn;
1358
+ N_VScale(ONE, zn[0], yout);
1359
+ next_q = qprime;
1360
+ next_h = hprime;
1361
+ break;
1362
+ }
1363
+ CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tn;
1364
+ CVMEM cvode_step_fraction = (tn - t0) / (tout - t0);
1365
+ /*
1366
+ CVMEM warning_msg(CVMEM sformatf("ODE: tn %e, t0 %e, tout %e, step_frac %e\n", (double) tn, (double) t0, (double) tout, (double) cvode_step_fraction));
1367
+ */
1368
+ /* Check if tout reached, and if so interpolate and exit loop */
1369
+
1370
+ if ((tn - tout) * h >= ZERO)
1371
+ {
1372
+ /*
1373
+ CVMEM warning_msg("*tn %e, t0 %e, tout %e, h %e\n", tn, t0, tout,h).c_str());
1374
+ */
1375
+ CVMEM cvode_rate_sim_time = CVMEM cvode_rate_sim_time_start + tout;
1376
+ CVMEM cvode_step_fraction = 1.0;
1377
+ istate = SUCCESS;
1378
+ *t = tout;
1379
+ (void) CVodeDky(cv_mem, tout, 0, yout);
1380
+ next_q = qprime;
1381
+ next_h = hprime;
1382
+ break;
1383
+ }
1384
+ }
1385
+
1386
+ /* End of step loop; load optional outputs and return */
1387
+
1388
+ if (iopt != NULL)
1389
+ {
1390
+ iopt[NST] = nst;
1391
+ iopt[NFE] = nfe;
1392
+ iopt[NSETUPS] = nsetups;
1393
+ iopt[NNI] = nni;
1394
+ iopt[NCFN] = ncfn;
1395
+ iopt[NETF] = netf;
1396
+ iopt[QU] = q;
1397
+ iopt[QCUR] = next_q;
1398
+ }
1399
+
1400
+ if (ropt != NULL)
1401
+ {
1402
+ ropt[HU] = h;
1403
+ ropt[HCUR] = next_h;
1404
+ ropt[TCUR] = tn;
1405
+ ropt[TOLSF] = tolsf;
1406
+ }
1407
+ #ifdef DEBUG_CVODE
1408
+ /*
1409
+ * check interpolation
1410
+ */
1411
+ CVMEM cvode_test = TRUE;
1412
+ f(N, tn, y, ftemp, f_data);
1413
+ CVMEM cvode_test = FALSE;
1414
+ if (CVMEM cvode_error == TRUE)
1415
+ {
1416
+ //CVMEM warning_msg("End of cvode, Interpolated y Fail\n");
1417
+ fprintf(stderr, "End of cvode, Interpolated y Fail\n");
1418
+ return (-1);
1419
+ }
1420
+ else
1421
+ {
1422
+ //CVMEM warning_msg("End of cvode, Interpolated y OK\n");
1423
+ //fprintf(stderr, "End of cvode, Interpolated y OK\n");
1424
+ //for (int i = 0; i <= N; i++)
1425
+ //{
1426
+ // fprintf(stderr, "%d %e\n", i, Ith(y, i));
1427
+ //}
1428
+ }
1429
+ #endif
1430
+ return (istate);
1431
+ }
1432
+
1433
+ /*************** CVodeDky ********************************************
1434
+
1435
+ This routine computes the k-th derivative of the interpolating
1436
+ polynomial at the time t and stores the result in the vector dky.
1437
+ The formula is:
1438
+ q
1439
+ dky = SUM c(j,k) * (t - tn)^(j-k) * h^(-j) * zn[j] ,
1440
+ j=k
1441
+ where c(j,k) = j*(j-1)*...*(j-k+1), q is the current order, and
1442
+ zn[j] is the j-th column of the Nordsieck history array.
1443
+
1444
+ This function is called by CVode with k = 0 and t = tout, but
1445
+ may also be called directly by the user.
1446
+
1447
+ **********************************************************************/
1448
+
1449
+ int
1450
+ CVodeDky(void *cvode_mem, realtype t, int k, N_Vector dky)
1451
+ {
1452
+ realtype s, c, r;
1453
+ realtype tfuzz, tp, tn1;
1454
+ int i, j;
1455
+ CVodeMem cv_mem;
1456
+
1457
+ cv_mem = (CVodeMem) cvode_mem;
1458
+
1459
+ /* Check all inputs for legality */
1460
+
1461
+ if (cvode_mem == NULL)
1462
+ {
1463
+ /*
1464
+ CVMEM warning_msg(MSG_DKY_NO_MEM);
1465
+ */
1466
+ return (DKY_NO_MEM);
1467
+ }
1468
+
1469
+ if (dky == NULL)
1470
+ {
1471
+ CVMEM warning_msg(MSG_BAD_DKY);
1472
+ return (BAD_DKY);
1473
+ }
1474
+
1475
+ if ((k < 0) || (k > q))
1476
+ {
1477
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_K, k));
1478
+ return (BAD_K);
1479
+ }
1480
+
1481
+ tfuzz = FUZZ_FACTOR * uround * (ABS(tn) + ABS(hu));
1482
+ if (hu < ZERO)
1483
+ tfuzz = -tfuzz;
1484
+ tp = tn - hu - tfuzz;
1485
+ tn1 = tn + tfuzz;
1486
+ if ((t - tp) * (t - tn1) > ZERO)
1487
+ {
1488
+ CVMEM warning_msg(CVMEM sformatf(MSG_BAD_T, (double) t, (double) (tn - hu),
1489
+ (double) tn));
1490
+ return (BAD_T);
1491
+ }
1492
+
1493
+ /* Sum the differentiated interpolating polynomial */
1494
+
1495
+ s = (t - tn) / h;
1496
+ for (j = q; j >= k; j--)
1497
+ {
1498
+ c = ONE;
1499
+ for (i = j; i >= j - k + 1; i--)
1500
+ c *= i;
1501
+ if (j == q)
1502
+ {
1503
+ N_VScale(c, zn[q], dky);
1504
+ }
1505
+ else
1506
+ {
1507
+ N_VLinearSum(c, zn[j], s, dky, dky);
1508
+ }
1509
+ }
1510
+ if (k == 0)
1511
+ return (OKAY);
1512
+ r = RPowerI(h, -k);
1513
+ N_VScale(r, dky, dky);
1514
+ return (OKAY);
1515
+ }
1516
+
1517
+ /********************* CVodeFree **********************************
1518
+
1519
+ This routine frees the problem memory allocated by CVodeMalloc.
1520
+ Such memory includes all the vectors allocated by CVAllocVectors,
1521
+ and the memory lmem for the linear solver (deallocated by a call
1522
+ to lfree).
1523
+
1524
+ *******************************************************************/
1525
+
1526
+ void
1527
+ CVodeFree(void *cvode_mem)
1528
+ {
1529
+ CVodeMem cv_mem;
1530
+
1531
+ cv_mem = (CVodeMem) cvode_mem;
1532
+
1533
+ if (cvode_mem == NULL)
1534
+ return;
1535
+
1536
+ CVFreeVectors(cv_mem, qmax);
1537
+ if (iter == NEWTON)
1538
+ lfree(cv_mem);
1539
+ CVMEM_MALLOC PHRQ_free(cv_mem);
1540
+ }
1541
+
1542
+
1543
+ /***************************************************************/
1544
+ /********** END Exported Functions Implementation **************/
1545
+ /***************************************************************/
1546
+
1547
+
1548
+ /*******************************************************************/
1549
+ /******** BEGIN Private Helper Functions Implementation ************/
1550
+ /*******************************************************************/
1551
+
1552
+ /****************** CVAllocVectors ***********************************
1553
+
1554
+ This routine allocates the CVODE vectors ewt, acor, tempv, ftemp, and
1555
+ zn[0], ..., zn[maxord]. The length of the vectors is the input
1556
+ parameter neq and the maximum order (needed to allocate zn) is the
1557
+ input parameter maxord. If all memory allocations are successful,
1558
+ CVAllocVectors returns TRUE. Otherwise all allocated memory is freed
1559
+ and CVAllocVectors returns FALSE.
1560
+ This routine also sets the optional outputs lrw and liw, which are
1561
+ (respectively) the lengths of the real and integer work spaces
1562
+ allocated here.
1563
+
1564
+ **********************************************************************/
1565
+
1566
+ static booleantype
1567
+ CVAllocVectors(CVodeMem cv_mem, integertype neq, int maxord, M_Env machEnv)
1568
+ {
1569
+ int i, j;
1570
+
1571
+ /* Allocate ewt, acor, tempv, ftemp */
1572
+
1573
+ ewt = N_VNew(neq, machEnv);
1574
+ if (ewt == NULL)
1575
+ return (FALSE);
1576
+ acor = N_VNew(neq, machEnv);
1577
+ if (acor == NULL)
1578
+ {
1579
+ N_VFree(ewt);
1580
+ return (FALSE);
1581
+ }
1582
+ tempv = N_VNew(neq, machEnv);
1583
+ if (tempv == NULL)
1584
+ {
1585
+ N_VFree(ewt);
1586
+ N_VFree(acor);
1587
+ return (FALSE);
1588
+ }
1589
+ ftemp = N_VNew(neq, machEnv);
1590
+ if (ftemp == NULL)
1591
+ {
1592
+ N_VFree(tempv);
1593
+ N_VFree(ewt);
1594
+ N_VFree(acor);
1595
+ return (FALSE);
1596
+ }
1597
+
1598
+ /* Allocate zn[0] ... zn[maxord] */
1599
+
1600
+ for (j = 0; j <= maxord; j++)
1601
+ {
1602
+ zn[j] = N_VNew(neq, machEnv);
1603
+ if (zn[j] == NULL)
1604
+ {
1605
+ N_VFree(ewt);
1606
+ N_VFree(acor);
1607
+ N_VFree(tempv);
1608
+ N_VFree(ftemp);
1609
+ for (i = 0; i < j; i++)
1610
+ N_VFree(zn[i]);
1611
+ return (FALSE);
1612
+ }
1613
+ }
1614
+
1615
+ /* Set solver workspace lengths */
1616
+
1617
+ lrw = (maxord + 5) * neq;
1618
+ liw = 0;
1619
+
1620
+ return (TRUE);
1621
+ }
1622
+
1623
+ /***************** CVFreeVectors *********************************
1624
+
1625
+ This routine frees the CVODE vectors allocated in CVAllocVectors.
1626
+
1627
+ ******************************************************************/
1628
+
1629
+ static void
1630
+ CVFreeVectors(CVodeMem cv_mem, int maxord)
1631
+ {
1632
+ int j;
1633
+
1634
+ N_VFree(ewt);
1635
+ N_VFree(acor);
1636
+ N_VFree(tempv);
1637
+ N_VFree(ftemp);
1638
+ for (j = 0; j <= maxord; j++)
1639
+ N_VFree(zn[j]);
1640
+ }
1641
+
1642
+ /*********************** CVEwtSet **************************************
1643
+
1644
+ This routine is responsible for setting the error weight vector ewt,
1645
+ according to tol_type, as follows:
1646
+
1647
+ (1) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + *abstol), i=0,...,neq-1
1648
+ if tol_type = SS
1649
+ (2) ewt[i] = 1 / (*reltol * ABS(ycur[i]) + abstol[i]), i=0,...,neq-1
1650
+ if tol_type = SV
1651
+
1652
+ CVEwtSet returns TRUE if ewt is successfully set as above to a
1653
+ positive vector and FALSE otherwise. In the latter case, ewt is
1654
+ considered undefined after the FALSE return from CVEwtSet.
1655
+
1656
+ All the real work is done in the routines CVEwtSetSS, CVEwtSetSV.
1657
+
1658
+ ***********************************************************************/
1659
+
1660
+ static booleantype
1661
+ CVEwtSet(CVodeMem cv_mem, N_Vector ycur)
1662
+ {
1663
+ switch (itol)
1664
+ {
1665
+ case SS:
1666
+ return (CVEwtSetSS(cv_mem, ycur));
1667
+ case SV:
1668
+ return (CVEwtSetSV(cv_mem, ycur));
1669
+ }
1670
+ return (-99);
1671
+ }
1672
+
1673
+ /*********************** CVEwtSetSS *********************************
1674
+
1675
+ This routine sets ewt as described above in the case tol_type = SS.
1676
+ It tests for non-positive components before inverting. CVEwtSetSS
1677
+ returns TRUE if ewt is successfully set to a positive vector
1678
+ and FALSE otherwise. In the latter case, ewt is considered
1679
+ undefined after the FALSE return from CVEwtSetSS.
1680
+
1681
+ ********************************************************************/
1682
+
1683
+ static booleantype
1684
+ CVEwtSetSS(CVodeMem cv_mem, N_Vector ycur)
1685
+ {
1686
+ realtype rtoli, atoli;
1687
+
1688
+ rtoli = *reltol;
1689
+ atoli = *((realtype *) abstol);
1690
+ N_VAbs(ycur, tempv);
1691
+ N_VScale(rtoli, tempv, tempv);
1692
+ N_VAddConst(tempv, atoli, tempv);
1693
+ if (N_VMin(tempv) <= ZERO)
1694
+ return (FALSE);
1695
+ N_VInv(tempv, ewt);
1696
+ return (TRUE);
1697
+ }
1698
+
1699
+ /*********************** CVEwtSetSV *********************************
1700
+
1701
+ This routine sets ewt as described above in the case tol_type = SV.
1702
+ It tests for non-positive components before inverting. CVEwtSetSV
1703
+ returns TRUE if ewt is successfully set to a positive vector
1704
+ and FALSE otherwise. In the latter case, ewt is considered
1705
+ undefined after the FALSE return from CVEwtSetSV.
1706
+
1707
+ ********************************************************************/
1708
+
1709
+ static booleantype
1710
+ CVEwtSetSV(CVodeMem cv_mem, N_Vector ycur)
1711
+ {
1712
+ realtype rtoli;
1713
+ rtoli = *reltol;
1714
+ N_VAbs(ycur, tempv);
1715
+ N_VLinearSum(rtoli, tempv, ONE, (N_Vector) abstol, tempv);
1716
+ if (N_VMin(tempv) <= ZERO)
1717
+ return (FALSE);
1718
+ N_VInv(tempv, ewt);
1719
+ return (TRUE);
1720
+ }
1721
+
1722
+ /******************* CVHin ***************************************
1723
+
1724
+ This routine computes a tentative initial step size h0.
1725
+ If tout is too close to tn (= t0), then CVHin returns FALSE and
1726
+ h remains uninitialized. Otherwise, CVHin sets h to the chosen
1727
+ value h0 and returns TRUE.
1728
+
1729
+ The algorithm used seeks to find h0 as a solution of
1730
+ (WRMS norm of (h0^2 ydd / 2)) = 1,
1731
+ where ydd = estimated second derivative of y.
1732
+
1733
+ *****************************************************************/
1734
+
1735
+ static booleantype
1736
+ CVHin(CVodeMem cv_mem, realtype tout)
1737
+ {
1738
+ int sign, count;
1739
+ realtype tdiff, tdist, tround, hlb, hub;
1740
+ realtype hg, hgs, hnew, hrat, h0, yddnrm;
1741
+
1742
+ /* Test for tout too close to tn */
1743
+
1744
+ if ((tdiff = tout - tn) == ZERO)
1745
+ return (FALSE);
1746
+
1747
+ sign = (tdiff > ZERO) ? 1 : -1;
1748
+ tdist = ABS(tdiff);
1749
+ tround = uround * MAX(ABS(tn), ABS(tout));
1750
+ if (tdist < TWO * tround)
1751
+ return (FALSE);
1752
+
1753
+ /* Set lower and upper bounds on h0, and take geometric mean
1754
+ Exit with this value if the bounds cross each other */
1755
+
1756
+ hlb = HLB_FACTOR * tround;
1757
+ hub = CVUpperBoundH0(cv_mem, tdist);
1758
+ hg = RSqrt(hlb * hub);
1759
+ hnew = hg;
1760
+ if (hub < hlb)
1761
+ {
1762
+ if (sign == -1)
1763
+ hg = -hg;
1764
+ h = hg;
1765
+ return (TRUE);
1766
+ }
1767
+
1768
+ /* Loop up to MAX_ITERS times to find h0.
1769
+ Stop if new and previous values differ by a factor < 2.
1770
+ Stop if hnew/hg > 2 after one iteration, as this probably means
1771
+ that the ydd value is bad because of cancellation error. */
1772
+
1773
+ count = 0;
1774
+ loop
1775
+ {
1776
+ count++;
1777
+ if (count >= MAX_ITERS)
1778
+ break;
1779
+ hgs = hg * sign;
1780
+ yddnrm = CVYddNorm(cv_mem, hgs);
1781
+ if (CVMEM cvode_error == TRUE)
1782
+ {
1783
+ hg /= 2.;
1784
+ #ifdef DEBUG_CVODE
1785
+ CVMEM warning_msg("halving step in CVHin\n");
1786
+ #endif
1787
+ continue;
1788
+ }
1789
+
1790
+ hnew =
1791
+ (yddnrm * hub * hub >
1792
+ TWO) ? RSqrt(TWO / yddnrm) : RSqrt(hg * hub);
1793
+
1794
+ hrat = hnew / hg;
1795
+ if ((hrat > HALF) && (hrat < TWO))
1796
+ break;
1797
+ if ((count >= 2) && (hrat > TWO))
1798
+ {
1799
+ hnew = hg;
1800
+ break;
1801
+ }
1802
+ hg = hnew;
1803
+ }
1804
+
1805
+ /* Apply bounds, bias factor, and attach sign */
1806
+
1807
+ h0 = H_BIAS * hnew;
1808
+ if (h0 < hlb)
1809
+ h0 = hlb;
1810
+ if (h0 > hub)
1811
+ h0 = hub;
1812
+ if (sign == -1)
1813
+ h0 = -h0;
1814
+ h = h0;
1815
+ return (TRUE);
1816
+ }
1817
+
1818
+ /******************** CVUpperBoundH0 ******************************
1819
+
1820
+ This routine sets an upper bound on abs(h0) based on
1821
+ tdist = abs(tout - t0) and the values of y[i]/y'[i].
1822
+
1823
+ ******************************************************************/
1824
+
1825
+ static realtype
1826
+ CVUpperBoundH0(CVodeMem cv_mem, realtype tdist)
1827
+ {
1828
+ realtype atoli, hub_inv, hub;
1829
+ booleantype vectorAtol;
1830
+ N_Vector temp1, temp2;
1831
+
1832
+ atoli = 0;
1833
+ vectorAtol = (itol == SV);
1834
+ if (!vectorAtol)
1835
+ atoli = *((realtype *) abstol);
1836
+ temp1 = tempv;
1837
+ temp2 = acor;
1838
+ N_VAbs(zn[0], temp1);
1839
+ N_VAbs(zn[1], temp2);
1840
+ if (vectorAtol)
1841
+ {
1842
+ N_VLinearSum(HUB_FACTOR, temp1, ONE, (N_Vector) abstol, temp1);
1843
+ }
1844
+ else
1845
+ {
1846
+ N_VScale(HUB_FACTOR, temp1, temp1);
1847
+ N_VAddConst(temp1, atoli, temp1);
1848
+ }
1849
+ N_VDiv(temp2, temp1, temp1);
1850
+ hub_inv = N_VMaxNorm(temp1);
1851
+ hub = HUB_FACTOR * tdist;
1852
+ if (hub * hub_inv > ONE)
1853
+ hub = ONE / hub_inv;
1854
+ return (hub);
1855
+ }
1856
+
1857
+ /****************** CVYddNorm *************************************
1858
+
1859
+ This routine computes an estimate of the second derivative of y
1860
+ using a difference quotient, and returns its WRMS norm.
1861
+
1862
+ ******************************************************************/
1863
+
1864
+ static realtype
1865
+ CVYddNorm(CVodeMem cv_mem, realtype hg)
1866
+ {
1867
+ realtype yddnrm;
1868
+
1869
+ N_VLinearSum(hg, zn[1], ONE, zn[0], y);
1870
+ f(N, tn + hg, y, tempv, f_data);
1871
+ #ifdef DEBUG_CVODE
1872
+ if (cvode_error == TRUE)
1873
+ {
1874
+ CVMEM warning_msg("CVYddNorm error\n");
1875
+ }
1876
+ #endif
1877
+ nfe++;
1878
+ N_VLinearSum(ONE, tempv, -ONE, zn[1], tempv);
1879
+ N_VScale(ONE / hg, tempv, tempv);
1880
+
1881
+ yddnrm = N_VWrmsNorm(tempv, ewt);
1882
+ return (yddnrm);
1883
+ }
1884
+
1885
+ /********************* CVStep **************************************
1886
+
1887
+ This routine performs one internal cvode step, from tn to tn + h.
1888
+ It calls other routines to do all the work.
1889
+
1890
+ The main operations done here are as follows:
1891
+ * preliminary adjustments if a new step size was chosen;
1892
+ * prediction of the Nordsieck history array zn at tn + h;
1893
+ * setting of multistep method coefficients and test quantities;
1894
+ * solution of the nonlinear system;
1895
+ * testing the local error;
1896
+ * updating zn and other state data if successful;
1897
+ * resetting stepsize and order for the next step.
1898
+ * if SLDET is on, check for stability, reduce order if necessary.
1899
+ On a failure in the nonlinear system solution or error test, the
1900
+ step may be reattempted, depending on the nature of the failure.
1901
+
1902
+ ********************************************************************/
1903
+
1904
+ static int
1905
+ CVStep(CVodeMem cv_mem)
1906
+ {
1907
+ realtype saved_t, dsm;
1908
+ int ncf, nef, nflag;
1909
+ booleantype passed;
1910
+
1911
+ int kflag;
1912
+
1913
+ saved_t = tn;
1914
+ ncf = nef = 0;
1915
+ nflag = FIRST_CALL;
1916
+
1917
+
1918
+ if ((nst > 0) && (hprime != h))
1919
+ CVAdjustParams(cv_mem);
1920
+
1921
+ /* Looping point for attempts to take a step */
1922
+ loop
1923
+ {
1924
+ bool predict_fail = false;
1925
+ CVMEM cvode_test = TRUE;
1926
+ f(N, tn, y, ftemp, f_data);
1927
+ CVMEM cvode_test = FALSE;
1928
+ if (CVMEM cvode_error == TRUE)
1929
+ {
1930
+ predict_fail = true;
1931
+ #ifdef DEBUG_CVODE
1932
+ CVMEM warning_msg("Before predict, y Fail, time %e\n", tn);
1933
+ #endif
1934
+ }
1935
+ else
1936
+ {
1937
+ CVMEM cvode_prev_good_time = CVMEM cvode_last_good_time;
1938
+ N_VScale(1.0, CVMEM cvode_last_good_y, CVMEM cvode_prev_good_y);
1939
+ CVMEM cvode_last_good_time = tn;
1940
+ N_VScale(1.0, y, CVMEM cvode_last_good_y);
1941
+ #ifdef DEBUG_CVODE
1942
+ CVMEM warning_msg("Before predict, y OK, time %e\n", tn);
1943
+ #endif
1944
+ }
1945
+ #ifdef DEBUG_CVODE
1946
+ cvode_test = TRUE;
1947
+ f(N, tn, zn[0], ftemp, f_data);
1948
+ cvode_test = FALSE;
1949
+ if (cvode_error == TRUE)
1950
+ {
1951
+ CVMEM warning_msg("Before predict, zn Fail\n");
1952
+ }
1953
+ else
1954
+ {
1955
+ CVMEM warning_msg("Before predict, zn OK\n");
1956
+ }
1957
+ saved_t = tn;
1958
+ #endif
1959
+ CVPredict(cv_mem);
1960
+ #ifdef DEBUG_CVODE
1961
+ cvode_test = TRUE;
1962
+ f(N, tn, y, ftemp, f_data);
1963
+ cvode_test = FALSE;
1964
+ if (cvode_error == TRUE)
1965
+ {
1966
+ CVMEM warning_msg("After predict, y Fail\n");
1967
+ }
1968
+ else
1969
+ {
1970
+ CVMEM warning_msg("After predict, y OK\n");
1971
+ }
1972
+ cvode_test = TRUE;
1973
+ f(N, tn, zn[0], ftemp, f_data);
1974
+ cvode_test = FALSE;
1975
+ if (cvode_error == TRUE)
1976
+ {
1977
+ CVMEM warning_msg("After predict, zn Fail\n");
1978
+
1979
+ }
1980
+ else
1981
+ {
1982
+ CVMEM warning_msg("After predict, zn OK\n");
1983
+ }
1984
+ #endif
1985
+ CVSet(cv_mem);
1986
+ nflag = CVnls(cv_mem, nflag);
1987
+ if (CVMEM cvode_error == TRUE || predict_fail)
1988
+ {
1989
+ nflag = -1;
1990
+ }
1991
+ #ifdef DEBUG_CVODE
1992
+ cvode_test = TRUE;
1993
+ f(N, tn, y, ftemp, f_data);
1994
+ cvode_test = FALSE;
1995
+ if (cvode_error == TRUE)
1996
+ {
1997
+ CVMEM warning_msg("After CVnls, y Fail\n");
1998
+ }
1999
+ else
2000
+ {
2001
+ CVMEM warning_msg("After CVnls, y OK\n");
2002
+ }
2003
+ cvode_test = TRUE;
2004
+ f(N, tn, zn[0], ftemp, f_data);
2005
+ cvode_test = FALSE;
2006
+ if (cvode_error == TRUE)
2007
+ {
2008
+ CVMEM warning_msg("After CVnls, zn Fail\n");
2009
+ }
2010
+ else
2011
+ {
2012
+ CVMEM warning_msg("After CVnls, zn OK\n");
2013
+ }
2014
+ #endif
2015
+ //fprintf(stderr, "\nTime %e,\th %e\n", tn, h);
2016
+ kflag = CVHandleNFlag(cv_mem, &nflag, saved_t, &ncf);
2017
+ if (kflag == PREDICT_AGAIN)
2018
+ continue;
2019
+ if (kflag != DO_ERROR_TEST)
2020
+ return (kflag);
2021
+ /* Return if nonlinear solve failed and recovery not possible. */
2022
+ #ifdef DEBUG_CVODE
2023
+ cvode_test = TRUE;
2024
+ f(N, tn, y, ftemp, f_data);
2025
+ cvode_test = FALSE;
2026
+ if (cvode_error == TRUE)
2027
+ {
2028
+ CVMEM warning_msg("Before error test, y Fail\n");
2029
+ }
2030
+ else
2031
+ {
2032
+ CVMEM warning_msg("Before error test, y OK\n");
2033
+ }
2034
+ cvode_test = TRUE;
2035
+ f(N, tn, zn[0], ftemp, f_data);
2036
+ cvode_test = FALSE;
2037
+ if (cvode_error == TRUE)
2038
+ {
2039
+ CVMEM warning_msg("Before error test, zn Fail\n");
2040
+ }
2041
+ else
2042
+ {
2043
+ CVMEM warning_msg("Before error test, zn OK\n");
2044
+ }
2045
+ #endif
2046
+ passed = CVDoErrorTest(cv_mem, &nflag, &kflag, saved_t, &nef, &dsm);
2047
+ #ifdef DEBUG_CVODE
2048
+ cvode_test = TRUE;
2049
+ f(N, tn, y, ftemp, f_data);
2050
+ cvode_test = FALSE;
2051
+ if (cvode_error == TRUE)
2052
+ {
2053
+ CVMEM warning_msg(CVMEM sformatf("After error test, y Fail, passed %d\n",
2054
+ passed));
2055
+ }
2056
+ else
2057
+ {
2058
+ CVMEM warning_msg(CVMEM sformatf("After error test, y OK, passed %d\n",
2059
+ passed));
2060
+ }
2061
+ cvode_test = TRUE;
2062
+ f(N, tn, zn[0], ftemp, f_data);
2063
+ cvode_test = FALSE;
2064
+ if (cvode_error == TRUE)
2065
+ {
2066
+ CVMEM warning_msg("After error test, zn Fail\n");
2067
+ }
2068
+ else
2069
+ {
2070
+ CVMEM warning_msg("After error test, zn OK\n");
2071
+ }
2072
+ #endif
2073
+ /* Return if error test failed and recovery not possible. */
2074
+ if ((!passed) && (kflag == REP_ERR_FAIL))
2075
+ return (kflag);
2076
+ if (passed)
2077
+ break;
2078
+ /* Retry step if error test failed, nflag == PREV_ERR_FAIL */
2079
+ }
2080
+ #ifdef DEBUG_CVODE
2081
+ CVMEM warning_msg("Finished step in CVStep\n");
2082
+ #endif
2083
+ /* Nonlinear system solve and error test were both successful.
2084
+ Update data, and consider change of step and/or order. */
2085
+
2086
+
2087
+ CVCompleteStep(cv_mem);
2088
+ #ifdef DEBUG_CVODE
2089
+ CVMEM cvode_test = TRUE;
2090
+ f(N, tn, y, ftemp, f_data);
2091
+ CVMEM cvode_test = FALSE;
2092
+ if (CVMEM cvode_error == TRUE)
2093
+ {
2094
+ CVMEM warning_msg("After complete step, y Fail\n");
2095
+ }
2096
+ else
2097
+ {
2098
+ CVMEM warning_msg("After complete step, y OK\n");
2099
+ }
2100
+ CVMEM cvode_test = TRUE;
2101
+ f(N, tn, zn[0], ftemp, f_data);
2102
+ CVMEM cvode_test = FALSE;
2103
+ if (CVMEM cvode_error == TRUE)
2104
+ {
2105
+ CVMEM warning_msg("After complete step, zn Fail\n");
2106
+ }
2107
+ else
2108
+ {
2109
+ CVMEM warning_msg("After complete step, zn OK\n");
2110
+ }
2111
+ #endif
2112
+ CVPrepareNextStep(cv_mem, dsm);
2113
+
2114
+ /* If Stablilty Limit Detection is turned on, call stability limit
2115
+ detection routine for possible order reduction. */
2116
+
2117
+ if (sldeton)
2118
+ CVBDFStab(cv_mem);
2119
+ #ifdef DEBUG_CVODE
2120
+ cvode_test = TRUE;
2121
+ f(N, tn, y, ftemp, f_data);
2122
+ cvode_test = FALSE;
2123
+ if (cvode_error == TRUE)
2124
+ {
2125
+ CVMEM warning_msg("After cvbfdstab, y Fail\n");
2126
+ }
2127
+ else
2128
+ {
2129
+ CVMEM warning_msg("After cvbfdstab, y OK\n");
2130
+ }
2131
+ cvode_test = TRUE;
2132
+ f(N, tn, zn[0], ftemp, f_data);
2133
+ cvode_test = FALSE;
2134
+ if (cvode_error == TRUE)
2135
+ {
2136
+ CVMEM warning_msg("After cvbfdstab, zn Fail\n");
2137
+ }
2138
+ else
2139
+ {
2140
+ CVMEM warning_msg("After cvbfdstab, zn OK\n");
2141
+ }
2142
+ #endif
2143
+ etamax = (nst <= SMALL_NST) ? ETAMX2 : ETAMX3;
2144
+
2145
+ /* Finally, we rescale the acor array to be the
2146
+ estimated local error vector. */
2147
+
2148
+ N_VScale(ONE / tq[2], acor, acor);
2149
+ return (SUCCESS_STEP);
2150
+
2151
+ }
2152
+
2153
+
2154
+ /********************* CVAdjustParams ********************************
2155
+
2156
+ This routine is called when a change in step size was decided upon,
2157
+ and it handles the required adjustments to the history array zn.
2158
+ If there is to be a change in order, we call CVAdjustOrder and reset
2159
+ q, L = q+1, and qwait. Then in any case, we call CVRescale, which
2160
+ resets h and rescales the Nordsieck array.
2161
+
2162
+ **********************************************************************/
2163
+
2164
+ static void
2165
+ CVAdjustParams(CVodeMem cv_mem)
2166
+ {
2167
+ if (qprime != q)
2168
+ {
2169
+ CVAdjustOrder(cv_mem, qprime - q);
2170
+ q = qprime;
2171
+ L = q + 1;
2172
+ qwait = L;
2173
+ }
2174
+ CVRescale(cv_mem);
2175
+ }
2176
+
2177
+ /********************* CVAdjustOrder *****************************
2178
+
2179
+ This routine is a high level routine which handles an order
2180
+ change by an amount deltaq (= +1 or -1). If a decrease in order
2181
+ is requested and q==2, then the routine returns immediately.
2182
+ Otherwise CVAdjustAdams or CVAdjustBDF is called to handle the
2183
+ order change (depending on the value of lmm).
2184
+
2185
+ ******************************************************************/
2186
+
2187
+ static void
2188
+ CVAdjustOrder(CVodeMem cv_mem, int deltaq)
2189
+ {
2190
+ if ((q == 2) && (deltaq != 1))
2191
+ return;
2192
+
2193
+ switch (lmm)
2194
+ {
2195
+ case ADAMS:
2196
+ CVAdjustAdams(cv_mem, deltaq);
2197
+ break;
2198
+ case BDF:
2199
+ CVAdjustBDF(cv_mem, deltaq);
2200
+ break;
2201
+ }
2202
+ }
2203
+
2204
+ /*************** CVAdjustAdams ***********************************
2205
+
2206
+ This routine adjusts the history array on a change of order q by
2207
+ deltaq, in the case that lmm == ADAMS.
2208
+
2209
+ *****************************************************************/
2210
+
2211
+ static void
2212
+ CVAdjustAdams(CVodeMem cv_mem, int deltaq)
2213
+ {
2214
+ int i, j;
2215
+ realtype xi, hsum;
2216
+
2217
+ /* On an order increase, set new column of zn to zero and return */
2218
+
2219
+ if (deltaq == 1)
2220
+ {
2221
+ N_VConst(ZERO, zn[L]);
2222
+ return;
2223
+ }
2224
+
2225
+ /* On an order decrease, each zn[j] is adjusted by a multiple
2226
+ of zn[q]. The coefficients in the adjustment are the
2227
+ coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_j),
2228
+ integrated, where xi_j = [t_n - t_(n-j)]/h. */
2229
+
2230
+ for (i = 0; i <= qmax; i++)
2231
+ l[i] = ZERO;
2232
+ l[1] = ONE;
2233
+ hsum = ZERO;
2234
+ for (j = 1; j <= q - 2; j++)
2235
+ {
2236
+ hsum += tau[j];
2237
+ xi = hsum / hscale;
2238
+ for (i = j + 1; i >= 1; i--)
2239
+ l[i] = l[i] * xi + l[i - 1];
2240
+ }
2241
+
2242
+ for (j = 1; j <= q - 2; j++)
2243
+ l[j + 1] = q * (l[j] / (j + 1));
2244
+
2245
+ for (j = 2; j < q; j++)
2246
+ N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]);
2247
+ }
2248
+
2249
+ /********************** CVAdjustBDF *******************************
2250
+
2251
+ This is a high level routine which handles adjustments to the
2252
+ history array on a change of order by deltaq in the case that
2253
+ lmm == BDF. CVAdjustBDF calls CVIncreaseBDF if deltaq = +1 and
2254
+ CVDecreaseBDF if deltaq = -1 to do the actual work.
2255
+
2256
+ ******************************************************************/
2257
+
2258
+ static void
2259
+ CVAdjustBDF(CVodeMem cv_mem, int deltaq)
2260
+ {
2261
+ switch (deltaq)
2262
+ {
2263
+ case 1:
2264
+ CVIncreaseBDF(cv_mem);
2265
+ return;
2266
+ case -1:
2267
+ CVDecreaseBDF(cv_mem);
2268
+ return;
2269
+ }
2270
+ }
2271
+
2272
+ /******************** CVIncreaseBDF **********************************
2273
+
2274
+ This routine adjusts the history array on an increase in the
2275
+ order q in the case that lmm == BDF.
2276
+ A new column zn[q+1] is set equal to a multiple of the saved
2277
+ vector (= acor) in zn[qmax]. Then each zn[j] is adjusted by
2278
+ a multiple of zn[q+1]. The coefficients in the adjustment are the
2279
+ coefficients of the polynomial x*x*(x+xi_1)*...*(x+xi_(q-1)),
2280
+ where xi_j = [t_n - t_(n-j)]/h.
2281
+
2282
+ *********************************************************************/
2283
+
2284
+ static void
2285
+ CVIncreaseBDF(CVodeMem cv_mem)
2286
+ {
2287
+ realtype alpha0, alpha1, prod, xi, xiold, hsum, A1;
2288
+ int i, j;
2289
+
2290
+ for (i = 0; i <= qmax; i++)
2291
+ l[i] = ZERO;
2292
+ l[2] = alpha1 = prod = xiold = ONE;
2293
+ alpha0 = -ONE;
2294
+ hsum = hscale;
2295
+ if (q > 1)
2296
+ {
2297
+ for (j = 1; j < q; j++)
2298
+ {
2299
+ hsum += tau[j + 1];
2300
+ xi = hsum / hscale;
2301
+ prod *= xi;
2302
+ alpha0 -= ONE / (j + 1);
2303
+ alpha1 += ONE / xi;
2304
+ for (i = j + 2; i >= 2; i--)
2305
+ l[i] = l[i] * xiold + l[i - 1];
2306
+ xiold = xi;
2307
+ }
2308
+ }
2309
+ A1 = (-alpha0 - alpha1) / prod;
2310
+ if (L >= 0 && L <= qmax)
2311
+ {
2312
+ N_VScale(A1, zn[qmax], zn[L]);
2313
+ for (j = 2; j <= q; j++)
2314
+ {
2315
+ N_VLinearSum(l[j], zn[L], ONE, zn[j], zn[j]);
2316
+ }
2317
+ }
2318
+ }
2319
+
2320
+ /********************* CVDecreaseBDF ******************************
2321
+
2322
+ This routine adjusts the history array on a decrease in the
2323
+ order q in the case that lmm == BDF.
2324
+ Each zn[j] is adjusted by a multiple of zn[q]. The coefficients
2325
+ in the adjustment are the coefficients of the polynomial
2326
+ x*x*(x+xi_1)*...*(x+xi_(q-2)), where xi_j = [t_n - t_(n-j)]/h.
2327
+
2328
+ ******************************************************************/
2329
+
2330
+ static void
2331
+ CVDecreaseBDF(CVodeMem cv_mem)
2332
+ {
2333
+ realtype hsum, xi;
2334
+ int i, j;
2335
+
2336
+ for (i = 0; i <= qmax; i++)
2337
+ l[i] = ZERO;
2338
+ l[2] = ONE;
2339
+ hsum = ZERO;
2340
+ for (j = 1; j <= q - 2; j++)
2341
+ {
2342
+ hsum += tau[j];
2343
+ xi = hsum / hscale;
2344
+ for (i = j + 2; i >= 2; i--)
2345
+ l[i] = l[i] * xi + l[i - 1];
2346
+ }
2347
+
2348
+ for (j = 2; j < q; j++)
2349
+ N_VLinearSum(-l[j], zn[q], ONE, zn[j], zn[j]);
2350
+ }
2351
+
2352
+ /**************** CVRescale ***********************************
2353
+
2354
+ This routine rescales the Nordsieck array by multiplying the
2355
+ jth column zn[j] by eta^j, j = 1, ..., q. Then the value of
2356
+ h is rescaled by eta, and hscale is reset to h.
2357
+
2358
+ ***************************************************************/
2359
+
2360
+ static void
2361
+ CVRescale(CVodeMem cv_mem)
2362
+ {
2363
+ int j;
2364
+ realtype factor;
2365
+
2366
+ factor = eta;
2367
+ for (j = 1; j <= q; j++)
2368
+ {
2369
+ N_VScale(factor, zn[j], zn[j]);
2370
+ factor *= eta;
2371
+ }
2372
+ h = hscale * eta;
2373
+ hscale = h;
2374
+ nscon = 0;
2375
+ }
2376
+
2377
+ /********************* CVPredict *************************************
2378
+
2379
+ This routine advances tn by the tentative step size h, and computes
2380
+ the predicted array z_n(0), which is overwritten on zn. The
2381
+ prediction of zn is done by repeated additions.
2382
+
2383
+ *********************************************************************/
2384
+
2385
+ static void
2386
+ CVPredict(CVodeMem cv_mem)
2387
+ {
2388
+ int j, k;
2389
+
2390
+ tn += h;
2391
+ for (k = 1; k <= q; k++)
2392
+ for (j = q; j >= k; j--)
2393
+ N_VLinearSum(ONE, zn[j - 1], ONE, zn[j], zn[j - 1]);
2394
+ }
2395
+
2396
+ /************************** CVSet *********************************
2397
+
2398
+ This routine is a high level routine which calls CVSetAdams or
2399
+ CVSetBDF to set the polynomial l, the test quantity array tq,
2400
+ and the related variables rl1, gamma, and gamrat.
2401
+
2402
+ ******************************************************************/
2403
+
2404
+ static void
2405
+ CVSet(CVodeMem cv_mem)
2406
+ {
2407
+ switch (lmm)
2408
+ {
2409
+ case ADAMS:
2410
+ CVSetAdams(cv_mem);
2411
+ break;
2412
+ case BDF:
2413
+ CVSetBDF(cv_mem);
2414
+ break;
2415
+ }
2416
+ rl1 = ONE / l[1];
2417
+ gamma = h * rl1;
2418
+ if (nst == 0)
2419
+ gammap = gamma;
2420
+ gamrat = (nst > 0) ? gamma / gammap : ONE; /* protect x / x != 1.0 */
2421
+ }
2422
+
2423
+ /******************** CVSetAdams *********************************
2424
+
2425
+ This routine handles the computation of l and tq for the
2426
+ case lmm == ADAMS.
2427
+
2428
+ The components of the array l are the coefficients of a
2429
+ polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by
2430
+ q-1
2431
+ (d/dx) Lambda(x) = c * PRODUCT (1 + x / xi_i) , where
2432
+ i=1
2433
+ Lambda(-1) = 0, Lambda(0) = 1, and c is a normalization factor.
2434
+ Here xi_i = [t_n - t_(n-i)] / h.
2435
+
2436
+ The array tq is set to test quantities used in the convergence
2437
+ test, the error test, and the selection of h at a new order.
2438
+
2439
+ *****************************************************************/
2440
+
2441
+ static void
2442
+ CVSetAdams(CVodeMem cv_mem)
2443
+ {
2444
+ realtype m[L_MAX], M[3], hsum;
2445
+
2446
+ if (q == 1)
2447
+ {
2448
+ l[0] = l[1] = tq[1] = tq[5] = ONE;
2449
+ tq[2] = TWO;
2450
+ tq[3] = TWELVE;
2451
+ tq[4] = CORTES * tq[2]; /* = 0.1 * tq[2] */
2452
+ return;
2453
+ }
2454
+
2455
+ hsum = CVAdamsStart(cv_mem, m);
2456
+
2457
+ M[0] = CVAltSum(q - 1, m, 1);
2458
+ M[1] = CVAltSum(q - 1, m, 2);
2459
+
2460
+ CVAdamsFinish(cv_mem, m, M, hsum);
2461
+ }
2462
+
2463
+ /****************** CVAdamsStart ********************************
2464
+
2465
+ This routine generates in m[] the coefficients of the product
2466
+ polynomial needed for the Adams l and tq coefficients for q > 1.
2467
+
2468
+ ******************************************************************/
2469
+
2470
+ static realtype
2471
+ CVAdamsStart(CVodeMem cv_mem, realtype m[])
2472
+ {
2473
+ realtype hsum, xi_inv, sum;
2474
+ int i, j;
2475
+
2476
+ hsum = h;
2477
+ m[0] = ONE;
2478
+ for (i = 1; i <= q; i++)
2479
+ m[i] = ZERO;
2480
+ for (j = 1; j < q; j++)
2481
+ {
2482
+ if ((j == q - 1) && (qwait == 1))
2483
+ {
2484
+ sum = CVAltSum(q - 2, m, 2);
2485
+ tq[1] = m[q - 2] / (q * sum);
2486
+ }
2487
+ xi_inv = h / hsum;
2488
+ for (i = j; i >= 1; i--)
2489
+ m[i] += m[i - 1] * xi_inv;
2490
+ hsum += tau[j];
2491
+ /* The m[i] are coefficients of product(1 to j) (1 + x/xi_i) */
2492
+ }
2493
+ return (hsum);
2494
+ }
2495
+
2496
+ /****************** CVAdamsFinish *******************************
2497
+
2498
+ This routine completes the calculation of the Adams l and tq.
2499
+
2500
+ ******************************************************************/
2501
+
2502
+ static void
2503
+ CVAdamsFinish(CVodeMem cv_mem, realtype m[], realtype M[], realtype hsum)
2504
+ {
2505
+ int i;
2506
+ realtype M0_inv, xi, xi_inv;
2507
+
2508
+ M0_inv = ONE / M[0];
2509
+
2510
+ l[0] = ONE;
2511
+ for (i = 1; i <= q; i++)
2512
+ l[i] = M0_inv * (m[i - 1] / i);
2513
+ xi = hsum / h;
2514
+ xi_inv = ONE / xi;
2515
+
2516
+ tq[2] = xi * M[0] / M[1];
2517
+ tq[5] = xi / l[q];
2518
+
2519
+ if (qwait == 1)
2520
+ {
2521
+ for (i = q; i >= 1; i--)
2522
+ m[i] += m[i - 1] * xi_inv;
2523
+ M[2] = CVAltSum(q, m, 2);
2524
+ tq[3] = L * M[0] / M[2];
2525
+ }
2526
+
2527
+ tq[4] = CORTES * tq[2];
2528
+ }
2529
+
2530
+ /****************** CVAltSum **************************************
2531
+
2532
+ CVAltSum returns the value of the alternating sum
2533
+ sum (i= 0 ... iend) [ (-1)^i * (a[i] / (i + k)) ].
2534
+ If iend < 0 then CVAltSum returns 0.
2535
+ This operation is needed to compute the integral, from -1 to 0,
2536
+ of a polynomial x^(k-1) M(x) given the coefficients of M(x).
2537
+
2538
+ ******************************************************************/
2539
+
2540
+ static realtype
2541
+ CVAltSum(int iend, realtype a[], int k)
2542
+ {
2543
+ int i, sign;
2544
+ realtype sum;
2545
+
2546
+ if (iend < 0)
2547
+ return (ZERO);
2548
+
2549
+ sum = ZERO;
2550
+ sign = 1;
2551
+ for (i = 0; i <= iend; i++)
2552
+ {
2553
+ sum += sign * (a[i] / (i + k));
2554
+ sign = -sign;
2555
+ }
2556
+ return (sum);
2557
+ }
2558
+
2559
+ /***************** CVSetBDF **************************************
2560
+
2561
+ This routine computes the coefficients l and tq in the case
2562
+ lmm == BDF. CVSetBDF calls CVSetTqBDF to set the test
2563
+ quantity array tq.
2564
+
2565
+ The components of the array l are the coefficients of a
2566
+ polynomial Lambda(x) = l_0 + l_1 x + ... + l_q x^q, given by
2567
+ q-1
2568
+ Lambda(x) = (1 + x / xi*_q) * PRODUCT (1 + x / xi_i) , where
2569
+ i=1
2570
+ xi_i = [t_n - t_(n-i)] / h.
2571
+
2572
+ The array tq is set to test quantities used in the convergence
2573
+ test, the error test, and the selection of h at a new order.
2574
+
2575
+
2576
+ *****************************************************************/
2577
+
2578
+ static void
2579
+ CVSetBDF(CVodeMem cv_mem)
2580
+ {
2581
+ realtype alpha0, alpha0_hat, xi_inv, xistar_inv, hsum;
2582
+ int i, j;
2583
+
2584
+ l[0] = l[1] = xi_inv = xistar_inv = ONE;
2585
+ for (i = 2; i <= q; i++)
2586
+ l[i] = ZERO;
2587
+ alpha0 = alpha0_hat = -ONE;
2588
+ hsum = h;
2589
+ if (q > 1)
2590
+ {
2591
+ for (j = 2; j < q; j++)
2592
+ {
2593
+ hsum += tau[j - 1];
2594
+ xi_inv = h / hsum;
2595
+ alpha0 -= ONE / j;
2596
+ for (i = j; i >= 1; i--)
2597
+ l[i] += l[i - 1] * xi_inv;
2598
+ /* The l[i] are coefficients of product(1 to j) (1 + x/xi_i) */
2599
+ }
2600
+
2601
+ /* j = q */
2602
+ alpha0 -= ONE / q;
2603
+ xistar_inv = -l[1] - alpha0;
2604
+ hsum += tau[q - 1];
2605
+ xi_inv = h / hsum;
2606
+ alpha0_hat = -l[1] - xi_inv;
2607
+ for (i = q; i >= 1; i--)
2608
+ l[i] += l[i - 1] * xistar_inv;
2609
+ }
2610
+
2611
+ CVSetTqBDF(cv_mem, hsum, alpha0, alpha0_hat, xi_inv, xistar_inv);
2612
+ }
2613
+
2614
+ /****************** CVSetTqBDF ************************************
2615
+
2616
+ This routine sets the test quantity array tq when lmm == BDF.
2617
+
2618
+ ******************************************************************/
2619
+
2620
+ static void
2621
+ CVSetTqBDF(CVodeMem cv_mem, realtype hsum, realtype alpha0,
2622
+ realtype alpha0_hat, realtype xi_inv, realtype xistar_inv)
2623
+ {
2624
+ realtype A1, A2, A3, A4, A5, A6;
2625
+ realtype C, CPrime, CPrimePrime;
2626
+
2627
+ A1 = ONE - alpha0_hat + alpha0;
2628
+ A2 = ONE + q * A1;
2629
+ tq[2] = ABS(alpha0 * (A2 / A1));
2630
+ tq[5] = ABS((A2) / (l[q] * xi_inv / xistar_inv));
2631
+ if (qwait == 1)
2632
+ {
2633
+ C = xistar_inv / l[q];
2634
+ A3 = alpha0 + ONE / q;
2635
+ A4 = alpha0_hat + xi_inv;
2636
+ CPrime = A3 / (ONE - A4 + A3);
2637
+ tq[1] = ABS(CPrime / C);
2638
+ hsum += tau[q];
2639
+ xi_inv = h / hsum;
2640
+ A5 = alpha0 - (ONE / (q + 1));
2641
+ A6 = alpha0_hat - xi_inv;
2642
+ CPrimePrime = A2 / (ONE - A6 + A5);
2643
+ tq[3] = ABS(CPrimePrime * xi_inv * (q + 2) * A5);
2644
+ }
2645
+ tq[4] = CORTES * tq[2];
2646
+ }
2647
+
2648
+ /****************** CVnls *****************************************
2649
+
2650
+ This routine attempts to solve the nonlinear system associated
2651
+ with a single implicit step of the linear multistep method.
2652
+ Depending on iter, it calls CVnlsFunctional or CVnlsNewton
2653
+ to do the work.
2654
+
2655
+ ******************************************************************/
2656
+
2657
+ static int
2658
+ CVnls(CVodeMem cv_mem, int nflag)
2659
+ {
2660
+ switch (iter)
2661
+ {
2662
+ case FUNCTIONAL:
2663
+ return (CVnlsFunctional(cv_mem));
2664
+ case NEWTON:
2665
+ return (CVnlsNewton(cv_mem, nflag));
2666
+ }
2667
+ return (-99);
2668
+ }
2669
+
2670
+ /***************** CVnlsFunctional ********************************
2671
+
2672
+ This routine attempts to solve the nonlinear system using
2673
+ functional iteration (no matrices involved).
2674
+
2675
+ ******************************************************************/
2676
+
2677
+ static int
2678
+ CVnlsFunctional(CVodeMem cv_mem)
2679
+ {
2680
+ int m;
2681
+ realtype del, delp, dcon;
2682
+
2683
+ /* Initialize counter and evaluate f at predicted y */
2684
+
2685
+ delp = 0;
2686
+ crate = ONE;
2687
+ m = 0;
2688
+ f(N, tn, zn[0], tempv, f_data);
2689
+ nfe++;
2690
+ if (CVMEM cvode_error == TRUE)
2691
+ {
2692
+ #ifdef DEBUG_CVODE
2693
+ CVMEM warning_msg("CVnlsFunctional, Fail at beginning\n");
2694
+ #endif
2695
+ return (CONV_FAIL);
2696
+ }
2697
+ else
2698
+ {
2699
+ #ifdef DEBUG_CVODE
2700
+ CVMEM warning_msg("CVnlsFunctional, OK at beginning\n");
2701
+ #endif
2702
+ }
2703
+ N_VConst(ZERO, acor);
2704
+
2705
+ /* Loop until convergence; accumulate corrections in acor */
2706
+
2707
+ loop
2708
+ {
2709
+ /* Correct y directly from the last f value */
2710
+ N_VLinearSum(h, tempv, -ONE, zn[1], tempv);
2711
+ N_VScale(rl1, tempv, tempv);
2712
+ N_VLinearSum(ONE, zn[0], ONE, tempv, y);
2713
+ /* Get WRMS norm of current correction to use in convergence test */
2714
+ N_VLinearSum(ONE, tempv, -ONE, acor, acor);
2715
+ del = N_VWrmsNorm(acor, ewt);
2716
+ N_VScale(ONE, tempv, acor);
2717
+
2718
+ /* Test for convergence. If m > 0, an estimate of the convergence
2719
+ rate constant is stored in crate, and used in the test. */
2720
+ if (m > 0)
2721
+ crate = MAX(CRDOWN * crate, del / delp);
2722
+ dcon = del * MIN(ONE, crate) / tq[4];
2723
+ if (dcon <= ONE)
2724
+ {
2725
+ acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt);
2726
+ return (SOLVED); /* Convergence achieved */
2727
+ }
2728
+
2729
+ /* Stop at maxcor iterations or if iter. seems to be diverging */
2730
+ m++;
2731
+ if ((m == maxcor) || ((m >= 2) && (del > RDIV * delp)))
2732
+ return (CONV_FAIL);
2733
+ /* Save norm of correction, evaluate f, and loop again */
2734
+ delp = del;
2735
+ f(N, tn, y, tempv, f_data);
2736
+ if (CVMEM cvode_error == TRUE)
2737
+ {
2738
+ #ifdef DEBUG_CVODE
2739
+ CVMEM warning_msg("CVnlsFunctional, Fail at end\n");
2740
+ #endif
2741
+ return (CONV_FAIL);
2742
+ }
2743
+ else
2744
+ {
2745
+ #ifdef DEBUG_CVODE
2746
+ CVMEM warning_msg("CVnlsFunctional, OK at end\n");
2747
+ #endif
2748
+ }
2749
+ nfe++;
2750
+ }
2751
+ }
2752
+
2753
+ /*********************** CVnlsNewton **********************************
2754
+
2755
+ This routine handles the Newton iteration. It calls lsetup if
2756
+ indicated, calls CVNewtonIteration to perform the iteration, and
2757
+ retries a failed attempt at Newton iteration if that is indicated.
2758
+ See return values at top of this file.
2759
+
2760
+ **********************************************************************/
2761
+
2762
+ static int
2763
+ CVnlsNewton(CVodeMem cv_mem, int nflag)
2764
+ {
2765
+ N_Vector vtemp1, vtemp2, vtemp3;
2766
+ int convfail, ier;
2767
+ booleantype callSetup;
2768
+
2769
+ vtemp1 = acor; /* rename acor as vtemp1 for readability */
2770
+ vtemp2 = y; /* rename y as vtemp2 for readability */
2771
+ vtemp3 = tempv; /* rename tempv as vtemp3 for readability */
2772
+
2773
+ /* Set flag convfail, input to lsetup for its evaluation decision */
2774
+ convfail = ((nflag == FIRST_CALL) || (nflag == PREV_ERR_FAIL)) ?
2775
+ NO_FAILURES : FAIL_OTHER;
2776
+
2777
+ /* Decide whether or not to call setup routine (if one exists) */
2778
+ if (setupNonNull)
2779
+ {
2780
+ callSetup = (nflag == PREV_CONV_FAIL) || (nflag == PREV_ERR_FAIL) ||
2781
+ (nst == 0) || (nst >= nstlp + MSBP)
2782
+ || (ABS(gamrat - ONE) > DGMAX);
2783
+ }
2784
+ else
2785
+ {
2786
+ crate = ONE;
2787
+ callSetup = FALSE;
2788
+ }
2789
+
2790
+ /* Looping point for the solution of the nonlinear system.
2791
+ Evaluate f at the predicted y, call lsetup if indicated, and
2792
+ call CVNewtonIteration for the Newton iteration itself. */
2793
+
2794
+ loop
2795
+ {
2796
+ f(N, tn, zn[0], ftemp, f_data);
2797
+
2798
+ nfe++;
2799
+ if (CVMEM cvode_error == TRUE)
2800
+ {
2801
+ #ifdef DEBUG_CVODE
2802
+ CVMEM warning_msg(CVMEM sformatf("CVnlsNewton, start of loop, time %e\n",
2803
+ tn));
2804
+ #endif
2805
+ return (CONV_FAIL);
2806
+ }
2807
+ else
2808
+ {
2809
+ #ifdef DEBUG_CVODE
2810
+ CVMEM warning_msg(CVMEM sformatf(
2811
+ "CVnlsNewton, OK, start of loop, time %e\n", tn));
2812
+ #endif
2813
+ }
2814
+
2815
+ if (callSetup)
2816
+ {
2817
+ ier = lsetup(cv_mem, convfail, zn[0], ftemp, &jcur,
2818
+ vtemp1, vtemp2, vtemp3);
2819
+ nsetups++;
2820
+ callSetup = FALSE;
2821
+ gamrat = crate = ONE;
2822
+ gammap = gamma;
2823
+ nstlp = nst;
2824
+ /* Return if lsetup failed */
2825
+ if (ier < 0)
2826
+ return (SETUP_FAIL_UNREC);
2827
+ if (ier > 0)
2828
+ return (CONV_FAIL);
2829
+ }
2830
+
2831
+ /* Set acor to zero and load prediction into y vector */
2832
+ N_VConst(ZERO, acor);
2833
+ N_VScale(ONE, zn[0], y);
2834
+
2835
+ /* Do the Newton iteration */
2836
+ ier = CVNewtonIteration(cv_mem);
2837
+ if (CVMEM cvode_error == TRUE)
2838
+ {
2839
+ return (CONV_FAIL);
2840
+ }
2841
+ CVMEM cvode_test = TRUE;
2842
+ f(N, tn, y, ftemp, f_data);
2843
+ CVMEM cvode_test = FALSE;
2844
+ if (CVMEM cvode_error == TRUE)
2845
+ {
2846
+ #ifdef DEBUG_CVODE
2847
+ CVMEM warning_msg(CVMEM sformatf(
2848
+ "After CVNewtonIteration, Fail, ier %d\n", ier));
2849
+ #endif
2850
+ return (CONV_FAIL);
2851
+ }
2852
+ else
2853
+ {
2854
+ #ifdef DEBUG_CVODE
2855
+ CVMEM warning_msg(CVMEM sformatf("After CVNewtonIteration, OK, ier %d\n",
2856
+ ier));
2857
+ #endif
2858
+ }
2859
+ /* If there is a convergence failure and the Jacobian-related
2860
+ data appears not to be current, loop again with a call to lsetup
2861
+ in which convfail=FAIL_BAD_J. Otherwise return. */
2862
+ if (ier != TRY_AGAIN_CVODE)
2863
+ return (ier);
2864
+ callSetup = TRUE;
2865
+ convfail = FAIL_BAD_J;
2866
+ }
2867
+ }
2868
+
2869
+ /********************** CVNewtonIteration ****************************
2870
+
2871
+ This routine performs the Newton iteration. If the iteration succeeds,
2872
+ it returns the value SOLVED. If not, it may signal the CVnlsNewton
2873
+ routine to call lsetup again and reattempt the iteration, by
2874
+ returning the value TRY_AGAIN_CVODE. (In this case, CVnlsNewton must set
2875
+ convfail to FAIL_BAD_J before calling setup again).
2876
+ Otherwise, this routine returns one of the appropriate values
2877
+ SOLVE_FAIL_UNREC or CONV_FAIL back to CVnlsNewton.
2878
+
2879
+ *********************************************************************/
2880
+
2881
+ static int
2882
+ CVNewtonIteration(CVodeMem cv_mem)
2883
+ {
2884
+ int m, ret;
2885
+ realtype del, delp, dcon;
2886
+ N_Vector b;
2887
+
2888
+
2889
+ mnewt = m = 0;
2890
+ delp = 0;
2891
+
2892
+ /* Looping point for Newton iteration */
2893
+ loop
2894
+ {
2895
+
2896
+ /* Evaluate the residual of the nonlinear system */
2897
+ N_VLinearSum(rl1, zn[1], ONE, acor, tempv);
2898
+ N_VLinearSum(gamma, ftemp, -ONE, tempv, tempv);
2899
+
2900
+ /* Call the lsolve function */
2901
+ b = tempv;
2902
+ ret = lsolve(cv_mem, b, y, ftemp);
2903
+ nni++;
2904
+
2905
+ if (ret < 0)
2906
+ return (SOLVE_FAIL_UNREC);
2907
+
2908
+ /* If lsolve had a recoverable failure and Jacobian data is
2909
+ not current, signal to try the solution again */
2910
+ if (ret > 0)
2911
+ {
2912
+ if ((!jcur) && (setupNonNull))
2913
+ return (TRY_AGAIN_CVODE);
2914
+ return (CONV_FAIL);
2915
+ }
2916
+ /* Get WRMS norm of correction; add correction to acor and y */
2917
+ del = N_VWrmsNorm(b, ewt);
2918
+ N_VLinearSum(ONE, acor, ONE, b, acor);
2919
+ N_VLinearSum(ONE, zn[0], ONE, acor, y);
2920
+
2921
+ /* Test for convergence. If m > 0, an estimate of the convergence
2922
+ rate constant is stored in crate, and used in the test. */
2923
+ if (m > 0)
2924
+ {
2925
+ crate = MAX(CRDOWN * crate, del / delp);
2926
+ }
2927
+ dcon = del * MIN(ONE, crate) / tq[4];
2928
+
2929
+ #ifdef DEBUG_CVODE
2930
+ /* added before SOLVED */
2931
+ cvode_test = TRUE;
2932
+ f(N, tn, y, ftemp, f_data);
2933
+ cvode_test = FALSE;
2934
+ if (cvode_error == TRUE)
2935
+ {
2936
+ CVMEM warning_msg("CVnlsNewton, Fail at SOLVED\n");
2937
+ return (CONV_FAIL);
2938
+ }
2939
+ else
2940
+ {
2941
+ CVMEM warning_msg("CVnlsNewton, OK at SOLVED\n");
2942
+ }
2943
+ #endif
2944
+ if (dcon <= ONE)
2945
+ {
2946
+ acnrm = (m == 0) ? del : N_VWrmsNorm(acor, ewt);
2947
+ jcur = FALSE;
2948
+ return (SOLVED); /* Nonlinear system was solved successfully */
2949
+ }
2950
+
2951
+ mnewt = ++m;
2952
+
2953
+ /* Stop at maxcor iterations or if iter. seems to be diverging.
2954
+ If still not converged and Jacobian data is not current,
2955
+ signal to try the solution again */
2956
+ if ((m == maxcor) || ((m >= 2) && (del > RDIV * delp)))
2957
+ {
2958
+ if ((!jcur) && (setupNonNull))
2959
+ return (TRY_AGAIN_CVODE);
2960
+ return (CONV_FAIL);
2961
+ }
2962
+
2963
+ /* Save norm of correction, evaluate f, and loop again */
2964
+ delp = del;
2965
+ f(N, tn, y, ftemp, f_data);
2966
+
2967
+ if (CVMEM cvode_error == TRUE)
2968
+ {
2969
+ #ifdef DEBUG_CVODE
2970
+ CVMEM warning_msg("CVnlsNewton, Fail at end\n");
2971
+ #endif
2972
+ return (CONV_FAIL);
2973
+ }
2974
+ else
2975
+ {
2976
+ #ifdef DEBUG_CVODE
2977
+ CVMEM warning_msg("CVnlsNewton, OK at end\n");
2978
+ #endif
2979
+ }
2980
+ nfe++;
2981
+ }
2982
+ }
2983
+
2984
+ /********************** CVHandleNFlag *******************************
2985
+
2986
+ This routine takes action on the return value nflag = *nflagPtr
2987
+ returned by CVnls, as follows:
2988
+
2989
+ If CVnls succeeded in solving the nonlinear system, then
2990
+ CVHandleNFlag returns the constant DO_ERROR_TEST, which tells CVStep
2991
+ to perform the error test.
2992
+
2993
+ If the nonlinear system was not solved successfully, then ncfn and
2994
+ ncf = *ncfPtr are incremented and Nordsieck array zn is restored.
2995
+
2996
+ If the solution of the nonlinear system failed due to an
2997
+ unrecoverable failure by setup, we return the value SETUP_FAILED.
2998
+
2999
+ If it failed due to an unrecoverable failure in solve, then we return
3000
+ the value SOLVE_FAILED.
3001
+
3002
+ Otherwise, a recoverable failure occurred when solving the
3003
+ nonlinear system (CVnls returned nflag == CONV_FAIL).
3004
+ In this case, we return the value REP_CONV_FAIL if ncf is now
3005
+ equal to MXNCF or |h| = hmin.
3006
+ If not, we set *nflagPtr = PREV_CONV_FAIL and return the value
3007
+ PREDICT_AGAIN, telling CVStep to reattempt the step.
3008
+
3009
+ *********************************************************************/
3010
+
3011
+ static int
3012
+ CVHandleNFlag(CVodeMem cv_mem, int *nflagPtr, realtype saved_t, int *ncfPtr)
3013
+ {
3014
+ int nflag;
3015
+
3016
+ nflag = *nflagPtr;
3017
+
3018
+ if (nflag == SOLVED)
3019
+ return (DO_ERROR_TEST);
3020
+
3021
+ /* The nonlinear soln. failed; increment ncfn and restore zn */
3022
+ ncfn++;
3023
+ CVRestore(cv_mem, saved_t);
3024
+
3025
+ /* Return if lsetup or lsolve failed unrecoverably */
3026
+ if (nflag == SETUP_FAIL_UNREC)
3027
+ return (SETUP_FAILED);
3028
+ if (nflag == SOLVE_FAIL_UNREC)
3029
+ return (SOLVE_FAILED);
3030
+
3031
+ /* At this point, nflag == CONV_FAIL; increment ncf */
3032
+
3033
+ (*ncfPtr)++;
3034
+ etamax = ONE;
3035
+ /* If we had MXNCF failures or |h| = hmin, return REP_CONV_FAIL */
3036
+ if ((ABS(h) <= hmin * ONEPSM) || (*ncfPtr == MXNCF))
3037
+ return (REP_CONV_FAIL);
3038
+
3039
+ /* Reduce step size; return to reattempt the step */
3040
+ eta = MAX(ETACF, hmin / ABS(h));
3041
+ *nflagPtr = PREV_CONV_FAIL;
3042
+ CVRescale(cv_mem);
3043
+ return (PREDICT_AGAIN);
3044
+ }
3045
+
3046
+ /********************** CVRestore ************************************
3047
+
3048
+ This routine restores the value of tn to saved_t and undoes the
3049
+ prediction. After execution of CVRestore, the Nordsieck array zn has
3050
+ the same values as before the call to CVPredict.
3051
+
3052
+ ********************************************************************/
3053
+
3054
+ static void
3055
+ CVRestore(CVodeMem cv_mem, realtype saved_t)
3056
+ {
3057
+ int j, k;
3058
+
3059
+ tn = saved_t;
3060
+ for (k = 1; k <= q; k++)
3061
+ for (j = q; j >= k; j--)
3062
+ N_VLinearSum(ONE, zn[j - 1], -ONE, zn[j], zn[j - 1]);
3063
+ }
3064
+
3065
+ /******************* CVDoErrorTest ********************************
3066
+
3067
+ This routine performs the local error test.
3068
+ The weighted local error norm dsm is loaded into *dsmPtr, and
3069
+ the test dsm ?<= 1 is made.
3070
+
3071
+ If the test passes, CVDoErrorTest returns TRUE.
3072
+
3073
+ If the test fails, we undo the step just taken (call CVRestore),
3074
+ set *nflagPtr to PREV_ERR_FAIL, and return FALSE.
3075
+
3076
+ If MXNEF error test failures have occurred or if ABS(h) = hmin,
3077
+ we set *kflagPtr = REP_ERR_FAIL. (Otherwise *kflagPtr has the
3078
+ value last returned by CVHandleNflag.)
3079
+
3080
+ If more than MXNEF1 error test failures have occurred, an order
3081
+ reduction is forced.
3082
+
3083
+ ******************************************************************/
3084
+
3085
+ static booleantype
3086
+ CVDoErrorTest(CVodeMem cv_mem, int *nflagPtr, int *kflagPtr,
3087
+ realtype saved_t, int *nefPtr, realtype * dsmPtr)
3088
+ {
3089
+ realtype dsm;
3090
+
3091
+ dsm = acnrm / tq[2];
3092
+
3093
+ /* If est. local error norm dsm passes test, return TRUE */
3094
+ *dsmPtr = dsm;
3095
+ if (dsm <= ONE)
3096
+ return (TRUE);
3097
+
3098
+ /* Test failed; increment counters, set nflag, and restore zn array */
3099
+ (*nefPtr)++;
3100
+ netf++;
3101
+ *nflagPtr = PREV_ERR_FAIL;
3102
+ CVRestore(cv_mem, saved_t);
3103
+
3104
+ /* At MXNEF failures or |h| = hmin, return with kflag = REP_ERR_FAIL */
3105
+ if ((ABS(h) <= hmin * ONEPSM) || (*nefPtr == MXNEF))
3106
+ {
3107
+ *kflagPtr = REP_ERR_FAIL;
3108
+ return (FALSE);
3109
+ }
3110
+
3111
+ /* Set etamax = 1 to prevent step size increase at end of this step */
3112
+ etamax = ONE;
3113
+
3114
+ /* Set h ratio eta from dsm, rescale, and return for retry of step */
3115
+ if (*nefPtr <= MXNEF1)
3116
+ {
3117
+ eta = ONE / (RPowerR(BIAS2 * dsm, ONE / L) + ADDON);
3118
+ eta = MAX(ETAMIN, MAX(eta, hmin / ABS(h)));
3119
+ if (*nefPtr >= SMALL_NEF)
3120
+ eta = MIN(eta, ETAMXF);
3121
+ CVRescale(cv_mem);
3122
+ return (FALSE);
3123
+ }
3124
+
3125
+ /* After MXNEF1 failures, force an order reduction and retry step */
3126
+ if (q > 1)
3127
+ {
3128
+ eta = MAX(ETAMIN, hmin / ABS(h));
3129
+ CVAdjustOrder(cv_mem, -1);
3130
+ L = q;
3131
+ q--;
3132
+ qwait = L;
3133
+ CVRescale(cv_mem);
3134
+ return (FALSE);
3135
+ }
3136
+
3137
+ /* If already at order 1, restart: reload zn from scratch */
3138
+ eta = MAX(ETAMIN, hmin / ABS(h));
3139
+ h *= eta;
3140
+ hscale = h;
3141
+ qwait = LONG_WAIT;
3142
+ nscon = 0;
3143
+ f(N, tn, zn[0], tempv, f_data);
3144
+ if (CVMEM cvode_error == TRUE)
3145
+ {
3146
+ CVMEM warning_msg("CVDoErrorTest");
3147
+ /*exit(8); */
3148
+ CVMEM error_msg("CVDoErrorTest", 1 /* STOP */ );
3149
+ #if !defined(R_SO)
3150
+ exit(4);
3151
+ #endif
3152
+ }
3153
+ nfe++;
3154
+ N_VScale(h, tempv, zn[1]);
3155
+ return (FALSE);
3156
+ }
3157
+
3158
+ /*************** CVCompleteStep **********************************
3159
+
3160
+ This routine performs various update operations when the solution
3161
+ to the nonlinear system has passed the local error test.
3162
+ We increment the step counter nst, record the values hu and qu,
3163
+ update the tau array, and apply the corrections to the zn array.
3164
+ The tau[i] are the last q values of h, with tau[1] the most recent.
3165
+ The counter qwait is decremented, and if qwait == 1 (and q < qmax)
3166
+ we save acor and tq[5] for a possible order increase.
3167
+
3168
+ ******************************************************************/
3169
+
3170
+ static void
3171
+ CVCompleteStep(CVodeMem cv_mem)
3172
+ {
3173
+ int i, j;
3174
+
3175
+ nst++;
3176
+ nscon++;
3177
+ hu = h;
3178
+ qu = q;
3179
+
3180
+ for (i = q; i >= 2; i--)
3181
+ tau[i] = tau[i - 1];
3182
+ if ((q == 1) && (nst > 1))
3183
+ tau[2] = tau[1];
3184
+ tau[1] = h;
3185
+
3186
+ for (j = 0; j <= q; j++)
3187
+ N_VLinearSum(l[j], acor, ONE, zn[j], zn[j]);
3188
+ qwait--;
3189
+ if ((qwait == 1) && (q != qmax))
3190
+ {
3191
+ N_VScale(ONE, acor, zn[qmax]);
3192
+ saved_tq5 = tq[5];
3193
+ }
3194
+ }
3195
+
3196
+ /************* CVPrepareNextStep **********************************
3197
+
3198
+ This routine handles the setting of stepsize and order for the
3199
+ next step -- hprime and qprime. Along with hprime, it sets the
3200
+ ratio eta = hprime/h. It also updates other state variables
3201
+ related to a change of step size or order.
3202
+
3203
+ ******************************************************************/
3204
+
3205
+ static void
3206
+ CVPrepareNextStep(CVodeMem cv_mem, realtype dsm)
3207
+ {
3208
+ /* If etamax = 1, defer step size or order changes */
3209
+ if (etamax == ONE)
3210
+ {
3211
+ qwait = MAX(qwait, 2);
3212
+ qprime = q;
3213
+ hprime = h;
3214
+ eta = ONE;
3215
+ return;
3216
+ }
3217
+
3218
+ /* etaq is the ratio of new to old h at the current order */
3219
+ etaq = ONE / (RPowerR(BIAS2 * dsm, ONE / L) + ADDON);
3220
+
3221
+ /* If no order change, adjust eta and acor in CVSetEta and return */
3222
+ if (qwait != 0)
3223
+ {
3224
+ eta = etaq;
3225
+ qprime = q;
3226
+ CVSetEta(cv_mem);
3227
+ return;
3228
+ }
3229
+
3230
+ /* If qwait = 0, consider an order change. etaqm1 and etaqp1 are
3231
+ the ratios of new to old h at orders q-1 and q+1, respectively.
3232
+ CVChooseEta selects the largest; CVSetEta adjusts eta and acor */
3233
+ qwait = 2;
3234
+ etaqm1 = CVComputeEtaqm1(cv_mem);
3235
+ etaqp1 = CVComputeEtaqp1(cv_mem);
3236
+ CVChooseEta(cv_mem);
3237
+ CVSetEta(cv_mem);
3238
+ }
3239
+
3240
+ /***************** CVSetEta ***************************************
3241
+
3242
+ This routine adjusts the value of eta according to the various
3243
+ heuristic limits and the optional input hmax. It also resets
3244
+ etamax to be the estimated local error vector.
3245
+
3246
+ *******************************************************************/
3247
+
3248
+ static void
3249
+ CVSetEta(CVodeMem cv_mem)
3250
+ {
3251
+
3252
+ /* If eta below the threshold THRESH, reject a change of step size */
3253
+ if (eta < THRESH)
3254
+ {
3255
+ eta = ONE;
3256
+ hprime = h;
3257
+ }
3258
+ else
3259
+ {
3260
+ /* Limit eta by etamax and hmax, then set hprime */
3261
+ eta = MIN(eta, etamax);
3262
+ eta /= MAX(ONE, ABS(h) * hmax_inv * eta);
3263
+ hprime = h * eta;
3264
+ if (qprime < q)
3265
+ nscon = 0;
3266
+ }
3267
+
3268
+ /* Reset etamax for the next step size change, and scale acor */
3269
+ }
3270
+
3271
+ /*************** CVComputeEtaqm1 **********************************
3272
+
3273
+ This routine computes and returns the value of etaqm1 for a
3274
+ possible decrease in order by 1.
3275
+
3276
+ ******************************************************************/
3277
+
3278
+ static realtype
3279
+ CVComputeEtaqm1(CVodeMem cv_mem)
3280
+ {
3281
+ realtype ddn;
3282
+
3283
+ etaqm1 = ZERO;
3284
+ if (q > 1)
3285
+ {
3286
+ ddn = N_VWrmsNorm(zn[q], ewt) / tq[1];
3287
+ etaqm1 = ONE / (RPowerR(BIAS1 * ddn, ONE / q) + ADDON);
3288
+ }
3289
+ return (etaqm1);
3290
+ }
3291
+
3292
+ /*************** CVComputeEtaqp1 **********************************
3293
+
3294
+ This routine computes and returns the value of etaqp1 for a
3295
+ possible increase in order by 1.
3296
+
3297
+ ******************************************************************/
3298
+
3299
+ static realtype
3300
+ CVComputeEtaqp1(CVodeMem cv_mem)
3301
+ {
3302
+ realtype dup, cquot;
3303
+
3304
+ etaqp1 = ZERO;
3305
+ if (q != qmax)
3306
+ {
3307
+ cquot = (tq[5] / saved_tq5) * RPowerI(h / tau[2], L);
3308
+ N_VLinearSum(-cquot, zn[qmax], ONE, acor, tempv);
3309
+ dup = N_VWrmsNorm(tempv, ewt) / tq[3];
3310
+ etaqp1 = ONE / (RPowerR(BIAS3 * dup, ONE / (L + 1)) + ADDON);
3311
+ }
3312
+ return (etaqp1);
3313
+ }
3314
+
3315
+ /******************* CVChooseEta **********************************
3316
+
3317
+ Given etaqm1, etaq, etaqp1 (the values of eta for qprime =
3318
+ q - 1, q, or q + 1, respectively), this routine chooses the
3319
+ maximum eta value, sets eta to that value, and sets qprime to the
3320
+ corresponding value of q. If there is a tie, the preference
3321
+ order is to (1) keep the same order, then (2) decrease the order,
3322
+ and finally (3) increase the order. If the maximum eta value
3323
+ is below the threshold THRESH, the order is kept unchanged and
3324
+ eta is set to 1.
3325
+
3326
+ ******************************************************************/
3327
+
3328
+ static void
3329
+ CVChooseEta(CVodeMem cv_mem)
3330
+ {
3331
+ realtype etam;
3332
+
3333
+ etam = MAX(etaqm1, MAX(etaq, etaqp1));
3334
+
3335
+ if (etam < THRESH)
3336
+ {
3337
+ eta = ONE;
3338
+ qprime = q;
3339
+ return;
3340
+ }
3341
+
3342
+ if (etam == etaq)
3343
+ {
3344
+ eta = etaq;
3345
+ qprime = q;
3346
+ }
3347
+ else if (etam == etaqm1)
3348
+ {
3349
+ eta = etaqm1;
3350
+ qprime = q - 1;
3351
+ }
3352
+ else
3353
+ {
3354
+ eta = etaqp1;
3355
+ qprime = q + 1;
3356
+ if (lmm == BDF)
3357
+ N_VScale(ONE, acor, zn[qmax]);
3358
+ }
3359
+ }
3360
+
3361
+ /****************** CVHandleFailure ******************************
3362
+
3363
+ This routine prints error messages for all cases of failure by
3364
+ CVStep. It returns to CVode the value that CVode is to return to
3365
+ the user.
3366
+
3367
+ *****************************************************************/
3368
+
3369
+ static int
3370
+ CVHandleFailure(CVodeMem cv_mem, int kflag)
3371
+ {
3372
+ /* Set vector of absolute weighted local errors */
3373
+ N_VProd(acor, ewt, tempv);
3374
+ N_VAbs(tempv, tempv);
3375
+
3376
+ /* Depending on kflag, print error message and return error flag */
3377
+ switch (kflag)
3378
+ {
3379
+ case REP_ERR_FAIL:
3380
+ {
3381
+ char * error_string = CVMEM sformatf(MSG_ERR_FAILS, (double) tn, (double) h);
3382
+ CVMEM warning_msg(error_string);
3383
+ }
3384
+ return (ERR_FAILURE);
3385
+ case REP_CONV_FAIL:
3386
+ {
3387
+ char * error_string = CVMEM sformatf(MSG_CONV_FAILS, (double) tn, (double) h);
3388
+ CVMEM warning_msg(error_string);
3389
+ }
3390
+
3391
+ return (CONV_FAILURE);
3392
+ case SETUP_FAILED:
3393
+ {
3394
+ char * error_string = CVMEM sformatf(MSG_SETUP_FAILED, (double) tn);
3395
+ CVMEM warning_msg(error_string);
3396
+ }
3397
+ return (SETUP_FAILURE);
3398
+ case SOLVE_FAILED:
3399
+ {
3400
+ char * error_string = CVMEM sformatf(MSG_SOLVE_FAILED, (double) tn);
3401
+ CVMEM warning_msg(error_string);
3402
+ }
3403
+ return (SOLVE_FAILURE);
3404
+ }
3405
+ return (-99);
3406
+ }
3407
+
3408
+ /****************** CVBDFStab ***********************************
3409
+ This routine handles the BDF Stability Limit Detection Algorithm
3410
+ STALD. It is called if lmm = BDF and the SLDET option is on.
3411
+ If the order is 3 or more, the required norm data is saved.
3412
+ If a decision to reduce order has not already been made, and
3413
+ enough data has been saved, CVsldet is called. If it signals
3414
+ a stability limit violation, the order is reduced, and the step
3415
+ size is reset accordingly.
3416
+
3417
+ *****************************************************************/
3418
+ #ifdef ORIGINAL_CVBDFStab
3419
+ void
3420
+ CVBDFStab(CVodeMem cv_mem)
3421
+ {
3422
+ int i, k, ldflag, factorial;
3423
+ realtype sq, sqm1, sqm2;
3424
+
3425
+ /* If order is 3 or greater, then save scaled derivative data,
3426
+ push old data down in i, then add current values to top. */
3427
+
3428
+ if (q >= 3)
3429
+ {
3430
+ for (k = 1; k <= 3; k++)
3431
+ {
3432
+ for (i = 5; i >= 2; i--)
3433
+ ssdat[i][k] = ssdat[i - 1][k];
3434
+ }
3435
+ factorial = 1;
3436
+ for (i = 1; i <= q - 1; i++)
3437
+ factorial *= i;
3438
+ sq = factorial * q * (q + 1) * acnrm / tq[5];
3439
+ sqm1 = factorial * q * N_VWrmsNorm(zn[q], ewt);
3440
+ sqm2 = factorial * N_VWrmsNorm(zn[q - 1], ewt);
3441
+ ssdat[1][1] = sqm2 * sqm2;
3442
+ ssdat[1][2] = sqm1 * sqm1;
3443
+ ssdat[1][3] = sq * sq;
3444
+ }
3445
+
3446
+ if (qprime >= q)
3447
+ {
3448
+
3449
+ /* If order is 3 or greater, and enough ssdat has been saved,
3450
+ nscon >= q+5, then call stability limit detection routine. */
3451
+
3452
+ if ((q >= 3) && (nscon >= q + 5))
3453
+ {
3454
+ ldflag = CVsldet(cv_mem);
3455
+ if (ldflag > 3)
3456
+ {
3457
+ /* A stability limit violation is indicated by
3458
+ a return flag of 4, 5, or 6.
3459
+ Reduce new order. */
3460
+ qprime = q - 1;
3461
+ eta = etaqm1;
3462
+ eta = MIN(eta, etamax);
3463
+ eta = eta / MAX(ONE, ABS(h) * hmax_inv * eta);
3464
+ hprime = h * eta;
3465
+ iopt[NOR] = iopt[NOR] + 1;
3466
+ /* CVMEM warning_msg(CVMEM sformatf(
3467
+ " Order reduced to %d by CVBDFStab at nst = %d,\n h = %e hnew = %e\n",
3468
+ qprime,nst,h,h*eta)); */
3469
+ }
3470
+ }
3471
+ }
3472
+ else
3473
+ {
3474
+ /* Otherwise, let order increase happen, and
3475
+ reset stability limit counter, nscon. */
3476
+ nscon = 0;
3477
+ }
3478
+ }
3479
+ #endif
3480
+ void
3481
+ CVBDFStab(CVodeMem cv_mem)
3482
+ {
3483
+ // appt try...
3484
+ if (q >= 3 && qprime >= q)
3485
+ {
3486
+ if (tq[5] < saved_tq5)
3487
+ qprime = 1;
3488
+ //else
3489
+ //nscon = 0;
3490
+ }
3491
+
3492
+ //int i, k, ldflag, factorial;
3493
+ //realtype sq, sqm1, sqm2;
3494
+
3495
+ ///* If order is 3 or greater, then save scaled derivative data,
3496
+ // push old data down in i, then add current values to top. */
3497
+
3498
+ //if (q >= 3)
3499
+ //{
3500
+ // for (k = 1; k <= 3; k++)
3501
+ // {
3502
+ // for (i = 5; i >= 2; i--)
3503
+ // ssdat[i][k] = ssdat[i - 1][k];
3504
+ // }
3505
+ // factorial = 1;
3506
+ // for (i = 1; i <= q - 1; i++)
3507
+ // factorial *= i;
3508
+ // sq = factorial * q * (q + 1) * acnrm / MAX(tq[5], TINY);
3509
+ // sqm1 = factorial * q * N_VWrmsNorm(zn[q], ewt);
3510
+ // sqm2 = factorial * N_VWrmsNorm(zn[q - 1], ewt);
3511
+ // ssdat[1][1] = sqm2 * sqm2;
3512
+ // ssdat[1][2] = sqm1 * sqm1;
3513
+ // ssdat[1][3] = sq * sq;
3514
+ //}
3515
+
3516
+ //if (qprime >= q)
3517
+ //{
3518
+
3519
+ // /* If order is 3 or greater, and enough ssdat has been saved,
3520
+ // nscon >= q+5, then call stability limit detection routine. */
3521
+
3522
+ // if ((q >= 3) && (nscon >= q + 5))
3523
+ // {
3524
+ // ldflag = CVsldet(cv_mem);
3525
+ // //cv_mem->cv_machenv->phreeqc_ptr->set_forward_output_to_log(1); // appt
3526
+ // qprime = 1; // appt try
3527
+ // //CVMEM warning_msg(CVMEM sformatf(
3528
+ // // "CVBDFStab: ldflag = %d, order(q) = %d, qprime = %d, nst = %d, h = %8.2e, time = %8.2e\n",
3529
+ // // ldflag, q, qprime, nst, h, CVMEM cvode_last_good_time));
3530
+
3531
+ // if (ldflag > 3)
3532
+ // {
3533
+ // /* A stability limit violation is indicated by
3534
+ // a return flag of 4, 5, or 6.
3535
+ // Reduce new order. */
3536
+ // qprime = q - 1;
3537
+ // eta = etaqm1;
3538
+ // eta = MIN(eta, etamax);
3539
+ // eta = eta / MAX(ONE, ABS(h) * hmax_inv * eta);
3540
+ // hprime = h * eta;
3541
+ // iopt[NOR] = iopt[NOR] + 1;
3542
+ // //CVMEM warning_msg(CVMEM sformatf(
3543
+ // // " Order reduced to %d by CVBDFStab at nst = %d,\n h = %e hnew = %e\n",
3544
+ // // qprime,nst,h,h*eta));
3545
+ // }
3546
+ // }
3547
+ //}
3548
+ //else
3549
+ //{
3550
+ // /* Otherwise, let order increase happen, and
3551
+ // reset stability limit counter, nscon. */
3552
+ // nscon = 0;
3553
+ //}
3554
+ }
3555
+
3556
+ /********************* CVsldet ************************************
3557
+ This routine detects stability limitation using stored scaled
3558
+ derivatives data. CVsldet returns the magnitude of the
3559
+ dominate characteristic root, rr. The presents of a stability
3560
+ limit is indicated by rr > "something a little less then 1.0",
3561
+ and a positive kflag. This routine should only be called if
3562
+ order is greater than or equal to 3, and data has been collected
3563
+ for 5 time steps.
3564
+
3565
+ Returned values:
3566
+ kflag = 1 -> Found stable characteristic root, normal matrix case
3567
+ kflag = 2 -> Found stable characteristic root, quartic solution
3568
+ kflag = 3 -> Found stable characteristic root, quartic solution,
3569
+ with Newton correction
3570
+ kflag = 4 -> Found stability violation, normal matrix case
3571
+ kflag = 5 -> Found stability violation, quartic solution
3572
+ kflag = 6 -> Found stability violation, quartic solution,
3573
+ with Newton correction
3574
+
3575
+ kflag < 0 -> No stability limitation,
3576
+ or could not compute limitation.
3577
+
3578
+ kflag = -1 -> Min/max ratio of ssdat too small.
3579
+ kflag = -2 -> For normal matrix case, vmax > vrrt2*vrrt2
3580
+ kflag = -3 -> For normal matrix case, The three ratios
3581
+ are inconsistent.
3582
+ kflag = -4 -> Small coefficient prevents elimination of quartics.
3583
+ kflag = -5 -> R value from quartics not consistent.
3584
+ kflag = -6 -> No corrected root passes test on qk values
3585
+ kflag = -7 -> Trouble solving for sigsq.
3586
+ kflag = -8 -> Trouble solving for B, or R via B.
3587
+ kflag = -9 -> R via sigsq[k] disagrees with R from data.
3588
+
3589
+ ********************************************************************/
3590
+
3591
+ #ifdef ORIGINAL_CVBDFStab
3592
+ static int
3593
+ CVsldet(CVodeMem cv_mem)
3594
+ {
3595
+ integertype i, k, j, it, kmin, kflag = 0;
3596
+ realtype rat[5][4], rav[4], qkr[4], sigsq[4], smax[4], ssmax[4];
3597
+ realtype drr[4], rrc[4], sqmx[4], qjk[4][4], vrat[5], qc[6][4], qco[6][4];
3598
+ realtype rr, rrcut, vrrtol, vrrt2, sqtol, rrtol;
3599
+ realtype smink, smaxk, sumrat, sumrsq, vmin, vmax, drrmax, adrr;
3600
+ realtype /*small_cvode,*/ tem, sqmax, saqk, qp, s, sqmaxk, saqj, sqmin;
3601
+ //realtype rsa, rsb, rsc, rsd, rse, rd1a, rd1b, rd1c, rd1d;
3602
+ realtype rsa, rsb, rsc, rsd, rd1a, rd1b, rd1c;
3603
+ //realtype rd2a, rd2b, rd2c, rd3a, rd3b, cest1, corr1;
3604
+ realtype rd2a, rd2b, rd3a, cest1, corr1;
3605
+ realtype ratp, ratm, qfac1, qfac2, bb, rrb;
3606
+
3607
+ /* The following are cutoffs and tolerances used by this routine */
3608
+
3609
+ rrcut = 0.98;
3610
+ vrrtol = 1.0e-4;
3611
+ vrrt2 = 5.0e-4;
3612
+ sqtol = 1.0e-3;
3613
+ rrtol = 1.0e-2;
3614
+
3615
+ rr = ZERO;
3616
+
3617
+ /* Index k corresponds to the degree of the interpolating polynomial. */
3618
+ /* k = 1 -> q-1 */
3619
+ /* k = 2 -> q */
3620
+ /* k = 3 -> q+1 */
3621
+
3622
+ /* Index i is a backward-in-time index, i = 1 -> current time, */
3623
+ /* i = 2 -> previous step, etc */
3624
+
3625
+ /* get maxima, minima, and variances, and form quartic coefficients */
3626
+
3627
+ for (k = 1; k <= 3; k++)
3628
+ {
3629
+ smink = ssdat[1][k];
3630
+ smaxk = ZERO;
3631
+
3632
+ for (i = 1; i <= 5; i++)
3633
+ {
3634
+ smink = MIN(smink, ssdat[i][k]);
3635
+ smaxk = MAX(smaxk, ssdat[i][k]);
3636
+ }
3637
+
3638
+ if (smink < TINY * smaxk)
3639
+ {
3640
+ kflag = -1;
3641
+ return (kflag);
3642
+ }
3643
+ smax[k] = smaxk;
3644
+ ssmax[k] = smaxk * smaxk;
3645
+
3646
+ sumrat = ZERO;
3647
+ sumrsq = ZERO;
3648
+ for (i = 1; i <= 4; i++)
3649
+ {
3650
+ rat[i][k] = ssdat[i][k] / ssdat[i + 1][k];
3651
+ sumrat = sumrat + rat[i][k];
3652
+ sumrsq = sumrsq + rat[i][k] * rat[i][k];
3653
+ }
3654
+ rav[k] = FOURTH * sumrat;
3655
+ vrat[k] = ABS(FOURTH * sumrsq - rav[k] * rav[k]);
3656
+
3657
+ qc[5][k] = ssdat[1][k] * ssdat[3][k] - ssdat[2][k] * ssdat[2][k];
3658
+ qc[4][k] = ssdat[2][k] * ssdat[3][k] - ssdat[1][k] * ssdat[4][k];
3659
+ qc[3][k] = ZERO;
3660
+ qc[2][k] = ssdat[2][k] * ssdat[5][k] - ssdat[3][k] * ssdat[4][k];
3661
+ qc[1][k] = ssdat[4][k] * ssdat[4][k] - ssdat[3][k] * ssdat[5][k];
3662
+
3663
+ for (i = 1; i <= 5; i++)
3664
+ {
3665
+ qco[i][k] = qc[i][k];
3666
+ }
3667
+ } /* End of k loop */
3668
+
3669
+ /* Isolate normal or nearly-normal matrix case. Three quartic will
3670
+ have common or nearly-common roots in this case.
3671
+ Return a kflag = 1 if this procedure works. If three root
3672
+ differ more than vrrt2, return error kflag = -3. */
3673
+
3674
+ vmin = MIN(vrat[1], MIN(vrat[2], vrat[3]));
3675
+ vmax = MAX(vrat[1], MAX(vrat[2], vrat[3]));
3676
+
3677
+ if (vmin < vrrtol * vrrtol)
3678
+ {
3679
+ if (vmax > vrrt2 * vrrt2)
3680
+ {
3681
+ kflag = -2;
3682
+ return (kflag);
3683
+ }
3684
+ else
3685
+ {
3686
+ rr = (rav[1] + rav[2] + rav[3]) / THREE;
3687
+
3688
+ drrmax = ZERO;
3689
+ for (k = 1; k <= 3; k++)
3690
+ {
3691
+ adrr = ABS(rav[k] - rr);
3692
+ drrmax = MAX(drrmax, adrr);
3693
+ }
3694
+ if (drrmax > vrrt2)
3695
+ {
3696
+ kflag = -3;
3697
+ }
3698
+
3699
+ kflag = 1;
3700
+
3701
+ /* can compute charactistic root, drop to next section */
3702
+
3703
+ }
3704
+ }
3705
+ else
3706
+ {
3707
+
3708
+ /* use the quartics to get rr. */
3709
+
3710
+ if (ABS(qco[1][1]) < TINY * ssmax[1])
3711
+ {
3712
+ //small_cvode = qco[1][1];
3713
+ kflag = -4;
3714
+ return (kflag);
3715
+ }
3716
+
3717
+ tem = qco[1][2] / qco[1][1];
3718
+ for (i = 2; i <= 5; i++)
3719
+ {
3720
+ qco[i][2] = qco[i][2] - tem * qco[i][1];
3721
+ }
3722
+
3723
+ qco[1][2] = ZERO;
3724
+ tem = qco[1][3] / qco[1][1];
3725
+ for (i = 2; i <= 5; i++)
3726
+ {
3727
+ qco[i][3] = qco[i][3] - tem * qco[i][1];
3728
+ }
3729
+ qco[1][3] = ZERO;
3730
+
3731
+ if (ABS(qco[2][2]) < TINY * ssmax[2])
3732
+ {
3733
+ //small_cvode = qco[2][2];
3734
+ kflag = -4;
3735
+ return (kflag);
3736
+ }
3737
+
3738
+ tem = qco[2][3] / qco[2][2];
3739
+ for (i = 3; i <= 5; i++)
3740
+ {
3741
+ qco[i][3] = qco[i][3] - tem * qco[i][2];
3742
+ }
3743
+
3744
+ if (ABS(qco[4][3]) < TINY * ssmax[3])
3745
+ {
3746
+ //small_cvode = qco[4][3];
3747
+ kflag = -4;
3748
+ return (kflag);
3749
+ }
3750
+
3751
+ rr = -qco[5][3] / qco[4][3];
3752
+
3753
+ if (rr < TINY || rr > HUN)
3754
+ {
3755
+ kflag = -5;
3756
+ return (kflag);
3757
+ }
3758
+
3759
+ for (k = 1; k <= 3; k++)
3760
+ {
3761
+ qkr[k] =
3762
+ qc[5][k] + rr * (qc[4][k] +
3763
+ rr * rr * (qc[2][k] + rr * qc[1][k]));
3764
+ }
3765
+
3766
+ sqmax = ZERO;
3767
+ for (k = 1; k <= 3; k++)
3768
+ {
3769
+ saqk = ABS(qkr[k]) / ssmax[k];
3770
+ if (saqk > sqmax)
3771
+ sqmax = saqk;
3772
+ }
3773
+ sqmin = sqmax;
3774
+ if (sqmax < sqtol)
3775
+ {
3776
+ kflag = 2;
3777
+
3778
+ /* can compute charactistic root, drop to "given rr,etc" */
3779
+
3780
+ }
3781
+ else
3782
+ {
3783
+
3784
+ /* do Newton corrections to improve rr. */
3785
+
3786
+ for (it = 1; it <= 3; it++)
3787
+ {
3788
+ for (k = 1; k <= 3; k++)
3789
+ {
3790
+ qp = qc[4][k] + rr * rr * (THREE * qc[2][k] +
3791
+ rr * FOUR * qc[1][k]);
3792
+ drr[k] = ZERO;
3793
+ if (ABS(qp) > TINY * ssmax[k])
3794
+ drr[k] = -qkr[k] / qp;
3795
+ rrc[k] = rr + drr[k];
3796
+ }
3797
+
3798
+ for (k = 1; k <= 3; k++)
3799
+ {
3800
+ s = rrc[k];
3801
+ sqmaxk = ZERO;
3802
+ for (j = 1; j <= 3; j++)
3803
+ {
3804
+ qjk[j][k] = qc[5][j] + s * (qc[4][j] +
3805
+ s * s * (qc[2][j] +
3806
+ s * qc[1][j]));
3807
+ saqj = ABS(qjk[j][k]) / ssmax[j];
3808
+ if (saqj > sqmaxk)
3809
+ sqmaxk = saqj;
3810
+ }
3811
+ sqmx[k] = sqmaxk;
3812
+ }
3813
+
3814
+ sqmin = sqmx[1];
3815
+ kmin = 1;
3816
+ for (k = 2; k <= 3; k++)
3817
+ {
3818
+ if (sqmx[k] < sqmin)
3819
+ {
3820
+ kmin = k;
3821
+ sqmin = sqmx[k];
3822
+ }
3823
+ }
3824
+ rr = rrc[kmin];
3825
+
3826
+ if (sqmin < sqtol)
3827
+ {
3828
+ kflag = 3;
3829
+ /* can compute charactistic root */
3830
+ /* break out of Newton correction loop and drop to "given rr,etc" */
3831
+ break;
3832
+ }
3833
+ else
3834
+ {
3835
+ for (j = 1; j <= 3; j++)
3836
+ {
3837
+ qkr[j] = qjk[j][kmin];
3838
+ }
3839
+ }
3840
+ } /* end of Newton correction loop */
3841
+
3842
+ if (sqmin > sqtol)
3843
+ {
3844
+ kflag = -6;
3845
+ return (kflag);
3846
+ }
3847
+ } /* end of if (sqmax < sqtol) else */
3848
+ } /* end of if(vmin < vrrtol*vrrtol) else, quartics to get rr. */
3849
+
3850
+ /* given rr, find sigsq[k] and verify rr. */
3851
+ /* All positive kflag drop to this section */
3852
+
3853
+ for (k = 1; k <= 3; k++)
3854
+ {
3855
+ rsa = ssdat[1][k];
3856
+ rsb = ssdat[2][k] * rr;
3857
+ rsc = ssdat[3][k] * rr * rr;
3858
+ rsd = ssdat[4][k] * rr * rr * rr;
3859
+ //rse = ssdat[5][k] * rr * rr * rr * rr;
3860
+ rd1a = rsa - rsb;
3861
+ rd1b = rsb - rsc;
3862
+ rd1c = rsc - rsd;
3863
+ //rd1d = rsd - rse;
3864
+ rd2a = rd1a - rd1b;
3865
+ rd2b = rd1b - rd1c;
3866
+ //rd2c = rd1c - rd1d;
3867
+ rd3a = rd2a - rd2b;
3868
+ //rd3b = rd2b - rd2c;
3869
+ /* rd3b = rd3b; */
3870
+
3871
+ if (ABS(rd1b) < TINY * smax[k])
3872
+ {
3873
+ kflag = -7;
3874
+ return (kflag);
3875
+ }
3876
+
3877
+ cest1 = -rd3a / rd1b;
3878
+ if (cest1 < TINY || cest1 > FOUR)
3879
+ {
3880
+ kflag = -7;
3881
+ return (kflag);
3882
+ }
3883
+ corr1 = (rd2b / cest1) / (rr * rr);
3884
+ sigsq[k] = ssdat[3][k] + corr1;
3885
+ }
3886
+
3887
+ if (sigsq[2] < TINY)
3888
+ {
3889
+ kflag = -8;
3890
+ return (kflag);
3891
+ }
3892
+
3893
+ ratp = sigsq[3] / sigsq[2];
3894
+ ratm = sigsq[1] / sigsq[2];
3895
+ qfac1 = FOURTH * (q * q - ONE);
3896
+ qfac2 = TWO / (q - ONE);
3897
+ bb = ratp * ratm - ONE - qfac1 * ratp;
3898
+ tem = ONE - qfac2 * bb;
3899
+
3900
+ if (ABS(tem) < TINY)
3901
+ {
3902
+ kflag = -8;
3903
+ return (kflag);
3904
+ }
3905
+
3906
+ rrb = ONE / tem;
3907
+
3908
+ if (ABS(rrb - rr) > rrtol)
3909
+ {
3910
+ kflag = -9;
3911
+ return (kflag);
3912
+ }
3913
+
3914
+ /* Check to see if rr is above cutoff rrcut */
3915
+ if (rr > rrcut)
3916
+ {
3917
+ if (kflag == 1)
3918
+ kflag = 4;
3919
+ if (kflag == 2)
3920
+ kflag = 5;
3921
+ if (kflag == 3)
3922
+ kflag = 6;
3923
+ }
3924
+
3925
+ /* All positive kflag returned at this point */
3926
+
3927
+ return (kflag);
3928
+
3929
+ }
3930
+ #endif
3931
+
3932
+ /*******************************************************************/
3933
+ /********* END Private Helper Functions Implementation *************/
3934
+ /*******************************************************************/
3935
+
3936
+
3937
+ /***************************************************************/
3938
+ /************** END CVODE Implementation ***********************/
3939
+ /***************************************************************/