summaryrefslogtreecommitdiff
path: root/src/toy_setup.c
blob: 228acbcdcb1269c042f1b7529f7df7ee123fb8a4 (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

#include "fracture.h"

bool break_fuses(unsigned int width, double *fuse_thres, double *field,
								 bool *fuses) {
	assert(fuse_thres != NULL);
	assert(field != NULL);
	assert(fuses != NULL);
	unsigned int size = pow(width, 2);

	for (unsigned int i = 0; i < size; i++) {
		if (fuses[i]) {
			if (1 / fuse_thres[i] > field[i]) {
				fuses[i] = 0;
			}
		}
	}

	return true;
}

bool gen_toy_field(unsigned int width, double strength, double *field) {
	assert(field != NULL);
	unsigned int size = pow(width, 2);

	for (unsigned intint i = 0; i < size; i++) {
		int x = i / width + 1;
		int y = i % width + 1;
		if (y < (width + 1) / 2.)
			field[i] = fabs((width) / 2. - x) / strength;
		else
			field[i] =
					sqrt(pow((width) / 2. - x, 2) + pow((width) / 2. - y, 2)) / strength;
	}

	return true;
}