home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / meschach / !Meschach / h / sparse < prev    next >
Encoding:
Text File  |  1994-01-13  |  6.3 KB  |  239 lines

  1. ed from it.  
  2. **      This clause shall not be construed as constraining other software
  3. **      distributed on the same medium as this software, nor is a
  4. **      distribution fee considered a charge.
  5. **
  6. ***************************************************************************/
  7.  
  8.  
  9. /* iter.h  14/09/93 */
  10.  
  11. /* 
  12.  
  13.   Structures for iterative methods
  14.  
  15. */
  16.  
  17. #ifndef ITERHH
  18.  
  19. #define ITERHH
  20.  
  21. /* RCS id: $Id: iter.h,v 1.2 1994/03/08 05:48:27 des Exp $  */
  22.  
  23.  
  24. #include    "sparse.h"
  25.  
  26.  
  27. /* basic structure for iterative methods */
  28.  
  29. /* type Fun_Ax for functions to get y = A*x */
  30. #ifdef ANSI_C
  31. typedef VEC  *(*Fun_Ax)(void *,VEC *,VEC *);
  32. #else
  33. typedef VEC *(*Fun_Ax)();
  34. #endif
  35.  
  36.  
  37. /* type ITER */
  38. typedef struct Iter_data {
  39.    int shared_x;   /* if TRUE then x is shared and it will not be free'd */ 
  40.    int shared_b;   /* if TRUE then b is shared and it will not be free'd */
  41.    unsigned k;   /* no. of direction (search) vectors; =0 - none */
  42.    int limit;    /* upper bound on the no. of iter. steps */
  43.    int steps;    /* no. of iter. steps done */
  44.    Real eps;     /* accuracy required */
  45.    
  46.    VEC *x;       /* input: initial guess;
  47.             output: approximate solution */
  48.    VEC *b;       /* right hand side of the equation A*x = b */
  49.  
  50.    Fun_Ax   Ax;         /* function computing y = A*x */
  51.    void *A_par;         /* parameters for Ax */
  52.  
  53.    Fun_Ax  ATx;         /* function  computing y = A^T*x;
  54.                            T = transpose */
  55.    void *AT_par;         /* parameters for ATx */
  56.  
  57.    Fun_Ax  Bx; /* function computing y = B*x; B - preconditioner */
  58.    void *B_par;         /* parameters for Bx */
  59.  
  60. #ifdef ANSI_C
  61.  
  62. #ifdef PROTOTYPES_IN_STRUCT
  63.    void (*info)(struct Iter_data *, double, VEC *,VEC *);
  64.             /* function giving some information for a user;
  65.            nres - a norm of a residual res */
  66.    
  67.    int (*stop_crit)(struct Iter_data *, double, VEC *,VEC *);
  68.            /* stopping criterion:
  69.           nres - a norm of res;
  70.           res - residual;
  71.         if returned value == TRUE then stop;
  72.         if returned value == FALSE then continue; */
  73. #else
  74.    void (*info)();
  75.    int  (*stop_crit)();
  76. #endif /* PROTOTYPES_IN_STRUCT */
  77.  
  78. #else
  79.  
  80.    void (*info)();
  81.             /* function giving some information for a user */
  82.    
  83.    int (*stop_crit)();
  84.            /* stopping criterion:
  85.         if returned value == TRUE then stop;
  86.         if returned value == FALSE then continue; */
  87.  
  88. #endif /* ANSI_C */
  89.  
  90.    Real init_res;   /* the norm of the initial residual */
  91.  
  92. }  ITER;
  93.  
  94.  
  95. #define INULL   (ITER *)NULL
  96.  
  97. /* type Fun_info */
  98. #ifdef ANSI_C
  99. typedef void (*Fun_info)(ITER *, double, VEC *,VEC *);
  100. #else
  101. typedef void (*Fun_info)();
  102. #endif
  103.  
  104. /* type Fun_stp_crt */
  105. #ifdef ANSI_C
  106. typedef int (*Fun_stp_crt)(ITER *, double, VEC *,VEC *);
  107. #else
  108. typedef int (*Fun_stp_crt)();
  109. #endif
  110.  
  111.  
  112.  
  113. /* macros */
  114. /* default values */
  115.  
  116. #define ITER_LIMIT_DEF  1000
  117. #define ITER_EPS_DEF    1e-6
  118.  
  119. /* other macros */
  120.  
  121. /* set ip->Ax=fun and ip->A_par=fun_par */
  122. #define iter_Ax(ip,fun,fun_par) \
  123.   (ip->Ax=(Fun_Ax)(fun),ip->A_par=(void *)(fun_par),0)
  124. #define iter_ATx(ip,fun,fun_par) \
  125.   (ip->ATx=(Fun_Ax)(fun),ip->AT_par=(void *)(fun_par),0)
  126. #define iter_Bx(ip,fun,fun_par) \
  127.   (ip->Bx=(Fun_Ax)(fun),ip->B_par=(void *)(fun_par),0)
  128.  
  129. /* save free macro */
  130. #define ITER_FREE(ip)  (iter_free(ip), (ip)=(ITER *)NULL)
  131.  
  132.  
  133. /* prototypes from iter0.c */
  134.  
  135. #ifdef ANSI_C
  136. /* standard information */
  137. void iter_std_info(ITER *ip,double nres,VEC *res,VEC *Bres);
  138. /* standard stopping criterion */
  139. int iter_std_stop_crit(ITER *ip, double nres, VEC *res,VEC *Bres);
  140.  
  141. /* get, resize and free ITER variable */
  142. ITER *iter_get(int lenb, int lenx);
  143. ITER *iter_resize(ITER *ip,int lenb,int lenx);
  144. int iter_free(ITER *ip);
  145.  
  146. void iter_dump(FILE *fp,ITER *ip);
  147.  
  148. /* copy ip1 to ip2 copying also elements of x and b */
  149. ITER *iter_copy(ITER *ip1, ITER *ip2);
  150. /* copy ip1 to ip2 without copying elements of x and b */
  151. ITER *iter_copy2(ITER *ip1,ITER *ip2);
  152.  
  153. /* functions for generating sparse matrices with random elements */
  154. SPMAT    *iter_gen_sym(int n, int nrow);
  155. SPMAT    *iter_gen_nonsym(int m,int n,int nrow,double diag);
  156. SPMAT    *iter_gen_nonsym_posdef(int n,int nrow);
  157.  
  158. #else
  159.  
  160. void iter_std_info();
  161. int iter_std_stop_crit();
  162. ITER *iter_get();
  163. int iter_free();
  164. ITER *iter_resize();
  165. void iter_dump();
  166. ITER *iter_copy();
  167. ITER *iter_copy2();
  168. SPMAT    *iter_gen_sym();
  169. SPMAT    *iter_gen_nonsym();
  170. SPMAT    *iter_gen_nonsym_posdef();
  171.  
  172. #endif
  173.  
  174. /* prototypes from iter.c */
  175.  
  176. /* different iterative procedures */
  177. #ifdef ANSI_C
  178. VEC  *iter_cg(ITER *ip);
  179. VEC  *iter_cg1(ITER *ip);
  180. VEC  *iter_spcg(SPMAT *A,SPMAT *LLT,VEC *b,double eps,VEC *x,int limit,
  181.         int *steps);
  182. VEC  *iter_cgs(ITER *ip,VEC *r0);
  183. VEC  *iter_spcgs(SPMAT *A,SPMAT *B,VEC *b,VEC *r0,double eps,VEC *x,
  184.          int limit, int *steps);
  185. VEC  *iter_lsqr(ITER *ip);
  186. VEC  *iter_splsqr(SPMAT *A,VEC *b,double tol,VEC *x,
  187.           int limit,int *steps);
  188. VEC  *iter_gmres(ITER *ip);
  189. VEC  *iter_spgmres(SPMAT *A,SPMAT *B,VEC *b,double tol,VEC *x,int k,
  190.            int limit, int *steps);
  191. MAT  *iter_arnoldi_iref(ITER *ip,Real *h,MAT *Q,MAT *H);
  192. MAT  *iter_arnoldi(ITER *ip,Real *h,MAT *Q,MAT *H);
  193. MAT  *iter_sparnoldi(SPMAT *A,VEC *x0,int k,Real *h,MAT *Q,MAT *H);
  194. VEC  *iter_mgcr(ITER *ip);
  195. VEC  *iter_spmgcr(SPMAT *A,SPMAT *B,VEC *b,double tol,VEC *x,int k,
  196.           int limit, int *steps);
  197. void    iter_lanczos(ITER *ip,VEC *a,VEC *b,Real *beta2,MAT *Q);
  198. void    iter_splanczos(SPMAT *A,int m,VEC *x0,VEC *a,VEC *b,Real *beta2,
  199.                MAT *Q);
  200. VEC  *iter_lanczos2(ITER *ip,VEC *evals,VEC *err_est);
  201. VEC  *iter_splanczos2(SPMAT *A,int m,VEC *x0,VEC *evals,VEC *err_est);
  202. VEC  *iter_cgne(ITER *ip);
  203. VEC  *iter_spcgne(SPMAT *A,SPMAT *B,VEC *b,double eps,VEC *x,
  204.           int limit,int *steps);
  205. #else
  206. VEC  *iter_cg();
  207. VEC  *iter_cg1();
  208. VEC  *iter_spcg();
  209. VEC  *iter_cgs();
  210. VEC  *iter_spcgs();
  211. VEC  *iter_lsqr();
  212. VEC  *iter_splsqr();
  213. VEC  *iter_gmres();
  214. VEC  *iter_spgmres();
  215. MAT  *iter_arnoldi_iref();
  216. MAT  *iter_arnoldi();
  217. MAT  *iter_sparnoldi();
  218. VEC  *iter_mgcr();
  219. VEC  *iter_spmgcr();
  220. void  iter_lanczos();
  221. void  iter_splanczos();
  222. VEC  *iter_lanczos2();
  223. VEC  *iter_splanczos2();
  224. VEC  *iter_cgne();
  225. VEC  *iter_spcgne();
  226.  
  227. #endif
  228.  
  229.  
  230. #endif  /* ITERHH */
  231. FileDataŵmachineEÿÿÿ¸V⇧r÷/* machine.h.  Generated automatically by configure.  */
  232. /* Any machine specific stuff goes here */
  233. /* Add details necessary for your own installation here! */
  234.  
  235. /* This is for use with "configure" -- if you are not using configure
  236.     then use machine.van for the "vanilla" version of machine.h */
  237.  
  238. /* Note special macros: ANSI_C (ANSI C syntax)
  239.             SEGMENTED (segmented memory machi