Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
XtrSamg.c
Go to the documentation of this file.
1
16#include <math.h>
17#include <time.h>
18
19#include "fasp.h"
20#include "fasp_functs.h"
21
22/*---------------------------------*/
23/*-- Public Functions --*/
24/*---------------------------------*/
25
37 char *filename)
38{
39 INT m = vec->row, i;
40
41 FILE *fp=fopen(filename,"w");
42 if ( fp == NULL ) {
43 printf("### ERROR: Opening file %s failed!\n",filename);
44 exit(ERROR_OPEN_FILE);
45 }
46
47 printf("%s: writing vector to `%s'...\n", __FUNCTION__, filename);
48
49 for (i=0;i<m;++i) fprintf(fp,"%0.15le\n",vec->val[i]);
50
51 fclose(fp);
52}
53
66 char *filefrm,
67 char *fileamg)
68{
69 FILE *fp = NULL;
70 INT file_base = 1;
71
72 REAL *A_data = A -> val;
73 INT *A_i = A -> IA;
74 INT *A_j = A -> JA;
75 INT num_rowsA = A -> row;
76 INT num_nonzeros = A_i[num_rowsA] - A_i[0];
77
78 INT matrix_type = 0;
79 INT rowsum_type = 0;
80 INT symmetry_type = 0;
81
82 INT i,j;
83 REAL rowsum;
84
86
87 /* check symmetry type of the matrix */
88 symmetry_type = fasp_check_symm(A);
89
90 /* check rowsum type of the matrix */
91 for (i = 0; i < num_rowsA; ++i) {
92 rowsum = 0.0;
93 for (j = A_i[i]; j < A_i[i+1]; ++j) {
94 rowsum += A_data[j];
95 }
96 if (rowsum*rowsum > 0.0) {
97 rowsum_type = 1;
98 break;
99 }
100 }
101
102 /* Get the matrix type of A */
103 if (symmetry_type == 0) {
104 if (rowsum_type == 0)
105 matrix_type = 11;
106 else
107 matrix_type = 12;
108 }
109 else {
110 if (rowsum_type == 0)
111 matrix_type = 21;
112 else
113 matrix_type = 22;
114 }
115
116 /* write the *.frm file */
117 fp = fopen(filefrm, "w");
118 fprintf(fp, "%s %d\n", "f", 4);
119 fprintf(fp, "%d %d %d %d %d\n", num_nonzeros, num_rowsA, matrix_type, 1, 0);
120 fclose(fp);
121
122 /* write the *.amg file */
123 fp = fopen(fileamg, "w");
124 for (j = 0; j <= num_rowsA; ++j) {
125 fprintf(fp, "%d\n", A_i[j] + file_base);
126 }
127 for (j = 0; j < num_nonzeros; ++j) {
128 fprintf(fp, "%d\n", A_j[j] + file_base);
129 }
130 if (A_data) {
131 for (j = 0; j < num_nonzeros; ++j) {
132 fprintf(fp, "%.15le\n", A_data[j]); // we always use "%.15le\n"
133 }
134 }
135 else {
136 fprintf(fp, "### WARNING: No matrix data!\n");
137 }
138 fclose(fp);
139
140 return FASP_SUCCESS;
141}
142
143/*---------------------------------*/
144/*-- End of File --*/
145/*---------------------------------*/
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: BlaSparseCSR.c:680
INT fasp_check_symm(const dCSRmat *A)
Check symmetry of a sparse matrix of CSR format.
void dvector2SAMGInput(dvector *vec, char *filename)
Write a dvector to disk file in SAMG format (coordinate format)
Definition: XtrSamg.c:36
INT dCSRmat2SAMGInput(dCSRmat *A, char *filefrm, char *fileamg)
Write SAMG Input data from a sparse matrix of CSR format.
Definition: XtrSamg.c:65
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define INT
Definition: fasp.h:72
#define ERROR_OPEN_FILE
Definition: fasp_const.h:22
#define FASP_SUCCESS
Definition of return status and error messages.
Definition: fasp_const.h:19
Sparse matrix of REAL type in CSR format.
Definition: fasp.h:151
Vector with n entries of REAL type.
Definition: fasp.h:354
REAL * val
actual vector entries
Definition: fasp.h:360
INT row
number of rows
Definition: fasp.h:357