Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
interface_samg.c
Go to the documentation of this file.
1 
10 #include <math.h>
11 #include <time.h>
12 
13 #include "fasp.h"
14 #include "fasp_functs.h"
15 
16 /*---------------------------------*/
17 /*-- Public Functions --*/
18 /*---------------------------------*/
19 
31  char *filename)
32 {
33  INT m = vec->row, i;
34 
35  FILE *fp=fopen(filename,"w");
36  if (fasp_mem_check((void *)fp,NULL,ERROR_OPEN_FILE) < 0) {
37  printf("### ERROR: Opening file %s failed!\n",filename);
38  exit(ERROR_OPEN_FILE);
39  }
40 
41  printf("%s: writing vector to `%s'...\n", __FUNCTION__, filename);
42 
43  for (i=0;i<m;++i) fprintf(fp,"%0.15le\n",vec->val[i]);
44 
45  fclose(fp);
46 }
47 
60  char *filefrm,
61  char *fileamg)
62 {
63  FILE *fp = NULL;
64  INT file_base = 1;
65 
66  REAL *A_data = A -> val;
67  INT *A_i = A -> IA;
68  INT *A_j = A -> JA;
69  INT num_rowsA = A -> row;
70  INT num_nonzeros = A_i[num_rowsA] - A_i[0];
71 
72  INT matrix_type = 0;
73  INT rowsum_type = 0;
74  INT symmetry_type = 0;
75 
76  INT i,j;
77  REAL rowsum;
78 
80 
81  /* check symmetry type of the matrix */
82  symmetry_type = fasp_check_symm(A);
83 
84  /* check rowsum type of the matrix */
85  for (i = 0; i < num_rowsA; ++i) {
86  rowsum = 0.0;
87  for (j = A_i[i]; j < A_i[i+1]; ++j) {
88  rowsum += A_data[j];
89  }
90  if (rowsum*rowsum > 0.0) {
91  rowsum_type = 1;
92  break;
93  }
94  }
95 
96  /* Get the matrix type of A */
97  if (symmetry_type == 0) {
98  if (rowsum_type == 0)
99  matrix_type = 11;
100  else
101  matrix_type = 12;
102  }
103  else {
104  if (rowsum_type == 0)
105  matrix_type = 21;
106  else
107  matrix_type = 22;
108  }
109 
110  /* write the *.frm file */
111  fp = fopen(filefrm, "w");
112  fprintf(fp, "%s %d\n", "f", 4);
113  fprintf(fp, "%d %d %d %d %d\n", num_nonzeros, num_rowsA, matrix_type, 1, 0);
114  fclose(fp);
115 
116  /* write the *.amg file */
117  fp = fopen(fileamg, "w");
118  for (j = 0; j <= num_rowsA; ++j) {
119  fprintf(fp, "%d\n", A_i[j] + file_base);
120  }
121  for (j = 0; j < num_nonzeros; ++j) {
122  fprintf(fp, "%d\n", A_j[j] + file_base);
123  }
124  if (A_data) {
125  for (j = 0; j < num_nonzeros; ++j) {
126  fprintf(fp, "%.15le\n", A_data[j]); // we always use "%.15le\n"
127  }
128  }
129  else {
130  fprintf(fp, "### WARNING: No matrix data!\n");
131  }
132  fclose(fp);
133 
134  return FASP_SUCCESS;
135 }
136 
137 /*---------------------------------*/
138 /*-- End of File --*/
139 /*---------------------------------*/
#define ERROR_OPEN_FILE
Definition: fasp_const.h:29
void fasp_dcsr_diagpref(dCSRmat *A)
Re-order the column and data arrays of a CSR matrix, so that the first entry in each row is the diago...
Definition: sparse_csr.c:553
#define REAL
Definition: fasp.h:67
INT dCSRmat2SAMGInput(dCSRmat *A, char *filefrm, char *fileamg)
Write SAMG Input data from a sparse matrix of CSR format.
INT fasp_check_symm(dCSRmat *A)
Check symmetry of a sparse matrix of CSR format.
Definition: checkmat.c:153
REAL * val
actual vector entries
Definition: fasp.h:348
Vector with n entries of REAL type.
Definition: fasp.h:342
#define INT
Definition: fasp.h:64
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:27
Main header file for FASP.
SHORT fasp_mem_check(void *ptr, const char *message, INT ERR)
Check wether a point is null or not.
Definition: memory.c:197
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:148
INT row
number of rows
Definition: fasp.h:345
void dvector2SAMGInput(dvector *vec, char *filename)
Write a dvector to disk file in SAMG format (coordinate format)