sundials_dense.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * -----------------------------------------------------------------
  3. * $Revision: 4378 $
  4. * $Date: 2015-02-19 10:55:14 -0800 (Thu, 19 Feb 2015) $
  5. * -----------------------------------------------------------------
  6. * Programmer: Radu Serban @ 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 package of DENSE matrix
  19. * operations, based on the DlsMat type defined in sundials_direct.h.
  20. *
  21. * There are two sets of dense solver routines listed in
  22. * this file: one set uses type DlsMat defined below and the
  23. * other set uses the type realtype ** for dense matrix arguments.
  24. * Routines that work with the type DlsMat begin with "Dense".
  25. * Routines that work with realtype** begin with "dense".
  26. * -----------------------------------------------------------------
  27. */
  28. #ifndef _SUNDIALS_DENSE_H
  29. #define _SUNDIALS_DENSE_H
  30. #include <sundials/sundials_direct.h>
  31. #ifdef __cplusplus /* wrapper to enable C++ usage */
  32. extern "C" {
  33. #endif
  34. /*
  35. * -----------------------------------------------------------------
  36. * Functions: DenseGETRF and DenseGETRS
  37. * -----------------------------------------------------------------
  38. * DenseGETRF performs the LU factorization of the M by N dense
  39. * matrix A. This is done using standard Gaussian elimination
  40. * with partial (row) pivoting. Note that this applies only
  41. * to matrices with M >= N and full column rank.
  42. *
  43. * A successful LU factorization leaves the matrix A and the
  44. * pivot array p with the following information:
  45. *
  46. * (1) p[k] contains the row number of the pivot element chosen
  47. * at the beginning of elimination step k, k=0, 1, ..., N-1.
  48. *
  49. * (2) If the unique LU factorization of A is given by PA = LU,
  50. * where P is a permutation matrix, L is a lower trapezoidal
  51. * matrix with all 1's on the diagonal, and U is an upper
  52. * triangular matrix, then the upper triangular part of A
  53. * (including its diagonal) contains U and the strictly lower
  54. * trapezoidal part of A contains the multipliers, I-L.
  55. *
  56. * For square matrices (M=N), L is unit lower triangular.
  57. *
  58. * DenseGETRF returns 0 if successful. Otherwise it encountered
  59. * a zero diagonal element during the factorization. In this case
  60. * it returns the column index (numbered from one) at which
  61. * it encountered the zero.
  62. *
  63. * DenseGETRS solves the N-dimensional system A x = b using
  64. * the LU factorization in A and the pivot information in p
  65. * computed in DenseGETRF. The solution x is returned in b. This
  66. * routine cannot fail if the corresponding call to DenseGETRF
  67. * did not fail.
  68. * DenseGETRS does NOT check for a square matrix!
  69. *
  70. * -----------------------------------------------------------------
  71. * DenseGETRF and DenseGETRS are simply wrappers around denseGETRF
  72. * and denseGETRS, respectively, which perform all the work by
  73. * directly accessing the data in the DlsMat A (i.e. the field cols)
  74. * -----------------------------------------------------------------
  75. */
  76. SUNDIALS_EXPORT long int DenseGETRF(DlsMat A, long int *p);
  77. SUNDIALS_EXPORT void DenseGETRS(DlsMat A, long int *p, realtype *b);
  78. SUNDIALS_EXPORT long int denseGETRF(realtype **a, long int m, long int n, long int *p);
  79. SUNDIALS_EXPORT void denseGETRS(realtype **a, long int n, long int *p, realtype *b);
  80. /*
  81. * -----------------------------------------------------------------
  82. * Functions : DensePOTRF and DensePOTRS
  83. * -----------------------------------------------------------------
  84. * DensePOTRF computes the Cholesky factorization of a real symmetric
  85. * positive definite matrix A.
  86. * -----------------------------------------------------------------
  87. * DensePOTRS solves a system of linear equations A*X = B with a
  88. * symmetric positive definite matrix A using the Cholesky factorization
  89. * A = L*L**T computed by DensePOTRF.
  90. *
  91. * -----------------------------------------------------------------
  92. * DensePOTRF and DensePOTRS are simply wrappers around densePOTRF
  93. * and densePOTRS, respectively, which perform all the work by
  94. * directly accessing the data in the DlsMat A (i.e. the field cols)
  95. * -----------------------------------------------------------------
  96. */
  97. SUNDIALS_EXPORT long int DensePOTRF(DlsMat A);
  98. SUNDIALS_EXPORT void DensePOTRS(DlsMat A, realtype *b);
  99. SUNDIALS_EXPORT long int densePOTRF(realtype **a, long int m);
  100. SUNDIALS_EXPORT void densePOTRS(realtype **a, long int m, realtype *b);
  101. /*
  102. * -----------------------------------------------------------------
  103. * Functions : DenseGEQRF and DenseORMQR
  104. * -----------------------------------------------------------------
  105. * DenseGEQRF computes a QR factorization of a real M-by-N matrix A:
  106. * A = Q * R (with M>= N).
  107. *
  108. * DenseGEQRF requires a temporary work vector wrk of length M.
  109. * -----------------------------------------------------------------
  110. * DenseORMQR computes the product w = Q * v where Q is a real
  111. * orthogonal matrix defined as the product of k elementary reflectors
  112. *
  113. * Q = H(1) H(2) . . . H(k)
  114. *
  115. * as returned by DenseGEQRF. Q is an M-by-N matrix, v is a vector
  116. * of length N and w is a vector of length M (with M>=N).
  117. *
  118. * DenseORMQR requires a temporary work vector wrk of length M.
  119. *
  120. * -----------------------------------------------------------------
  121. * DenseGEQRF and DenseORMQR are simply wrappers around denseGEQRF
  122. * and denseORMQR, respectively, which perform all the work by
  123. * directly accessing the data in the DlsMat A (i.e. the field cols)
  124. * -----------------------------------------------------------------
  125. */
  126. SUNDIALS_EXPORT int DenseGEQRF(DlsMat A, realtype *beta, realtype *wrk);
  127. SUNDIALS_EXPORT int DenseORMQR(DlsMat A, realtype *beta, realtype *vn, realtype *vm,
  128. realtype *wrk);
  129. SUNDIALS_EXPORT int denseGEQRF(realtype **a, long int m, long int n, realtype *beta, realtype *v);
  130. SUNDIALS_EXPORT int denseORMQR(realtype **a, long int m, long int n, realtype *beta,
  131. realtype *v, realtype *w, realtype *wrk);
  132. /*
  133. * -----------------------------------------------------------------
  134. * Function : DenseCopy
  135. * -----------------------------------------------------------------
  136. * DenseCopy copies the contents of the M-by-N matrix A into the
  137. * M-by-N matrix B.
  138. *
  139. * DenseCopy is a wrapper around denseCopy which accesses the data
  140. * in the DlsMat A and B (i.e. the fields cols)
  141. * -----------------------------------------------------------------
  142. */
  143. SUNDIALS_EXPORT void DenseCopy(DlsMat A, DlsMat B);
  144. SUNDIALS_EXPORT void denseCopy(realtype **a, realtype **b, long int m, long int n);
  145. /*
  146. * -----------------------------------------------------------------
  147. * Function: DenseScale
  148. * -----------------------------------------------------------------
  149. * DenseScale scales the elements of the M-by-N matrix A by the
  150. * constant c and stores the result back in A.
  151. *
  152. * DenseScale is a wrapper around denseScale which performs the actual
  153. * scaling by accessing the data in the DlsMat A (i.e. the field
  154. * cols).
  155. * -----------------------------------------------------------------
  156. */
  157. SUNDIALS_EXPORT void DenseScale(realtype c, DlsMat A);
  158. SUNDIALS_EXPORT void denseScale(realtype c, realtype **a, long int m, long int n);
  159. /*
  160. * -----------------------------------------------------------------
  161. * Function: denseAddIdentity
  162. * -----------------------------------------------------------------
  163. * denseAddIdentity adds the identity matrix to the n-by-n matrix
  164. * stored in the realtype** arrays.
  165. * -----------------------------------------------------------------
  166. */
  167. SUNDIALS_EXPORT void denseAddIdentity(realtype **a, long int n);
  168. /*
  169. * -----------------------------------------------------------------
  170. * Function: DenseMatvec
  171. * -----------------------------------------------------------------
  172. * DenseMatvec computes the matrix-vector product y = A*x, where A
  173. * is an M-by-N matrix, x is a vector of length N, and y is a vector
  174. * of length M. No error checking is performed on the length of the
  175. * arrays x and y. Only y is modified in this routine.
  176. *
  177. * DenseMatvec is a wrapper around denseMatvec which performs the
  178. * actual product by accessing the data in the DlsMat A.
  179. * -----------------------------------------------------------------
  180. */
  181. SUNDIALS_EXPORT void DenseMatvec(DlsMat A, realtype *x, realtype *y);
  182. SUNDIALS_EXPORT void denseMatvec(realtype **a, realtype *x, realtype *y, long int m, long int n);
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186. #endif