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-2020, 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 <sundials/sundials_linearsolver.h> 32 #include <sundials/sundials_matrix.h> 33 #include <sundials/sundials_nvector.h> 34 35 #ifdef __cplusplus /* wrapper to enable C++ usage */ 36 extern "C" { 37 #endif 38 39 /* Default SPGMR solver parameters */ 40 #define SUNSPGMR_MAXL_DEFAULT 5 41 #define SUNSPGMR_MAXRS_DEFAULT 0 42 #define SUNSPGMR_GSTYPE_DEFAULT MODIFIED_GS 43 44 /* ---------------------------------------- 45 * SPGMR Implementation of SUNLinearSolver 46 * ---------------------------------------- */ 47 48 struct _SUNLinearSolverContent_SPGMR { 49 int maxl; 50 int pretype; 51 int gstype; 52 int max_restarts; 53 int numiters; 54 realtype resnorm; 55 int last_flag; 56 57 ATimesFn ATimes; 58 void* ATData; 59 PSetupFn Psetup; 60 PSolveFn Psolve; 61 void* PData; 62 63 N_Vector s1; 64 N_Vector s2; 65 N_Vector *V; 66 realtype **Hes; 67 realtype *givens; 68 N_Vector xcor; 69 realtype *yg; 70 N_Vector vtemp; 71 72 realtype *cv; 73 N_Vector *Xv; 74 }; 75 76 typedef struct _SUNLinearSolverContent_SPGMR *SUNLinearSolverContent_SPGMR; 77 78 79 /* --------------------------------------- 80 * Exported Functions for SUNLINSOL_SPGMR 81 * --------------------------------------- */ 82 83 SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, 84 int pretype, 85 int maxl); 86 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, 87 int pretype); 88 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, 89 int gstype); 90 SUNDIALS_EXPORT int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, 91 int maxrs); 92 93 /* deprecated */ 94 SUNDIALS_EXPORT SUNLinearSolver SUNSPGMR(N_Vector y, int pretype, int maxl); 95 /* deprecated */ 96 SUNDIALS_EXPORT int SUNSPGMRSetPrecType(SUNLinearSolver S, int pretype); 97 /* deprecated */ 98 SUNDIALS_EXPORT int SUNSPGMRSetGSType(SUNLinearSolver S, int gstype); 99 /* deprecated */ 100 SUNDIALS_EXPORT int SUNSPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); 101 102 SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S); 103 SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S); 104 SUNDIALS_EXPORT int SUNLinSolInitialize_SPGMR(SUNLinearSolver S); 105 SUNDIALS_EXPORT int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data, 106 ATimesFn ATimes); 107 SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, 108 void* P_data, 109 PSetupFn Pset, 110 PSolveFn Psol); 111 SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, 112 N_Vector s1, 113 N_Vector s2); 114 SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A); 115 SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, 116 N_Vector x, N_Vector b, realtype tol); 117 SUNDIALS_EXPORT int SUNLinSolNumIters_SPGMR(SUNLinearSolver S); 118 SUNDIALS_EXPORT realtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S); 119 SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S); 120 SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S); 121 SUNDIALS_EXPORT int SUNLinSolSpace_SPGMR(SUNLinearSolver S, 122 long int *lenrwLS, 123 long int *leniwLS); 124 SUNDIALS_EXPORT int SUNLinSolFree_SPGMR(SUNLinearSolver S); 125 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif 132