def test_traits_transferred_even_for_diff_geometries(self, simple_object): new_object = PySALEObject(([0, 0], [0, 1], [.2, .2])) new_object.set_material(8) simple_object.set_material(7) simple_object.copy_properties_to_new_polygon(new_object) assert new_object.material == simple_object.material assert len(simple_object.exterior.coords) \ != len(new_object.exterior.coords)
def simple_impactor_target(square_even_mesh): x = square_even_mesh.x_physical y = square_even_mesh.y_physical target = PySALEObject([(0, 0), (x, 0), (x, y / 2), (0, y / 2)]) impactor = PySALEObject([(0, y / 2), (x, y / 2), (x, y), (0, y)]) impactor.set_material(1) target.set_material(2) return target, impactor
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
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)
def test_all_traits_transferred(self, simple_object): simple_object.spawn_polygon_in_shape(([0, 0], [0, 1], [.5, .5])) simple_object.set_material_colormap('magma') simple_object.set_material(5) simple_object.set_velocity(10., 10.) new_object = PySALEObject(([0, 0], [0.1, 0.1], [0.2, 0.7])) simple_object.copy_properties_to_new_polygon(new_object) properties = [(simple_object.material_colors, new_object.material_colors), (simple_object.material, new_object.material), (simple_object.velocity, new_object.velocity), (simple_object.children, new_object.children)] for simple_prop, new_prop in properties: assert simple_prop == new_prop
""" MesoParticles2D+ ================ This example is based on the iSALE example MesoParticles2D and uses the same basic geometries. However in this script we demonstrate the versatility of PySALESetup to affect things like the resolution with ease """ from PySALESetup import PySALEObject, PySALEMesh, PySALEDomain import matplotlib.pyplot as plt # Create The geometries for the simulation impactor = PySALEObject([(0., 0.003), (0.001, 0.003), (0.001, 0.005), (0, 0.005)]) impactor.set_material(1) 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)
def object_with_weibull_distributions(): object_ = PySALEObject.generate_ellipse([0, 0], 2, 1, 0) radii = PySALEWeibull2Distribution(1, 1) areas = PySALEWeibull2Distribution(pi, pi) angles = PySALEWeibull2Distribution(0, 180) return object_, radii, areas, angles
def object_with_uniform_distributions(): object_ = PySALEObject.generate_ellipse([0, 0], 2, 1, 0) radii = PySALEUniformDistribution((.5, 2)) areas = PySALEUniformDistribution((pi * .5, pi * 2)) angles = PySALEUniformDistribution((0, 360)) return object_, radii, areas, angles
def square_object(): object_ = PySALEObject([(0, 0), (0, 10), (10, 10), (10, 0)]) return object_
def rectangle(): return PySALEObject([(0, 0), (2, 0), (2, 1), (0, 1)])
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)
def spawn_new_ellipse(domain: PySALEObject, xy, major, minor, rotation): return domain.spawn_ellipse_in_shape(xy, major, minor, rotation)
def spawn_new(domain: PySALEObject, coords): return domain.spawn_polygon_in_shape(coords)
def test_rotate_about_origin(self, square_object): new_object = square_object.rotate(180, Point([0., 0.])) mock_object = PySALEObject(([0, 0], [-10, 0], [-10, -10], [0, -10])) self.assert_coords_equivalent(new_object, mock_object)
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)
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()
from PySALESetup.mesh import ExtensionZone, Region, \ ExtensionZoneFactor import matplotlib.pyplot as plt # Construct 4 extension zones: one for each region extension_zones = [ ExtensionZone(15, region, 1., ExtensionZoneFactor(1.05, 20)) for region in [Region.NORTH, Region.SOUTH, Region.EAST, Region.WEST] ] # Build a mesh using the extension zones m = PySALEMesh(100, 100, extension_zones=extension_zones, cell_size=1.) object1 = PySALEObject.generate_ellipse([56, 56], 50., 50., material=1, rotation=0) object2 = PySALEObject.generate_ellipse([159, 159], 50., 50., material=2, rotation=0) object3 = PySALEObject.generate_ellipse([107.2, 107.2], 50., 50., material=3, rotation=0) m.project_polygons_onto_mesh([object1, object2, object3])
def circle(): return PySALEObject.generate_ellipse([5., 5.], 1., 1., 0.)