-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtetrahedral.h
120 lines (104 loc) · 3.02 KB
/
tetrahedral.h
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
class TetrahedralBasis {
public:
static const int spatial_dim = 3;
static const int nodes_per_element = 10;
template <typename T>
static void eval_basis_grad(const T pt[], T Nxi[]) {
// Corner node derivatives
Nxi[0] = 4.0 * pt[0] + 4.0 * pt[1] + 4.0 * pt[2] - 3.0;
Nxi[1] = 4.0 * pt[0] + 4.0 * pt[1] + 4.0 * pt[2] - 3.0;
Nxi[2] = 4.0 * pt[0] + 4.0 * pt[1] + 4.0 * pt[2] - 3.0;
Nxi[3] = 4.0 * pt[0] - 1.0;
Nxi[4] = 0.0;
Nxi[5] = 0.0;
Nxi[6] = 0.0;
Nxi[7] = 4.0 * pt[1] - 1.0;
Nxi[8] = 0.0;
Nxi[9] = 0.0;
Nxi[10] = 0.0;
Nxi[11] = 4.0 * pt[2] - 1.0;
// Mid node derivatives
Nxi[12] = -4.0 * (2.0 * pt[0] + pt[1] + pt[2] - 1.0);
Nxi[13] = -4.0 * pt[0];
Nxi[14] = -4.0 * pt[0];
Nxi[15] = 4.0 * pt[1];
Nxi[16] = 4.0 * pt[0];
Nxi[17] = 0.0;
Nxi[18] = -4.0 * pt[1];
Nxi[19] = -4.0 * (pt[0] + 2.0 * pt[1] + pt[2] - 1.0);
Nxi[20] = -4.0 * pt[1];
Nxi[21] = -4.0 * pt[2];
Nxi[22] = -4.0 * pt[2];
Nxi[23] = -4.0 * (pt[0] + pt[1] + 2.0 * pt[2] - 1.0);
Nxi[24] = 4.0 * pt[2];
Nxi[25] = 0.0;
Nxi[26] = 4.0 * pt[0];
Nxi[27] = 0.0;
Nxi[28] = 4.0 * pt[2];
Nxi[29] = 4.0 * pt[1];
}
template <typename T, int dim>
static void eval_grad(const T pt[], const T dof[], T grad[]) {
T Nxi[spatial_dim * nodes_per_element];
eval_basis_grad(pt, Nxi);
for (int k = 0; k < spatial_dim * dim; k++) {
grad[k] = 0.0;
}
for (int i = 0; i < nodes_per_element; i++) {
for (int k = 0; k < dim; k++) {
grad[spatial_dim * k] += Nxi[spatial_dim * i] * dof[dim * i + k];
grad[spatial_dim * k + 1] +=
Nxi[spatial_dim * i + 1] * dof[dim * i + k];
grad[spatial_dim * k + 2] +=
Nxi[spatial_dim * i + 2] * dof[dim * i + k];
}
}
}
template <typename T, int dim>
static void add_grad(const T pt[], const T coef[], T res[]) {
T Nxi[spatial_dim * nodes_per_element];
eval_basis_grad(pt, Nxi);
for (int i = 0; i < nodes_per_element; i++) {
for (int k = 0; k < dim; k++) {
res[dim * i + k] +=
(coef[spatial_dim * k] * Nxi[spatial_dim * i] +
coef[spatial_dim * k + 1] * Nxi[spatial_dim * i + 1] +
coef[spatial_dim * k + 2] * Nxi[spatial_dim * i + 2]);
}
}
}
};
class TetrahedralQuadrature {
public:
static const int num_quadrature_pts = 5;
template <typename T>
static T get_quadrature_pt(int k, T pt[]) {
if (k == 0) {
pt[0] = 0.25;
pt[1] = 0.25;
pt[2] = 0.25;
return -2.0 / 15;
} else if (k == 1) {
pt[0] = 1.0 / 6.0;
pt[1] = 1.0 / 6.0;
pt[2] = 1.0 / 6.0;
return 3.0 / 40;
} else if (k == 2) {
pt[0] = 0.5;
pt[1] = 1.0 / 6.0;
pt[2] = 1.0 / 6.0;
return 3.0 / 40;
} else if (k == 3) {
pt[0] = 1.0 / 6.0;
pt[1] = 0.5;
pt[2] = 1.0 / 6.0;
return 3.0 / 40;
} else if (k == 4) {
pt[0] = 1.0 / 6.0;
pt[1] = 1.0 / 6.0;
pt[2] = 0.5;
return 3.0 / 40;
}
return 0.0;
}
};