-
Notifications
You must be signed in to change notification settings - Fork 1
/
elements.c
100 lines (81 loc) · 2.65 KB
/
elements.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
#include <stdlib.h>
#include "elements.h"
#include "domain.h"
// Creates elements and stores it in the triangular elements list
int create_triangular_elements_for_cartesian_domain(domain* cartesian_domain)
{
int i, j;
int nT, sqid, tid;
vertex* vertex1;
vertex* vertex2;
vertex* vertex3;
vertex* vertex4;
#define CDN (cartesian_domain->cartesian_grid->N + 1)
#define CDV (cartesian_domain->vertices)
nT = 2 * (CDN - 1) * (CDN - 1);
_total_grid_elements = 0;
_triangular_elements = calloc(nT, sizeof(triangular_element));
for(i = 0; i < CDN - 1; i++)
{
for(j = 0; j < CDN - 1; j++)
{
sqid = i * (CDN - 1) + j;
tid = 2 * sqid;
vertex1 = &CDV[i * CDN + j];
vertex2 = &CDV[i * CDN + j + 1];
vertex3 = &CDV[(i + 1) * CDN + j];
vertex4 = &CDV[(i + 1) * CDN + j + 1];
_triangular_elements[tid].id = tid;
_triangular_elements[tid].cartesian_domain = cartesian_domain;
_triangular_elements[tid].grid_vertex[0] = vertex3;
_triangular_elements[tid].grid_vertex[1] = vertex1;
_triangular_elements[tid].grid_vertex[2] = vertex4;
_total_grid_elements++;
_triangular_elements[tid + 1].id = tid + 1;
_triangular_elements[tid + 1].cartesian_domain = cartesian_domain;
_triangular_elements[tid + 1].grid_vertex[0] = vertex2;
_triangular_elements[tid + 1].grid_vertex[1] = vertex4;
_triangular_elements[tid + 1].grid_vertex[2] = vertex1;
_total_grid_elements++;
}
}
#undef CDN
#undef CDV
return 0;
}
// Add element indices to subdomains
int add_triangular_elements_to_subdomains(domain* cartesian_domain, int idx)
{
int i, j, count;
int nT, sqid, tid;
#define CSD (cartesian_domain->subdomains)
#define CDN (cartesian_domain->cartesian_grid->N + 1)
nT = 2 * (CSD[idx].dimX - 1) * (CSD[idx].dimY - 1);
CSD[idx].elements = calloc(nT, sizeof(int));
CSD[idx].elements_count = 0;
count = 0;
for(i = CSD[idx].bottom_left_y; i < CSD[idx].top_right_y; i++)
{
for(j = CSD[idx].bottom_left_x; j < CSD[idx].top_right_x; j++)
{
sqid = i * (CDN - 1) + j;
tid = 2 * sqid;
CSD[idx].elements[count++] = tid++;
CSD[idx].elements[count++] = tid;
CSD[idx].elements_count += 2; // Even though this can be initialized
// like allocating space, this can be used to debug later
}
}
#undef CSD
#undef CDN
return 0;
}
// Remove all triangular elements from heap
int cleanup_triangular_elements()
{
if(_triangular_elements != NULL)
{
free(_triangular_elements);
}
return 0;
}