Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 16222 was 16222, checked in by gkronber, 6 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: 10.2 KB
Line 
1/*
2 * -----------------------------------------------------------------
3 * $Revision$
4 * $Date$
5 * -----------------------------------------------------------------
6 * Programmer(s): 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 the implementation of the scaled
19 * preconditioned Transpose-Free Quasi-Minimal Residual (SPTFQMR)
20 * linear solver.
21 *
22 * The SPTFQMR algorithm solves a linear system of the form Ax = b.
23 * Preconditioning is allowed on the left (PREC_LEFT), right
24 * (PREC_RIGHT), or both (PREC_BOTH).  Scaling is allowed on both
25 * sides.  We denote the preconditioner and scaling matrices as
26 * follows:
27 *   P1 = left preconditioner
28 *   P2 = right preconditioner
29 *   S1 = diagonal matrix of scale factors for P1-inverse b
30 *   S2 = diagonal matrix of scale factors for P2 x
31 * The matrices A, P1, and P2 are not required explicitly; only
32 * routines that provide A, P1-inverse, and P2-inverse as operators
33 * are required.
34 *
35 * In this notation, SPTFQMR applies the underlying TFQMR method to
36 * the equivalent transformed system:
37 *   Abar xbar = bbar, where
38 *   Abar = S1 (P1-inverse) A (P2-inverse) (S2-inverse),
39 *   bbar = S1 (P1-inverse) b, and
40 *   xbar = S2 P2 x.
41 *
42 * The scaling matrices must be chosen so that vectors
43 * S1 P1-inverse b and S2 P2 x have dimensionless components.  If
44 * preconditioning is done on the left only (P2 = I), by a matrix P,
45 * then S2 must be a scaling for x, while S1 is a scaling for
46 * P-inverse b, and so may also be taken as a scaling for x.
47 * Similarly, if preconditioning is done on the right only (P1 = I,
48 * P2 = P), then S1 must be a scaling for b, while S2 is a scaling
49 * for P x, and may also be taken as a scaling for b.
50 *
51 * The stopping test for the SPTFQMR iterations is on the L2-norm of
52 * the scaled preconditioned residual:
53 *   || bbar - Abar xbar ||_2 < delta
54 * with an input test constant delta.
55 *
56 * The usage of this SPTFQMR solver involves supplying two routines
57 * and making three calls.  The user-supplied routines are:
58 *   atimes(A_data, x, y) to compute y = A x, given x,
59 * and
60 *   psolve(P_data, y, x, lr) to solve P1 x = y or P2 x = y for x,
61 *                            given y.
62 * The three user calls are:
63 *   mem  = SptfqmrMalloc(lmax, vec_tmpl);
64 *          to initialize memory
65 *   flag = SptfqmrSolve(mem, A_data, x, b, pretype, delta, P_data,
66 *                       sx, sb, atimes, psolve, res_norm, nli, nps);
67 *          to solve the system, and
68 *   SptfqmrFree(mem);
69 *          to free the memory allocated by SptfqmrMalloc().
70 * Complete details for specifying atimes() and psolve() and for the
71 * usage calls are given in the paragraphs below and in the header
72 * file sundials_iterative.h.
73 * -----------------------------------------------------------------
74 */
75
76#ifndef _SPTFQMR_H
77#define _SPTFQMR_H
78
79#include <sundials/sundials_iterative.h>
80
81#ifdef __cplusplus  /* wrapper to enable C++ usage */
82extern "C" {
83#endif
84
85/*
86 * -----------------------------------------------------------------
87 * Types: struct SptfqmrMemRec and struct *SptfqmrMem
88 * -----------------------------------------------------------------
89 * A variable declaration of type struct *SptfqmrMem denotes a pointer
90 * to a data structure of type struct SptfqmrMemRec. The SptfqmrMemRec
91 * structure contains numerous fields that must be accessed by the
92 * SPTFQMR linear solver module.
93 *
94 *  l_max  maximum Krylov subspace dimension that SptfqmrSolve will
95 *         be permitted to use
96 *
97 *  r_star  vector (type N_Vector) which holds the initial scaled,
98 *          preconditioned linear system residual
99 *
100 *  q/d/v/p/u/r  vectors (type N_Vector) used for workspace by
101 *               the SPTFQMR algorithm
102 *
103 *  vtemp1/vtemp2/vtemp3  scratch vectors (type N_Vector) used as
104 *                        temporary storage
105 * -----------------------------------------------------------------
106 */
107
108typedef struct {
109
110  int l_max;
111
112  N_Vector r_star;
113  N_Vector q;
114  N_Vector d;
115  N_Vector v;
116  N_Vector p;
117  N_Vector *r;
118  N_Vector u;
119  N_Vector vtemp1;
120  N_Vector vtemp2;
121  N_Vector vtemp3;
122
123} SptfqmrMemRec, *SptfqmrMem;
124
125/*
126 * -----------------------------------------------------------------
127 * Function : SptfqmrMalloc
128 * -----------------------------------------------------------------
129 * SptfqmrMalloc allocates additional memory needed by the SPTFQMR
130 * linear solver module.
131 *
132 *  l_max  maximum Krylov subspace dimension that SptfqmrSolve will
133 *         be permitted to use
134 *
135 *  vec_tmpl  implementation-specific template vector (type N_Vector)
136 *            (created using either N_VNew_Serial or N_VNew_Parallel)
137 *
138 * If successful, SptfqmrMalloc returns a non-NULL memory pointer. If
139 * an error occurs, then a NULL pointer is returned.
140 * -----------------------------------------------------------------
141 */
142
143SUNDIALS_EXPORT SptfqmrMem SptfqmrMalloc(int l_max, N_Vector vec_tmpl);
144
145/*
146 * -----------------------------------------------------------------
147 * Function : SptfqmrSolve
148 * -----------------------------------------------------------------
149 * SptfqmrSolve solves the linear system Ax = b by means of a scaled
150 * preconditioned Transpose-Free Quasi-Minimal Residual (SPTFQMR)
151 * method.
152 *
153 *  mem  pointer to an internal memory block allocated during a
154 *       prior call to SptfqmrMalloc
155 *
156 *  A_data  pointer to a data structure containing information
157 *          about the coefficient matrix A (passed to user-supplied
158 *          function referenced by atimes (function pointer))
159 *
160 *  x  vector (type N_Vector) containing initial guess x_0 upon
161 *     entry, but which upon return contains an approximate solution
162 *     of the linear system Ax = b (solution only valid if return
163 *     value is either SPTFQMR_SUCCESS or SPTFQMR_RES_REDUCED)
164 *
165 *  b  vector (type N_Vector) set to the right-hand side vector b
166 *     of the linear system (undisturbed by function)
167 *
168 *  pretype  variable (type int) indicating the type of
169 *           preconditioning to be used (see sundials_iterative.h)
170 *
171 *  delta  tolerance on the L2 norm of the scaled, preconditioned
172 *         residual (if return value == SPTFQMR_SUCCESS, then
173 *         ||sb*P1_inv*(b-Ax)||_L2 <= delta)
174 *
175 *  P_data  pointer to a data structure containing preconditioner
176 *          information (passed to user-supplied function referenced
177 *          by psolve (function pointer))
178 *
179 *  sx  vector (type N_Vector) containing positive scaling factors
180 *      for x (pass sx == NULL if scaling NOT required)
181 *
182 *  sb  vector (type N_Vector) containing positive scaling factors
183 *      for b (pass sb == NULL if scaling NOT required)
184 *
185 *  atimes  user-supplied routine responsible for computing the
186 *          matrix-vector product Ax (see sundials_iterative.h)
187 *
188 *  psolve  user-supplied routine responsible for solving the
189 *          preconditioned linear system Pz = r (ignored if
190 *          pretype == PREC_NONE) (see sundials_iterative.h)
191 *
192 *  res_norm  pointer (type realtype*) to the L2 norm of the
193 *            scaled, preconditioned residual (if return value
194 *            is either SPTFQMR_SUCCESS or SPTFQMR_RES_REDUCED, then
195 *            *res_norm = ||sb*P1_inv*(b-Ax)||_L2, where x is
196 *            the computed approximate solution, sb is the diagonal
197 *            scaling matrix for the right-hand side b, and P1_inv
198 *            is the inverse of the left-preconditioner matrix)
199 *
200 *  nli  pointer (type int*) to the total number of linear
201 *       iterations performed
202 *
203 *  nps  pointer (type int*) to the total number of calls made
204 *       to the psolve routine
205 * -----------------------------------------------------------------
206 */
207
208SUNDIALS_EXPORT int SptfqmrSolve(SptfqmrMem mem, void *A_data, N_Vector x, N_Vector b,
209         int pretype, realtype delta, void *P_data, N_Vector sx,
210         N_Vector sb, ATimesFn atimes, PSolveFn psolve,
211         realtype *res_norm, int *nli, int *nps);
212
213/* Return values for SptfqmrSolve */
214
215#define SPTFQMR_SUCCESS            0  /* SPTFQMR algorithm converged          */
216#define SPTFQMR_RES_REDUCED        1  /* SPTFQMR did NOT converge, but the
217                 residual was reduced                 */
218#define SPTFQMR_CONV_FAIL          2  /* SPTFQMR algorithm failed to converge */
219#define SPTFQMR_PSOLVE_FAIL_REC    3  /* psolve failed recoverably            */
220#define SPTFQMR_ATIMES_FAIL_REC    4  /* atimes failed recoverably            */
221#define SPTFQMR_PSET_FAIL_REC      5  /* pset faild recoverably               */
222
223#define SPTFQMR_MEM_NULL          -1  /* mem argument is NULL                 */
224#define SPTFQMR_ATIMES_FAIL_UNREC -2  /* atimes returned failure flag         */
225#define SPTFQMR_PSOLVE_FAIL_UNREC -3  /* psolve failed unrecoverably          */
226#define SPTFQMR_PSET_FAIL_UNREC   -4  /* pset failed unrecoverably            */
227
228/*
229 * -----------------------------------------------------------------
230 * Function : SptfqmrFree
231 * -----------------------------------------------------------------
232 * SptfqmrFree frees the memory allocated by a call to SptfqmrMalloc.
233 * It is illegal to use the pointer mem after a call to SptfqmrFree.
234 * -----------------------------------------------------------------
235 */
236
237SUNDIALS_EXPORT void SptfqmrFree(SptfqmrMem mem);
238
239/*
240 * -----------------------------------------------------------------
241 * Macro : SPTFQMR_VTEMP
242 * -----------------------------------------------------------------
243 * This macro provides access to the work vector vtemp1 in the
244 * memory block of the SPTFQMR module. The argument mem is the
245 * memory pointer returned by SptfqmrMalloc, of type SptfqmrMem,
246 * and the macro value is of type N_Vector.
247 *
248 * Note: Only used by IDA (vtemp1 contains P_inverse F if
249 *       nli_inc == 0).
250 * -----------------------------------------------------------------
251 */
252
253#define SPTFQMR_VTEMP(mem) (mem->vtemp1)
254
255#ifdef __cplusplus
256}
257#endif
258
259#endif
Note: See TracBrowser for help on using the repository browser.