-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstructures.h
214 lines (199 loc) · 8.52 KB
/
structures.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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#ifndef STRUCTURES_H
#define STRUCTURES_H
#include <iostream>
#include "constants.h"
/*
* Структура, описывающая координаты и номер узла, а также радиус-вектор узла.
*/
struct points {
double x;
double y;
// TODO проверить, что радиус-вектор в цилиндрических координатах вычисляется так
double rad_vector() { return x; }
uint_fast32_t point_num;
};
/*
* Структура, описывающая координаты точек и номер треугольника,
* а также вычисляющая коэффициенты функции формы узлов, входящих в треугольник,
* а также вычисляюая площадь треугольника и матрицы элементов [K], [C], [F].
*/
struct triangles {
points first_point;
points second_point;
points third_point;
void coef_a(double* a)
{
a[0] = second_point.x * third_point.y - third_point.x * second_point.y;
a[1] = third_point.x * first_point.y - first_point.x * third_point.y;
a[2] = first_point.x * second_point.y - second_point.x * first_point.y;
}
void coef_b(double* b)
{
b[0] = second_point.y - third_point.y;
b[1] = third_point.y - first_point.y;
b[2] = first_point.y - second_point.y;
}
void coef_c(double* c)
{
c[0] = third_point.x - second_point.x;
c[1] = first_point.x - third_point.x;
c[2] = second_point.x - first_point.x;
}
double GetSquareTriangleArea()
{
return STEP_X * 2 * STEP_X * 0.5;
}
double GetMatrixADeterminant()
{
return 0.5 * (second_point.x * third_point.y
- third_point.x * second_point.y
- first_point.x * third_point.y
+ first_point.x * second_point.y
+ third_point.x * first_point.y
- second_point.x * first_point.y);
}
double GetR() {
points p[3];
p[0].x = first_point.x;
p[0].y = first_point.y;
p[1].x = second_point.x;
p[1].y = second_point.y;
p[2].x = third_point.x;
p[2].y = third_point.y;
double R = (0.0833333333333333333333333) * ((2 * p[0].rad_vector()
+ p[1].rad_vector()
+ p[2].rad_vector())
* p[0].rad_vector()
+ (p[0].rad_vector()
+ 2 * p[1].rad_vector()
+ p[2].rad_vector())
* p[1].rad_vector()
+ (p[0].rad_vector()
+ p[1].rad_vector()
+ 2 * p[2].rad_vector())
* p[2].rad_vector());
return R;
}
void Matrix_K(double** K)
{
points p[3];
double a[3];
double b[3];
double c[3];
coef_a(a);
coef_b(b);
coef_c(c);
p[0].x = first_point.x;
p[0].y = first_point.y;
p[1].x = second_point.x;
p[1].y = second_point.y;
p[2].x = third_point.x;
p[2].y = third_point.y;
//std::cout << "p[0].rad_vector() = " << p[0].rad_vector() << std::endl;
//std::cout << "p[1].rad_vector() = " << p[1].rad_vector() << std::endl;
//std::cout << "p[2].rad_vector() = " << p[2].rad_vector() << std::endl;
double R = (0.0833333333333333333333333) * ((2 * p[0].rad_vector()
+ p[1].rad_vector()
+ p[2].rad_vector())
* p[0].rad_vector()
+ (p[0].rad_vector()
+ 2 * p[1].rad_vector()
+ p[2].rad_vector())
* p[1].rad_vector()
+ (p[0].rad_vector()
+ p[1].rad_vector()
+ 2 * p[2].rad_vector())
* p[2].rad_vector());
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
//std::cout << "Thermal_Diffusivity = " << Thermal_Diffusivity << std::endl;
//std::cout << "PI = " << PI << std::endl;
//std::cout << "R = " << R << std::endl;
///std::cout << "this->GetMatrixADeterminant() = " << this->GetMatrixADeterminant() << std::endl;
//std::cout << "b[i] = " << b[i] << "b[j] = " << b[j] << std::endl;
//std::cout << "c[i] = " << c[i] << "c[j] = " << c[j] << std::endl;
/* Для теста из учебника (стр. 95) подставить вместо Thermal_Diffusivity 40 */
K[i][j] = (Thermal_Diffusivity * 2.0 * PI * R / (4.0 * this->GetMatrixADeterminant()))
* (b[i] * b[j] + c[i] * c[j]);
//std::cout << K[i][j] << " ";
}
//std::cout << std::endl;
}
}
void Matrix_C(double** C)
{
points p[3];
p[0].x = first_point.x;
p[0].y = first_point.y;
p[1].x = second_point.x;
p[1].y = second_point.y;
p[2].x = third_point.x;
p[2].y = third_point.y;
double D = 2 * PI * this->GetMatrixADeterminant() / 180;
double R[3];
for (int i = 0; i < 3; i++) {
R[i] = p[i].rad_vector();
}
C[0][0] = D * (12 * R[0] * R[0]
+ 2 * R[1] * R[1]
+ 2 * R[2] * R[2]
+ 6 * R[0] * R[1]
+ 6 * R[0] * R[2]
+ 2 * R[1] * R[2]);
C[0][1] = D * (3 * R[0] * R[0]
+ 3 * R[1] * R[1]
+ R[2] * R[2]
+ 4 * R[0] * R[1]
+ 2 * R[0] * R[2]
+ 2 * R[1] * R[2]);
C[0][2] = D * (3 * R[0] * R[0]
+ 1 * R[1] * R[1]
+ 3 * R[2] * R[2]
+ 2 * R[0] * R[1]
+ 4 * R[0] * R[2]
+ 2 * R[1] * R[2]);
C[1][0] = C[0][1];
C[2][0] = C[0][2];
C[1][1] = D * (2 * R[0] * R[0]
+ 12 * R[1] * R[1]
+ 2 * R[2] * R[2]
+ 6 * R[0] * R[1]
+ 2 * R[0] * R[2]
+ 6 * R[1] * R[2]);
C[1][2] = D * (1 * R[0] * R[0]
+ 3 * R[1] * R[1]
+ 3 * R[2] * R[2]
+ 2 * R[0] * R[1]
+ 2 * R[0] * R[2]
+ 4 * R[1] * R[2]);
C[2][2] = D * (2 * R[0] * R[0]
+ 2 * R[1] * R[1]
+ 12 * R[2] * R[2]
+ 2 * R[0] * R[1]
+ 6 * R[0] * R[2]
+ 6 * R[1] * R[2]);
C[2][1] = C[1][2];
}
void Column_F(double* F, double q)
{
double L = sqrt(STEP_X * STEP_X + 4 * STEP_X * STEP_X);
/* Для теста из учебника (стр. 95) */
//L = 1;
double k = L * q * 2.0 * PI / 6;
F[0] = 0;
F[1] = 0;
F[2] = 0;
if (fabs(2 * first_point.x - first_point.y) < EPS_T
&& fabs(2 * third_point.x - third_point.y) < EPS_T) {
F[0] = k * (2.0 * first_point.rad_vector() + third_point.rad_vector());
F[2] = k * (first_point.rad_vector() + 2 * third_point.rad_vector());
}
/* Для теста из учебника (стр. 95) */
/*
if (fabs( second_point.y - third_point.y) < EPS_T ) {
F[1] = k * (2 * second_point.rad_vector() + third_point.rad_vector());
F[2] = k * (second_point.rad_vector() + 2 * third_point.rad_vector());
}*/
}
};
#endif //STRUCTURES_H