Page MenuHomec4science

test_matvec.py
No OneTemporary

File Metadata

Created
Mon, May 6, 07:34

test_matvec.py

# -*- coding: utf-8 -*-
#
# Copyright (©) 2016-2022 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/>.
import pytest
import numpy as np
import tamaas as tm
from numpy.testing import assert_allclose
from test_dumper import model_fixture # noqa
linalg = pytest.importorskip('scipy.sparse.linalg')
def test_matvec_westergaard(model_fixture):
m = model_fixture
m.be_engine.registerNeumann()
op = m.operators['Westergaard::neumann']
linop = linalg.aslinearoperator(op)
x = [np.linspace(0, L, N, endpoint=False)
for (L, N) in zip(m.boundary_system_size, m.boundary_shape)]
coords = np.meshgrid(*x, indexing='ij')
t = m.traction
res = np.zeros_like(m.displacement)
volume = len(m.shape) != len(m.boundary_shape)
basic = m.type in (tm.model_type.basic_1d, tm.model_type.basic_2d)
# Adapting to special cases
if basic:
t = t[..., np.newaxis]
res = res[..., np.newaxis]
t[:] = 0
t[..., -1] = np.sin(2 * np.pi * coords[0])
# Computing using native API
op(t, res)
# Only look at surface displacement
if volume:
res = res[0]
# Computing using LinearOperator API
y = np.reshape(linop * np.ravel(t), res.shape)
assert_allclose(res, y)

Event Timeline