sundials_nvector.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Radu Serban and Aaron Collier @ 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 a generic NVECTOR package.
  19. * It defines the N_Vector structure (_generic_N_Vector) which
  20. * contains the following fields:
  21. * - an implementation-dependent 'content' field which contains
  22. * the description and actual data of the vector
  23. * - an 'ops' filed which contains a structure listing operations
  24. * acting on such vectors
  25. *
  26. * Part I of this file contains type declarations for the
  27. * _generic_N_Vector and _generic_N_Vector_Ops structures, as well
  28. * as references to pointers to such structures (N_Vector).
  29. *
  30. * Part II of this file contains the prototypes for the vector
  31. * functions which operate on N_Vector.
  32. *
  33. * At a minimum, a particular implementation of an NVECTOR must
  34. * do the following:
  35. * - specify the 'content' field of N_Vector,
  36. * - implement the operations on those N_Vectors,
  37. * - provide a constructor routine for new vectors
  38. *
  39. * Additionally, an NVECTOR implementation may provide the following:
  40. * - macros to access the underlying N_Vector data
  41. * - a constructor for an array of N_Vectors
  42. * - a constructor for an empty N_Vector (i.e., a new N_Vector with
  43. * a NULL data pointer).
  44. * - a routine to print the content of an N_Vector
  45. * -----------------------------------------------------------------
  46. */
  47. #ifndef _NVECTOR_H
  48. #define _NVECTOR_H
  49. #include <sundials/sundials_types.h>
  50. #ifdef __cplusplus /* wrapper to enable C++ usage */
  51. extern "C" {
  52. #endif
  53. /*
  54. * -----------------------------------------------------------------
  55. * Generic definition of N_Vector
  56. * -----------------------------------------------------------------
  57. */
  58. /* Forward reference for pointer to N_Vector_Ops object */
  59. typedef struct _generic_N_Vector_Ops *N_Vector_Ops;
  60. /* Forward reference for pointer to N_Vector object */
  61. typedef struct _generic_N_Vector *N_Vector;
  62. /* Define array of N_Vectors */
  63. typedef N_Vector *N_Vector_S;
  64. /* Structure containing function pointers to vector operations */
  65. struct _generic_N_Vector_Ops {
  66. N_Vector (*nvclone)(N_Vector);
  67. N_Vector (*nvcloneempty)(N_Vector);
  68. void (*nvdestroy)(N_Vector);
  69. void (*nvspace)(N_Vector, long int *, long int *);
  70. realtype* (*nvgetarraypointer)(N_Vector);
  71. void (*nvsetarraypointer)(realtype *, N_Vector);
  72. void (*nvlinearsum)(realtype, N_Vector, realtype, N_Vector, N_Vector);
  73. void (*nvconst)(realtype, N_Vector);
  74. void (*nvprod)(N_Vector, N_Vector, N_Vector);
  75. void (*nvdiv)(N_Vector, N_Vector, N_Vector);
  76. void (*nvscale)(realtype, N_Vector, N_Vector);
  77. void (*nvabs)(N_Vector, N_Vector);
  78. void (*nvinv)(N_Vector, N_Vector);
  79. void (*nvaddconst)(N_Vector, realtype, N_Vector);
  80. realtype (*nvdotprod)(N_Vector, N_Vector);
  81. realtype (*nvmaxnorm)(N_Vector);
  82. realtype (*nvwrmsnorm)(N_Vector, N_Vector);
  83. realtype (*nvwrmsnormmask)(N_Vector, N_Vector, N_Vector);
  84. realtype (*nvmin)(N_Vector);
  85. realtype (*nvwl2norm)(N_Vector, N_Vector);
  86. realtype (*nvl1norm)(N_Vector);
  87. void (*nvcompare)(realtype, N_Vector, N_Vector);
  88. booleantype (*nvinvtest)(N_Vector, N_Vector);
  89. booleantype (*nvconstrmask)(N_Vector, N_Vector, N_Vector);
  90. realtype (*nvminquotient)(N_Vector, N_Vector);
  91. };
  92. /*
  93. * -----------------------------------------------------------------
  94. * A vector is a structure with an implementation-dependent
  95. * 'content' field, and a pointer to a structure of vector
  96. * operations corresponding to that implementation.
  97. * -----------------------------------------------------------------
  98. */
  99. struct _generic_N_Vector {
  100. void *content;
  101. struct _generic_N_Vector_Ops *ops;
  102. };
  103. /*
  104. * -----------------------------------------------------------------
  105. * Functions exported by NVECTOR module
  106. * -----------------------------------------------------------------
  107. */
  108. /*
  109. * -----------------------------------------------------------------
  110. * N_VClone
  111. * Creates a new vector of the same type as an existing vector.
  112. * It does not copy the vector, but rather allocates storage for
  113. * the new vector.
  114. *
  115. * N_VCloneEmpty
  116. * Creates a new vector of the same type as an existing vector,
  117. * but does not allocate storage.
  118. *
  119. * N_VDestroy
  120. * Destroys a vector created with N_VClone.
  121. *
  122. * N_VSpace
  123. * Returns space requirements for one N_Vector (type 'realtype' in
  124. * lrw and type 'long int' in liw).
  125. *
  126. * N_VGetArrayPointer
  127. * Returns a pointer to the data component of the given N_Vector.
  128. * NOTE: This function assumes that the internal data is stored
  129. * as a contiguous 'realtype' array. This routine is only used in
  130. * the solver-specific interfaces to the dense and banded linear
  131. * solvers, as well as the interfaces to the banded preconditioners
  132. * distributed with SUNDIALS.
  133. *
  134. * N_VSetArrayPointer
  135. * Overwrites the data field in the given N_Vector with a user-supplied
  136. * array of type 'realtype'.
  137. * NOTE: This function assumes that the internal data is stored
  138. * as a contiguous 'realtype' array. This routine is only used in
  139. * the interfaces to the dense linear solver.
  140. *
  141. * N_VLinearSum
  142. * Performs the operation z = a*x + b*y
  143. *
  144. * N_VConst
  145. * Performs the operation z[i] = c for i = 0, 1, ..., N-1
  146. *
  147. * N_VProd
  148. * Performs the operation z[i] = x[i]*y[i] for i = 0, 1, ..., N-1
  149. *
  150. * N_VDiv
  151. * Performs the operation z[i] = x[i]/y[i] for i = 0, 1, ..., N-1
  152. *
  153. * N_VScale
  154. * Performs the operation z = c*x
  155. *
  156. * N_VAbs
  157. * Performs the operation z[i] = |x[i]| for i = 0, 1, ..., N-1
  158. *
  159. * N_VInv
  160. * Performs the operation z[i] = 1/x[i] for i = 0, 1, ..., N-1
  161. * This routine does not check for division by 0. It should be
  162. * called only with an N_Vector x which is guaranteed to have
  163. * all non-zero components.
  164. *
  165. * N_VAddConst
  166. * Performs the operation z[i] = x[i] + b for i = 0, 1, ..., N-1
  167. *
  168. * N_VDotProd
  169. * Returns the dot product of two vectors:
  170. * sum (i = 0 to N-1) {x[i]*y[i]}
  171. *
  172. * N_VMaxNorm
  173. * Returns the maximum norm of x:
  174. * max (i = 0 to N-1) ABS(x[i])
  175. *
  176. * N_VWrmsNorm
  177. * Returns the weighted root mean square norm of x with weight
  178. * vector w:
  179. * sqrt [(sum (i = 0 to N-1) {(x[i]*w[i])^2})/N]
  180. *
  181. * N_VWrmsNormMask
  182. * Returns the weighted root mean square norm of x with weight
  183. * vector w, masked by the elements of id:
  184. * sqrt [(sum (i = 0 to N-1) {(x[i]*w[i]*msk[i])^2})/N]
  185. * where msk[i] = 1.0 if id[i] > 0 and
  186. * msk[i] = 0.0 if id[i] < 0
  187. *
  188. * N_VMin
  189. * Returns the smallest element of x:
  190. * min (i = 0 to N-1) x[i]
  191. *
  192. * N_VWL2Norm
  193. * Returns the weighted Euclidean L2 norm of x with weight
  194. * vector w:
  195. * sqrt [(sum (i = 0 to N-1) {(x[i]*w[i])^2})]
  196. *
  197. * N_VL1Norm
  198. * Returns the L1 norm of x:
  199. * sum (i = 0 to N-1) {ABS(x[i])}
  200. *
  201. * N_VCompare
  202. * Performs the operation
  203. * z[i] = 1.0 if ABS(x[i]) >= c i = 0, 1, ..., N-1
  204. * 0.0 otherwise
  205. *
  206. * N_VInvTest
  207. * Performs the operation z[i] = 1/x[i] with a test for
  208. * x[i] == 0.0 before inverting x[i].
  209. * This routine returns TRUE if all components of x are non-zero
  210. * (successful inversion) and returns FALSE otherwise.
  211. *
  212. * N_VConstrMask
  213. * Performs the operation :
  214. * m[i] = 1.0 if constraint test fails for x[i]
  215. * m[i] = 0.0 if constraint test passes for x[i]
  216. * where the constraint tests are as follows:
  217. * If c[i] = +2.0, then x[i] must be > 0.0.
  218. * If c[i] = +1.0, then x[i] must be >= 0.0.
  219. * If c[i] = -1.0, then x[i] must be <= 0.0.
  220. * If c[i] = -2.0, then x[i] must be < 0.0.
  221. * This routine returns a boolean FALSE if any element failed
  222. * the constraint test, TRUE if all passed. It also sets a
  223. * mask vector m, with elements equal to 1.0 where the
  224. * corresponding constraint test failed, and equal to 0.0
  225. * where the constraint test passed.
  226. * This routine is specialized in that it is used only for
  227. * constraint checking.
  228. *
  229. * N_VMinQuotient
  230. * Performs the operation :
  231. * minq = min ( num[i]/denom[i]) over all i such that
  232. * denom[i] != 0.
  233. * This routine returns the minimum of the quotients obtained
  234. * by term-wise dividing num[i] by denom[i]. A zero element
  235. * in denom will be skipped. If no such quotients are found,
  236. * then the large value BIG_REAL is returned.
  237. *
  238. * -----------------------------------------------------------------
  239. *
  240. * The following table lists the vector functions used by
  241. * different modules in SUNDIALS. The symbols in the table
  242. * have the following meaning:
  243. * S - called by the solver;
  244. * D - called by the dense linear solver module
  245. * B - called by the band linear solver module
  246. * Di - called by the diagonal linear solver module
  247. * I - called by the iterative linear solver module
  248. * BP - called by the band preconditioner module
  249. * BBDP - called by the band-block diagonal preconditioner module
  250. * F - called by the Fortran-to-C interface
  251. *
  252. * ------------------------------------------------
  253. * MODULES
  254. * NVECTOR ------------------------------------------------
  255. * FUNCTIONS CVODE/CVODES IDA KINSOL
  256. * -----------------------------------------------------------------
  257. * N_VClone S Di I S I BBDP S I BBDP
  258. * -----------------------------------------------------------------
  259. * N_VCloneEmpty F F F
  260. * -----------------------------------------------------------------
  261. * N_VDestroy S Di I S I BBDP S I BBDP
  262. * -----------------------------------------------------------------
  263. * N_VSpace S S S
  264. * -----------------------------------------------------------------
  265. * N_VGetArrayPointer D B BP BBDP F D B BBDP BBDP F
  266. * -----------------------------------------------------------------
  267. * N_VSetArrayPointer D F D F
  268. * -----------------------------------------------------------------
  269. * N_VLinearSum S D Di I S D I S I
  270. * -----------------------------------------------------------------
  271. * N_VConst S I S I I
  272. * -----------------------------------------------------------------
  273. * N_VProd S Di I S I S I
  274. * -----------------------------------------------------------------
  275. * N_VDiv S Di I S I S I
  276. * -----------------------------------------------------------------
  277. * N_VScale S D B Di I BP BBDP S D B I BBDP S I BBDP
  278. * -----------------------------------------------------------------
  279. * N_VAbs S S S
  280. * -----------------------------------------------------------------
  281. * N_VInv S Di S S
  282. * -----------------------------------------------------------------
  283. * N_VAddConst S Di S
  284. * -----------------------------------------------------------------
  285. * N_VDotProd I I I
  286. * -----------------------------------------------------------------
  287. * N_VMaxNorm S S S
  288. * -----------------------------------------------------------------
  289. * N_VWrmsNorm S D B I BP BBDP S
  290. * -----------------------------------------------------------------
  291. * N_VWrmsNormMask S
  292. * -----------------------------------------------------------------
  293. * N_VMin S S S
  294. * -----------------------------------------------------------------
  295. * N_VWL2Norm S I
  296. * -----------------------------------------------------------------
  297. * N_VL1Norm I
  298. * -----------------------------------------------------------------
  299. * N_VCompare Di S
  300. * -----------------------------------------------------------------
  301. * N_VInvTest Di
  302. * -----------------------------------------------------------------
  303. * N_VConstrMask S S
  304. * -----------------------------------------------------------------
  305. * N_VMinQuotient S S
  306. * -----------------------------------------------------------------
  307. */
  308. SUNDIALS_EXPORT N_Vector N_VClone(N_Vector w);
  309. SUNDIALS_EXPORT N_Vector N_VCloneEmpty(N_Vector w);
  310. SUNDIALS_EXPORT void N_VDestroy(N_Vector v);
  311. SUNDIALS_EXPORT void N_VSpace(N_Vector v, long int *lrw, long int *liw);
  312. SUNDIALS_EXPORT realtype *N_VGetArrayPointer(N_Vector v);
  313. SUNDIALS_EXPORT void N_VSetArrayPointer(realtype *v_data, N_Vector v);
  314. SUNDIALS_EXPORT void N_VLinearSum(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z);
  315. SUNDIALS_EXPORT void N_VConst(realtype c, N_Vector z);
  316. SUNDIALS_EXPORT void N_VProd(N_Vector x, N_Vector y, N_Vector z);
  317. SUNDIALS_EXPORT void N_VDiv(N_Vector x, N_Vector y, N_Vector z);
  318. SUNDIALS_EXPORT void N_VScale(realtype c, N_Vector x, N_Vector z);
  319. SUNDIALS_EXPORT void N_VAbs(N_Vector x, N_Vector z);
  320. SUNDIALS_EXPORT void N_VInv(N_Vector x, N_Vector z);
  321. SUNDIALS_EXPORT void N_VAddConst(N_Vector x, realtype b, N_Vector z);
  322. SUNDIALS_EXPORT realtype N_VDotProd(N_Vector x, N_Vector y);
  323. SUNDIALS_EXPORT realtype N_VMaxNorm(N_Vector x);
  324. SUNDIALS_EXPORT realtype N_VWrmsNorm(N_Vector x, N_Vector w);
  325. SUNDIALS_EXPORT realtype N_VWrmsNormMask(N_Vector x, N_Vector w, N_Vector id);
  326. SUNDIALS_EXPORT realtype N_VMin(N_Vector x);
  327. SUNDIALS_EXPORT realtype N_VWL2Norm(N_Vector x, N_Vector w);
  328. SUNDIALS_EXPORT realtype N_VL1Norm(N_Vector x);
  329. SUNDIALS_EXPORT void N_VCompare(realtype c, N_Vector x, N_Vector z);
  330. SUNDIALS_EXPORT booleantype N_VInvTest(N_Vector x, N_Vector z);
  331. SUNDIALS_EXPORT booleantype N_VConstrMask(N_Vector c, N_Vector x, N_Vector m);
  332. SUNDIALS_EXPORT realtype N_VMinQuotient(N_Vector num, N_Vector denom);
  333. /*
  334. * -----------------------------------------------------------------
  335. * Additional functions exported by NVECTOR module
  336. * -----------------------------------------------------------------
  337. */
  338. /*
  339. * -----------------------------------------------------------------
  340. * N_VCloneEmptyVectorArray
  341. * Creates (by cloning 'w') an array of 'count' empty N_Vectors
  342. *
  343. * N_VCloneVectorArray
  344. * Creates (by cloning 'w') an array of 'count' N_Vectors
  345. *
  346. * N_VDestroyVectorArray
  347. * Frees memory for an array of 'count' N_Vectors that was
  348. * created by a call to N_VCloneVectorArray
  349. *
  350. * These functions are used by the SPGMR iterative linear solver
  351. * module and by the CVODES and IDAS solvers.
  352. * -----------------------------------------------------------------
  353. */
  354. SUNDIALS_EXPORT N_Vector *N_VCloneEmptyVectorArray(int count, N_Vector w);
  355. SUNDIALS_EXPORT N_Vector *N_VCloneVectorArray(int count, N_Vector w);
  356. SUNDIALS_EXPORT void N_VDestroyVectorArray(N_Vector *vs, int count);
  357. #ifdef __cplusplus
  358. }
  359. #endif
  360. #endif