1 /*
2  * -----------------------------------------------------------------
3  * Programmer(s): Daniel Reynolds, Ashley Crawford @ SMU
4  * -----------------------------------------------------------------
5  * SUNDIALS Copyright Start
6  * Copyright (c) 2002-2019, 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 #include <sundials/sundials_pcg.h>
32 
33 #ifdef __cplusplus  /* wrapper to enable C++ usage */
34 extern "C" {
35 #endif
36 
37 /* Default PCG solver parameters */
38 #define SUNPCG_MAXL_DEFAULT    5
39 
40 /* --------------------------------------
41  * PCG Implementation of SUNLinearSolver
42  * -------------------------------------- */
43 
44 struct _SUNLinearSolverContent_PCG {
45   int maxl;
46   int pretype;
47   int numiters;
48   realtype resnorm;
49   long int last_flag;
50 
51   ATimesFn ATimes;
52   void* ATData;
53   PSetupFn Psetup;
54   PSolveFn Psolve;
55   void* PData;
56 
57   N_Vector s;
58   N_Vector r;
59   N_Vector p;
60   N_Vector z;
61   N_Vector Ap;
62 };
63 
64 typedef struct _SUNLinearSolverContent_PCG *SUNLinearSolverContent_PCG;
65 
66 
67 /* -------------------------------------
68  * Exported Functions for SUNLINSOL_PCG
69  * ------------------------------------- */
70 
71 SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_PCG(N_Vector y,
72                                               int pretype,
73                                               int maxl);
74 SUNDIALS_EXPORT int SUNLinSol_PCGSetPrecType(SUNLinearSolver S,
75                                              int pretype);
76 SUNDIALS_EXPORT int SUNLinSol_PCGSetMaxl(SUNLinearSolver S,
77                                          int maxl);
78 
79 /* deprecated */
80 SUNDIALS_EXPORT SUNLinearSolver SUNPCG(N_Vector y, int pretype, int maxl);
81 /* deprecated */
82 SUNDIALS_EXPORT int SUNPCGSetPrecType(SUNLinearSolver S, int pretype);
83 /* deprecated */
84 SUNDIALS_EXPORT int SUNPCGSetMaxl(SUNLinearSolver S, int maxl);
85 
86 SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_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 long int 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 
109 #ifdef __cplusplus
110 }
111 #endif
112 
113 #endif
114