Пример #1
0
def test_shift_surface():
    n = 10
    flat1 = s.FlatSurface(shape=(n, n), grid_spacing=1, generate=True)
    flat2 = s.FlatSurface(shape=(n, n), grid_spacing=1, generate=True)
    roughness = s.FlatSurface(shape=(n, 2 * n), grid_spacing=1, generate=True)
    rolling = s.RollingSurface(roughness, flat2)

    model = c.ContactModel('test_mod', rolling, flat1)

    state = {
        "contact_nodes": np.ones(shape=(n, n)),
        'time_step': 1.0,
        'surface_1_points': rolling.get_points_from_extent(),
        'surface_2_points': flat1.get_points_from_extent()
    }
    step = c.RepeatingStateStep('', time_steps=n, state=state)
    model.add_step(step)

    ct = c.sub_models.ResultContactTime('', False)
    shift = c.sub_models.UpdateShiftRollingSurface('', 1, 1)
    step.add_sub_model(ct)
    step.add_sub_model(shift)

    result = model.solve(skip_data_check=True)
    npt.assert_array_equal(result['contact_time_1'][0],
                           np.flip(np.arange(1, 11)))
    npt.assert_array_equal(result['contact_time_2'],
                           n * np.ones_like(result['contact_time_2']))
def test_get_gap_shape():
    i = 0
    for spec in spec_list:
        print(i)
        s1 = s.FlatSurface(shape=spec[0], grid_spacing=spec[2], generate=True)
        s2 = s.FlatSurface(shape=spec[1], grid_spacing=spec[3], generate=True)
        model = c.ContactModel('my_model', s1, s2)
        gap, s1_pts, s2_pts = c._model_utils.get_gap_from_model(
            model, 0, spec[4], periodic=spec[5])
        print(gap.shape)
        assert gap.shape == spec[6]
        i += 1
Пример #3
0
def test_hertz_agreement_static_load_fftw():
    """ Test that the load controlled static step gives approximately the same answer as the
    analytical hertz solver

    """
    try:
        import pyfftw  # noqa: F401
    except ImportError:
        warnings.warn(
            "Could not import pyfftw, could not test the fftw backend")
        return

    with slippy.OverRideCuda():
        # make surfaces
        flat_surface = s.FlatSurface(shift=(0, 0))
        round_surface = s.RoundSurface((1, 1, 1),
                                       extent=(0.006, 0.006),
                                       shape=(255, 255),
                                       generate=True)
        # set materials
        steel = c.Elastic('Steel', {'E': 200e9, 'v': 0.3})
        aluminum = c.Elastic('Aluminum', {'E': 70e9, 'v': 0.33})
        flat_surface.material = aluminum
        round_surface.material = steel
        # create model
        my_model = c.ContactModel('model-1', round_surface, flat_surface)
        # set model parameters
        total_load = 100
        my_step = c.StaticStep('contact', normal_load=total_load)
        my_model.add_step(my_step)

        out = my_model.solve(skip_data_check=True)

        final_load = sum(out['loads'].z.flatten() *
                         round_surface.grid_spacing**2)

        # check the converged load is the same as the set load
        npt.assert_approx_equal(final_load, total_load, 3)

        # get the analytical hertz result
        a_result = c.hertz_full([1, 1], [np.inf, np.inf], [200e9, 70e9],
                                [0.3, 0.33], 100)

        # check max pressure
        npt.assert_approx_equal(a_result['max_pressure'],
                                max(out['loads'].z.flatten()), 2)

        # check contact area
        found_area = round_surface.grid_spacing**2 * sum(
            out['contact_nodes'].flatten())
        npt.assert_approx_equal(a_result['contact_area'], found_area, 2)

        # check deflection
        npt.assert_approx_equal(a_result['total_deflection'],
                                out['interference'], 4)
