.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\basic_examples\particle_wall_interaction_with_motion.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_examples_basic_examples_particle_wall_interaction_with_motion.py: .. _ref_particle_wall_interaction_with_motion: Particle simulation with moving wall interaction ------------------------------------------------ This example sets up and solves a simulation of particles interacting with a rotating L-shape tube wall. .. GENERATED FROM PYTHON SOURCE LINES 32-35 .. image:: /_static/Lshape_tube_result.png :width: 400pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 37-40 Perform imports and create a project ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Perform the required imports and create an empty project. .. GENERATED FROM PYTHON SOURCE LINES 40-55 .. code-block:: Python import os.path import tempfile import ansys.rocky.core as pyrocky from ansys.rocky.core import examples # Create a temp directory to save the project. project_dir = tempfile.mkdtemp(prefix="pyrocky_") # Launch Rocky and open a project. rocky = pyrocky.launch_rocky() project = rocky.api.CreateProject() project.SaveProject(os.path.join(project_dir, "rocky-testing.rocky")) .. GENERATED FROM PYTHON SOURCE LINES 56-58 Configure the study ~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 58-99 .. code-block:: Python study = project.GetStudy() # Download the STL file that was imported into Rocky to represent a wall. file_name = "Lshape_tube.stl" file_path = examples.download_file(project_dir, file_name, "pyrocky/geometries") wall = study.ImportWall(file_path)[0] # Create a particle with the default shape (sphere) and size distribution (single # distribution with a sieve size of 0.1 m). particle = study.CreateParticle() # Create a circular surface to used as the inlet. circular_surface = study.CreateCircularSurface() circular_surface.SetMaxRadius(0.8, unit="m") # Create a rectangular surface to use as the outlet. rectangular_surface = study.CreateRectangularSurface() rectangular_surface.SetLength(3, unit="m") rectangular_surface.SetWidth(3, unit="m") rectangular_surface.SetCenter((5, -7.5, 0), unit="m") # Set the inlet and outlet. particle_inlet = study.CreateParticleInlet(circular_surface, particle) input_property_list = particle_inlet.GetInputPropertiesList() input_property_list[0].SetMassFlowRate(1000) outlet = study.CreateOutlet(rectangular_surface) # Set the motion rotation over the Y axis and apply it on the wall and the # rectagular surface used as the outlet. motion_frame_source = study.GetMotionFrameSource() motion_frame = motion_frame_source.NewFrame() motion_frame.AddRotationMotion(angular_velocity=((0.0, 0.5, 0.0), "rad/s")) motion_frame.ApplyTo(rectangular_surface) motion_frame.ApplyTo(wall) # The domain settings define the domain limits where the particles are enabled to be # computed in the simulation. domain = study.GetDomainSettings() domain.DisableUseBoundaryLimits() domain.SetCoordinateLimitsMaxValues((10, 1, 10), unit="m") .. rst-class:: sphx-glr-script-out .. code-block:: none Download successful. File path: C:\Users\ansys\AppData\Local\Temp\pyrocky_ikf2q0fy\Lshape_tube.stl .. GENERATED FROM PYTHON SOURCE LINES 100-102 Set up the solver and run the simulation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 102-107 .. code-block:: Python solver = study.GetSolver() solver.SetSimulationDuration(5, unit="s") study.StartSimulation() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 108-111 Postprocess ~~~~~~~~~~~ Obtain the in and out mass flows of the particles. .. GENERATED FROM PYTHON SOURCE LINES 111-130 .. code-block:: Python particles = study.GetParticles() times, mass_flow_in = particles.GetNumpyCurve("Particles Mass Flow In", unit="t/h") times, mass_flow_out = particles.GetNumpyCurve("Particles Mass Flow Out", unit="t/h") # Obtain the maximum and minimum velocities of the particles at each time step. import numpy as np simulation_times = study.GetTimeSet() velocity_gf = particles.GetGridFunction("Velocity : Translational : Absolute") velocity_max = np.array( [velocity_gf.GetMax(unit="m/s", time_step=i) for i in range(len(simulation_times))] ) velocity_min = np.array( [velocity_gf.GetMin(unit="m/s", time_step=i) for i in range(len(simulation_times))] ) .. GENERATED FROM PYTHON SOURCE LINES 131-133 Plot curves +++++++++++ .. GENERATED FROM PYTHON SOURCE LINES 133-153 .. code-block:: Python import matplotlib.pyplot as plt fig, (ax1, ax2) = plt.subplots(2, 1) ax1.plot(times, mass_flow_in, "b", label="Mass Flow In") ax1.plot(times, mass_flow_out, "r", label="Mass Flow Out") ax1.set_xlabel("Time [s]") ax1.set_ylabel("Mass Flow [t/h]") ax1.legend(loc="upper left") ax2.plot(simulation_times, velocity_max, "b", label="Max Velocity") ax2.plot(simulation_times, velocity_min, "r", label="Min Velocity") ax2.set_xlabel("Time [s]") ax2.set_ylabel("Velocity [m/s]") ax2.legend(loc="upper left") plt.draw() rocky.close() .. image-sg:: /examples/basic_examples/images/sphx_glr_particle_wall_interaction_with_motion_001.png :alt: particle wall interaction with motion :srcset: /examples/basic_examples/images/sphx_glr_particle_wall_interaction_with_motion_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 4.953 seconds) .. _sphx_glr_download_examples_basic_examples_particle_wall_interaction_with_motion.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: particle_wall_interaction_with_motion.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: particle_wall_interaction_with_motion.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_