Page MenuHomec4science

test_westergaard.py
No OneTemporary

File Metadata

Created
Sat, May 18, 21:29

test_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
import pytest
@pytest.fixture(scope="module",
params=[tm.PolonskyKeerRey.pressure,
tm.PolonskyKeerRey.gap])
def pkr(westergaard, request):
loads = {
tm.PolonskyKeerRey.pressure: westergaard.load,
tm.PolonskyKeerRey.gap: 0.06697415181446396
}
model = tm.ModelFactory.createModel(tm.model_type.basic_1d, [1.],
[westergaard.n])
model.setElasticity(westergaard.e_star, 0)
solver = tm.PolonskyKeerRey(model, westergaard.surface, 1e-12,
request.param,
request.param)
solver.setMaxIterations(5000)
solver.solve(loads[request.param])
return model, westergaard
def test_energy(pkr):
model, sol = pkr
traction, displacement = model.getTraction(), model.getDisplacement()
error = norm((traction - sol.pressure)*(displacement - sol.displacement))
error /= norm(sol.pressure * sol.displacement)
assert error < 4e-6
def test_pkr_multi(westergaard):
model_basic = tm.ModelFactory.createModel(tm.model_type.basic_1d, [1.],
[westergaard.n])
model_volume = tm.ModelFactory.createModel(tm.model_type.volume_1d,
[1., 1.],
[20, westergaard.n])
pressures = {}
for model in [model_basic, model_volume]:
print(model)
solver = tm.PolonskyKeerRey(model, westergaard.surface, 1e-12,
tm.PolonskyKeerRey.pressure,
tm.PolonskyKeerRey.pressure)
solver.solve(westergaard.load)
pressures[model] = model.getTraction()
error = norm(pressures[model_basic] - pressures[model_volume][:, 1])\
/ westergaard.load
assert error < 1e-16
if __name__ == "__main__":
print("Test is meant to run with pytest")

Event Timeline