Пример #4
0
def test_hertz_agreement_static_interference_fftw():
    try:
        import pyfftw  # noqa: F401
        slippy.CUDA = False
    except ImportError:
        warnings.warn(
            "Could not import pyfftw, could not test the fftw backend")
        return

    with slippy.OverRideCuda():
        """Tests that the static normal interference step agrees with the analytical hertz solution"""
        flat_surface = s.FlatSurface(shift=(0, 0))
        round_surface = s.RoundSurface((1, 1, 1),
                                       extent=(0.006, 0.006),
                                       shape=(255, 255),
                                       generate=True)
        # set materials
        steel = c.Elastic('Steel', {'E': 200e9, 'v': 0.3})
        aluminum = c.Elastic('Aluminum', {'E': 70e9, 'v': 0.33})
        flat_surface.material = aluminum
        round_surface.material = steel
        # create model
        my_model = c.ContactModel('model-1', round_surface, flat_surface)

        set_load = 100

        a_result = c.hertz_full([1, 1], [np.inf, np.inf], [200e9, 70e9],
                                [0.3, 0.33], set_load)

        my_step = c.StaticStep('step',
                               interference=a_result['total_deflection'])
        my_model.add_step(my_step)
        final_state = my_model.solve()

        # check that the solution gives the set interference
        npt.assert_approx_equal(final_state['interference'],
                                a_result['total_deflection'])

        # check that the load converged to the correct results
        num_total_load = round_surface.grid_spacing**2 * sum(
            final_state['loads'].z.flatten())
        npt.assert_approx_equal(num_total_load, set_load, significant=4)

        # check that the max pressure is the same
        npt.assert_approx_equal(a_result['max_pressure'],
                                max(final_state['loads'].z.flatten()),
                                significant=2)

        # check that the contact area is in line with analytical solution
        npt.assert_approx_equal(a_result['contact_area'],
                                round_surface.grid_spacing**2 *
                                sum(final_state['contact_nodes'].flatten()),
                                significant=2)
def test_contact_stiffness():
    """
    Test the contact stiffness sub model against a known analytical result
    Also tests the example
    """
    diameter = 1
    resolution = 512
    x, y = np.meshgrid(np.linspace(-diameter, diameter, resolution),
                       np.linspace(-diameter, diameter, resolution))
    indenter_profile = np.array((x**2 + y**2) < (diameter / 2)**2,
                                dtype=np.float32)
    grid_spacing = x[1, 1] - x[0, 0]
    indenter = s.Surface(profile=indenter_profile, grid_spacing=grid_spacing)
    half_space = s.FlatSurface(shape=(resolution, resolution),
                               grid_spacing=grid_spacing,
                               generate=True)

    indenter.material = c.rigid
    e, v = 200e9, 0.3
    half_space.material = c.Elastic('steel', {'E': e, 'v': v})
    reduced_modulus = 1 / ((1 - v**2) / e)

    my_model = c.ContactModel('Contact_stiffness_example', half_space,
                              indenter)

    step = c.StaticStep('loading', interference=1e-4, periodic_geometry=True)
    sub_model = c.sub_models.ResultContactStiffness('stiffness',
                                                    definition='far points',
                                                    loading=False)
    step.add_sub_model(sub_model)
    my_model.add_step(step)

    # we don't need to solve the contact model we already know what the contact nodes will be

    contact_nodes = (x**2 + y**2) < (diameter / 2)**2

    current_state = {
        'contact_nodes': contact_nodes,
        'loads_z': np.zeros_like(contact_nodes)
    }

    results = sub_model.solve(current_state)

    numerical_stiffness = results['s_contact_stiffness_unloading_fp_z_0'] * (
        2 * diameter)**2
    analytical_stiffness = reduced_modulus * diameter

    npt.assert_approx_equal(numerical_stiffness, analytical_stiffness, 2)
def test_hertz_agreement_pk_static_load_cuda_spatial_im():
    """ Test that the load controlled static step gives approximately the same answer as the
    analytical hertz solver
    """
    try:
        import cupy  # noqa: F401
        slippy.CUDA = True
    except ImportError:
        return
    # make surfaces
    flat_surface = s.FlatSurface(shift=(0, 0))
    round_surface = s.RoundSurface((1, 1, 1), extent=(0.006, 0.006), shape=(255, 255), generate=True)
    # set materials
    steel_2 = c.Elastic('Steel_a', {'E': 200e9, 'v': 0.3}, use_frequency_domain=False)
    aluminum_2 = c.Elastic('Aluminum_a', {'E': 70e9, 'v': 0.33}, use_frequency_domain=False)
    flat_surface.material = aluminum_2
    round_surface.material = steel_2
    # create model
    my_model = c.ContactModel('model-1', round_surface, flat_surface)
    # set model parameters
    total_load = 100
    my_step = c.StaticStep('contact', normal_load=total_load, )
    my_model.add_step(my_step)

    out = my_model.solve(skip_data_check=True)

    final_load = sum(out['loads_z'].flatten() * round_surface.grid_spacing ** 2)

    # check the converged load is the same as the set load
    npt.assert_approx_equal(final_load, total_load, 3)

    # get the analytical hertz result
    a_result = c.hertz_full([1, 1], [np.inf, np.inf], [200e9, 70e9], [0.3, 0.33], 100)

    # check max pressure
    npt.assert_approx_equal(a_result['max_pressure'], max(out['loads_z'].flatten()), 3)

    # check contact area
    found_area = round_surface.grid_spacing ** 2 * sum(out['contact_nodes'].flatten())
    npt.assert_approx_equal(a_result['contact_area'], found_area, 2)

    # check deflection
    npt.assert_approx_equal(a_result['total_deflection'], out['interference'], 4)
