Ejemplo n.º 1
0
 def test_threshold_check(self, simple_object, threshold_):
     domain = PySALEDomain(simple_object)
     inserted_area, insertion_possible, threshold = \
         domain._check_threshold_input(threshold_)
     assert inserted_area == 0.
     assert insertion_possible
     assert threshold == threshold_
Ejemplo n.º 2
0
 def test_move_object_to_random_coords(self, simple_object):
     domain = PySALEDomain(simple_object)
     simple_object = \
         domain._move_object_to_random_coordinate_in_domain(
             simple_object, 1., 1., 0., 0.
         )
     assert 0. < simple_object.centroid.x < 1.
     assert 0. < simple_object.centroid.y < 1.
Ejemplo n.º 3
0
 def test_fill_to_threshold(self, simple_object):
     domain = PySALEDomain(simple_object)
     grain = PySALEObject([(0, 0), (0.5, 0.5), (1, 0)])
     domain.fill_with_random_grains_to_threshold(grain, 20)
     frac = sum([c.area
                 for c in simple_object.children]) / simple_object.area
     tolerance = (grain.area / simple_object.area) * 100
     assert isclose(frac * 100., 20., abs_tol=tolerance)
Ejemplo n.º 4
0
 def test_threshold_check_already_populated(self, simple_object,
                                            threshold_):
     domain = PySALEDomain(simple_object)
     simple_object.spawn_polygon_in_shape([(0, 0), (0, 5), (5, 5), (5, 0)])
     inserted_area, insertion_possible, threshold = \
         domain._check_threshold_input(threshold_)
     assert inserted_area == 25.
     assert insertion_possible
     assert threshold == threshold_
Ejemplo n.º 5
0
 def test_optimise_materials(self, simple_object):
     domain = PySALEDomain(simple_object)
     domain.fill_with_random_grains_to_threshold(
         PySALEObject.generate_ellipse([0, 0], .5, .5, 0, 1), 50.)
     domain.optimise_materials()
     materials = {grain.material for grain in domain.object.children}
     assert len(materials) == 9
Ejemplo n.º 6
0
from PySALESetup import PySALEObject, PySALEDomain, PySALEMesh
import matplotlib.pyplot as plt

main = PySALEObject.generate_ellipse([5., 5.], 5., 5., 0.)
main.set_material(1)
domain = PySALEDomain(main)
circle = PySALEObject.generate_ellipse([0., 0.], .5, .5, 0.)
circle.set_as_void()
domain.fill_with_random_grains_to_threshold(circle, 40)
mesh = PySALEMesh(100, 100, cell_size=.1)
for child in main.children:
    child.set_as_void()
mesh.project_polygons_onto_mesh([main])
mesh.plot_materials()
main.plot()
plt.show()
Ejemplo n.º 7
0
impactor.set_velocity(0, -500.)

host = PySALEObject([(0, 0.001),
                     (0.001, 0.001),
                     (0.001, 0.003),
                     (0, 0.003)])
host.set_material(0)

back_plate = PySALEObject([(0, 0.0002),
                           (0.001, 0.0002),
                           (0.001, 0.001),
                           (0, 0.001)])
back_plate.set_material(1)

# Create a domain object which will perform the particle insertions
domain = PySALEDomain(host)
# Create a particle to be used for insertion
# Its centroid does not matter here as we'll just move it around
# anyway, so use [0, 0]
particle = PySALEObject.generate_ellipse([0, 0], 50e-6, 50e-6, 0, 1)
domain.fill_to_threshold_area(particle, 40)
# Optimise particle materials so that none touch of the same material
domain.optimise_materials([2, 3, 4, 5, 6, 7, 8, 9])

# plot the geometries we've created
fig, ax = host.plot()
impactor.plot(ax)
back_plate.plot(ax)
plt.show()

# Create the mesh onto which we'll apply these geometries
Ejemplo n.º 8
0
 def test_object_unchanged(self, simple_object, area):
     domain = PySALEDomain(simple_object)
     new = domain.randomly_resize_object(simple_object, area=area)
     assert new.area == simple_object.area
Ejemplo n.º 9
0
 def test_rectangle_rotates(self, rectangle):
     dist = PySALENormalDistribution(45., 5.)
     domain = PySALEDomain(rectangle)
     new = domain.randomly_rotate_object(rectangle, dist)
     assert new.bounds != rectangle.bounds
Ejemplo n.º 10
0
 def test_object_unchanged(self, circle):
     domain = PySALEDomain(circle)
     new = domain.randomly_rotate_object(circle)
     assert new.bounds == circle.bounds
Ejemplo n.º 11
0
 def test_insert_randomly_invalid_max_attempts(self, simple_object,
                                               max_attempts):
     domain = PySALEDomain(simple_object)
     grain = PySALEObject([(0, 0), (11, 11), (12, 0)])
     with pytest.raises(AssertionError):
         domain.insert_randomly(grain, max_attempts=max_attempts)
Ejemplo n.º 12
0
 def test_insert_randomly_maxes_out(self, simple_object, max_attempts):
     domain = PySALEDomain(simple_object)
     grain = PySALEObject([(0, 0), (11, 11), (12, 0)])
     with pytest.warns(UserWarning):
         domain.insert_randomly(grain, max_attempts=max_attempts)
Ejemplo n.º 13
0
 def test_object_already_over_threshold(self, simple_object, threshold_):
     domain = PySALEDomain(simple_object)
     simple_object.spawn_polygon_in_shape([(0, 0), (0, 5), (5, 5), (5, 0)])
     with pytest.raises(AssertionError):
         _, _, _ = domain._check_threshold_input(threshold_)
Ejemplo n.º 14
0
 def resize_object_based_on_dist(self, object_, radii):
     domain = PySALEDomain(object_)
     result = domain.randomly_resize_object(object_,
                                            size_distribution=radii,
                                            area=False)
     self.assert_shapes_different_coords(object_, result)