summaryrefslogtreecommitdiff
path: root/src/update_beta.c
blob: 4c1bf65c6d4bb3d4995b6577a7373968e0c967bc (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

#include "fracture.h"

double f(double damage) {
	assert(damage <= 1 && damage >= 0);
	return sqrt(1 - sqrt(1 - damage));
	//	return 0.5 - 0.68182 * (0.5 - damage);
}

double update_beta(double beta, unsigned int width, const double *stress,
									 const double *damage, double bound_total) {

	double total = 0;
	unsigned int num_totaled = 0;

	for (unsigned int i = 0; i < pow(width, 2); i++) {
		unsigned int stress_index =
				width / 4 + (width / 4 + (i / width) / 2) * width + (i % width) / 2;
		double outer_damage = f(pow(fabs(stress[i]), beta));
		double inner_stress = fabs(2 * stress[stress_index] / bound_total);

		if (outer_damage > 0 && inner_stress > 0 && inner_stress != 1) {
			total += log(outer_damage) / log(inner_stress);
			num_totaled++;
		}
	}

	assert(num_totaled > 0);
	assert(total == total);

	double new_beta = total / num_totaled;

	return new_beta;
}