nvector_serial.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer(s): Scott D. Cohen, Alan C. Hindmarsh, Radu Serban,
  7. * and Aaron Collier @ LLNL
  8. * -----------------------------------------------------------------
  9. * LLNS Copyright Start
  10. * Copyright (c) 2014, Lawrence Livermore National Security
  11. * This work was performed under the auspices of the U.S. Department
  12. * of Energy by Lawrence Livermore National Laboratory in part under
  13. * Contract W-7405-Eng-48 and in part under Contract DE-AC52-07NA27344.
  14. * Produced at the Lawrence Livermore National Laboratory.
  15. * All rights reserved.
  16. * For details, see the LICENSE file.
  17. * LLNS Copyright End
  18. * -----------------------------------------------------------------
  19. * This is the header file for the serial implementation of the
  20. * NVECTOR module.
  21. *
  22. * Part I contains declarations specific to the serial
  23. * implementation of the supplied NVECTOR module.
  24. *
  25. * Part II defines accessor macros that allow the user to
  26. * efficiently use the type N_Vector without making explicit
  27. * references to the underlying data structure.
  28. *
  29. * Part III contains the prototype for the constructor N_VNew_Serial
  30. * as well as implementation-specific prototypes for various useful
  31. * vector operations.
  32. *
  33. * Notes:
  34. *
  35. * - The definition of the generic N_Vector structure can be found
  36. * in the header file sundials_nvector.h.
  37. *
  38. * - The definition of the type 'realtype' can be found in the
  39. * header file sundials_types.h, and it may be changed (at the
  40. * configuration stage) according to the user's needs.
  41. * The sundials_types.h file also contains the definition
  42. * for the type 'booleantype'.
  43. *
  44. * - N_Vector arguments to arithmetic vector operations need not
  45. * be distinct. For example, the following call:
  46. *
  47. * N_VLinearSum_Serial(a,x,b,y,y);
  48. *
  49. * (which stores the result of the operation a*x+b*y in y)
  50. * is legal.
  51. * -----------------------------------------------------------------
  52. */
  53. #ifndef _NVECTOR_SERIAL_H
  54. #define _NVECTOR_SERIAL_H
  55. #include <sundials/sundials_nvector.h>
  56. #ifdef __cplusplus /* wrapper to enable C++ usage */
  57. extern "C" {
  58. #endif
  59. /*
  60. * -----------------------------------------------------------------
  61. * PART I: SERIAL implementation of N_Vector
  62. * -----------------------------------------------------------------
  63. */
  64. /* serial implementation of the N_Vector 'content' structure
  65. contains the length of the vector, a pointer to an array
  66. of 'realtype' components, and a flag indicating ownership of
  67. the data */
  68. struct _N_VectorContent_Serial {
  69. long int length;
  70. booleantype own_data;
  71. realtype *data;
  72. };
  73. typedef struct _N_VectorContent_Serial *N_VectorContent_Serial;
  74. /*
  75. * -----------------------------------------------------------------
  76. * PART II: macros NV_CONTENT_S, NV_DATA_S, NV_OWN_DATA_S,
  77. * NV_LENGTH_S, and NV_Ith_S
  78. * -----------------------------------------------------------------
  79. * In the descriptions below, the following user declarations
  80. * are assumed:
  81. *
  82. * N_Vector v;
  83. * long int i;
  84. *
  85. * (1) NV_CONTENT_S
  86. *
  87. * This routines gives access to the contents of the serial
  88. * vector N_Vector.
  89. *
  90. * The assignment v_cont = NV_CONTENT_S(v) sets v_cont to be
  91. * a pointer to the serial N_Vector content structure.
  92. *
  93. * (2) NV_DATA_S NV_OWN_DATA_S and NV_LENGTH_S
  94. *
  95. * These routines give access to the individual parts of
  96. * the content structure of a serial N_Vector.
  97. *
  98. * The assignment v_data = NV_DATA_S(v) sets v_data to be
  99. * a pointer to the first component of v. The assignment
  100. * NV_DATA_S(v) = data_V sets the component array of v to
  101. * be data_v by storing the pointer data_v.
  102. *
  103. * The assignment v_len = NV_LENGTH_S(v) sets v_len to be
  104. * the length of v. The call NV_LENGTH_S(v) = len_v sets
  105. * the length of v to be len_v.
  106. *
  107. * (3) NV_Ith_S
  108. *
  109. * In the following description, the components of an
  110. * N_Vector are numbered 0..n-1, where n is the length of v.
  111. *
  112. * The assignment r = NV_Ith_S(v,i) sets r to be the value of
  113. * the ith component of v. The assignment NV_Ith_S(v,i) = r
  114. * sets the value of the ith component of v to be r.
  115. *
  116. * Note: When looping over the components of an N_Vector v, it is
  117. * more efficient to first obtain the component array via
  118. * v_data = NV_DATA_S(v) and then access v_data[i] within the
  119. * loop than it is to use NV_Ith_S(v,i) within the loop.
  120. * -----------------------------------------------------------------
  121. */
  122. #define NV_CONTENT_S(v) ( (N_VectorContent_Serial)(v->content) )
  123. #define NV_LENGTH_S(v) ( NV_CONTENT_S(v)->length )
  124. #define NV_OWN_DATA_S(v) ( NV_CONTENT_S(v)->own_data )
  125. #define NV_DATA_S(v) ( NV_CONTENT_S(v)->data )
  126. #define NV_Ith_S(v,i) ( NV_DATA_S(v)[i] )
  127. /*
  128. * -----------------------------------------------------------------
  129. * PART III: functions exported by nvector_serial
  130. *
  131. * CONSTRUCTORS:
  132. * N_VNew_Serial
  133. * N_VNewEmpty_Serial
  134. * N_VMake_Serial
  135. * N_VCloneVectorArray_Serial
  136. * N_VCloneVectorArrayEmpty_Serial
  137. * DESTRUCTORS:
  138. * N_VDestroy_Serial
  139. * N_VDestroyVectorArray_Serial
  140. * OTHER:
  141. * N_VPrint_Serial
  142. * -----------------------------------------------------------------
  143. */
  144. /*
  145. * -----------------------------------------------------------------
  146. * Function : N_VNew_Serial
  147. * -----------------------------------------------------------------
  148. * This function creates and allocates memory for a serial vector.
  149. * -----------------------------------------------------------------
  150. */
  151. SUNDIALS_EXPORT N_Vector N_VNew_Serial(long int vec_length);
  152. /*
  153. * -----------------------------------------------------------------
  154. * Function : N_VNewEmpty_Serial
  155. * -----------------------------------------------------------------
  156. * This function creates a new serial N_Vector with an empty (NULL)
  157. * data array.
  158. * -----------------------------------------------------------------
  159. */
  160. SUNDIALS_EXPORT N_Vector N_VNewEmpty_Serial(long int vec_length);
  161. /*
  162. * -----------------------------------------------------------------
  163. * Function : N_VMake_Serial
  164. * -----------------------------------------------------------------
  165. * This function creates and allocates memory for a serial vector
  166. * with a user-supplied data array.
  167. * -----------------------------------------------------------------
  168. */
  169. SUNDIALS_EXPORT N_Vector N_VMake_Serial(long int vec_length, realtype *v_data);
  170. /*
  171. * -----------------------------------------------------------------
  172. * Function : N_VCloneVectorArray_Serial
  173. * -----------------------------------------------------------------
  174. * This function creates an array of 'count' SERIAL vectors by
  175. * cloning a given vector w.
  176. * -----------------------------------------------------------------
  177. */
  178. SUNDIALS_EXPORT N_Vector *N_VCloneVectorArray_Serial(int count, N_Vector w);
  179. /*
  180. * -----------------------------------------------------------------
  181. * Function : N_VCloneVectorArrayEmpty_Serial
  182. * -----------------------------------------------------------------
  183. * This function creates an array of 'count' SERIAL vectors each
  184. * with an empty (NULL) data array by cloning w.
  185. * -----------------------------------------------------------------
  186. */
  187. SUNDIALS_EXPORT N_Vector *N_VCloneVectorArrayEmpty_Serial(int count, N_Vector w);
  188. /*
  189. * -----------------------------------------------------------------
  190. * Function : N_VDestroyVectorArray_Serial
  191. * -----------------------------------------------------------------
  192. * This function frees an array of SERIAL vectors created with
  193. * N_VCloneVectorArray_Serial or N_VCloneVectorArrayEmpty_Serial.
  194. * -----------------------------------------------------------------
  195. */
  196. SUNDIALS_EXPORT void N_VDestroyVectorArray_Serial(N_Vector *vs, int count);
  197. /*
  198. * -----------------------------------------------------------------
  199. * Function : N_VPrint_Serial
  200. * -----------------------------------------------------------------
  201. * This function prints the content of a serial vector to stdout.
  202. * -----------------------------------------------------------------
  203. */
  204. SUNDIALS_EXPORT void N_VPrint_Serial(N_Vector v);
  205. /*
  206. * -----------------------------------------------------------------
  207. * serial implementations of various useful vector operations
  208. * -----------------------------------------------------------------
  209. */
  210. SUNDIALS_EXPORT N_Vector N_VCloneEmpty_Serial(N_Vector w);
  211. SUNDIALS_EXPORT N_Vector N_VClone_Serial(N_Vector w);
  212. SUNDIALS_EXPORT void N_VDestroy_Serial(N_Vector v);
  213. SUNDIALS_EXPORT void N_VSpace_Serial(N_Vector v, long int *lrw, long int *liw);
  214. SUNDIALS_EXPORT realtype *N_VGetArrayPointer_Serial(N_Vector v);
  215. SUNDIALS_EXPORT void N_VSetArrayPointer_Serial(realtype *v_data, N_Vector v);
  216. SUNDIALS_EXPORT void N_VLinearSum_Serial(realtype a, N_Vector x, realtype b, N_Vector y, N_Vector z);
  217. SUNDIALS_EXPORT void N_VConst_Serial(realtype c, N_Vector z);
  218. SUNDIALS_EXPORT void N_VProd_Serial(N_Vector x, N_Vector y, N_Vector z);
  219. SUNDIALS_EXPORT void N_VDiv_Serial(N_Vector x, N_Vector y, N_Vector z);
  220. SUNDIALS_EXPORT void N_VScale_Serial(realtype c, N_Vector x, N_Vector z);
  221. SUNDIALS_EXPORT void N_VAbs_Serial(N_Vector x, N_Vector z);
  222. SUNDIALS_EXPORT void N_VInv_Serial(N_Vector x, N_Vector z);
  223. SUNDIALS_EXPORT void N_VAddConst_Serial(N_Vector x, realtype b, N_Vector z);
  224. SUNDIALS_EXPORT realtype N_VDotProd_Serial(N_Vector x, N_Vector y);
  225. SUNDIALS_EXPORT realtype N_VMaxNorm_Serial(N_Vector x);
  226. SUNDIALS_EXPORT realtype N_VWrmsNorm_Serial(N_Vector x, N_Vector w);
  227. SUNDIALS_EXPORT realtype N_VWrmsNormMask_Serial(N_Vector x, N_Vector w, N_Vector id);
  228. SUNDIALS_EXPORT realtype N_VMin_Serial(N_Vector x);
  229. SUNDIALS_EXPORT realtype N_VWL2Norm_Serial(N_Vector x, N_Vector w);
  230. SUNDIALS_EXPORT realtype N_VL1Norm_Serial(N_Vector x);
  231. SUNDIALS_EXPORT void N_VCompare_Serial(realtype c, N_Vector x, N_Vector z);
  232. SUNDIALS_EXPORT booleantype N_VInvTest_Serial(N_Vector x, N_Vector z);
  233. SUNDIALS_EXPORT booleantype N_VConstrMask_Serial(N_Vector c, N_Vector x, N_Vector m);
  234. SUNDIALS_EXPORT realtype N_VMinQuotient_Serial(N_Vector num, N_Vector denom);
  235. #ifdef __cplusplus
  236. }
  237. #endif
  238. #endif