sundials_spbcgs.h

Go to the documentation of this file.
00001 /*
00002  * -----------------------------------------------------------------
00003  * $Revision: 1.2 $
00004  * $Date: 2006/11/29 00:05:07 $
00005  * -----------------------------------------------------------------
00006  * Programmer(s): Peter Brown and Aaron Collier @ LLNL
00007  * -----------------------------------------------------------------
00008  * Copyright (c) 2004, The Regents of the University of California.
00009  * Produced at the Lawrence Livermore National Laboratory.
00010  * All rights reserved.
00011  * For details, see the LICENSE file.
00012  * -----------------------------------------------------------------
00013  * This is the header file for the implementation of the scaled,
00014  * preconditioned Bi-CGSTAB (SPBCG) iterative linear solver.
00015  * -----------------------------------------------------------------
00016  */
00017 
00018 #ifndef _SPBCG_H
00019 #define _SPBCG_H
00020 
00021 #ifdef __cplusplus  /* wrapper to enable C++ usage */
00022 extern "C" {
00023 #endif
00024 
00025 #include <sundials/sundials_iterative.h>
00026 
00027 /*
00028  * -----------------------------------------------------------------
00029  * Types: struct SpbcgMemRec and struct *SpbcgMem
00030  * -----------------------------------------------------------------
00031  * A variable declaration of type struct *SpbcgMem denotes a pointer
00032  * to a data structure of type struct SpbcgMemRec. The SpbcgMemRec
00033  * structure contains numerous fields that must be accessed by the
00034  * SPBCG linear solver module.
00035  *
00036  *  l_max  maximum Krylov subspace dimension that SpbcgSolve will
00037  *         be permitted to use
00038  *
00039  *  r  vector (type N_Vector) which holds the scaled, preconditioned
00040  *     linear system residual
00041  *
00042  *  r_star  vector (type N_Vector) which holds the initial scaled,
00043  *          preconditioned linear system residual
00044  *
00045  *  p, q, u and Ap  vectors (type N_Vector) used for workspace by
00046  *                  the SPBCG algorithm
00047  *
00048  *  vtemp  scratch vector (type N_Vector) used as temporary vector
00049  *         storage
00050  * -----------------------------------------------------------------
00051  */
00052 
00053 typedef struct {
00054 
00055   int l_max;
00056 
00057   N_Vector r_star;
00058   N_Vector r;
00059   N_Vector p;
00060   N_Vector q;
00061   N_Vector u;
00062   N_Vector Ap;
00063   N_Vector vtemp;
00064 
00065 } SpbcgMemRec, *SpbcgMem;
00066 
00067 /*
00068  * -----------------------------------------------------------------
00069  * Function : SpbcgMalloc
00070  * -----------------------------------------------------------------
00071  * SpbcgMalloc allocates additional memory needed by the SPBCG
00072  * linear solver module.
00073  *
00074  *  l_max  maximum Krylov subspace dimension that SpbcgSolve will
00075  *         be permitted to use
00076  *
00077  *  vec_tmpl  implementation-specific template vector (type N_Vector)
00078  *            (created using either N_VNew_Serial or N_VNew_Parallel)
00079  *
00080  * If successful, SpbcgMalloc returns a non-NULL memory pointer. If
00081  * an error occurs, then a NULL pointer is returned.
00082  * -----------------------------------------------------------------
00083  */
00084 
00085 SUNDIALS_EXPORT SpbcgMem SpbcgMalloc(int l_max, N_Vector vec_tmpl);
00086 
00087 /*
00088  * -----------------------------------------------------------------
00089  * Function : SpbcgSolve
00090  * -----------------------------------------------------------------
00091  * SpbcgSolve solves the linear system Ax = b by means of a scaled
00092  * preconditioned Bi-CGSTAB (SPBCG) iterative method.
00093  *
00094  *  mem  pointer to an internal memory block allocated during a
00095  *       prior call to SpbcgMalloc
00096  *
00097  *  A_data  pointer to a data structure containing information
00098  *          about the coefficient matrix A (passed to user-supplied
00099  *          function referenced by atimes (function pointer))
00100  *
00101  *  x  vector (type N_Vector) containing initial guess x_0 upon
00102  *     entry, but which upon return contains an approximate solution
00103  *     of the linear system Ax = b (solution only valid if return
00104  *     value is either SPBCG_SUCCESS or SPBCG_RES_REDUCED)
00105  *
00106  *  b  vector (type N_Vector) set to the right-hand side vector b
00107  *     of the linear system (undisturbed by function)
00108  *
00109  *  pretype  variable (type int) indicating the type of
00110  *           preconditioning to be used (see sundials_iterative.h)
00111  *
00112  *  delta  tolerance on the L2 norm of the scaled, preconditioned
00113  *         residual (if return value == SPBCG_SUCCESS, then
00114  *         ||sb*P1_inv*(b-Ax)||_L2 <= delta)
00115  *
00116  *  P_data  pointer to a data structure containing preconditioner
00117  *          information (passed to user-supplied function referenced
00118  *          by psolve (function pointer))
00119  *
00120  *  sx  vector (type N_Vector) containing positive scaling factors
00121  *      for x (pass sx == NULL if scaling NOT required)
00122  *
00123  *  sb  vector (type N_Vector) containing positive scaling factors
00124  *      for b (pass sb == NULL if scaling NOT required)
00125  *
00126  *  atimes  user-supplied routine responsible for computing the
00127  *          matrix-vector product Ax (see sundials_iterative.h)
00128  *
00129  *  psolve  user-supplied routine responsible for solving the
00130  *          preconditioned linear system Pz = r (ignored if
00131  *          pretype == PREC_NONE) (see sundials_iterative.h)
00132  *
00133  *  res_norm  pointer (type realtype*) to the L2 norm of the
00134  *            scaled, preconditioned residual (if return value
00135  *            is either SPBCG_SUCCESS or SPBCG_RES_REDUCED, then
00136  *            *res_norm = ||sb*P1_inv*(b-Ax)||_L2, where x is
00137  *            the computed approximate solution, sb is the diagonal
00138  *            scaling matrix for the right-hand side b, and P1_inv
00139  *            is the inverse of the left-preconditioner matrix)
00140  *
00141  *  nli  pointer (type int*) to the total number of linear
00142  *       iterations performed
00143  *
00144  *  nps  pointer (type int*) to the total number of calls made
00145  *       to the psolve routine
00146  * -----------------------------------------------------------------
00147  */
00148 
00149 SUNDIALS_EXPORT int SpbcgSolve(SpbcgMem mem, void *A_data, N_Vector x, N_Vector b,
00150                    int pretype, realtype delta, void *P_data, N_Vector sx,
00151                    N_Vector sb, ATimesFn atimes, PSolveFn psolve,
00152                    realtype *res_norm, int *nli, int *nps);
00153 
00154 /* Return values for SpbcgSolve */
00155 
00156 #define SPBCG_SUCCESS            0  /* SPBCG algorithm converged          */
00157 #define SPBCG_RES_REDUCED        1  /* SPBCG did NOT converge, but the
00158                        residual was reduced               */
00159 #define SPBCG_CONV_FAIL          2  /* SPBCG algorithm failed to converge */
00160 #define SPBCG_PSOLVE_FAIL_REC    3  /* psolve failed recoverably          */
00161 #define SPBCG_ATIMES_FAIL_REC    4  /* atimes failed recoverably          */
00162 #define SPBCG_PSET_FAIL_REC      5  /* pset faild recoverably             */
00163 
00164 #define SPBCG_MEM_NULL          -1  /* mem argument is NULL               */
00165 #define SPBCG_ATIMES_FAIL_UNREC -2  /* atimes returned failure flag       */
00166 #define SPBCG_PSOLVE_FAIL_UNREC -3  /* psolve failed unrecoverably        */
00167 #define SPBCG_PSET_FAIL_UNREC   -4  /* pset failed unrecoverably          */
00168 
00169 /*
00170  * -----------------------------------------------------------------
00171  * Function : SpbcgFree
00172  * -----------------------------------------------------------------
00173  * SpbcgFree frees the memory allocated by a call to SpbcgMalloc.
00174  * It is illegal to use the pointer mem after a call to SpbcgFree.
00175  * -----------------------------------------------------------------
00176  */
00177 
00178 SUNDIALS_EXPORT void SpbcgFree(SpbcgMem mem);
00179 
00180 /*
00181  * -----------------------------------------------------------------
00182  * Macro : SPBCG_VTEMP
00183  * -----------------------------------------------------------------
00184  * This macro provides access to the vector r in the
00185  * memory block of the SPBCG module. The argument mem is the
00186  * memory pointer returned by SpbcgMalloc, of type SpbcgMem,
00187  * and the macro value is of type N_Vector.
00188  *
00189  * Note: Only used by IDA (r contains P_inverse F if nli_inc == 0).
00190  * -----------------------------------------------------------------
00191  */
00192 
00193 #define SPBCG_VTEMP(mem) (mem->r)
00194 
00195 #ifdef __cplusplus
00196 }
00197 #endif
00198 
00199 #endif

Generated on Fri Sep 26 07:44:17 2008 for SimTKcore by  doxygen 1.5.6