This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged in dham/gauss_legendre (pull request #17)
gauss_legendre quadrature and elements
- Loading branch information
Showing
6 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (C) 2015 Imperial College London and others. | ||
# | ||
# This file is part of FIAT. | ||
# | ||
# FIAT 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. | ||
# | ||
# FIAT 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 FIAT. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Written by David A. Ham (david.ham@imperial.ac.uk), 2015 | ||
|
||
from __future__ import absolute_import, print_function, division | ||
from . import finite_element, polynomial_set, dual_set, functional, quadrature | ||
from .reference_element import LINE | ||
|
||
|
||
class GaussLegendreDualSet(dual_set.DualSet): | ||
"""The dual basis for 1D discontinuous elements with nodes at the | ||
Gauss-Legendre points.""" | ||
def __init__(self, ref_el, degree): | ||
entity_ids = {0: {0: [], 1: []}, | ||
1: {0: list(range(0, degree+1))}} | ||
l = quadrature.GaussLegendreQuadratureLineRule(ref_el, degree+1) | ||
nodes = [functional.PointEvaluation(ref_el, x) for x in l.pts] | ||
|
||
dual_set.DualSet.__init__(self, nodes, ref_el, entity_ids) | ||
|
||
|
||
class GaussLegendre(finite_element.FiniteElement): | ||
"""1D discontinuous element with nodes at the Gauss-Legendre points.""" | ||
def __init__(self, ref_el, degree): | ||
if ref_el.shape != LINE: | ||
raise ValueError("Gauss-Legendre elements are only defined in one dimension.") | ||
poly_set = polynomial_set.ONPolynomialSet(ref_el, degree) | ||
dual = GaussLegendreDualSet(ref_el, degree) | ||
finite_element.FiniteElement.__init__(self, poly_set, dual, degree) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright (C) 2016 Imperial College London and others | ||
# | ||
# This file is part of FIAT. | ||
# | ||
# FIAT 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. | ||
# | ||
# FIAT 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 FIAT. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
# Authors: | ||
# | ||
# David Ham | ||
|
||
from __future__ import absolute_import, print_function, division | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
|
||
@pytest.mark.parametrize("degree", range(1, 7)) | ||
def test_gl_basis_values(degree): | ||
"""Ensure that integrating a simple monomial produces the expected results.""" | ||
from FIAT import ufc_simplex, GaussLegendre, make_quadrature | ||
|
||
s = ufc_simplex(1) | ||
q = make_quadrature(s, degree + 1) | ||
|
||
fe = GaussLegendre(s, degree) | ||
tab = fe.tabulate(0, q.pts)[(0,)] | ||
|
||
for test_degree in range(degree + 1): | ||
coefs = [n(lambda x: x[0]**test_degree) for n in fe.dual.nodes] | ||
integral = np.dot(coefs, np.dot(tab, q.wts)) | ||
reference = np.dot([x[0]**test_degree | ||
for x in q.pts], q.wts) | ||
assert np.allclose(integral, reference, rtol=1e-14) | ||
|
||
|
||
if __name__ == '__main__': | ||
import os | ||
pytest.main(os.path.abspath(__file__)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters