-
Notifications
You must be signed in to change notification settings - Fork 4
/
grid_utilities.c
183 lines (145 loc) · 5.78 KB
/
grid_utilities.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "grid_utilities.h"
#include "local_matrix.h"
void setFixedDof_halo(struct gridContext *gc, const int l) {
const int ncell = pow(2, l);
const int32_t nelyc = (*gc).nely / ncell;
const int32_t nelzc = (*gc).nelz / ncell;
const int paddingyc =
(STENCIL_SIZE_Y - ((nelyc + 1) % STENCIL_SIZE_Y)) % STENCIL_SIZE_Y;
const int paddingzc =
(STENCIL_SIZE_Z - ((nelzc + 1) % STENCIL_SIZE_Z)) % STENCIL_SIZE_Z;
const int wrapyc = nelyc + paddingyc + 3;
const int wrapzc = nelzc + paddingzc + 3;
const int nzc = (nelzc + 1);
const int nyc = (nelyc + 1);
// classic cantilever
// (*gc).fixedDofs[l].n = 3 * nyc * nzc;
// (*gc).fixedDofs[l].idx = malloc(sizeof(uint_fast32_t) *
// (*gc).fixedDofs[l].n); int offset = 0; for (uint_fast32_t k = 1; k < (nzc +
// 1); k++)
// for (uint_fast32_t j = 1; j < (nyc + 1); j++) {
// (*gc).fixedDofs[l].idx[offset + 0] =
// 3 * (wrapyc * wrapzc + wrapyc * k + j) + 0;
// (*gc).fixedDofs[l].idx[offset + 1] =
// 3 * (wrapyc * wrapzc + wrapyc * k + j) + 1;
// (*gc).fixedDofs[l].idx[offset + 2] =
// 3 * (wrapyc * wrapzc + wrapyc * k + j) + 2;
// offset += 3;
// }
// new cantilever
const int nodelimit = (nelyc / 4) + 1;
(*gc).fixedDofs[l].n = 3 * nzc * 2 * nodelimit;
(*gc).fixedDofs[l].idx = malloc(sizeof(uint_fast32_t) * (*gc).fixedDofs[l].n);
int offset = 0;
const int i = 1;
for (uint_fast32_t k = 1; k < (nzc + 1); k++) {
for (uint_fast32_t j = 1; j < nodelimit + 1; j++) {
(*gc).fixedDofs[l].idx[offset + 0] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 0;
(*gc).fixedDofs[l].idx[offset + 1] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 1;
(*gc).fixedDofs[l].idx[offset + 2] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 2;
offset += 3;
}
for (uint_fast32_t j = (nyc + 1) - nodelimit; j < (nyc + 1); j++) {
(*gc).fixedDofs[l].idx[offset + 0] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 0;
(*gc).fixedDofs[l].idx[offset + 1] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 1;
(*gc).fixedDofs[l].idx[offset + 2] =
3 * (i * wrapyc * wrapzc + wrapyc * k + j) + 2;
offset += 3;
}
}
}
void initializeGridContext(struct gridContext *gc, const int nl) {
const int paddingx =
(STENCIL_SIZE_X - (((*gc).nelx + 1) % STENCIL_SIZE_X)) % STENCIL_SIZE_X;
const int paddingy =
(STENCIL_SIZE_Y - (((*gc).nely + 1) % STENCIL_SIZE_Y)) % STENCIL_SIZE_Y;
const int paddingz =
(STENCIL_SIZE_Z - (((*gc).nelz + 1) % STENCIL_SIZE_Z)) % STENCIL_SIZE_Z;
(*gc).wrapx = (*gc).nelx + paddingx + 3;
(*gc).wrapy = (*gc).nely + paddingy + 3;
(*gc).wrapz = (*gc).nelz + paddingz + 3;
(*gc).precomputedKE = malloc(sizeof(MTYPE *) * nl);
(*gc).fixedDofs = malloc(sizeof(struct FixedDofs) * nl);
for (int l = 0; l < nl; l++) {
const int ncell = pow(2, l);
const int pKESize = 24 * 24 * ncell * ncell * ncell;
(*gc).precomputedKE[l] = malloc(sizeof(MTYPE) * pKESize);
getKEsubspace((*gc).precomputedKE[l], (*gc).nu, l);
setFixedDof_halo(gc, l);
}
}
void freeGridContext(struct gridContext *gc, const int nl) {
for (int l = 0; l < nl; l++) {
free((*gc).precomputedKE[l]);
free((*gc).fixedDofs[l].idx);
}
free((*gc).precomputedKE);
free((*gc).fixedDofs);
}
void allocateStateField(const struct gridContext gc, const int l, CTYPE **v) {
const int ncell = pow(2, l);
const int nelx = gc.nelx / ncell;
const int nely = gc.nely / ncell;
const int nelz = gc.nelz / ncell;
const int paddingx =
(STENCIL_SIZE_X - ((nelx + 1) % STENCIL_SIZE_X)) % STENCIL_SIZE_X;
const int paddingy =
(STENCIL_SIZE_Y - ((nely + 1) % STENCIL_SIZE_Y)) % STENCIL_SIZE_Y;
const int paddingz =
(STENCIL_SIZE_Z - ((nelz + 1) % STENCIL_SIZE_Z)) % STENCIL_SIZE_Z;
const int wrapx = nelx + paddingx + 3;
const int wrapy = nely + paddingy + 3;
const int wrapz = nelz + paddingz + 3;
const int ndof = 3 * wrapx * wrapy * wrapz;
(*v) = malloc(sizeof(CTYPE) * ndof);
#pragma omp parallel for schedule(static)
for (int i = 0; i < ndof; i++)
(*v)[i] = 0.0;
}
void allocateStateField_MTYPE(const struct gridContext gc, const int l,
MTYPE **v) {
const int ncell = pow(2, l);
const int nelx = gc.nelx / ncell;
const int nely = gc.nely / ncell;
const int nelz = gc.nelz / ncell;
const int paddingx =
(STENCIL_SIZE_X - ((nelx + 1) % STENCIL_SIZE_X)) % STENCIL_SIZE_X;
const int paddingy =
(STENCIL_SIZE_Y - ((nely + 1) % STENCIL_SIZE_Y)) % STENCIL_SIZE_Y;
const int paddingz =
(STENCIL_SIZE_Z - ((nelz + 1) % STENCIL_SIZE_Z)) % STENCIL_SIZE_Z;
const int wrapx = nelx + paddingx + 3;
const int wrapy = nely + paddingy + 3;
const int wrapz = nelz + paddingz + 3;
const int ndof = 3 * wrapx * wrapy * wrapz;
(*v) = malloc(sizeof(MTYPE) * ndof);
#pragma omp parallel for schedule(static)
for (int i = 0; i < ndof; i++)
(*v)[i] = 0.0;
}
void allocateStateField_STYPE(const struct gridContext gc, const int l,
STYPE **v) {
const int ncell = pow(2, l);
const int nelx = gc.nelx / ncell;
const int nely = gc.nely / ncell;
const int nelz = gc.nelz / ncell;
const int paddingx =
(STENCIL_SIZE_X - ((nelx + 1) % STENCIL_SIZE_X)) % STENCIL_SIZE_X;
const int paddingy =
(STENCIL_SIZE_Y - ((nely + 1) % STENCIL_SIZE_Y)) % STENCIL_SIZE_Y;
const int paddingz =
(STENCIL_SIZE_Z - ((nelz + 1) % STENCIL_SIZE_Z)) % STENCIL_SIZE_Z;
const int wrapx = nelx + paddingx + 3;
const int wrapy = nely + paddingy + 3;
const int wrapz = nelz + paddingz + 3;
const int ndof = 3 * wrapx * wrapy * wrapz;
(*v) = malloc(sizeof(STYPE) * ndof);
#pragma omp parallel for schedule(static)
for (int i = 0; i < ndof; i++)
(*v)[i] = 0.0;
}