.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/rigid_body_freefall.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_rigid_body_freefall.py: Rigid body free fall — validation with NonLinear solver. A rigid sphere falls under gravity. Compared with z(t) = z0 - 0.5*g*t^2. Uses RigidBody + NonLinear (Fedoo's standard solver). .. GENERATED FROM PYTHON SOURCE LINES 6-54 .. rst-class:: sphx-glr-script-out .. code-block:: none ============================================================ RIGID BODY FREE FALL — Fedoo validation m=1.0kg, z0=1.0m, dt=0.001s ============================================================ z_final = -0.7658m (analytical: -0.7658m) error = 2.69e-14m PASS | .. code-block:: Python import time import numpy as np import pyvista as pv import fedoo as fd g = 9.81 mass = 1.0 radius = 0.1 z0 = 1.0 dt = 1e-3 t_end = 0.6 print("=" * 60) print("RIGID BODY FREE FALL — Fedoo validation") print(f" m={mass}kg, z0={z0}m, dt={dt}s") print("=" * 60) space = fd.ModelingSpace("3D") space.new_variable("DispX") space.new_variable("DispY") space.new_variable("DispZ") space.new_vector("Disp", ("DispX", "DispY", "DispZ")) mesh = fd.Mesh.from_pyvista( pv.Sphere(radius=radius, center=(0, 0, z0), theta_resolution=8, phi_resolution=8) ) body = fd.constraint.RigidBody( mesh, mass=mass, inertia_tensor=0.004 * np.eye(3), center_of_mass=np.array([0, 0, z0]), ) body.set_force([0, 0, -mass * g]) pb = body.solve(dt=dt, tmax=t_end, print_info=0) # Read trajectory from final state idx = body.assembly._dof_indices dof = pb.get_dof_solution() dz_final = dof[idx[2]] z_final = z0 + dz_final z_analytical = z0 - 0.5 * g * t_end**2 print(f" z_final = {z_final:.4f}m (analytical: {z_analytical:.4f}m)") print(f" error = {abs(z_final - z_analytical):.2e}m") print(f" {'PASS' if abs(z_final - z_analytical) < 0.01 else 'FAIL'}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.033 seconds) .. _sphx_glr_download_examples_rigid_body_freefall.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_freefall.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: rigid_body_freefall.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: rigid_body_freefall.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_