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  * SUNDIALS Copyright Start
8  * Copyright (c) 2002-2019, Lawrence Livermore National Security
9  * and Southern Methodist University.
10  * All rights reserved.
11  *
12  * See the top-level LICENSE and NOTICE files for details.
13  *
14  * SPDX-License-Identifier: BSD-3-Clause
15  * SUNDIALS Copyright End
16  * -----------------------------------------------------------------
17  * This is the header file for the SPFGMR implementation of the
18  * SUNLINSOL module, SUNLINSOL_SPFGMR.  The SPFGMR algorithm is based
19  * on the Scaled Preconditioned FGMRES (Flexible Generalized Minimal
20  * Residual) method [Y. Saad, SIAM J. Sci. Comput., 1993].
21  *
22  * Note:
23  *   - The definition of the generic SUNLinearSolver structure can
24  *     be found in the header file sundials_linearsolver.h.
25  * -----------------------------------------------------------------
26  */
27 
28 #ifndef _SUNLINSOL_SPFGMR_H
29 #define _SUNLINSOL_SPFGMR_H
30 
31 #include <sundials/sundials_linearsolver.h>
32 #include <sundials/sundials_matrix.h>
33 #include <sundials/sundials_nvector.h>
34 #include <sundials/sundials_spfgmr.h>
35 
36 #ifdef __cplusplus  /* wrapper to enable C++ usage */
37 extern "C" {
38 #endif
39 
40 /* Default SPFGMR solver parameters */
41 #define SUNSPFGMR_MAXL_DEFAULT    5
42 #define SUNSPFGMR_MAXRS_DEFAULT   0
43 #define SUNSPFGMR_GSTYPE_DEFAULT  MODIFIED_GS
44 
45 /* -----------------------------------------
46  * SPFGMR Implementation of SUNLinearSolver
47  * ----------------------------------------- */
48 
49 struct _SUNLinearSolverContent_SPFGMR {
50   int maxl;
51   int pretype;
52   int gstype;
53   int max_restarts;
54   int numiters;
55   realtype resnorm;
56   long int last_flag;
57 
58   ATimesFn ATimes;
59   void* ATData;
60   PSetupFn Psetup;
61   PSolveFn Psolve;
62   void* PData;
63 
64   N_Vector s1;
65   N_Vector s2;
66   N_Vector *V;
67   N_Vector *Z;
68   realtype **Hes;
69   realtype *givens;
70   N_Vector xcor;
71   realtype *yg;
72   N_Vector vtemp;
73 
74   realtype *cv;
75   N_Vector *Xv;
76 };
77 
78 typedef struct _SUNLinearSolverContent_SPFGMR *SUNLinearSolverContent_SPFGMR;
79 
80 /* ----------------------------------------
81  * Exported Functions for SUNLINSOL_SPFGMR
82  * ---------------------------------------- */
83 
84 SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y,
85                                                  int pretype,
86                                                  int maxl);
87 SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S,
88                                                 int pretype);
89 SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S,
90                                               int gstype);
91 SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S,
92                                                    int maxrs);
93 
94 /* deprecated */
95 SUNDIALS_EXPORT SUNLinearSolver SUNSPFGMR(N_Vector y, int pretype, int maxl);
96 /* deprecated */
97 SUNDIALS_EXPORT int SUNSPFGMRSetPrecType(SUNLinearSolver S, int pretype);
98 /* deprecated */
99 SUNDIALS_EXPORT int SUNSPFGMRSetGSType(SUNLinearSolver S, int gstype);
100 /* deprecated */
101 SUNDIALS_EXPORT int SUNSPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs);
102 
103 
104 SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S);
105 SUNDIALS_EXPORT int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S);
106 SUNDIALS_EXPORT int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* A_data,
107                                               ATimesFn ATimes);
108 SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S,
109                                                       void* P_data,
110                                                       PSetupFn Pset,
111                                                       PSolveFn Psol);
112 SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S,
113                                                       N_Vector s1,
114                                                       N_Vector s2);
115 SUNDIALS_EXPORT int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A);
116 SUNDIALS_EXPORT int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A,
117                                           N_Vector x, N_Vector b, realtype tol);
118 SUNDIALS_EXPORT int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S);
119 SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S);
120 SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S);
121 SUNDIALS_EXPORT long int SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S);
122 SUNDIALS_EXPORT int SUNLinSolSpace_SPFGMR(SUNLinearSolver S,
123                                           long int *lenrwLS,
124                                           long int *leniwLS);
125 SUNDIALS_EXPORT int SUNLinSolFree_SPFGMR(SUNLinearSolver S);
126 
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif
133