def animate(self, motion, *args, **kwargs): """Display a motion as a 3D animation. Parameters ========== motion: dict or pd.Series or str A dict or series mapping the name of the dofs to its amplitude. If a single string is passed, it is assumed to be the name of a dof and this dof with a unit amplitude will be displayed. """ from capytaine.ui.vtk.animation import Animation if isinstance(motion, str): motion = {motion: 1.0} elif isinstance(motion, xr.DataArray): motion = { k: motion.sel(radiating_dof=k).data for k in motion.coords["radiating_dof"].data } animation = Animation(*args, **kwargs) animation._add_actor(self.mesh.merged(), faces_motion=sum( motion[dof_name] * dof for dof_name, dof in self.dofs.items() if dof_name in motion)) return animation
radiating_dof="Heave", omega=2.0) radiation_result = solver.solve(radiation_problem) # Define a mesh of the free surface and compute the free surface elevation free_surface = cpt.FreeSurface(x_range=(-50, 50), y_range=(-50, 50), nx=150, ny=150) diffraction_elevation_at_faces = solver.get_free_surface_elevation( diffraction_result, free_surface) radiation_elevation_at_faces = solver.get_free_surface_elevation( radiation_result, free_surface) # Add incoming waves diffraction_elevation_at_faces = diffraction_elevation_at_faces + free_surface.incoming_waves( diffraction_result) # Run the animations # animation = Animation(loop_duration=diffraction_result.period) # animation.add_body(full_sphere, faces_motion=None) # animation.add_free_surface(free_surface, faces_elevation=0.5*diffraction_elevation_at_faces) # animation.run(camera_position=(-30, -30, 30)) # The camera is oriented towards (0, 0, 0) by default. # animation.save("path/to/the/video/file.ogv", camera_position=(-30, -30, 30)) animation = Animation(loop_duration=radiation_result.period) animation.add_body(full_sphere, faces_motion=full_sphere.dofs["Heave"]) animation.add_free_surface(free_surface, faces_elevation=3.0 * radiation_elevation_at_faces) animation.run(camera_position=(-30, -30, 30)) # animation.save("path/to/the/video/file.ogv", camera_position=(-30, -30, 30))
# Define a mesh of the free surface and compute the free surface elevation free_surface = cpt.FreeSurface(x_range=(-50, 50), y_range=(-50, 50), nx=150, ny=150) diffraction_elevation_at_faces = solver.get_free_surface_elevation( diffraction_result, free_surface) radiation_elevation_at_faces = solver.get_free_surface_elevation( radiation_result, free_surface) # Add incoming waves diffraction_elevation_at_faces = diffraction_elevation_at_faces + free_surface.incoming_waves( diffraction_result) # Run the animations animation = Animation(loop_duration=diffraction_result.period) animation.add_body(full_sphere, faces_motion=None) animation.add_free_surface(free_surface, faces_elevation=0.5 * diffraction_elevation_at_faces) animation.run(camera_position=( -30, -30, 30)) # The camera is oriented towards (0, 0, 0) by default. # animation.save("path/to/the/video/file.ogv", camera_position=(-30, -30, 30)) animation = Animation(loop_duration=radiation_result.period) animation.add_body(full_sphere, faces_motion=full_sphere.dofs["Heave"]) animation.add_free_surface(free_surface, faces_elevation=3.0 * radiation_elevation_at_faces) animation.run(camera_position=(-30, -30, 30)) # animation.save("path/to/the/video/file.ogv", camera_position=(-30, -30, 30))