.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/03-advanced/rigid_body_bounce.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_03-advanced_rigid_body_bounce.py: Rigid-body bounce with IPC contact ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This example lets a rigid sphere fall under gravity and bounce on a fixed plane. It illustrates the rigid-body constraint, Newmark time integration, and IPC contact with a deliberately coarse model suitable for the online example gallery. The longer, higher-resolution demonstration is available in ``examples/rigid_body/rigid_body_bounce_ipc.py``. .. GENERATED FROM PYTHON SOURCE LINES 13-20 .. code-block:: Python import numpy as np import pyvista as pv import fedoo as fd .. GENERATED FROM PYTHON SOURCE LINES 21-25 Model ----- Only the rigid body's six generalized degrees of freedom are integrated; the surface meshes describe the contact geometry. .. GENERATED FROM PYTHON SOURCE LINES 25-67 .. code-block:: Python gravity = 9.81 mass = 1.0 radius = 0.1 initial_height = 0.4 space = fd.ModelingSpace("3D") space.new_variable("DispX") space.new_variable("DispY") space.new_variable("DispZ") space.new_vector("Disp", ("DispX", "DispY", "DispZ")) sphere_mesh = fd.Mesh.from_pyvista( pv.Sphere( radius=radius, center=(0, 0, initial_height), theta_resolution=16, phi_resolution=16, ) ) floor_mesh = fd.Mesh.from_pyvista( pv.Plane( center=(0, 0, 0), direction=(0, 0, 1), i_size=1.0, j_size=1.0, i_resolution=3, j_resolution=3, ).triangulate(), name="Floor", ) body = fd.constraint.RigidBody( sphere_mesh, mass=mass, inertia_tensor=(2 / 5) * mass * radius**2 * np.eye(3), center_of_mass=np.array([0, 0, initial_height]), ) body.set_force([0, 0, -mass * gravity]) body.set_rayleigh_damping(0.5) body.set_static_obstacle(floor_mesh, dhat=0.01, kappa=1e8) .. GENERATED FROM PYTHON SOURCE LINES 68-73 Transient solution ------------------ The output interval limits the trajectory to a small number of animation frames. The time step is also larger than in the standalone demonstration to keep documentation builds reasonably short. .. GENERATED FROM PYTHON SOURCE LINES 73-92 .. code-block:: Python problem = fd.problem.NonLinear(body.assembly) problem.set_time_integrator(fd.time.SECOND_ORDER, fd.time.Newmark()) results = problem.add_output( "rigid_body_bounce_gallery", ["Disp", "RigidDisp", "RigidRot"], include_static_obstacles=True, ) dt = 2e-3 problem.nlsolve( dt=dt, dt_max=dt, tmax=0.8, update_dt=True, print_info=0, interval_output=0.04, ) .. GENERATED FROM PYTHON SOURCE LINES 93-98 Animation --------- :meth:`fedoo.MultiFrameDataSet.write_movie` loads and plots the saved frames automatically. Since the output includes static obstacles, the floor is present in the movie without any additional PyVista animation code. .. GENERATED FROM PYTHON SOURCE LINES 98-107 .. code-block:: Python plotter = pv.Plotter(window_size=(640, 480), off_screen=True) plotter.camera_position = [(0.8, -0.8, 0.55), (0, 0, 0.2), (0, 0, 1)] results.write_movie( "rigid_body_bounce.gif", framerate=15, plotter=plotter, show_edges=True, ) .. image-sg:: /examples/03-advanced/images/sphx_glr_rigid_body_bounce_001.gif :alt: rigid body bounce :srcset: /examples/03-advanced/images/sphx_glr_rigid_body_bounce_001.gif :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 10.734 seconds) .. _sphx_glr_download_examples_03-advanced_rigid_body_bounce.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: rigid_body_bounce.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rigid_body_bounce.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rigid_body_bounce.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_