| 1 |
# Copyright (C) 2016 Imperial College London and others |
| 2 |
# |
| 3 |
# This file is part of FIAT. |
| 4 |
# |
| 5 |
# FIAT is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU Lesser General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# FIAT is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU Lesser General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU Lesser General Public License |
| 16 |
# along with FIAT. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
# |
| 18 |
# Authors: |
| 19 |
# |
| 20 |
# David Ham |
| 21 |
|
| 22 |
import pytest |
| 23 |
import numpy as np |
| 24 |
|
| 25 |
|
| 26 |
@pytest.mark.parametrize("dim, degree", [(dim, degree) |
| 27 |
for dim in range(1, 4) |
| 28 |
for degree in range(4)]) |
| 29 |
def test_basis_values(dim, degree): |
| 30 |
"""Ensure that integrating a simple monomial produces the expected results.""" |
| 31 |
from FIAT import ufc_simplex, DiscontinuousTaylor, make_quadrature |
| 32 |
|
| 33 |
s = ufc_simplex(dim) |
| 34 |
q = make_quadrature(s, degree + 1) |
| 35 |
|
| 36 |
fe = DiscontinuousTaylor(s, degree) |
| 37 |
tab = fe.tabulate(0, q.pts)[(0,) * dim] |
| 38 |
|
| 39 |
for test_degree in range(degree + 1): |
| 40 |
coefs = [n(lambda x: x[0]**test_degree) for n in fe.dual.nodes] |
| 41 |
integral = np.float(np.dot(coefs, np.dot(tab, q.wts))) |
| 42 |
reference = np.dot([x[0]**test_degree |
| 43 |
for x in q.pts], q.wts) |
| 44 |
assert np.isclose(integral, reference, rtol=1e-14) |
| 45 |
|
| 46 |
|
| 47 |
if __name__ == '__main__': |
| 48 |
import os |
| 49 |
pytest.main(os.path.abspath(__file__)) |