SpM Handbook 1.2.4
Loading...
Searching...
No Matches
spm_dof_extend.c
Go to the documentation of this file.
1/**
2 *
3 * @file spm_dof_extend.c
4 *
5 * SParse Matrix package random multi-dofs generator.
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 Pierre Ramet
14 * @author Tony Delarue
15 * @date 2024-05-29
16 *
17 **/
18#include "common.h"
19
20/**
21 *******************************************************************************
22 *
23 * @ingroup spm
24 *
25 * @brief Generate a random multidof spm from a given spm (with dof=1).
26 *
27 *******************************************************************************
28 *
29 * @param[in] spm
30 * The sparse matrix used to generate the new multidof spm.
31 *
32 * @param[in] type
33 * Defines how to generate dofs.
34 * - 0: Generate a constant dof vector,
35 * - else: Generate a variable dof vector.
36 *
37 * @param[in] dof
38 * The maximum value for dofs.
39 *
40 * @param[inout] newspm
41 * On entry, the allocated spm structure, on exit the structure filled
42 * with the extended multidof spm.
43 *
44 ********************************************************************************
45 *
46 * @retval SPM_SUCCESS on success,
47 * @retval SPM_ERR_BADPARAMETER otherwise.
48 *
49 *******************************************************************************/
50int
52 const int type,
53 const int dof,
54 spmatrix_t *newspm )
55{
56 /* Quick return */
57 if ( dof == 1 ) {
58 spmCopy( spm, newspm );
59 return SPM_SUCCESS;
60 }
61
62 if ( spm->dof != 1 ) {
63 spm_print_error( "Cannot extend spm including dofs already\n" );
65 }
66
67 spmCopy( spm, newspm );
68
69 /*
70 * Generate constant dof
71 */
72 if (type == 0) {
73 newspm->dof = dof;
74 }
75 else {
76 spm_int_t i, dofi, baseval;
77 spm_int_t *dofptr;
78
79 baseval = spm->baseval;
80
81 newspm->dof = -1;
82 newspm->dofs = malloc( (spm->gN+1) * sizeof(spm_int_t) );
83 dofptr = newspm->dofs;
84
85 /*
86 * Initialize the dofs array where the degree of freedom of vertex i is
87 * dof[i+1] - dof[i]
88 */
89 if( spm->clustnum == 0 ) {
90 *dofptr = baseval;
91 for(i=0; i<spm->gN; i++, dofptr++) {
92 dofi = 1 + ( rand() % dof );
93 dofptr[1] = dofptr[0] + dofi;
94 }
95 }
96#if defined(SPM_WITH_MPI)
97 MPI_Bcast( newspm->dofs, spm->gN+1, SPM_MPI_INT, 0, spm->comm );
98#endif
99 }
100
101 spmUpdateComputedFields( newspm );
102
103 switch (spm->flttype) {
104 case SpmFloat:
105 s_spmDofExtend( newspm );
106 break;
107
108 case SpmDouble:
109 d_spmDofExtend( newspm );
110 break;
111
112 case SpmComplex32:
113 c_spmDofExtend( newspm );
114 break;
115
116 case SpmComplex64:
117 z_spmDofExtend( newspm );
118 break;
119
120 case SpmPattern:
121 ;
122 }
123
124 return SPM_SUCCESS;
125}
@ SPM_ERR_BADPARAMETER
Definition const.h:89
@ SPM_SUCCESS
Definition const.h:82
@ SpmComplex64
Definition const.h:66
@ SpmDouble
Definition const.h:64
@ SpmFloat
Definition const.h:63
@ SpmComplex32
Definition const.h:65
@ SpmPattern
Definition const.h:62
void s_spmDofExtend(spmatrix_t *spm)
Extend a single dof sparse matrix to a multi-dof sparse matrix.
void z_spmDofExtend(spmatrix_t *spm)
Extend a single dof sparse matrix to a multi-dof sparse matrix.
void c_spmDofExtend(spmatrix_t *spm)
Extend a single dof 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.
spm_coeftype_t flttype
Definition spm.h:67
spm_int_t * dofs
Definition spm.h:85
spm_int_t dof
Definition spm.h:82
SPM_Comm comm
Definition spm.h:97
spm_int_t baseval
Definition spm.h:71
int clustnum
Definition spm.h:95
spm_int_t gN
Definition spm.h:72
#define SPM_MPI_INT
The MPI type associated to spm_int_t.
Definition datatypes.h:72
void spmUpdateComputedFields(spmatrix_t *spm)
Update all the computed fields based on the static values stored.
int spm_int_t
The main integer datatype used in spm arrays.
Definition datatypes.h:70
int spmDofExtend(const spmatrix_t *spm, int type, int dof, spmatrix_t *spm_out)
Generate a random multidof spm from a given spm (with dof=1).
void spmCopy(const spmatrix_t *spm_in, spmatrix_t *spm_out)
Create a copy of the spm.
Definition spm.c:969
The sparse matrix data structure.
Definition spm.h:64