Page MenuHomec4science

test_patch_westergaard.py
No OneTemporary

File Metadata

Created
Mon, May 20, 23:00

test_patch_westergaard.py

#!/usr/bin/env python
# coding: utf-8
# -----------------------------------------------------------------------------
# @author Lucas Frérot <lucas.frerot@epfl.ch>
#
# @section LICENSE
#
# Copyright (©) 2016 EPFL (Ecole Polytechnique Fédérale de
# Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
# Solides)
#
# Tamaas is free software: you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Tamaas 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 Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
# -----------------------------------------------------------------------------
from __future__ import division, print_function
import numpy as np
from numpy.linalg import norm
import tamaas as tm
def constructSinProfile(size, mode, amplitude):
x = np.linspace(0, 1, size, endpoint=False)
y = np.linspace(0, 1, size, endpoint=False)
x, y = np.meshgrid(x, y, indexing='ij')
surface = amplitude * np.sin(2*np.pi*x*mode[0]) * np.sin(2*np.pi*y*mode[1])
return surface.copy()
def constructCosProfile(size, mode, amplitude):
x = np.linspace(0, 1, size, endpoint=False)
y = np.linspace(0, 1, size, endpoint=False)
x, y = np.meshgrid(x, y, indexing='ij')
surface = amplitude * np.cos(2*np.pi*x*mode[0]) * np.cos(2*np.pi*y*mode[1])
return surface.copy()
def test_patch_westergaard():
tm.initialize()
E = 3.
nu = 0.
E_star = E / (1-nu**2)
grid_size = 6
modes = np.array([2, 1])
input_pressure = constructSinProfile(grid_size, modes, 1)
model = tm.ModelFactory.createModel(tm.model_type.basic_2d,
[1., 1.],
[grid_size, grid_size])
model.setElasticity(E, nu)
model.getTraction()[:, :] = input_pressure[:, :]
model.solveNeumann()
output_displ = model.getDisplacement()
solution = constructSinProfile(grid_size, modes, 1 / (np.pi * E_star * norm(modes)))
error = norm(solution - output_displ) / norm(solution)
assert error < 1e-15, "Neumann error = {}".format(error)
output_displ[:, :] = solution[:, :]
model.solveDirichlet()
error = norm(input_pressure - model.getTraction()) / norm(input_pressure)
assert error < 1e-15, "Dirichlet error = {}".format(error)
tm.finalize()
def test_patch_westergaard_surface():
def constructSinProfile(size, mode, amplitude):
x = np.linspace(0, 1, size, endpoint=False)
y = np.linspace(0, 1, size, endpoint=False)
x, y = np.meshgrid(x, y, indexing='ij')
surface = amplitude * np.sin(2*np.pi*x*mode)
return surface.copy()
def constructCosProfile(size, mode, amplitude):
x = np.linspace(0, 1, size, endpoint=False)
y = np.linspace(0, 1, size, endpoint=False)
x, y = np.meshgrid(x, y, indexing='ij')
surface = amplitude * np.cos(2*np.pi*x*mode)
return surface.copy()
tm.initialize()
E = 3.
nu = 0.
E_star = E / (1-nu**2)
mu = E / (2*(1+nu))
grid_size = 4
input_pressure = constructCosProfile(grid_size, 1, 1)
model = tm.ModelFactory.createModel(tm.model_type.surface_2d,
[1., 1.],
[grid_size, grid_size])
model.setElasticity(E, nu)
model.getTraction()[:, :, 2] = input_pressure[:, :]
model.solveNeumann()
output_displ = model.getDisplacement()
solution = np.zeros_like(output_displ)
solution[:, :, 2] = constructCosProfile(grid_size, 1, 1 / (np.pi * E_star))
solution[:, :, 0] = constructSinProfile(grid_size, 1, -(1-2*nu) / (4 * mu * np.pi))
error = norm(solution - output_displ) / norm(solution)
assert error < 1e-15, "Neumann error = {}".format(error)
if __name__ == "__main__":
test_patch_westergaard()

Event Timeline