def test_representation(): r"""str and repr tests""" f = Force((1., 2., 3.), (1., 2., 3.)) assert str(f) == "F:(1.0, 2.0, 3.0)@(1.0, 2.0, 3.0)-name: no_name" f = Force((1., 2., 3.), (1., 2., 3.), name="The Force") assert str(f) == "F:(1.0, 2.0, 3.0)@(1.0, 2.0, 3.0)-name: The Force" assert repr(f) == "F:(1.0, 2.0, 3.0)@(1.0, 2.0, 3.0)-name: The Force"
def test_coe_position_sideforce_production_keuning_verwerft(): r"""Centre of effort position tests.""" sof_1 = SystemOfForces() sof_2 = SystemOfForces() force = \ sideforce_production_keuning_verwerft(boatspeed=4., heel_angle=20., leeway_angle=5., rudder_angle=5., keel_projected_area=0.025240, keel_span=0.42 - Tc - bulb_diameter, rudder_projected_area=0.012402, rudder_span=0.248, lwl=lwl, bwl=bwl, Tc=Tc, # hull_coe=None, keel_coe=(0.460, 0., -0.2167), rudder_coe=(0.0536, 0., -0.11495), keel_sweep_back_angle=20.) for f in force: sof_1.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert sof_1.moment[2] < 0 # assert force.position[0] > 0.0536 # assert force.position[0] < 0.460 # assert force.position[1] < 0. # assert force.position[2] > - 0.2167 force = \ sideforce_production_keuning_verwerft(boatspeed=4., heel_angle=-20., leeway_angle=5., rudder_angle=5., keel_projected_area=0.025240, keel_span=0.42 - Tc - bulb_diameter, rudder_projected_area=0.012402, rudder_span=0.248, lwl=lwl, bwl=bwl, Tc=Tc, # hull_coe=None, keel_coe=(0.460, 0., -0.2167), rudder_coe=(0.0536, 0., -0.11495), keel_sweep_back_angle=20.) for f in force: sof_2.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) # assert force.position[0] > 0.0536 # assert force.position[0] < 0.460 # assert force.position[1] > 0. # assert force.position[2] > - 0.2167 assert sof_2.moment[2] < 0
def test_wrong_input(): r"""The inputs are wrong.""" with pytest.raises(ValueError): Force((1., 2., 3., 4.), None) with pytest.raises(ValueError): Force(None, (1., 2., 3., 4.)) with pytest.raises(ValueError): Force(('a', 2., 3.), (1., 2., 3.)) with pytest.raises(ValueError): Force((1., 2., 3.), (1., 'a', 3.))
def test_rm_sign_and_symmetry_rm_estimate_gerritsma(): r"""Test righting moment sign.""" s = SystemOfForces() for f in rm: s.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s.mx > 0 assert s.my == 0. assert s.mz == 0.
def test_trm_sign_and_symmetry_trm_estimate(): r"""Test trim righting moment sign.""" s = SystemOfForces() for f in trm: s.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s.my > 0 assert s.mx == 0. assert s.mz == 0.
def test_good_input(): r"""Force and point are OK.""" f = Force((1., 2., 3.), (1., 2., 3.)) assert f.x == 1. assert f.y == 2. assert f.z == 3. assert f.px == 1. assert f.py == 2. assert f.pz == 3.
def test_none_input(): r"""Force and point are None.""" f = Force(None, None) assert f.x == 0 assert f.y == 0 assert f.z == 0 assert f.px == 0 assert f.py == 0 assert f.pz == 0
def test_trm_negative_pitch_trm_estimate(): r"""Test moments with negative trim.""" s1 = SystemOfForces() for f in trm_estimate(trim_angle=-3., displacement=displacement, lwl=lwl, bwl=bwl, Tc=Tc, Gdwl=Gdwl, rho_water=rho_water): s1.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s1.mx == 0. assert s1.my < 0 assert s1.mz == 0.
def test_rm_negative_heel_rm_estimate_gerritsma(): r"""Test righting moment with negative heel.""" s1 = SystemOfForces() for f in rm_estimate_gerritsma(boatspeed=1., heel_angle=-30., displacement=displacement, lwl=lwl, bwl=bwl, Tc=Tc, Gdwl=Gdwl, rho_water=rho_water): s1.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s1.mx < 0 assert s1.my == 0. assert s1.mz == 0.
def test_rm_going_backwards_rm_estimate_gerritsma(): r"""Test righting moment going backwards.""" s = SystemOfForces() for f in rm_estimate_gerritsma(boatspeed=-1., heel_angle=30., displacement=displacement, lwl=lwl, bwl=bwl, Tc=Tc, Gdwl=Gdwl, rho_water=rho_water): s.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s.mx > 0 assert s.my == 0. assert s.mz == 0.
def test_trm_zero_heel_moving_trm_estimate(): r"""Check moments and sum pf forces is 0 when upright.""" s = SystemOfForces() for f in trm_estimate(trim_angle=0., displacement=displacement, lwl=lwl, bwl=bwl, Tc=Tc, Gdwl=Gdwl): s.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s.mx == 0. assert s.my == 0. assert s.mz == 0. assert s.x == 0. assert s.y == 0. assert s.z == 0.
def test_rm_zero_heel_rm_estimate_gerritsma(): r"""Test righting moment and sum of forces are 0 when upright.""" s = SystemOfForces() for f in rm_estimate_gerritsma(boatspeed=1., heel_angle=0., displacement=displacement, lwl=lwl, bwl=bwl, Tc=Tc, Gdwl=Gdwl, rho_water=rho_water): s.add_force(Force((f.fx, f.fy, f.fz), (f.px, f.py, f.pz))) assert s.mx == 0. assert s.my == 0. assert s.mz == 0. assert s.x == 0. assert s.y == 0. assert s.z == 0.
#!/usr/bin/env python # coding: utf-8 r"""Forces example.""" from ydeos_forces.forces import Force, SystemOfForces force_x_plus_at_0_m1_0 = Force((1., 0., 10.), (0., -1., 0.)) force_x_minus_at_0_1_0 = Force((-1., 0., 10.), (0., 1., 0.)) force_y_plus_at_m1_0_0 = Force((0., 1., 10.), (-1., 0., 0.)) force_y_minus_at_1_0_0 = Force((0., -1., -30.), (1., 0., 0.)) sf = SystemOfForces(moments_point_of_reference=(0., 0., 0.)) sf_2 = SystemOfForces(moments_point_of_reference=(10., 22., 3800.)) sf.add_force(force_x_plus_at_0_m1_0) sf.add_force(force_x_minus_at_0_1_0) sf.add_force(force_y_plus_at_m1_0_0) sf.add_force(force_y_minus_at_1_0_0) sf_2.add_force(force_x_plus_at_0_m1_0) sf_2.add_force(force_x_minus_at_0_1_0) sf_2.add_force(force_y_plus_at_m1_0_0) sf_2.add_force(force_y_minus_at_1_0_0) print('*************') print('System of Forces - ref at 0,0,0') print(f'Total force : {sf.force}') print(f'Total moment : {sf.moment}')