Example #1
0
 def test_apply_void_geometries(self, simple_object):
     simple_object.set_material(3)
     ellipse = simple_object.spawn_ellipse_in_shape([5, 5], 3, 3, 0)
     mesh = PySALEMesh(100, 100, 1)
     ellipse.set_as_void()
     mesh.project_polygons_onto_mesh([simple_object])
     assert np.sum(mesh.material_meshes[3]) > 0
     assert np.sum(mesh.material_meshes[1]) == 0
Example #2
0
def square_mesh_with_extension_zones() -> PySALEMesh:
    n = ExtensionZone(10, Region.NORTH, .5, ExtensionZoneFactor(1.01, 3))
    w = ExtensionZone(10, Region.WEST, .5, ExtensionZoneFactor(1.01, 3))
    e = ExtensionZone(10, Region.EAST, .5, ExtensionZoneFactor(1.01, 3))
    s = ExtensionZone(10, Region.SOUTH, .5, ExtensionZoneFactor(1.01, 3))
    mesh = PySALEMesh.from_dimensions((10, 10), 0.5, extensions=[n, e, w, s])
    return mesh
Example #3
0
 def test_apply_geometry(self, simple_object):
     simple_object.set_material(3)
     mesh = PySALEMesh(100, 100, 1)
     mesh.project_polygons_onto_mesh([simple_object])
     assert np.sum(mesh.material_meshes[3]) > 0
Example #4
0
 def test_geometric_centre(self):
     mesh = PySALEMesh(100, 100, 1)
     assert mesh.get_geometric_centre() == (50., 50.)
Example #5
0
 def test_creation(self):
     mesh = PySALEMesh(100, 100, 1)
     assert all(mesh.x_range == np.arange(100)+.5)
     assert all(mesh.y_range == np.arange(100)+.5)
Example #6
0
 def test_set_origin_x(self, y0):
     mesh = PySALEMesh.from_dimensions((1., 1.), 0.05, origin=(0., y0))
     if y0 < 0.:
         assert all(mesh.y_range > y0)
     elif y0 > 0.:
         assert all(mesh.y_range < y0)
Example #7
0
 def test_set_origin_x(self, x0):
     mesh = PySALEMesh.from_dimensions((1., 1.), 0.05, origin=(x0, 0.))
     if x0 < 0.:
         assert all(mesh.x_range > x0)
     elif x0 > 0.:
         assert all(mesh.x_range < x0)
Example #8
0
which dictates how much they alter the cell size by.
"""

from PySALESetup import PySALEObject, PySALEMesh
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,
Example #9
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()
Example #10
0
# 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
mesh_1 = PySALEMesh(100, 500, cell_size=10.e-6)
# Apply/project the geometries onto our mesh
for geometry in [host, impactor, back_plate]:
    mesh_1.apply_geometry(geometry)
# View the result!
mesh_1.plot_materials()

# we can also save the meso_m.iSALE file as well if needed
# mesh_1.save()
plt.show()


# The geometries are mesh-independent so we can easily change
# the resolution if we wish

mesh_2 = PySALEMesh(50, 250, cell_size=20.e-6)
Example #11
0
def rectangular_even_mesh() -> PySALEMesh:
    mesh = PySALEMesh.from_dimensions((10, 20), 0.5)
    return mesh
Example #12
0
def square_even_mesh() -> PySALEMesh:
    mesh = PySALEMesh.from_dimensions((10, 10), 0.5)
    return mesh