summaryrefslogtreecommitdiff
path: root/src/voronoi_bound_ini.c
blob: 38f41cc81f747747cbdd2fd05801a72f21f9bfbc (plain)
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

#include "fracture.h"

void voronoi_bound_ini(finst *instance, double *square_bound,
											 unsigned int width) {
	unsigned int square_num_verts = 2 * ((width + 1) / 2) * (width / 2 + 1);
	double total1 = 0;
	double total2 = 0;
	double total3 = 0;
	double total4 = 0;
	for (unsigned int i = 0; i < instance->network->num_bounds; i++) {
		for (unsigned int j = 0; j < instance->network->bound_inds[i + 1] -
																		 instance->network->bound_inds[i];
				 j++) {
			double x = instance->network
										 ->vert_coords[2 *
																	 instance->network->bound_verts
																			 [instance->network->bound_inds[i] + j]];
			double y =
					instance->network
							->vert_coords[2 *
																instance->network->bound_verts
																		[instance->network->bound_inds[i] + j] +
														1];

			unsigned int vw = (width + 1) / 2;
			unsigned int xp = (unsigned int)(x * vw);
			unsigned int yp = (unsigned int)(y * vw);

			if (i == 0) {
				((double *)instance->boundary_cond
						 ->x)[instance->network
											->bound_verts[instance->network->bound_inds[i] + j]] =
						square_bound[xp];
				total1 += square_bound[xp];
			}
			if (i == 1) {
				((double *)instance->boundary_cond
						 ->x)[instance->network
											->bound_verts[instance->network->bound_inds[i] + j]] =
						square_bound[square_num_verts - vw - 1 + xp];
				total2 += square_bound[square_num_verts - vw - 1 + xp];
			}
			if (i == 2) {
				((double *)instance->boundary_cond
						 ->x)[instance->network
											->bound_verts[instance->network->bound_inds[i] + j]] =
						square_bound[(width + 1) / 2 + yp * (width + 1)];
				total3 += square_bound[(width + 1) / 2 + yp * (width + 1)];
			}
			if (i == 3) {
				((double *)instance->boundary_cond
						 ->x)[instance->network
											->bound_verts[instance->network->bound_inds[i] + j]] =
						square_bound[(width + 1) / 2 + yp * (width + 1) + width / 2];
				total4 += square_bound[(width + 1) / 2 + yp * (width + 1) + width / 2];
			}
		}
	}

	((double *)instance->boundary_cond->x)[instance->network->num_verts] =
			- total1 / 2 - total2 / 2;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 1] =
			- total1 / 2 - total2 / 2;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 2] =
			-total3;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 3] =
			-total4;
	/*
	((double *)instance->boundary_cond->x)[instance->network->num_verts] =
			0;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 1] =
			0;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 2] =
			0;
	((double *)instance->boundary_cond->x)[instance->network->num_verts + 3] =
			0;
			*/
}