Page MenuHomec4science

test_patch_westergaard.py
No OneTemporary

File Metadata

Created
Sun, Apr 28, 11:33

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 sys
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)
surface = amplitude * np.sin(2*np.pi*x*mode) * np.sin(2*np.pi*y*mode)
return surface.copy()
def main():
E = 3.
nu = 0.
E_star = E / (1-nu**2)
grid_size = 4
input_pressure = constructSinProfile(grid_size, 1, 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, 1, 1 / (np.pi * E_star * np.sqrt(2)))
error = norm(solution - output_displ) / norm(solution)
if error > 1e-17:
print("Neumann error = {}".format(error))
return 1
output_displ[:, :] = solution[:, :]
model.solveDirichlet()
error = norm(input_pressure - model.getTraction()) / norm(input_pressure)
if error > 2e-17:
print("Dirichlet error = {}".format(error))
return 1
return 0
if __name__ == "__main__":
sys.exit(main())

Event Timeline