1 /*
2  * -----------------------------------------------------------------
3  * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU
4  * -----------------------------------------------------------------
5  * SUNDIALS Copyright Start
6  * Copyright (c) 2002-2021, Lawrence Livermore National Security
7  * and Southern Methodist University.
8  * All rights reserved.
9  *
10  * See the top-level LICENSE and NOTICE files for details.
11  *
12  * SPDX-License-Identifier: BSD-3-Clause
13  * SUNDIALS Copyright End
14  * -----------------------------------------------------------------
15  * This is the header file for the PCG implementation of the
16  * SUNLINSOL module, SUNLINSOL_PCG.  The PCG algorithm is based
17  * on the Preconditioned Conjugate Gradient.
18  *
19  * Note:
20  *   - The definition of the generic SUNLinearSolver structure can
21  *     be found in the header file sundials_linearsolver.h.
22  * -----------------------------------------------------------------
23  */
24 
25 #ifndef _SUNLINSOL_PCG_H
26 #define _SUNLINSOL_PCG_H
27 
28 #include <sundials/sundials_linearsolver.h>
29 #include <sundials/sundials_matrix.h>
30 #include <sundials/sundials_nvector.h>
31 
32 #ifdef __cplusplus  /* wrapper to enable C++ usage */
33 extern "C" {
34 #endif
35 
36 /* Default PCG solver parameters */
37 #define SUNPCG_MAXL_DEFAULT    5
38 
39 /* --------------------------------------
40  * PCG Implementation of SUNLinearSolver
41  * -------------------------------------- */
42 
43 struct _SUNLinearSolverContent_PCG {
44   int maxl;
45   int pretype;
46   int numiters;
47   realtype resnorm;
48   int last_flag;
49 
50   ATimesFn ATimes;
51   void* ATData;
52   PSetupFn Psetup;
53   PSolveFn Psolve;
54   void* PData;
55 
56   N_Vector s;
57   N_Vector r;
58   N_Vector p;
59   N_Vector z;
60   N_Vector Ap;
61 
62   int print_level;
63   FILE* info_file;
64 };
65 
66 typedef struct _SUNLinearSolverContent_PCG *SUNLinearSolverContent_PCG;
67 
68 
69 /* -------------------------------------
70  * Exported Functions for SUNLINSOL_PCG
71  * ------------------------------------- */
72 
73 SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_PCG(N_Vector y,
74                                               int pretype,
75                                               int maxl);
76 SUNDIALS_EXPORT int SUNLinSol_PCGSetPrecType(SUNLinearSolver S,
77                                              int pretype);
78 SUNDIALS_EXPORT int SUNLinSol_PCGSetMaxl(SUNLinearSolver S,
79                                          int maxl);
80 
81 SUNDIALS_DEPRECATED_EXPORT SUNLinearSolver SUNPCG(N_Vector y, int pretype, int maxl);
82 SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetPrecType(SUNLinearSolver S, int pretype);
83 SUNDIALS_DEPRECATED_EXPORT int SUNPCGSetMaxl(SUNLinearSolver S, int maxl);
84 
85 SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S);
86 SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S);
87 SUNDIALS_EXPORT int SUNLinSolInitialize_PCG(SUNLinearSolver S);
88 SUNDIALS_EXPORT int SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data,
89                                            ATimesFn ATimes);
90 SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S,
91                                                    void* P_data,
92                                                    PSetupFn Pset,
93                                                    PSolveFn Psol);
94 SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S,
95                                                    N_Vector s,
96                                                    N_Vector nul);
97 SUNDIALS_EXPORT int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul);
98 SUNDIALS_EXPORT int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul,
99                                        N_Vector x, N_Vector b, realtype tol);
100 SUNDIALS_EXPORT int SUNLinSolNumIters_PCG(SUNLinearSolver S);
101 SUNDIALS_EXPORT realtype SUNLinSolResNorm_PCG(SUNLinearSolver S);
102 SUNDIALS_EXPORT N_Vector SUNLinSolResid_PCG(SUNLinearSolver S);
103 SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S);
104 SUNDIALS_EXPORT int SUNLinSolSpace_PCG(SUNLinearSolver S,
105                                        long int *lenrwLS,
106                                        long int *leniwLS);
107 SUNDIALS_EXPORT int SUNLinSolFree_PCG(SUNLinearSolver S);
108 SUNDIALS_EXPORT int SUNLinSolSetInfoFile_PCG(SUNLinearSolver LS,
109                                              FILE* info_file);
110 SUNDIALS_EXPORT int SUNLinSolSetPrintLevel_PCG(SUNLinearSolver LS,
111                                                int print_level);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif
118