source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/sundials/include/sunmatrix/sunmatrix_dense.h @ 16222

Last change on this file since 16222 was 16222, checked in by gkronber, 4 years ago

#2925:

  • added comments about parameter identification for differential equation models
  • added source code of cvodes library (part of sundials) which provides functionality to calculate gradients for the parameters of partial differential equation models efficiently using the 'adjoint state method'.
  • added compiled version of cvodes
File size: 9.2 KB
Line 
1/*
2 * -----------------------------------------------------------------
3 * Programmer(s): Daniel Reynolds @ SMU
4 *                David Gardner @ LLNL
5 * Based on code sundials_direct.h by: Radu Serban @ LLNL
6 * -----------------------------------------------------------------
7 * LLNS/SMU Copyright Start
8 * Copyright (c) 2017, Southern Methodist University and
9 * Lawrence Livermore National Security
10 *
11 * This work was performed under the auspices of the U.S. Department
12 * of Energy by Southern Methodist University and Lawrence Livermore
13 * National Laboratory under Contract DE-AC52-07NA27344.
14 * Produced at Southern Methodist University and the Lawrence
15 * Livermore National Laboratory.
16 *
17 * All rights reserved.
18 * For details, see the LICENSE file.
19 * LLNS/SMU Copyright End
20 * -----------------------------------------------------------------
21 * This is the header file for the dense implementation of the
22 * SUNMATRIX module.
23 *
24 * Part I contains declarations specific to the dense implementation
25 * of the supplied SUNMATRIX module.
26 *
27 * Part II defines accessor macros that allow the user to
28 * efficiently use this SUNMatrix type without making explicit
29 * references to the underlying data structure.
30 *
31 * Part III contains the prototype for the constructor
32 * SUNDenseMatrix as well as implementation-specific prototypes
33 * for various useful matrix operations.
34 *
35 * Notes:
36 *
37 *   - The definition of the generic SUNMatrix structure can be found
38 *     in the header file sundials_matrix.h.
39 *
40 *   - The definition of the type 'realtype' can be found in the
41 *     header file sundials_types.h, and it may be changed (at the
42 *     configuration stage) according to the user's needs.
43 *     The sundials_types.h file also contains the definition
44 *     for the type 'booleantype' and 'indextype'.
45 *
46 * -----------------------------------------------------------------
47 */
48
49#ifndef _SUNMATRIX_DENSE_H
50#define _SUNMATRIX_DENSE_H
51
52#include <stdio.h>
53#include <sundials/sundials_matrix.h>
54
55#ifdef __cplusplus  /* wrapper to enable C++ usage */
56extern "C" {
57#endif
58
59/*
60 * -----------------------------------------------------------------
61 * PART I: Dense implementation of SUNMatrix
62 *
63 * The dense implementation of the SUNMatrix 'content' structure
64 * contains:
65 *   M     - number of rows
66 *   N     - number of columns
67 *   data  - pointer to a contiguous block of realtype variables
68 *   ldata - length of the data array = M*N
69 *   cols  - array of pointers. cols[j] points to the first element
70 *           of the j-th column of the matrix in the array data.
71 * The elements of a dense matrix are stored columnwise (i.e. columns
72 * are stored one on top of the other in memory); i.e. if A is a
73 * SUNMatrix_Dense object, then the (i,j)th element of A (with
74 * 0 <= i < M and 0 <= j < N) is given by (A->data)[j*M+i].
75 *
76 * -----------------------------------------------------------------
77 */
78 
79struct _SUNMatrixContent_Dense {
80  sunindextype M;
81  sunindextype N;
82  realtype *data;
83  sunindextype ldata;
84  realtype **cols;
85};
86
87typedef struct _SUNMatrixContent_Dense *SUNMatrixContent_Dense;
88
89/*
90 * -----------------------------------------------------------------
91 * PART II: macros SM_CONTENT_D, SM_DATA_D, SM_ROWS_D, SM_COLUMNS_D,
92 *          SM_COLUMN_D, and SM_ELEMENT_D
93 * -----------------------------------------------------------------
94 * In the descriptions below, the following user declarations
95 * are assumed:
96 *
97 * SUNMatrix A;
98 * SUNMatrixContent_Dense A_cont;
99 * realtype *A_col_j, *A_data, **A_cols, A_ij;
100 * sunindextype i, j, A_rows, A_columns, A_ldata;
101 *
102 * (1) SM_CONTENT_D
103 *
104 *     This macro gives access to the contents of the dense
105 *     SUNMatrix
106 *
107 *     The assignment A_cont = SM_CONTENT_D(A) sets A_cont to be
108 *     a pointer to the dense SUNMatrix content structure.
109 *
110 * (2) SM_DATA_D, SM_COLS_D, SM_LDATA_D, SM_ROWS_D, SM_COLUMNS_D
111 *
112 *     These macros give access to the individual parts of
113 *     the content structure of a dense SUNMatrix.
114 *
115 *     The assignment A_data = SM_DATA_D(A) sets A_data to be
116 *     a pointer to the first component of A.
117 *
118 *     The assignment A_cols = SM_COLS_D(A) sets A_cols to be
119 *     a pointer to the content's 'cols' entry.
120 *
121 *     The assignment A_ldata = SM_LDATA_D(A) sets A_ldata to be
122 *     the length of the data array for A.
123 *
124 *     The assignment A_rows = SM_ROWS_D(A) sets A_rows to be
125 *     the number of rows in A.
126 *
127 *     The assignment A_columns = SM_COLUMNS_D(A) sets A_columns
128 *     to be the number of columns in A.
129 *
130 * (3) SM_COLUMN_D and SM_ELEMENT_D
131 *
132 *     These macros give access to the individual columns and
133 *     elements of a dense SUNMatrix, respectively.  In the
134 *     following, the entries of a SUNMatrix are indexed (i,j)
135 *     where i=0,...,M-1 and j=0,...,N-1.
136 *     
137 *     The assignment A_col_j = SM_COLUMN_D(A,j) sets A_col_j to
138 *     be a pointer to the jth column of the M-by-N dense
139 *     matrix A, 0 <= j < N.  After the assignment, A_col_j may
140 *     be treated as an array indexed from 0 to M-1.
141 *     The (i,j)-th element of A is thus referenced by col_j[i].
142 *
143 *     The assignment A_ij = SM_ELEMENT_D(A,i,j) sets A_ij to
144 *     the value of the (i,j)th element of the dense M-by-N matrix
145 *     A, 0 <= i < M ; 0 <= j < N.  Similarly, the assignment
146 *     SM_ELEMENT_D(A,i,j) = A_ij sets the value of A_ij into the
147 *     (i,j) location of the matrix A.
148 *
149 * -----------------------------------------------------------------
150 */
151
152#define SM_CONTENT_D(A)     ( (SUNMatrixContent_Dense)(A->content) )
153
154#define SM_ROWS_D(A)        ( SM_CONTENT_D(A)->M )
155
156#define SM_COLUMNS_D(A)     ( SM_CONTENT_D(A)->N )
157
158#define SM_LDATA_D(A)       ( SM_CONTENT_D(A)->ldata )
159
160#define SM_DATA_D(A)        ( SM_CONTENT_D(A)->data )
161
162#define SM_COLS_D(A)        ( SM_CONTENT_D(A)->cols )
163
164#define SM_COLUMN_D(A,j)    ( (SM_CONTENT_D(A)->cols)[j] )
165
166#define SM_ELEMENT_D(A,i,j) ( (SM_CONTENT_D(A)->cols)[j][i] )
167
168/*
169 * -----------------------------------------------------------------
170 * PART III: functions exported by sunmatrix_dense
171 *
172 * CONSTRUCTORS:
173 *    SUNDenseMatrix
174 * OTHER:
175 *    SUNDenseMatrix_Print
176 *    SUNDenseMatrix_Rows
177 *    SUNDenseMatrix_Columns
178 *    SUNDenseMatrix_LData
179 *    SUNDenseMatrix_Data
180 *    SUNDenseMatrix_Cols
181 *    SUNDenseMatrix_Column
182 * -----------------------------------------------------------------
183 */
184
185/*
186 * -----------------------------------------------------------------
187 * Function: SUNDenseMatrix
188 * -----------------------------------------------------------------
189 * Creates and allocates memory for an M-by-N dense SUNMatrix.
190 * -----------------------------------------------------------------
191 */
192
193SUNDIALS_EXPORT SUNMatrix SUNDenseMatrix(sunindextype M, sunindextype N);
194
195/*
196 * -----------------------------------------------------------------
197 * Functions: SUNDenseMatrix_Print
198 * -----------------------------------------------------------------
199 * This function prints the content of a M-by-N dense matrix A to
200 * file pointer as it would normally appear on paper.
201 * It is intended as debugging tools with small values of M and N.
202 * The elements are printed using the %g/%lg/%Lg option.
203 * A blank line is printed before and after the matrix.
204 * -----------------------------------------------------------------
205 */
206
207SUNDIALS_EXPORT void SUNDenseMatrix_Print(SUNMatrix A, FILE* outfile);
208
209
210/*
211 * -----------------------------------------------------------------
212 * Accessor Functions:
213 *
214 * SUNDenseMatrix_Rows
215 *    Returns the number of rows in the dense matrix
216 *
217 * SUNDenseMatrix_Columns
218 *    Returns the number of columns in the dense matrix
219 *
220 * SUNDenseMatrix_LData
221 *    Returns the total allocated data length for the dense matrix
222 *
223 * SUNDenseMatrix_Data
224 *    Returns a pointer to the data array for the dense matrix
225 *
226 * SUNDenseMatrix_Cols
227 *    Returns a pointer to the cols array for the dense matrix
228 *
229 * SUNDenseMatrix_Column
230 *    Returns a pointer to the jth column of the dense matrix
231 *
232 * -----------------------------------------------------------------
233 */
234
235SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Rows(SUNMatrix A);
236SUNDIALS_EXPORT sunindextype SUNDenseMatrix_Columns(SUNMatrix A);
237SUNDIALS_EXPORT sunindextype SUNDenseMatrix_LData(SUNMatrix A);
238SUNDIALS_EXPORT realtype* SUNDenseMatrix_Data(SUNMatrix A);
239SUNDIALS_EXPORT realtype** SUNDenseMatrix_Cols(SUNMatrix A);
240SUNDIALS_EXPORT realtype* SUNDenseMatrix_Column(SUNMatrix A, sunindextype j);
241
242/*
243 * -----------------------------------------------------------------
244 * dense implementations of various useful matrix operations
245 * -----------------------------------------------------------------
246 */
247
248SUNDIALS_EXPORT SUNMatrix_ID SUNMatGetID_Dense(SUNMatrix A);
249SUNDIALS_EXPORT SUNMatrix SUNMatClone_Dense(SUNMatrix A);
250SUNDIALS_EXPORT void SUNMatDestroy_Dense(SUNMatrix A);
251SUNDIALS_EXPORT int SUNMatZero_Dense(SUNMatrix A);
252SUNDIALS_EXPORT int SUNMatCopy_Dense(SUNMatrix A, SUNMatrix B);
253SUNDIALS_EXPORT int SUNMatScaleAdd_Dense(realtype c, SUNMatrix A, SUNMatrix B);
254SUNDIALS_EXPORT int SUNMatScaleAddI_Dense(realtype c, SUNMatrix A);
255SUNDIALS_EXPORT int SUNMatMatvec_Dense(SUNMatrix A, N_Vector x, N_Vector y);
256SUNDIALS_EXPORT int SUNMatSpace_Dense(SUNMatrix A, long int *lenrw,
257                                      long int *leniw);
258
259 
260#ifdef __cplusplus
261}
262#endif
263
264#endif
Note: See TracBrowser for help on using the repository browser.