Fast Auxiliary Space Preconditioning 2.7.7 Aug/28/2022
Loading...
Searching...
No Matches
BlaSparseSTR.c
Go to the documentation of this file.
1
14#include <math.h>
15
16#include "fasp.h"
17#include "fasp_functs.h"
18
19/*---------------------------------*/
20/*-- Public Functions --*/
21/*---------------------------------*/
22
42 const INT ny,
43 const INT nz,
44 const INT nc,
45 const INT nband,
46 INT *offsets)
47{
48 dSTRmat A;
49
50 INT i;
51
52 A.nx=nx; A.ny=ny; A.nz=nz;
53 A.nc=nc;
54 A.nxy=A.nx*A.ny;
55 A.ngrid=A.nxy*A.nz;
56 A.nband=nband;
57
58 A.offsets=(INT*)fasp_mem_calloc(nband, sizeof(INT));
59
60 for (i=0;i<nband;++i) A.offsets[i]=offsets[i];
61
62 A.diag=(REAL*)fasp_mem_calloc(A.ngrid*A.nc*A.nc, sizeof(REAL));
63
64 A.offdiag=(REAL**)fasp_mem_calloc(nband, sizeof(REAL*));
65
66 for (i=0;i<A.nband;++i) {
67 A.offdiag[i]=(REAL*)fasp_mem_calloc((A.ngrid-ABS(A.offsets[i]))*A.nc*A.nc, sizeof(REAL));
68 }
69
70 return(A);
71}
72
93void fasp_dstr_alloc (const INT nx,
94 const INT ny,
95 const INT nz,
96 const INT nxy,
97 const INT ngrid,
98 const INT nband,
99 const INT nc,
100 INT *offsets,
101 dSTRmat *A)
102{
103 INT i;
104
105 A->nx=nx;
106 A->ny=ny;
107 A->nz=nz;
108 A->nxy=nxy;
109 A->ngrid=ngrid;
110 A->nband=nband;
111 A->nc=nc;
112
113 A->offsets=(INT*)fasp_mem_calloc(nband, sizeof(INT));
114
115 for (i=0;i<nband;++i) A->offsets[i]=offsets[i];
116
117 A->diag=(REAL*)fasp_mem_calloc(ngrid*nc*nc, sizeof(REAL));
118
119 A->offdiag = (REAL **)fasp_mem_calloc(A->nband, sizeof(REAL*));
120
121 for (i=0;i<nband;++i) {
122 A->offdiag[i]=(REAL*)fasp_mem_calloc((ngrid-ABS(offsets[i]))*nc*nc, sizeof(REAL));
123 }
124}
125
137{
138 INT i;
139
140 fasp_mem_free(A->offsets); A->offsets = NULL;
141 fasp_mem_free(A->diag); A->diag = NULL;
142
143 for ( i = 0; i < A->nband; ++i ) {
144 fasp_mem_free(A->offdiag[i]); A->offdiag[i] = NULL;
145 }
146
147 A->nx = A->ny = A->nz = A->nxy=0;
148 A->ngrid = A->nband = A->nc=0;
149}
150
162void fasp_dstr_cp (const dSTRmat *A,
163 dSTRmat *B)
164{
165 const INT nc2 = (A->nc)*(A->nc);
166
167 INT i;
168 B->nx = A->nx;
169 B->ny = A->ny;
170 B->nz = A->nz;
171 B->nxy = A->nxy;
172 B->ngrid = A->ngrid;
173 B->nc = A->nc;
174 B->nband = A->nband;
175
176 memcpy(B->offsets,A->offsets,(A->nband)*sizeof(INT));
177 memcpy(B->diag,A->diag,(A->ngrid*nc2)*sizeof(REAL));
178 for (i=0;i<A->nband;++i) {
179 memcpy(B->offdiag[i],A->offdiag[i],
180 ((A->ngrid - ABS(A->offsets[i]))*nc2)*sizeof(REAL));
181 }
182}
183
184/*---------------------------------*/
185/*-- End of File --*/
186/*---------------------------------*/
void fasp_mem_free(void *mem)
Free up previous allocated memory body and set pointer to NULL.
Definition: AuxMemory.c:152
void * fasp_mem_calloc(const unsigned int size, const unsigned int type)
Allocate, initiate, and check memory.
Definition: AuxMemory.c:65
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: BlaSparseSTR.c:41
void fasp_dstr_free(dSTRmat *A)
Free STR sparse matrix data memeory space.
Definition: BlaSparseSTR.c:136
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: BlaSparseSTR.c:93
void fasp_dstr_cp(const dSTRmat *A, dSTRmat *B)
Copy a dSTRmat to a new one B=A.
Definition: BlaSparseSTR.c:162
Main header file for the FASP project.
#define REAL
Definition: fasp.h:75
#define ABS(a)
Definition: fasp.h:84
#define INT
Definition: fasp.h:72
Structure matrix of REAL type.
Definition: fasp.h:316
INT * offsets
offsets of the off-diagonals (length is nband)
Definition: fasp.h:343
INT nx
number of grids in x direction
Definition: fasp.h:319
INT nxy
number of grids on x-y plane
Definition: fasp.h:328
INT ny
number of grids in y direction
Definition: fasp.h:322
INT nband
number of off-diag bands
Definition: fasp.h:340
REAL * diag
diagonal entries (length is ngrid*(nc^2))
Definition: fasp.h:337
INT ngrid
number of grids
Definition: fasp.h:334
INT nc
size of each block (number of components)
Definition: fasp.h:331
INT nz
number of grids in z direction
Definition: fasp.h:325
REAL ** offdiag
off-diagonal entries (dimension is nband * [(ngrid-|offsets|) * nc^2])
Definition: fasp.h:346