-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
458 lines (366 loc) · 13.8 KB
/
main.cpp
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
//#include <Eigen/Dense>
#include <array>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
// Written by Christopher Wilkes, Cambridge University.
// In future, classes will be used to print vertices, elements and then boundaries in txt not json.
// Arpril 2021
//using Eigen::MatrixXd;
int main() {
// how many elements in each direction
const int xlen = 94;
const int ylen = 34;
const int zlen = 334;
//Length of each element (global)
double spacing = 0.03;
const double xorigin = 0.00001;
double xcoord = xorigin;
double zorigin = 0.00001;
double ycoord = 0.00001;
double zcoord = 0.00001;
double yorigin = 0.00001;
unsigned counter = 0;
unsigned size = 0;
unsigned esize = 0;
unsigned vsize = 0;
std::vector<std::vector<std::vector<int> > > mesh;
// Set up sizes
mesh.resize(xlen);
for (int i = 0; i < xlen; ++i) {
mesh[i].resize(ylen);
for (int j = 0; j < ylen; ++j)
mesh[i][j].resize(zlen);
}
int indices = 0;
//(rows - 1)
//create 3D array
for (unsigned x = 0; x < xlen; ++x) {
for (unsigned y = 0; y < ylen; ++y) {
for (unsigned z = 0; z < zlen; ++z) {
mesh[x][y][z] = indices;
++indices;
}
}
}
//calculate the number of elements to add to start of file
for (unsigned x = 0; x < xlen; ++x) {
for (unsigned y = 0; y < ylen; ++y) {
for (unsigned z = 0; z < zlen; ++z) {
if ((x > 0) && (x < (xlen - 1))) {
if ((y > 0) && (y < (ylen - 1))) {
if ((z > 0) && (z < (zlen - 1))) {
if (y > 1 && (zlen - z) > 2 && (xlen - x) > 2) {
esize ++;
}
}
}
}
}
}
}
//! Output file LOCATION IMPORTANT PLEASE CHANGE
std::string vertifilename = "/work/06435/cw646/frontera/frontera/gimp_col_kks/vertices.txt";
std::fstream verfile;
verfile.open(vertifilename, std::ios::out);
//calculate number of vertices
vsize = xlen*ylen*zlen;
//print number of vertices and elements
std::cout << "Vertices: " << vsize << " Elements: " << esize << '\n';
//write number of vertices and elements to start of file
verfile << vsize << '\t' << esize <<'\n';
//define coordinates
for (unsigned x = 0; x < xlen; ++x) {
for (unsigned y = 0; y < ylen; ++y) {
for (unsigned z = 0; z < zlen; ++z) {
//std::array<douable, 3> coord = {xcoord, ycoord, zcoord};
// write coordinates to file
verfile << xcoord<< '\t' << ycoord << '\t' << zcoord << '\n';
zcoord += spacing;
}
zcoord = zorigin;
ycoord += spacing;
}
ycoord = yorigin;
xcoord += spacing;
std::cout << xcoord << '\n';
}
// verfile.close();
std::cout << "Checkpoint 1" << '\n';
//std::string elefilename = "elements.txt";
//std::fstream elefile;
//elefile.open(elefilename, std::ios::out);
//crete elements by parsing 3D array
for (unsigned x = 0; x < xlen; ++x) {
for (unsigned y = 0; y < ylen; ++y) {
for (unsigned z = 0; z < zlen; ++z) {
// check node is not on boundaxy of mesh
if ((x > 0) && (x < (xlen - 1))) {
if ((y > 0) && (y < (ylen - 1))) {
if ((z > 0) && (z < (zlen - 1))) {
// check if rows above and to the side to genexate a GIMP
//allocate nodes to cell and write to file
if (y > 1 && (zlen - z) > 2 && (xlen - x) > 2) {
verfile << mesh[x][y][z] // 0
<<" "<< mesh[x + 1][y][z] // 1
<<" "<< mesh[x + 1][y][z + 1] // 2
<<" "<< mesh[x][y][z + 1] // 3
<<" "<< mesh[x][y - 1][z] // 4
<<" "<< mesh[x + 1][y - 1][z] // 5
<<" "<< mesh[x + 1][y - 1][z + 1] // 6
<<" "<< mesh[x][y - 1][z + 1] // 7
<<" "<< mesh[x - 1][y + 1][z - 1] // 8
<<" "<< mesh[x][y + 1][z - 1] // 9
<<" "<< mesh[x + 1][y + 1][z - 1] // 10
<<" "<< mesh[x + 2][y + 1][z - 1] // 11
<<" "<< mesh[x - 1][y + 1][z] // 12
<<" "<< mesh[x][y + 1][z] // 13
<<" "<< mesh[x + 1][y + 1][z] // 14
<<" "<< mesh[x + 2][y + 1][z] // 15
<<" "<< mesh[x - 1][y + 1][z + 1] // 16
<<" "<< mesh[x][y + 1][z + 1] // 17
<<" "<< mesh[x + 1][y + 1][z + 1] // 18
<<" "<< mesh[x + 2][y + 1][z + 1] // 19
<<" "<< mesh[x - 1][y + 1][z + 2] // 20
<<" "<< mesh[x][y + 1][z + 2] // 21
<<" "<< mesh[x + 1][y + 1][z + 2] // 22
<<" "<< mesh[x + 2][y + 1][z + 2] // 23
<<" "<< mesh[x - 1][y][z - 1] // 24
<<" "<< mesh[x][y][z - 1] // 25
<<" "<< mesh[x + 1][y][z - 1] // 26
<<" "<< mesh[x + 2][y][z - 1] // 27
<<" "<< mesh[x - 1][y][z] // 28
<<" "<< mesh[x + 2][y][z] // 29
<<" "<< mesh[x - 1][y][z + 1] // 30
<<" "<< mesh[x + 2][y][z + 1] // 31
<<" "<< mesh[x - 1][y][z + 2] // 32
<<" "<< mesh[x][y][z + 2] // 33
<<" "<< mesh[x + 1][y][z + 2] // 34
<<" "<< mesh[x + 2][y][z + 2] // 35
<<" "<< mesh[x - 1][y - 1][z - 1] // 36
<<" "<< mesh[x][y - 1][z - 1] // 37
<<" "<< mesh[x + 1][y - 1][z - 1] // 39
<<" "<< mesh[x + 2][y - 1][z - 1] // 39
<<" "<< mesh[x - 1][y - 1][z] // 40
<<" "<< mesh[x + 2][y - 1][z] // 41
<<" "<< mesh[x - 1][y - 1][z + 1] // 42
<<" "<< mesh[x + 2][y - 1][z + 1] // 43
<<" "<< mesh[x - 1][y - 1][z + 2] // 44
<<" "<< mesh[x][y - 1][z + 2] // 45
<<" "<< mesh[x + 1][y - 1][z + 2] // 46
<<" "<< mesh[x + 2][y - 1][z + 2] // 47
<<" "<< mesh[x - 1][y - 2][z - 1] // 48
<<" "<< mesh[x][y - 2][z - 1] // 49
<<" "<< mesh[x + 1][y - 2][z - 1] // 50
<<" "<< mesh[x + 2][y - 2][z - 1] // 51
<<" "<< mesh[x - 1][y - 2][z] // 52
<<" "<< mesh[x][y - 2][z] // 53
<<" "<< mesh[x + 1][y - 2][z] // 54
<<" "<< mesh[x + 2][y - 2][z] // 55
<<" "<< mesh[x - 1][y - 2][z + 1] // 56
<<" "<< mesh[x][y - 2][z + 1] // 57
<<" "<< mesh[x + 1][y - 2][z + 1] // 58
<<" "<< mesh[x + 2][y - 2][z + 1] // 59
<<" "<< mesh[x - 1][y - 2][z + 2] // 60
<<" "<< mesh[x][y - 2][z + 2] // 61
<<" "<< mesh[x + 1][y - 2][z + 2] // 62
<<" "<< mesh[x + 2][y - 2][z + 2] << '\n'; // 63
}
}
}
}
}
}
std::cout << x << '\n';
}
verfile.close();
//elefile.close();
//! Boundaries
std::cout << "Boundaries" << '\n';
// x begin
std::vector<int> x_left_boundaries;
std::vector<int> x_right_boundaries;
x_left_boundaries.resize(3*ylen*zlen);
x_right_boundaries.resize(3*ylen*zlen);
unsigned xl_i = 0;
unsigned xr_i = 0;
//y begin
std::vector<int> y_front_boundaries;
std::vector<int> y_back_boundaries;
y_front_boundaries.resize(3*xlen*zlen);
y_back_boundaries.resize(3*xlen*zlen);
unsigned yf_i = 0;
unsigned yb_i = 0;
//z begin
std::vector<int> z_bot_boundaries;
std::vector<int> z_top_boundaries;
z_bot_boundaries.resize(3*xlen*ylen);
z_top_boundaries.resize(3*xlen*ylen);
unsigned zb_i = 0;
unsigned zt_i = 0;
//calculate the number of elements to add to start of file
for (unsigned x = 0; x < xlen; ++x) {
for (unsigned y = 0; y < ylen; ++y) {
for (unsigned z = 0; z < zlen; ++z) {
if (x < 3) {
// x left
x_left_boundaries[xl_i] = mesh[x][y][z];
xl_i++;
}
if (x > (xlen - 4)) {
// x right
x_right_boundaries[xr_i] = mesh[x][y][z];
xr_i++;
}
if (y < 3) {
// x left
y_back_boundaries[yb_i] = mesh[x][y][z];
yb_i++;
}
if (y > (ylen - 4)) {
// x right
y_front_boundaries[yf_i] = mesh[x][y][z];
yf_i++;
}
if (z < 3) {
// x left
z_bot_boundaries[zb_i] = mesh[x][y][z];
zb_i++;
}
if (z > (zlen - 4)) {
// x right
z_top_boundaries[zt_i] = mesh[x][y][z];
zt_i++;
}
}
}
}
//! Output file
std::string boundaryfileneame = "/work/06435/cw646/frontera/frontera/gimp_col_kks/boundaries.json";
std::fstream boundaryfile;
boundaryfile.open(boundaryfileneame, std::ios::out);
if (boundaryfile.is_open()) {
unsigned counter = 0;
boundaryfile << "{" << '\n';
boundaryfile << '\t' << " \"node_sets\" : [ " << '\n';
boundaryfile << '\t' << '\t' << " { " << '\n';
// ----------------- X START -------------------------------
//set 0
boundaryfile << '\t' << '\t' << " \"id\" : 0," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x left (x_left_boundaries)
counter = 0;
for (auto const& boundaries : x_left_boundaries) {
if (counter < (xl_i-1)) {
boundaryfile << '\t' << '\t' << '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " }, " << '\n';
boundaryfile << '\t' << '\t' << " { " << '\n';
//set 1
boundaryfile << '\t' << '\t' << " \"id\" : 1," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x right (x_right_boundaries)
counter = 0;
for (auto const& boundaries : x_right_boundaries) {
if (counter < (xr_i-1)) {
boundaryfile << '\t' << '\t'<< '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " }, " << '\n';
// ----------------- X END -------------------------------
// ----------------- Y START -------------------------------
boundaryfile << '\t' << '\t' << " { " << '\n';
//set 2
boundaryfile << '\t' << '\t' << " \"id\" : 2," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x right (y_back_boundaries)
counter = 0;
for (auto const& boundaries : y_back_boundaries) {
if (counter < (yb_i-1)) {
boundaryfile << '\t' << '\t'<< '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " }, " << '\n';
boundaryfile << '\t' << '\t' << " { " << '\n';
//set 3
boundaryfile << '\t' << '\t' << " \"id\" : 3," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x right (y_front_boundaries)
counter = 0;
for (auto const& boundaries : y_front_boundaries) {
if (counter < (yf_i-1)) {
boundaryfile << '\t' << '\t'<< '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
// ----------------- Y END -------------------------------
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " }, " << '\n';
// ----------------- Z START -------------------------------
boundaryfile << '\t' << '\t' << " { " << '\n';
//set 4
boundaryfile << '\t' << '\t' << " \"id\" : 4," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x right (z_bot_boundaries)
counter = 0;
for (auto const& boundaries : z_bot_boundaries) {
if (counter < (zb_i-1)) {
boundaryfile << '\t' << '\t'<< '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " }, " << '\n';
boundaryfile << '\t' << '\t' << " { " << '\n';
//set 5
boundaryfile << '\t' << '\t' << " \"id\" : 5," << '\n';
boundaryfile << '\t' << '\t' << " \"set\" : [";
//! x right (z_top_boundaries)
counter = 0;
for (auto const& boundaries : z_top_boundaries) {
if (counter < (zt_i-1)) {
boundaryfile << '\t' << '\t'<< '\t' << boundaries << "," << '\n';
} else {
boundaryfile << '\t' << '\t' << '\t' << boundaries;
}
counter++;
}
//close system
boundaryfile << " ]" << '\n';
boundaryfile << '\t' << '\t' << " } " << '\n';
//close system
boundaryfile << '\t' << " ]" << '\n';
boundaryfile << " } " << '\n';
boundaryfile.close();
} else {
std::cout << "File not open";
}
/*
if ((y > 0) && (y < (ylen - 1))) {
if ((z > 0) && (z < (zlen - 1))) {
if (y > 1 && (zlen - z) > 2 && (xlen - x) > 2) {
esize ++;
}
}
}
&& (x < (xlen - 3))*/
std::cout << "Finish" << '\n';
}