Пример #7
0
def test_example_mixed_lubrication():
    """tests the mixed lubrication example"""
    radius = 0.01905  # The radius of the ball
    load = 800  # The load on the ball in N
    rolling_speed = 4  # The rolling speed in m/s (The mean speed of the surfaces)
    youngs_modulus = 200e9  # The youngs modulus of the surfaces
    p_ratio = 0.3  # The poission's ratio of the surfaces
    grid_size = 65  # The number of points in the descretisation grid
    eta_0 = 0.096  # Coefficient in the roelands pressure-viscosity equation
    roelands_p_0 = 1 / 5.1e-9  # Coefficient in the roelands pressure-viscosity equation
    roelands_z = 0.68  # Coefficient in the roelands pressure-viscosity equation

    # Solving the hertzian contact
    hertz_result = c.hertz_full([radius, radius], [float('inf'), float('inf')],
                                [youngs_modulus, youngs_modulus],
                                [p_ratio, p_ratio], load)
    hertz_pressure = hertz_result['max_pressure']
    hertz_a = hertz_result['contact_radii'][0]
    hertz_deflection = hertz_result['total_deflection']
    hertz_pressure_function = hertz_result['pressure_f']

    ball = s.RoundSurface((radius,) * 3, shape=(grid_size, grid_size),
                          extent=(hertz_a * 4, hertz_a * 4), generate=True)
    flat = s.FlatSurface()

    steel = c.Elastic('steel', {'E': youngs_modulus, 'v': p_ratio})
    ball.material = steel
    flat.material = steel

    oil = c.Lubricant('oil')  # Making a lubricant object to contain our sub models
    oil.add_sub_model('nd_viscosity', c.lubricant_models.nd_roelands(eta_0, roelands_p_0, hertz_pressure, roelands_z))
    oil.add_sub_model('nd_density', c.lubricant_models.nd_dowson_higginson(hertz_pressure))  # adding dowson higginson

    my_model = c.ContactModel('lubrication_test', ball, flat, oil)

    reynolds = c.UnifiedReynoldsSolver(time_step=0,
                                       grid_spacing=ball.grid_spacing,
                                       hertzian_pressure=hertz_pressure,
                                       radius_in_rolling_direction=radius,
                                       hertzian_half_width=hertz_a,
                                       dimentional_viscosity=eta_0,
                                       dimentional_density=872)

    # Find the hertzian pressure distribution as an initial guess
    x, y = ball.get_points_from_extent()
    x, y = x + ball._total_shift[0], y + ball._total_shift[1]
    hertzian_pressure_dist = hertz_pressure_function(x, y)

    # Making the step object
    step = c.IterSemiSystem('main', reynolds, rolling_speed, 1, no_time=True, normal_load=load,
                            initial_guess=[hertz_deflection, hertzian_pressure_dist],
                            relaxation_factor=0.05, max_it_interference=3000, rtol_interference=1e-3,
                            rtol_pressure=1e-4, no_update_warning=False)

    # Adding the step to the contact model
    my_model.add_step(step)
    state = my_model.solve()

    # gap is all greater than 0
    assert np.all(state['gap'] >= 0)
    # loads are all greater than or equal to 0
    assert np.all(state['pressure'] >= 0)
    # sum of pressures is total normal load and this has converged
    npt.assert_array_almost_equal(np.sum(state['pressure'])*ball.grid_spacing**2/load, 1.0, decimal=3)

    assert state['converged']
