Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/sundials/include/sunlinsol/sunlinsol_spfgmr.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.4 KB
Line 
1/*
2 * -----------------------------------------------------------------
3 * Programmer(s): Daniel Reynolds @ SMU
4 * Based on code sundials_spfgmr.h by: Daniel R. Reynolds and
5 *    Hilari C. Tiedeman @ SMU
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 SPFGMR implementation of the
22 * SUNLINSOL module.  The SPFGMR algorithm is based on the
23 * Scaled Preconditioned FGMRES (Flexible Generalized Minimal
24 * Residual) method [Y. Saad, SIAM J. Sci. Comput., 1993].
25 *
26 * The SPFGMR algorithm solves a linear system A x = b.
27 * Preconditioning is only allowed on the right.  Scaling is allowed
28 * on both sides, and restarts are also allowed. We denote the
29 * preconditioner and scaling matrices as follows:
30 *   P = right preconditioner
31 *   S1 = diagonal matrix of scale factors for P-inverse b
32 *   S2 = diagonal matrix of scale factors for x
33 * The matrices A and P are not required explicitly; only routines
34 * that provide A and P-inverse as operators are required.
35 *
36 * In this notation, SPFGMR applies the underlying GMRES method to
37 * the equivalent transformed system
38 *   Abar xbar = bbar , where
39 *   Abar = S1 A (P-inverse) (S2-inverse) ,
40 *   bbar = S1 b , and   xbar = S2 P x .
41 *
42 * The scaling matrices must be chosen so that vectors S1 b and
43 * S2 P x have dimensionless components. If preconditioning is not
44 * performed (P = I), then S2 must be a scaling for x, while S1 is a
45 * scaling for b.  Similarly, if preconditioning is performed, then
46 * S1 must be a scaling for b, while S2 is a scaling for P x, and may
47 * also be taken as a scaling for b.
48 *
49 * The stopping test for the SPFGMR iterations is on the L2 norm of
50 * the scaled preconditioned residual:
51 *      || bbar - Abar xbar ||_2  <  delta
52 * with an input test constant delta.
53 *
54 * The usage of this SPFGMR solver involves supplying up to three
55 * routines and making a variety of calls.  The user-supplied routines are
56 *    atimes (A_data, x, y) to compute y = A x, given x,
57 *    psolve (P_data, y, x, lr) to solve P1 x = y or P2 x = y for
58 *           x, given y,
59 *    psetup (P_data) to perform any 'setup' operations in
60 *           preparation for calling psolve.
61 * The three user calls are:
62 *    SUNLinearSolver LS = SUNSPFGMR(y, pretype, maxl);
63 *           to create the linear solver structure,
64 *    flag = SUNLinSolSetATimes(LS, A_data, atimes);
65 *           to set the matrix-vector product setup/apply routines,
66 *    flag = SUNLinSolSetPreconditioner(LS, P_data, psetup, psolve);
67 *           to *optionally* set the preconditioner setup/apply routines,
68 *    flag = SUNLinSolInitialize(LS);
69 *           to perform internal solver memory allocations,
70 *    flag = SUNLinSolSetup(LS, NULL);
71 *           to call the psetup routine (if non-NULL);
72 *    flag = SUNLinSolSolve(LS, NULL, x, b, w, tol);
73 *           to solve the linear system to the tolerance 'tol'
74 *    long int nli = SUNLinSolNumIters(LS);
75 *           to *optionally* retrieve the number of linear iterations
76 *           performed by the solver,
77 *    long int lastflag = SUNLinSolLastFlag(LS);
78 *           to *optionally* retrieve the last internal solver error flag,
79 *    flag = SUNLinSolFree(LS);
80 *           to free the solver memory.
81 * Complete details for specifying atimes, psetup and psolve
82 * and for the usage calls are given below.
83 *
84 * -----------------------------------------------------------------
85 *
86 * Part I contains declarations specific to the SPFGMR implementation
87 * of the supplied SUNLINSOL module.
88 *
89 * Part II contains the prototype for the constructor
90 * SUNSPFGMR as well as implementation-specific prototypes
91 * for various useful solver operations.
92 *
93 * Notes:
94 *
95 *   - The definition of the generic SUNLinearSolver structure can
96 *     be found in the header file sundials_linearsolver.h.
97 *
98 * -----------------------------------------------------------------
99 */
100
101#ifndef _SUNLINSOL_SPFGMR_H
102#define _SUNLINSOL_SPFGMR_H
103
104#include <sundials/sundials_linearsolver.h>
105#include <sundials/sundials_matrix.h>
106#include <sundials/sundials_nvector.h>
107#include <sundials/sundials_spfgmr.h>
108
109#ifdef __cplusplus  /* wrapper to enable C++ usage */
110extern "C" {
111#endif
112
113/* Default SPFGMR solver parameters */
114#define SUNSPFGMR_MAXL_DEFAULT    5
115#define SUNSPFGMR_MAXRS_DEFAULT   0
116#define SUNSPFGMR_GSTYPE_DEFAULT  MODIFIED_GS
117
118/*
119 * -----------------------------------------------------------------
120 * PART I: SPFGMR implementation of SUNLinearSolver
121 *
122 * The SPFGMR implementation of the SUNLinearSolver 'content'
123 * structure contains:
124 *     maxl -- number of GMRES basis vectors to use
125 *     pretype -- flag for type of preconditioning to employ
126 *     gstype -- flag for type of Gram-Schmidt orthogonalization
127 *     max_restarts -- number of GMRES restarts to allow
128 *     last_flag -- last error return flag from internal setup/solve
129 *     ATimes -- function pointer to ATimes routine
130 *     ATData -- pointer to structure for ATimes
131 *     Psetup -- function pointer to preconditioner setup routine
132 *     Psolve -- function pointer to preconditioner solve routine
133 *     PData -- pointer to structure for Psetup/Psolve
134 *     V -- the array of Krylov basis vectors v_1, ..., v_(maxl+1),
135 *         stored in V[0], ..., V[l_max]. Each v_i is a vector of
136 *         type N_Vector.
137 *     Z -- the array of preconditioned basis vectors z_1, ...,
138 *         z_(maxl+1), stored in Z[0], ..., Z[l_max]. Each z_i
139 *         is a vector of type N_Vector.
140 *     Hes -- the (maxl+1) x maxl Hessenberg matrix. It is stored
141 *         row-wise so that the (i,j)th element is given by Hes[i][j].
142 *     givens -- a length 2*max array which represents the Givens
143 *         rotation matrices that arise in the algorithm. The Givens
144 *         rotation matrices F_0, F_1, ..., F_j, where F_i is
145 *
146 *             1
147 *               1
148 *                 c_i  -s_i      <--- row i
149 *                 s_i   c_i
150 *                           1
151 *                             1
152 *
153 *         are represented in the givens vector as
154 *         givens[0]=c_0, givens[1]=s_0, givens[2]=c_1, givens[3]=s_1,
155 *         ..., givens[2j]=c_j, givens[2j+1]=s_j.
156 *     xcor -- a vector (type N_Vector) which holds the scaled,
157 *         preconditioned correction to the initial guess
158 *     yg -- a length (maxl+1) array of realtype used to hold "short"
159 *         vectors (e.g. y and g).
160 *     vtemp -- a vector (type N_Vector) used as temporary vector
161 *         storage during calculations.
162 * -----------------------------------------------------------------
163 */
164 
165struct _SUNLinearSolverContent_SPFGMR {
166  int maxl;
167  int pretype;
168  int gstype;
169  int max_restarts;
170  int numiters;
171  realtype resnorm;
172  long int last_flag;
173
174  ATimesFn ATimes;
175  void* ATData;
176  PSetupFn Psetup;
177  PSolveFn Psolve;
178  void* PData;
179
180  N_Vector s1;
181  N_Vector s2;
182  N_Vector *V;
183  N_Vector *Z;
184  realtype **Hes;
185  realtype *givens;
186  N_Vector xcor;
187  realtype *yg;
188  N_Vector vtemp;
189};
190
191typedef struct _SUNLinearSolverContent_SPFGMR *SUNLinearSolverContent_SPFGMR;
192
193/*
194 * -----------------------------------------------------------------
195 * PART II: functions exported by sunlinsol_spfgmr
196 *
197 * CONSTRUCTOR:
198 *    SUNSPFGMR creates and allocates memory for a SPFGMR solver
199 *
200 * "SET" ROUTINES:
201 *    SUNSPFGMRSetPrecType updates whether to use preconditioning. 
202 *       Since only right preconditioning is supported, the inputs
203 *       PREC_LEFT, PREC_RIGHT and PREC_BOTH all result in
204 *       PREC_RIGHT.  All other input values default to PREC_NONE.
205 *    SUNSPFGMRSetGSType sets the type of Gram-Schmidt
206 *       orthogonalization to use.  Supported values are MODIFIED_GS
207 *       and CLASSICAL_GS.
208 *    SUNSPFGMRSetMaxRestarts sets the number of FGMRES restarts to
209 *       allow.  A negative input will result in the default of 0.
210 *
211 * -----------------------------------------------------------------
212 */
213
214SUNDIALS_EXPORT SUNLinearSolver SUNSPFGMR(N_Vector y, int pretype, int maxl);
215SUNDIALS_EXPORT int SUNSPFGMRSetPrecType(SUNLinearSolver S, int pretype);
216SUNDIALS_EXPORT int SUNSPFGMRSetGSType(SUNLinearSolver S, int gstype);
217SUNDIALS_EXPORT int SUNSPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs);
218
219/*
220 * -----------------------------------------------------------------
221 * SPFGMR implementations of various useful linear solver operations
222 * -----------------------------------------------------------------
223 */
224
225SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S);
226SUNDIALS_EXPORT int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S);
227SUNDIALS_EXPORT int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* A_data,
228                                              ATimesFn ATimes);
229SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S,
230                                                      void* P_data,
231                                                      PSetupFn Pset,
232                                                      PSolveFn Psol);
233SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S,
234                                                      N_Vector s1,
235                                                      N_Vector s2);
236SUNDIALS_EXPORT int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A);
237SUNDIALS_EXPORT int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A,
238                                          N_Vector x, N_Vector b, realtype tol);
239SUNDIALS_EXPORT int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S);
240SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S);
241SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S);
242SUNDIALS_EXPORT long int SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S);
243SUNDIALS_EXPORT int SUNLinSolSpace_SPFGMR(SUNLinearSolver S,
244                                          long int *lenrwLS,
245                                          long int *leniwLS);
246SUNDIALS_EXPORT int SUNLinSolFree_SPFGMR(SUNLinearSolver S);
247
248
249#ifdef __cplusplus
250}
251#endif
252
253#endif
Note: See TracBrowser for help on using the repository browser.