SpM Handbook 1.2.4
Loading...
Searching...
No Matches
d_spm_dof_extend.c
Go to the documentation of this file.
1/**
2 *
3 * @file d_spm_dof_extend.c
4 *
5 * SParse Matrix package multi-dof matrix expanser.
6 *
7 * @copyright 2016-2024 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
8 * Univ. Bordeaux. All rights reserved.
9 *
10 * @version 1.2.4
11 * @author Mathieu Faverge
12 * @author Matias Hastaran
13 * @author Tony Delarue
14 * @date 2024-06-25
15 *
16 * @generated from /builds/2mk6rsew/0/fpruvost/spm/src/z_spm_dof_extend.c, normal z -> d, Fri Nov 29 11:34:29 2024
17 **/
18#include "common.h"
19
20/**
21 *******************************************************************************
22 *
23 * @ingroup spm_dev_dof
24 *
25 * @brief Update the newval array thanks to the old value and the degrees of
26 * freedom.
27 *
28 *******************************************************************************
29 *
30 * @param[inout] newval
31 * The extended value array.
32 *
33 * @param[in] value
34 * The old value that will be extended.
35 *
36 * @param[in] dofi
37 * A degree of freedom.
38 *
39 * @param[in] dofj
40 * A degree of freedom.
41 *
42 * @param[in] diag
43 * 1 if row == col, 0 otherwise.
44 *
45 *******************************************************************************/
46static inline void
48 double value,
49 spm_int_t dofi,
50 spm_int_t dofj,
51 int diag )
52{
53 spm_int_t ii, jj;
54 double *valptr = newval;
55
56 if ( !diag ) {
57 for(jj=0; jj<dofj; jj++)
58 {
59 for(ii=0; ii<dofi; ii++, valptr++)
60 {
61 *valptr = value;
62 }
63 }
64 }
65 else {
66 for(jj=0; jj<dofj; jj++)
67 {
68 for(ii=0; ii<dofi; ii++, valptr++)
69 {
70 *valptr = value / (labs((long)(ii - jj)) + 1.);
71 }
72 }
73 }
74}
75
76/**
77 *******************************************************************************
78 *
79 * @ingroup spm_dev_dof
80 *
81 * @brief Extend a single dof CSX sparse matrix to a multi-dof sparse matrix.
82 *
83 *******************************************************************************
84 *
85 * @param[inout] spm
86 * The sparse matrix to extend.
87 *
88 *******************************************************************************/
89static inline void
91{
92 spm_int_t i, j, baseval;
93 spm_int_t ig, jg, dofi, dofj;
94 spm_int_t *colptr, *rowptr, *dofs, *loc2glob;
95 double *newval, *oldval, *oldvalptr;
96
97 oldval = oldvalptr = (double*)(spm->values);
98 newval = spm->values = malloc( spm->nnzexp * sizeof(double) );
99
100 baseval = spm->baseval;
101 colptr = (spm->fmttype == SpmCSC) ? spm->colptr : spm->rowptr;
102 rowptr = (spm->fmttype == SpmCSC) ? spm->rowptr : spm->colptr;
103 dofs = spm->dofs;
104 loc2glob = spm->loc2glob;
105
106 for(j=0; j<spm->n; j++, colptr++, loc2glob++)
107 {
108 jg = spm->replicated ? j : *loc2glob - baseval;
109 dofj = (spm->dof > 0) ? spm->dof : dofs[jg+1] - dofs[jg];
110
111 for(i=colptr[0]; i<colptr[1]; i++, rowptr++, oldval++)
112 {
113 ig = *rowptr - baseval;
114 dofi = ( spm->dof > 0 ) ? spm->dof : dofs[ig+1] - dofs[ig];
115
116 d_spm_dof_extend_update_values( newval, *oldval, dofi, dofj, (ig == jg) );
117 newval += (dofi*dofj);
118 }
119 }
120 free( oldvalptr );
121
122 assert((newval - (double*)spm->values) == spm->nnzexp);
123}
124
125/**
126 *******************************************************************************
127 *
128 * @ingroup spm_dev_dof
129 *
130 * @brief Extend a single dof IJV sparse matrix to a multi-dof sparse matrix.
131 *
132 *******************************************************************************
133 *
134 * @param[inout] spm
135 * The sparse matrix to extend.
136 *
137 *******************************************************************************/
138static inline void
140{
141 spm_int_t k, baseval;
142 spm_int_t ig, jg, dofi, dofj;
143 spm_int_t *colptr, *rowptr, *dofs;
144 double *newval, *oldval, *oldvalptr;
145
146 oldval = oldvalptr = (double*)(spm->values);
147 newval = spm->values = malloc( spm->nnzexp * sizeof(double) );
148
149 baseval = spm->baseval;
150 colptr = spm->colptr;
151 rowptr = spm->rowptr;
152 dofs = spm->dofs;
153
154 for(k=0; k<spm->nnz; k++, rowptr++, colptr++, oldval++)
155 {
156 ig = *rowptr - baseval;
157 jg = *colptr - baseval;
158 dofi = (spm->dof > 0) ? spm->dof : dofs[ig+1] - dofs[ig];
159 dofj = (spm->dof > 0) ? spm->dof : dofs[jg+1] - dofs[jg];
160
161 d_spm_dof_extend_update_values( newval, *oldval, dofi, dofj, (ig == jg) );
162 newval += (dofi*dofj);
163 }
164 free( oldvalptr );
165
166 assert((newval - (double*)spm->values) == spm->nnzexp);
167}
168
169/**
170 *******************************************************************************
171 *
172 * @ingroup spm_dev_dof
173 *
174 * @brief Extend a single dof sparse matrix to a multi-dof sparse matrix.
175 *
176 *******************************************************************************
177 *
178 * @param[inout] spm
179 * The sparse matrix to extend.
180 *
181 *******************************************************************************/
182void
184{
185 if (spm->fmttype != SpmIJV) {
187 }
188 else {
190 }
191}
@ SpmCSC
Definition const.h:73
@ SpmIJV
Definition const.h:75
static void d_spm_dof_extend_ijv(spmatrix_t *spm)
Extend a single dof IJV sparse matrix to a multi-dof sparse matrix.
void d_spmDofExtend(spmatrix_t *spm)
Extend a single dof sparse matrix to a multi-dof sparse matrix.
static void d_spm_dof_extend_csx(spmatrix_t *spm)
Extend a single dof CSX sparse matrix to a multi-dof sparse matrix.
static void d_spm_dof_extend_update_values(double *newval, double value, spm_int_t dofi, spm_int_t dofj, int diag)
Update the newval array thanks to the old value and the degrees of freedom.
spm_int_t * dofs
Definition spm.h:85
void * values
Definition spm.h:92
spm_int_t nnz
Definition spm.h:75
spm_int_t nnzexp
Definition spm.h:80
spm_int_t * rowptr
Definition spm.h:90
spm_fmttype_t fmttype
Definition spm.h:69
spm_int_t dof
Definition spm.h:82
spm_int_t n
Definition spm.h:73
spm_int_t * loc2glob
Definition spm.h:91
spm_int_t baseval
Definition spm.h:71
spm_int_t * colptr
Definition spm.h:89
int replicated
Definition spm.h:98
int spm_int_t
The main integer datatype used in spm arrays.
Definition datatypes.h:70
The sparse matrix data structure.
Definition spm.h:64