Page MenuHomec4science

test_hertz_kato.py
No OneTemporary

File Metadata

Created
Wed, Jun 26, 17:31

test_hertz_kato.py

# -*- coding: utf-8 -*-
# @file
# @section LICENSE
#
# Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne),
# Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import division, print_function
import numpy as np
import tamaas as tm
def constructHertzProfile(size, curvature):
radius = 1. / curvature
x = np.linspace(-0.5, 0.5, size, dtype=tm.dtype)
y = np.linspace(-0.5, 0.5, size, dtype=tm.dtype)
x, y = np.meshgrid(x, y)
surface = np.sqrt(radius**2 - x**2 - y**2)
surface -= surface.mean()
return surface.copy()
def computeHertzDisplacement(e_star, contact_size, max_pressure, size):
x = np.linspace(-0.5, 0.5, size, dtype=tm.dtype)
y = np.linspace(-0.5, 0.5, size, dtype=tm.dtype)
x, y = np.meshgrid(x, y)
disp = np.pi * max_pressure / (4 * contact_size * e_star) \
* (2 * contact_size**2 - (x**2 + y**2))
return disp.copy()
def test_hertz_kato():
tm.initialize()
grid_size = 512
curvature = 0.1
effective_modulus = 1.
load = 0.0001
surface = constructHertzProfile(grid_size, curvature)
model = tm.ModelFactory.createModel(tm.model_type_basic_2d,
[1., 1.],
[grid_size]*2)
model.E = 1.
model.nu = 0
solver = tm.KatoSaturated(model, surface, 1e-12, 1e30)
solver.setMaxIterations(10000)
solver.solve(load)
tractions = model.getTraction()
displacements = model.getDisplacement()
# Testing contact area against Hertz solution for solids of revolution
contact_area = np.mean(tractions > 0)
print("Contact area =", contact_area)
hertz_contact_size = (3 * load / (4 * curvature
* effective_modulus))**(1. / 3.)
hertz_area = np.pi * hertz_contact_size**2
area_error = np.abs(hertz_area - contact_area) / hertz_area
print("Area error: {}".format(area_error))
# Testing maximum pressure
max_pressure = tractions.max()
hertz_max_pressure = (6 * load * effective_modulus**2
* curvature ** 2)**(1. / 3.) / np.pi
pressure_error = np.abs(hertz_max_pressure - max_pressure) \
/ hertz_max_pressure
print("Max pressure error: {}".format(pressure_error))
# Testing displacements
hertz_displacements = computeHertzDisplacement(effective_modulus,
hertz_contact_size,
hertz_max_pressure,
grid_size)
# Selecing only the points that are in contact
contact_indexes = [(i, j)
for i in range(grid_size) for j in range(grid_size)
if tractions[i, j] > 0]
# Displacements of bem are centered around the mean of the whole surface
# and Hertz displacements are not centered, so we need to compute mean
# on the contact zone for both arrays
bem_mean = 0.
hertz_mean = 0.
for index in contact_indexes:
bem_mean += displacements[index]
hertz_mean += hertz_displacements[index]
bem_mean /= len(contact_indexes)
hertz_mean /= len(contact_indexes)
# Correction applied when computing error
correction = hertz_mean - bem_mean
# Computation of error of displacement in contact zone
error = 0.
hertz_norm = 0.
for index in contact_indexes:
error += (hertz_displacements[index]
- displacements[index] - correction)**2
hertz_norm += (hertz_displacements[index] - hertz_mean)**2
displacement_error = np.sqrt(error / hertz_norm)
print("Displacement error (in contact zone): {}".format(displacement_error))
assert area_error < 6e-3 \
and pressure_error < 4e-3 \
and displacement_error < 3e-4
tm.finalize()
if __name__ == "__main__":
test_hertz_kato()

Event Timeline