.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/MesoParticles2D+.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_MesoParticles2D+.py: 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 .. GENERATED FROM PYTHON SOURCE LINES 10-36 .. code-block:: Python import pathlib from PySALESetup import (PySALEObject, PySALEMesh, PySALEDomain, AsteroidInput, AdditionalInput, TimeStep) 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) .. GENERATED FROM PYTHON SOURCE LINES 37-39 Create a domain object which will perform the particle insertions .. GENERATED FROM PYTHON SOURCE LINES 39-41 .. code-block:: Python domain = PySALEDomain(host) .. GENERATED FROM PYTHON SOURCE LINES 42-46 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] .. GENERATED FROM PYTHON SOURCE LINES 46-49 .. code-block:: Python particle = PySALEObject.generate_ellipse([0, 0], 50e-6, 50e-6, 0, 1) domain.fill_with_random_grains_to_threshold(particle, 40) .. rst-class:: sphx-glr-script-out .. code-block:: none 8.076612363155797e-07 .. GENERATED FROM PYTHON SOURCE LINES 50-52 Optimise particle materials so that none touch of the same material .. GENERATED FROM PYTHON SOURCE LINES 52-55 .. code-block:: Python domain.optimise_materials([2, 3, 4, 5, 6, 7, 8, 9]) .. GENERATED FROM PYTHON SOURCE LINES 56-58 plot the geometries we've created .. GENERATED FROM PYTHON SOURCE LINES 58-63 .. code-block:: Python fig, ax = host.plot() impactor.plot(ax) back_plate.plot(ax) plt.show() .. image-sg:: /auto_examples/images/sphx_glr_MesoParticles2D+_001.png :alt: MesoParticles2D+ :srcset: /auto_examples/images/sphx_glr_MesoParticles2D+_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-66 Create the mesh onto which we'll apply these geometries .. GENERATED FROM PYTHON SOURCE LINES 66-69 .. code-block:: Python mesh_1 = PySALEMesh(100, 500, cell_size=10.e-6) .. GENERATED FROM PYTHON SOURCE LINES 70-72 Apply/project the geometries onto our mesh .. GENERATED FROM PYTHON SOURCE LINES 72-75 .. code-block:: Python mesh_1.project_polygons_onto_mesh([host, impactor, back_plate]) .. GENERATED FROM PYTHON SOURCE LINES 76-78 View the result! .. GENERATED FROM PYTHON SOURCE LINES 78-82 .. code-block:: Python mesh_1.plot_materials() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_MesoParticles2D+_002.png :alt: Materials :srcset: /auto_examples/images/sphx_glr_MesoParticles2D+_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 83-87 we can also save the meso_m.iSALE file as well if needed We won't compress it here (although that is recommended) so you can inspect the result and see what it looks like. .. GENERATED FROM PYTHON SOURCE LINES 87-91 .. code-block:: Python mesh_1.save(pathlib.Path('./meso_m.iSALE.gz'), compress=True) .. GENERATED FROM PYTHON SOURCE LINES 92-97 To make life a bit easier this package will also assist in creating the correct iSALE input files required of the simulation. You may still have to merge/edit them yourself until they work, but the bones of the files can be created like the example below. .. GENERATED FROM PYTHON SOURCE LINES 97-108 .. code-block:: Python ast = AsteroidInput('MesoParticles2D+', TimeStep(4e-10, 1e-8, 4e-6, 1e-7), mesh_1) ast.write_to(pathlib.Path('./asteroid.inp')) add = AdditionalInput(mesh_1, {i+1: f'matter{i+1}' for i in range(9)}, host_object_number=1) add.write_to(pathlib.Path('./additional.inp')) .. GENERATED FROM PYTHON SOURCE LINES 109-113 The geometries are mesh-independent so we can easily change the resolution if we wish, and we don't have to keep it as multiples of the original! For example, let's do a mini resolution test... .. GENERATED FROM PYTHON SOURCE LINES 113-131 .. code-block:: Python for factor in [1/5, 2/5, 3/5, 4/5, 6/5, 7/5]: mesh_ = mesh_1.spawn_copy(factor) mesh_.project_polygons_onto_mesh([host, impactor, back_plate]) mesh_.save(pathlib.Path(f'./meso_m__{factor:g}.iSALE.gz'), compress=True) ast = AsteroidInput(f'MesoParticles2D_{factor:g}', TimeStep(4e-10, 1e-8, 4e-6, 1e-7), mesh_) ast.write_to(pathlib.Path(f'./asteroid_{factor:g}.inp')) add = AdditionalInput(mesh_, {i+1: f'matter{i+1}' for i in range(9)}, host_object_number=1) add.write_to(pathlib.Path(f'./additional_{factor:g}.inp')) mesh_.plot_materials() plt.show() .. image-sg:: /auto_examples/images/sphx_glr_MesoParticles2D+_003.png :alt: Materials :srcset: /auto_examples/images/sphx_glr_MesoParticles2D+_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 132-137 Finally, if we wanted to have particles that appear to extend beyond the mesh, we can do that too! We just need to make the host object slightly wider (here we do it by one radii on each side). .. GENERATED FROM PYTHON SOURCE LINES 137-157 .. code-block:: Python host = PySALEObject([(0-50e-6, 0.001), (0.001+50e-6, 0.001), (0.001+50e-6, 0.003), (0-50e-6, 0.003)]) host.set_material(0) domain = PySALEDomain(host) particle = PySALEObject.generate_ellipse([0, 0], 50e-6, 50e-6, 0, 1) domain.fill_with_random_grains_to_threshold(particle, 40) domain.optimise_materials([2, 3, 4, 5, 6, 7, 8, 9]) _, ax = host.plot() impactor.plot(ax) back_plate.plot(ax) plt.show() mesh_4 = PySALEMesh(100, 500, cell_size=10.e-6) mesh_4.project_polygons_onto_mesh([host, impactor, back_plate]) mesh_4.plot_materials() plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_MesoParticles2D+_004.png :alt: MesoParticles2D+ :srcset: /auto_examples/images/sphx_glr_MesoParticles2D+_004.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_MesoParticles2D+_005.png :alt: Materials :srcset: /auto_examples/images/sphx_glr_MesoParticles2D+_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/PySALESetup/PySALESetup/PySALESetup/creation.py:554: UserWarning: Max insertion attempts reached (100). Object can not be placed. warnings.warn(f'Max insertion attempts ' .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 12.787 seconds) .. _sphx_glr_download_auto_examples_MesoParticles2D+.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: MesoParticles2D+.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: MesoParticles2D+.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: MesoParticles2D+.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_