1 /*
2  * -----------------------------------------------------------------
3  * Programmer(s): Daniel Reynolds @ SMU
4  * Based on code sundials_spgmr.h by: Scott D. Cohen,
5  *      Alan C. Hindmarsh and Radu Serban @ LLNL
6  * -----------------------------------------------------------------
7  * SUNDIALS Copyright Start
8  * Copyright (c) 2002-2021, 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 SPGMR implementation of the
18  * SUNLINSOL module, SUNLINSOL_SPGMR.  The SPGMR algorithm is based
19  * on the Scaled Preconditioned GMRES (Generalized Minimal Residual)
20  * method.
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_SPGMR_H
29 #define _SUNLINSOL_SPGMR_H
30 
31 #include <stdio.h>
32 
33 #include <sundials/sundials_linearsolver.h>
34 #include <sundials/sundials_matrix.h>
35 #include <sundials/sundials_nvector.h>
36 
37 #ifdef __cplusplus  /* wrapper to enable C++ usage */
38 extern "C" {
39 #endif
40 
41 /* Default SPGMR solver parameters */
42 #define SUNSPGMR_MAXL_DEFAULT    5
43 #define SUNSPGMR_MAXRS_DEFAULT   0
44 #define SUNSPGMR_GSTYPE_DEFAULT  MODIFIED_GS
45 
46 /* ----------------------------------------
47  * SPGMR Implementation of SUNLinearSolver
48  * ---------------------------------------- */
49 
50 struct _SUNLinearSolverContent_SPGMR {
51   int maxl;
52   int pretype;
53   int gstype;
54   int max_restarts;
55   int numiters;
56   realtype resnorm;
57   int last_flag;
58 
59   ATimesFn ATimes;
60   void* ATData;
61   PSetupFn Psetup;
62   PSolveFn Psolve;
63   void* PData;
64 
65   N_Vector s1;
66   N_Vector s2;
67   N_Vector *V;
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   int print_level;
78   FILE* info_file;
79 };
80 
81 typedef struct _SUNLinearSolverContent_SPGMR *SUNLinearSolverContent_SPGMR;
82 
83 
84 /* ---------------------------------------
85  * Exported Functions for SUNLINSOL_SPGMR
86  * --------------------------------------- */
87 
88 SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y,
89                                                 int pretype,
90                                                 int maxl);
91 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S,
92                                                int pretype);
93 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S,
94                                              int gstype);
95 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S,
96                                                   int maxrs);
97 
98 SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNSPGMR(N_Vector y, int pretype, int maxl);
99 SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetPrecType(SUNLinearSolver S, int pretype);
100 SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetGSType(SUNLinearSolver S, int gstype);
101 SUNDIALS_DEPRECATED_EXPORT int SUNSPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs);
102 
103 SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S);
104 SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S);
105 SUNDIALS_EXPORT int SUNLinSolInitialize_SPGMR(SUNLinearSolver S);
106 SUNDIALS_EXPORT int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data,
107                                              ATimesFn ATimes);
108 SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S,
109                                                      void* P_data,
110                                                      PSetupFn Pset,
111                                                      PSolveFn Psol);
112 SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S,
113                                                      N_Vector s1,
114                                                      N_Vector s2);
115 SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A);
116 SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A,
117                                          N_Vector x, N_Vector b, realtype tol);
118 SUNDIALS_EXPORT int SUNLinSolNumIters_SPGMR(SUNLinearSolver S);
119 SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S);
120 SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S);
121 SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S);
122 SUNDIALS_EXPORT int SUNLinSolSpace_SPGMR(SUNLinearSolver S,
123                                          long int *lenrwLS,
124                                          long int *leniwLS);
125 SUNDIALS_EXPORT int SUNLinSolFree_SPGMR(SUNLinearSolver S);
126 SUNDIALS_EXPORT int SUNLinSolSetInfoFile_SPGMR(SUNLinearSolver LS,
127                                                FILE* info_file);
128 SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_SPGMR(SUNLinearSolver LS,
129                                                  int print_level);
130 
131 
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif
138