def test_get_gap_periodic():
    # each test block makes 2 surfaces, one large, one small it then steps
    # through moving increments of 1 *gs asserting that the result is as expected
    # then it fully wraps the surface and asserts that the result is as expected
    n = 8
    n_larger = 7
    gs = 1e-4
    # moving in the x direction
    larger = s.FlatSurface((1, 10000),
                           grid_spacing=gs,
                           shape=(n, n + n_larger),
                           generate=True,
                           shift=(0, 0))
    smaller = s.FlatSurface((10000, 1),
                            grid_spacing=gs,
                            shape=(n, n),
                            generate=True,
                            shift=(0, 0))
    model = c.ContactModel('model', larger, smaller)
    for i in range(n_larger):
        sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                         periodic=True,
                                                         off_set=(0, gs * i),
                                                         _return_sub=True)
        assert np.array_equal(sub_2, smaller.profile)
        assert np.array_equal(sub_1, larger.profile[:, i:n + i])
    sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                     periodic=True,
                                                     off_set=(0, gs *
                                                              (n + n_larger)),
                                                     _return_sub=True)
    assert np.array_equal(sub_1, larger.profile[:n, :n])
    assert np.array_equal(sub_2, smaller.profile)

    # moving in the -x direction with larger second surface
    larger = s.FlatSurface((1, 10000),
                           grid_spacing=gs,
                           shape=(n, n + n_larger),
                           generate=True,
                           shift=(0, 0))
    smaller = s.FlatSurface((10000, 1),
                            grid_spacing=gs,
                            shape=(n, n),
                            generate=True,
                            shift=(0, 0))
    model = c.ContactModel('model', smaller, larger)
    for i in range(n_larger):
        sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                         periodic=True,
                                                         off_set=(0, -gs * i),
                                                         _return_sub=True)
        assert np.array_equal(sub_1, smaller.profile)
        assert np.array_equal(sub_2, larger.profile[:, i:n + i])
    sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                     periodic=True,
                                                     off_set=(0, -gs *
                                                              (n + n_larger)),
                                                     _return_sub=True)
    assert np.array_equal(sub_2, larger.profile[:n, :n])
    assert np.array_equal(sub_1, smaller.profile)
    # moving in both directions
    larger = s.FlatSurface((1, 10000),
                           grid_spacing=gs,
                           shape=(n + n_larger, n + n_larger),
                           generate=True,
                           shift=(0, 0))
    smaller = s.FlatSurface((10000, 1),
                            grid_spacing=gs,
                            shape=(n, n),
                            generate=True,
                            shift=(0, 0))
    model = c.ContactModel('model', larger, smaller)
    for i in range(n_larger):
        sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                         periodic=True,
                                                         off_set=(gs * i,
                                                                  gs * i),
                                                         _return_sub=True)
        assert np.array_equal(sub_2, smaller.profile)
        assert np.array_equal(sub_1, larger.profile[i:n + i, i:n + i])
    sub_1, sub_2 = c._model_utils.get_gap_from_model(
        model,
        periodic=True,
        off_set=(gs * (n + n_larger), gs * (n + n_larger)),
        _return_sub=True)
    assert np.array_equal(sub_1, larger.profile[:n, :n])
    assert np.array_equal(sub_2, smaller.profile)
    larger = s.FlatSurface((1, 10000),
                           grid_spacing=gs,
                           shape=(n + n_larger, n + n_larger),
                           generate=True,
                           shift=(0, 0))
    smaller = s.FlatSurface((10000, 1),
                            grid_spacing=gs,
                            shape=(n, n),
                            generate=True,
                            shift=(0, 0))
    model = c.ContactModel('model', smaller, larger)
    for i in range(n_larger):
        sub_1, sub_2 = c._model_utils.get_gap_from_model(model,
                                                         periodic=True,
                                                         off_set=(-gs * i,
                                                                  -gs * i),
                                                         _return_sub=True)
        assert np.array_equal(sub_1, smaller.profile)
        assert np.array_equal(sub_2, larger.profile[i:n + i, i:n + i])
    sub_1, sub_2 = c._model_utils.get_gap_from_model(
        model,
        periodic=True,
        off_set=(-gs * (n + n_larger), -gs * (n + n_larger)),
        _return_sub=True)
    assert np.array_equal(sub_2, larger.profile[:n, :n])
    assert np.array_equal(sub_1, smaller.profile)