def test_animation_of_dofs(): body = cpt.Sphere() body.add_translation_dof(name="Heave") try: animation = body.animate({"Heave": 0.2}, loop_duration=1.0) animation.embed_in_notebook() except ImportError: warn("VTK is not installed and thus has not been tested.")
def test_sum_of_dofs(): body1 = cpt.Sphere(radius=1.0, ntheta=3, nphi=12, center=(0, 0, -3), name="body1") body1.add_translation_dof(name="Heave") body2 = cpt.Sphere(radius=1.0, ntheta=3, nphi=8, center=(5, 3, -1.5), name="body2") body2.add_translation_dof(name="Heave") both = body1 + body2 both.add_translation_dof(name="Heave") problems = [ cpt.RadiationProblem(body=both, radiating_dof=dof, omega=1.0) for dof in both.dofs ] solver = cpt.Nemoh() results = solver.solve_all(problems) dataset = cpt.assemble_dataset(results) both_added_mass = dataset['added_mass'].sel(radiating_dof="Heave", influenced_dof="Heave").data body1_added_mass = dataset['added_mass'].sel( radiating_dof="body1__Heave", influenced_dof="body1__Heave").data body2_added_mass = dataset['added_mass'].sel( radiating_dof="body2__Heave", influenced_dof="body2__Heave").data assert np.allclose(both_added_mass, body1_added_mass + body2_added_mass, rtol=1e-2)