Exemple #1
0
def prepare_triangles(vol_frac_goal, L, r_d, k_d, d_eq_d):
    """
    Prepares a list of truncated prisms from the given distributions.
    :param vol_frac_goal: Goal volume fraction.
    :param L: Size of window.
    :param r_d: Distribution (callback function) for r, truncation size.
    :param k_d: Distribution (callback function) for k, elongation factor.
    :param d_eq_d: Distribution (callback function) for d, equivalent diameter.
    :return: List of prisms which contain random locations and a random r, k, and d.
    """
    print("Prepare triangles")

    trunc_triangles = list()

    total_volume = L**3
    volume = 0.

    # Make random grains
    while volume < vol_frac_goal * total_volume:
        midpoint = L * np.random.random(3)
        r = r_d()
        k = k_d()
        d_eq = d_eq_d()

        rot_matrix = GeometryTools.random_rotation()

        trunc_triangle = tt.TruncatedTriangle(midpoint, rot_matrix, r, k, d_eq)

        trunc_triangles.append(trunc_triangle)

        volume += trunc_triangle.volume

    return trunc_triangles
Exemple #2
0
def prepare_triangles(vol_frac_goal, L, r_min=0.1, r_max=0.4, k_min=0.2, k_max=0.6):
	"""	
	Prepares random truncated_triangle objects.
	
	Grains are generated until the vol_frac_goal is exceeded.
	Geometry parameters r,k,d and rotation matrix are drawn from uniform distributions.
	Returns the list of truncated triangles sorted by size.
	"""
	print "Prepare triangles"

	d_eq_min = 0.5
	d_eq_max = 2

	trunc_triangles = []

	total_volume = L**3
	volume = 0.

	# Make random grains
	while volume/total_volume < vol_frac_goal:
		midpoint = L*np.random.random(3)
		r = (r_max-r_min)*np.random.random() + r_min
		k = (k_max-k_min)*np.random.random() + k_min
		d_eq = (d_eq_max-d_eq_min)*np.random.random() + d_eq_min

		rot_matrix = GeometryTools.random_rotation()

		trunc_triangle = tt.TruncatedTriangle(midpoint, rot_matrix, r, k, d_eq)

		trunc_triangles.append(trunc_triangle)

		volume += trunc_triangle.volume

	# Sort triangles w.r.t. volume, so that large triangles are added to the box first
	trunc_triangles.sort(key=lambda m: m.volume, reverse=True)

	return trunc_triangles