Fast Auxiliary Space Preconditioning  1.8.4 Feb/15/2016
sparse_str.c
Go to the documentation of this file.
1 
6 #include <math.h>
7 
8 #include "fasp.h"
9 #include "fasp_functs.h"
10 
11 /*---------------------------------*/
12 /*-- Public Functions --*/
13 /*---------------------------------*/
14 
26 {
27  A->nx=0;
28  A->ny=0;
29  A->nz=0;
30  A->nxy=0;
31  A->ngrid=0;
32  A->nband=0;
33  A->nc=0;
34  A->offsets=NULL;
35  A->diag=NULL;
36  A->offdiag=NULL;
37 }
38 
58  const INT ny,
59  const INT nz,
60  const INT nc,
61  const INT nband,
62  INT *offsets)
63 {
64  dSTRmat A;
65 
66  INT i;
67 
68  A.nx=nx; A.ny=ny; A.nz=nz;
69  A.nc=nc;
70  A.nxy=A.nx*A.ny;
71  A.ngrid=A.nxy*A.nz;
72  A.nband=nband;
73 
74  A.offsets=(INT*)fasp_mem_calloc(nband, sizeof(INT));
75 
76  for (i=0;i<nband;++i) A.offsets[i]=offsets[i];
77 
78  A.diag=(REAL*)fasp_mem_calloc(A.ngrid*A.nc*A.nc, sizeof(REAL));
79 
80  A.offdiag=(REAL**)fasp_mem_calloc(nband, sizeof(REAL*));
81 
82  for (i=0;i<A.nband;++i) {
83  A.offdiag[i]=(REAL*)fasp_mem_calloc((A.ngrid-ABS(A.offsets[i]))*A.nc*A.nc, sizeof(REAL));
84  }
85 
86  return(A);
87 }
88 
109 void fasp_dstr_alloc (const INT nx,
110  const INT ny,
111  const INT nz,
112  const INT nxy,
113  const INT ngrid,
114  const INT nband,
115  const INT nc,
116  INT *offsets,
117  dSTRmat *A)
118 {
119  INT i;
120 
121  A->nx=nx;
122  A->ny=ny;
123  A->nz=nz;
124  A->nxy=nxy;
125  A->ngrid=ngrid;
126  A->nband=nband;
127  A->nc=nc;
128 
129  A->offsets=(INT*)fasp_mem_calloc(nband, sizeof(INT));
130 
131  for (i=0;i<nband;++i) A->offsets[i]=offsets[i];
132 
133  A->diag=(REAL*)fasp_mem_calloc(ngrid*nc*nc, sizeof(REAL));
134 
135  A->offdiag = (REAL **)fasp_mem_calloc(A->nband, sizeof(REAL*));
136 
137  for (i=0;i<nband;++i) {
138  A->offdiag[i]=(REAL*)fasp_mem_calloc((ngrid-ABS(offsets[i]))*nc*nc, sizeof(REAL));
139  }
140 }
141 
153 {
154  INT i;
155 
157  fasp_mem_free(A->diag);
158 
159  for (i=0;i<A->nband;++i) fasp_mem_free(A->offdiag[i]);
160 
161  A->nx=0;
162  A->ny=0;
163  A->nz=0;
164  A->nxy=0;
165  A->ngrid=0;
166  A->nband=0;
167  A->nc=0;
168 }
169 
182  dSTRmat *A1)
183 {
184  const INT nc2 = (A->nc)*(A->nc);
185 
186  INT i;
187  A1->nx=A->nx;
188  A1->ny=A->ny;
189  A1->nz=A->nz;
190  A1->nxy=A->nxy;
191  A1->ngrid=A->ngrid;
192  A1->nc=A->nc;
193  A1->nband=A->nband;
194 
195  memcpy(A1->offsets,A->offsets,(A->nband)*sizeof(INT));
196  memcpy(A1->diag,A->diag,(A->ngrid*nc2)*sizeof(REAL));
197  for (i=0;i<A->nband;++i)
198  memcpy(A1->offdiag[i],A->offdiag[i],((A->ngrid - ABS(A->offsets[i]))*nc2)*sizeof(REAL));
199 
200 }
201 
202 /*---------------------------------*/
203 /*-- End of File --*/
204 /*---------------------------------*/
INT nx
number of grids in x direction
Definition: fasp.h:307
#define REAL
Definition: fasp.h:67
INT ngrid
number of grids
Definition: fasp.h:322
INT nc
size of each block (number of components)
Definition: fasp.h:319
REAL ** offdiag
off-diagonal entries (dimension is nband * [(ngrid-|offsets|) * nc^2])
Definition: fasp.h:334
INT * offsets
offsets of the off-diagonals (length is nband)
Definition: fasp.h:331
Structure matrix of REAL type.
Definition: fasp.h:304
INT nz
number of grids in z direction
Definition: fasp.h:313
void * fasp_mem_calloc(LONGLONG size, INT type)
1M = 1024*1024
Definition: memory.c:60
#define INT
Definition: fasp.h:64
INT nband
number of off-diag bands
Definition: fasp.h:328
void fasp_dstr_null(dSTRmat *A)
Initialize sparse matrix on structured grid.
Definition: sparse_str.c:25
void fasp_mem_free(void *mem)
Free up previous allocated memory body.
Definition: memory.c:150
dSTRmat fasp_dstr_create(const INT nx, const INT ny, const INT nz, const INT nc, const INT nband, INT *offsets)
Create STR sparse matrix data memory space.
Definition: sparse_str.c:57
Main header file for FASP.
REAL * diag
diagonal entries (length is ngrid*(nc^2))
Definition: fasp.h:325
#define ABS(a)
Definition: fasp.h:74
void fasp_dstr_alloc(const INT nx, const INT ny, const INT nz, const INT nxy, const INT ngrid, const INT nband, const INT nc, INT *offsets, dSTRmat *A)
Allocate STR sparse matrix memory space.
Definition: sparse_str.c:109
INT nxy
number of grids on x-y plane
Definition: fasp.h:316
void fasp_dstr_cp(dSTRmat *A, dSTRmat *A1)
Copy a dSTRmat to a new one A1=A.
Definition: sparse_str.c:181
void fasp_dstr_free(dSTRmat *A)
Free STR sparse matrix data memeory space.
Definition: sparse_str.c:152
INT ny
number of grids in y direction
Definition: fasp.h:310