cvodes_sparse.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4488 $
  4. * $Date: 2015-04-29 16:39:48 -0700 (Wed, 29 Apr 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer: Carol S. Woodward @ LLNL
  7. * -----------------------------------------------------------------
  8. * LLNS Copyright Start
  9. * Copyright (c) 2014, Lawrence Livermore National Security
  10. * This work was performed under the auspices of the U.S. Department
  11. * of Energy by Lawrence Livermore National Laboratory in part under
  12. * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
  13. * Produced at the Lawrence Livermore National Laboratory.
  14. * All rights reserved.
  15. * For details, see the LICENSE file.
  16. * LLNS Copyright End
  17. * -----------------------------------------------------------------
  18. * This is the header file for the Sparse linear solver module in CVODES.
  19. * -----------------------------------------------------------------
  20. */
  21. #ifndef _CVSSPARSE_H
  22. #define _CVSSPARSE_H
  23. #include <sundials/sundials_sparse.h>
  24. #include <sundials/sundials_nvector.h>
  25. #ifdef __cplusplus /* wrapper to enable C++ usage */
  26. extern "C" {
  27. #endif
  28. /*
  29. * =================================================================
  30. * C V S S P A R S E C O N S T A N T S
  31. * =================================================================
  32. */
  33. /*
  34. * -----------------------------------------------------------------
  35. * CVSSPARSE return values
  36. * -----------------------------------------------------------------
  37. */
  38. #define CVSLS_SUCCESS 0
  39. #define CVSLS_MEM_NULL -1
  40. #define CVSLS_LMEM_NULL -2
  41. #define CVSLS_ILL_INPUT -3
  42. #define CVSLS_MEM_FAIL -4
  43. #define CVSLS_JAC_NOSET -5
  44. #define CVSLS_PACKAGE_FAIL -6
  45. /* Additional last_flag values */
  46. #define CVSLS_JACFUNC_UNRECVR -7
  47. #define CVSLS_JACFUNC_RECVR -8
  48. /* Return values for the adjoint module */
  49. #define CVSLS_NO_ADJ -101
  50. #define CVSLS_LMEMB_NULL -102
  51. /*
  52. * =================================================================
  53. * PART I: F O R W A R D P R O B L E M S
  54. * =================================================================
  55. */
  56. /*
  57. * -----------------------------------------------------------------
  58. * FUNCTION TYPES
  59. * -----------------------------------------------------------------
  60. */
  61. /*
  62. * -----------------------------------------------------------------
  63. * Types : CVSlsSparseJacFn
  64. * -----------------------------------------------------------------
  65. *
  66. * A sparse Jacobian approximation function jac must be of type
  67. * CVSlsSparseJacFn.
  68. * Its parameters are:
  69. *
  70. * t is the current value of the independent variable t.
  71. *
  72. * y is the current value of the dependent variable vector,
  73. * namely the predicted value of y(t).
  74. *
  75. * fy is the vector f(t,y).
  76. * namely the predicted value of y'(t).
  77. *
  78. * JacMat is the compressed sparse column matrix (of type SlsMat)
  79. * to be loaded by an CVSlsSparseJacFn routine with an approximation
  80. * to the system Jacobian matrix
  81. * J = J = (df_i/dy_j) at the point (t,y).
  82. * Note that JacMat is NOT preset to zero!
  83. * Matrix data is for the nonzero entries of the Jacobian stored in
  84. * compressed column format. Row indices of entries in
  85. * column j are stored in J->rowvals[colptrs[j]]
  86. * through J->rowvals[colptrs[j+i]-1]
  87. * and corresponding numerical values of the Jacobian are stored
  88. * in the same entries of J->data.
  89. *
  90. * J_data is a pointer to user Jacobian data - the same as the
  91. * user_data parameter passed to CVodeSetFdata.
  92. *
  93. * tmp1, tmp2, tmp3 are pointers to memory allocated for
  94. * N_Vectors which can be used by an CVSparseJacFn routine
  95. * as temporary storage or work space.
  96. *
  97. * A CVSlsSparseJacFn should return
  98. * 0 if successful,
  99. * a positive int if a recoverable error occurred, or
  100. * a negative int if a nonrecoverable error occurred.
  101. *
  102. * -----------------------------------------------------------------
  103. *
  104. * NOTE: If the user's Jacobian routine needs other quantities,
  105. * they are accessible as follows: hcur (the current stepsize)
  106. * and ewt (the error weight vector) are accessible through
  107. * CVodeGetCurrentStep and CVodeGetErrWeights, respectively
  108. * (see cvode.h). The unit roundoff is available as
  109. * UNIT_ROUNDOFF defined in sundials_types.h.
  110. *
  111. * -----------------------------------------------------------------
  112. */
  113. typedef int (*CVSlsSparseJacFn)(realtype t,
  114. N_Vector y, N_Vector fy,
  115. SlsMat JacMat, void *user_data,
  116. N_Vector tmp1, N_Vector tmp2, N_Vector tmp3);
  117. /*
  118. * =================================================================
  119. * E X P O R T E D F U N C T I O N S
  120. * =================================================================
  121. */
  122. /*
  123. * -----------------------------------------------------------------
  124. * Optional inputs to the CVSPARSE linear solver
  125. * -----------------------------------------------------------------
  126. * CVSlsSetSparseJacFn specifies the Jacobian approximation
  127. * routine to be used for a sparse direct linear solver.
  128. *
  129. * The return value is one of:
  130. * CVSLS_SUCCESS if successful
  131. * CVSLS_MEM_NULL if the CVODE memory was NULL
  132. * CVSLS_LMEM_NULL if the linear solver memory was NULL
  133. * -----------------------------------------------------------------
  134. */
  135. SUNDIALS_EXPORT int CVSlsSetSparseJacFn(void *cvode_mem, CVSlsSparseJacFn jac);
  136. /*
  137. * -----------------------------------------------------------------
  138. * Optional outputs from the CVSLS linear solver
  139. * -----------------------------------------------------------------
  140. *
  141. * CVSlsGetNumJacEvals returns the number of calls made to the
  142. * Jacobian evaluation routine jac.
  143. * CVSlsGetLastFlag returns the last error flag set by any of
  144. * the CVSLS interface functions.
  145. *
  146. * The return value of CVSlsGet* is one of:
  147. * CVSLS_SUCCESS if successful
  148. * CVSLS_MEM_NULL if the IDA memory was NULL
  149. * CVSLS_LMEM_NULL if the linear solver memory was NULL
  150. * -----------------------------------------------------------------
  151. */
  152. SUNDIALS_EXPORT int CVSlsGetNumJacEvals(void *cvode_mem, long int *njevals);
  153. SUNDIALS_EXPORT int CVSlsGetLastFlag(void *cvode_mem, long int *flag);
  154. /*
  155. * -----------------------------------------------------------------
  156. * The following function returns the name of the constant
  157. * associated with a CVSLS return flag
  158. * -----------------------------------------------------------------
  159. */
  160. SUNDIALS_EXPORT char *CVSlsGetReturnFlagName(long int flag);
  161. /*
  162. * =================================================================
  163. * PART II: B A C K W A R D P R O B L E M S
  164. * =================================================================
  165. */
  166. /*
  167. * -----------------------------------------------------------------
  168. * FUNCTION TYPES
  169. * -----------------------------------------------------------------
  170. */
  171. /*
  172. * -----------------------------------------------------------------
  173. * Type: CVSlsSparseJacFnB
  174. * -----------------------------------------------------------------
  175. * A sparse Jacobian approximation function jacB for the adjoint
  176. * (backward) problem must have the prototype given below.
  177. * -----------------------------------------------------------------
  178. */
  179. typedef int (*CVSlsSparseJacFnB)(realtype t, N_Vector y,
  180. N_Vector yB, N_Vector fyB,
  181. SlsMat JB, void *user_dataB,
  182. N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B);
  183. /*
  184. * -----------------------------------------------------------------
  185. * Type: CVSlsSparseJacFnBS
  186. * -----------------------------------------------------------------
  187. * A sparse Jacobian approximation function jacBS for the adjoint
  188. * (backward) problem, sensitivity-dependent case, must have the
  189. * prototype given below.
  190. * -----------------------------------------------------------------
  191. */
  192. typedef int (*CVSlsSparseJacFnBS)(realtype t,
  193. N_Vector y, N_Vector *yS,
  194. N_Vector yB, N_Vector fyB,
  195. SlsMat JB, void *user_dataB,
  196. N_Vector tmp1B, N_Vector tmp2B, N_Vector tmp3B);
  197. /*
  198. * -----------------------------------------------------------------
  199. * EXPORTED FUNCTIONS
  200. * -----------------------------------------------------------------
  201. */
  202. /*
  203. * -----------------------------------------------------------------
  204. * Functions: CVSlsSetSparseJacFnB and CVSlsSetSparseJacFnBS
  205. * -----------------------------------------------------------------
  206. * CVSlsSetSparseJacFnB specifies the sparse Jacobian functions to
  207. * be used by a CVSPARSE linear solver for the backward integration phase
  208. * when the backward problem does not depend on forward sensitivities.
  209. * CVSlsSetSparseJacFnBS specifies the Jacobian
  210. * functions when the backward problem does depend on sensitivities.
  211. * The 'which' argument is the int returned by CVodeCreateB.
  212. * -----------------------------------------------------------------
  213. */
  214. SUNDIALS_EXPORT int CVSlsSetSparseJacFnB(void *cv_mem, int which,
  215. CVSlsSparseJacFnB jacB);
  216. SUNDIALS_EXPORT int CVSlsSetSparseJacFnBS(void *cv_mem, int which,
  217. CVSlsSparseJacFnBS jacBS);
  218. #ifdef __cplusplus
  219. }
  220. #endif
  221. #endif