def test_st_bearing_elements_odd_length(): tim0 = ShaftElement( L=0.25, idl=0, odl=0.05, material=steel, ) tim1 = ShaftElement( L=0.25, idl=0, odl=0.05, material=steel, ) shaft_elm = [tim0, tim1] disk0 = DiskElement(n=1, m=20, Id=1, Ip=1) brg0 = ST_BearingElement( n=0, kxx=[1e6, 2e6], cxx=[1e3, 2e3], is_random=["kxx", "cxx"], ) brg1 = ST_BearingElement( n=2, kxx=[1e6, 2e6, 3e6], cxx=[1e3, 2e3, 3e3], is_random=["kxx", "cxx"], ) with pytest.raises(ValueError) as ex: ST_Rotor(shaft_elm, [disk0], [brg0, brg1]) assert "not all random bearing elements lists have same length." in str( ex.value)
def rotor1(): # rotor with 6 shaft elements, 2 disks and 2 random bearings i_d = 0 o_d = 0.05 n = 6 L = [0.25 for _ in range(n)] shaft_elem = [ShaftElement(l, i_d, o_d, material=steel) for l in L] disk0 = DiskElement.from_geometry(n=2, material=steel, width=0.07, i_d=0.05, o_d=0.28) disk1 = DiskElement.from_geometry(n=4, material=steel, width=0.07, i_d=0.05, o_d=0.28) kxx = [1e6, 2e6] cxx = [1e3, 2e3] bearing0 = ST_BearingElement(n=0, kxx=kxx, cxx=cxx, is_random=["kxx", "cxx"]) bearing1 = ST_BearingElement(n=6, kxx=kxx, cxx=cxx, is_random=["kxx", "cxx"]) return ST_Rotor(shaft_elem, [disk0, disk1], [bearing0, bearing1])
def test_elements_odd_length(): tim0 = ST_ShaftElement( L=[1, 1.1], idl=0, odl=[0.1, 0.2], material=steel, is_random=["L", "odl"], ) shaft_elm = [tim0, tim0] disk0 = ST_DiskElement(n=0, m=[20, 30, 40], Id=1, Ip=1, is_random=["m"]) disk1 = ST_DiskElement(n=2, m=[20, 30, 40], Id=1, Ip=1, is_random=["m"]) disks = [disk0, disk1] brg0 = ST_BearingElement( n=0, kxx=[1e6, 2e6], cxx=[1e3, 2e3], is_random=["kxx", "cxx"], ) brg1 = ST_BearingElement( n=2, kxx=[1e6, 2e6], cxx=[1e3, 2e3], is_random=["kxx", "cxx"], ) bearings = [brg0, brg1] with pytest.raises(ValueError) as ex: ST_Rotor(shaft_elm, disks, bearings) assert "not all the random elements lists have the same length." in str( ex.value)
def st_rotor_example(): """Return an instance of random rotors. The purpose of this is to make available a simple model so that doctest can be written using this. Returns ------- An instance of random rotors. Examples -------- >>> import ross.stochastic as srs >>> rotors = srs.st_rotor_example() >>> len(list(iter(rotors))) 10 """ import ross as rs from ross.materials import steel i_d = 0 o_d = 0.05 n = 6 L = [0.25 for _ in range(n)] shaft_elem = [rs.ShaftElement(l, i_d, o_d, material=steel) for l in L] disk0 = rs.DiskElement.from_geometry(n=2, material=steel, width=0.07, i_d=0.05, o_d=0.28) disk1 = rs.DiskElement.from_geometry(n=4, material=steel, width=0.07, i_d=0.05, o_d=0.28) s = 10 kxx = np.random.uniform(1e6, 2e6, s) cxx = np.random.uniform(1e3, 2e3, s) bearing0 = ST_BearingElement(n=0, kxx=kxx, cxx=cxx, is_random=["kxx", "cxx"]) bearing1 = ST_BearingElement(n=6, kxx=kxx, cxx=cxx, is_random=["kxx", "cxx"]) return ST_Rotor(shaft_elem, [disk0, disk1], [bearing0, bearing1])
def rand_bearing_varying_coefs(): kxx = [[1e6, 1.1e6], [2e6, 2.1e6]] kxy = [[1.5e6, 1.6e6], [2.5e6, 2.6e6]] kyx = [[1.5e6, 1.6e6], [2.5e6, 2.6e6]] kyy = [[3e6, 3.1e6], [4e6, 4.1e6]] cxx = [[1e3, 1.1e3], [2e3, 2.1e3]] cxy = [[1.5e3, 1.6e3], [2.5e3, 2.6e3]] cyx = [[1.5e3, 1.6e3], [2.5e3, 2.6e3]] cyy = [[3e3, 3.1e3], [4e3, 4.1e3]] frequency = np.array([500, 800]) elm = ST_BearingElement( n=1, kxx=kxx, kxy=kxy, kyx=kyx, kyy=kyy, cxx=cxx, cxy=cxy, cyx=cyx, cyy=cyy, frequency=frequency, is_random=["kxx", "kxy", "kyx", "kyy", "cxx", "cxy", "cyx", "cyy"], ) return elm
def test_st_bearing_error_messages(rand_bearing_constant_coefs): kxx = [1e6, 2e6] cxx = [1e3, 2e3] freq = [500, 1000] with pytest.raises(ValueError) as ex: ST_BearingElement(n=1, kxx=kxx, cxx=cxx, frequency=freq, is_random=["kxx", "cxx", "frequency"]) assert "frequency can not be a random variable" in str(ex.value) with pytest.raises(ValueError) as ex: rand_bearing_constant_coefs.plot_random_var(["kxy"]) assert ( "Random variable not in var_list. Select variables from ['kxx', 'cxx', 'kyy', 'cyy']" in str(ex.value)) with pytest.raises(KeyError) as ex: rand_bearing_constant_coefs["odd"] = [1, 2] assert "Object does not have parameter: odd." in str(ex.value) with pytest.raises(KeyError) as ex: rand_bearing_constant_coefs["odd"] assert "Object does not have parameter: odd." in str(ex.value)
def rand_bearing_constant_coefs(): kxx = [1e6, 2e6] cxx = [1e3, 2e3] elm = ST_BearingElement(n=1, kxx=kxx, cxx=cxx, is_random=["kxx", "cxx"]) return elm