diff --git a/FIAT/brezzi_douglas_marini.py b/FIAT/brezzi_douglas_marini.py index 9bde96d6..249c144b 100644 --- a/FIAT/brezzi_douglas_marini.py +++ b/FIAT/brezzi_douglas_marini.py @@ -103,11 +103,9 @@ class BrezziDouglasMarini(finite_element.CiarletElement): def __init__(self, ref_el, degree, variant=None): if variant is None: - variant = "point" - print('Warning: Variant of BDM element will change from point evaluation to integral evaluation.' - 'You should project into variant="integral"') - #Replace by the following in a month time - #variant = "integral" + variant = "point" + print('Warning: Variant of BDM element will change from point evaluation to integral evaluation.' + 'You should project into variant="integral"') if not (variant == "point" or "integral" in variant): raise ValueError('Choose either variant="point" or variant="integral"' @@ -119,7 +117,7 @@ def __init__(self, ref_el, degree, variant=None): elif "integral" in variant: try: quad_deg = int(''.join(filter(str.isdigit, variant))) - except: + except ValueError: raise ValueError("Wrong format for variant") if quad_deg < degree + 1: raise ValueError("Warning, quadrature degree should be at least %s" % (degree + 1)) diff --git a/FIAT/functional.py b/FIAT/functional.py index e6f553e2..257d53d3 100644 --- a/FIAT/functional.py +++ b/FIAT/functional.py @@ -389,7 +389,6 @@ def tostr(self): class IntegralMomentOfEdgeTangentEvaluation(Functional): - r""" \int_e v\cdot t ds @@ -430,11 +429,9 @@ def tostr(self): return "(u.t%d)(%s)" % (self.tno, ','.join(x),) - class MonkIntegralMoment(Functional): def __init__(self, ref_el, Q, P_at_qpts, facet): sd = ref_el.get_spatial_dimension() - area = ref_el.volume_of_subcomplex(sd - 1, facet) weights = Q.get_weights() pt_dict = OrderedDict() transform = ref_el.get_entity_transform(sd-1, facet) @@ -445,7 +442,6 @@ def __init__(self, ref_el, Q, P_at_qpts, facet): class IntegralMomentOfFaceTangentEvaluation(Functional): - r""" \int_F v \times n \cdot p ds @@ -457,7 +453,6 @@ class IntegralMomentOfFaceTangentEvaluation(Functional): :arg facet: which facet. """ def __init__(self, ref_el, Q, P_at_qpts, facet): - #import ipdb; ipdb.set_trace() P_at_qpts = [[P_at_qpts[0][i], P_at_qpts[1][i], P_at_qpts[2][i]] for i in range(P_at_qpts.shape[1])] n = ref_el.compute_scaled_normal(facet) @@ -467,17 +462,15 @@ def __init__(self, ref_el, Q, P_at_qpts, facet): weights = Q.get_weights() pt_dict = OrderedDict() for pt, wgt, phi in zip(pts, weights, P_at_qpts): -# pt_dict[pt] = [(wgt*(-n[2]*phi[1]+n[1]*phi[2]), (0, )), -# (wgt*(n[2]*phi[0]-n[0]*phi[2]), (1, )), -# (wgt*(-n[1]*phi[0]+n[0]*phi[1]), (2, ))] - phixn = [phi[1]*n[2] - phi[2]*n[1], - phi[2]*n[0] - phi[0]*n[2], - phi[0]*n[1] - phi[1]*n[0]] - pt_dict[pt] = [(wgt*(-n[2]*phixn[1]+n[1]*phixn[2]), (0, )), - (wgt*(n[2]*phixn[0]-n[0]*phixn[2]), (1, )), - (wgt*(-n[1]*phixn[0]+n[0]*phixn[1]), (2, ))] + phixn = [phi[1]*n[2] - phi[2]*n[1], + phi[2]*n[0] - phi[0]*n[2], + phi[0]*n[1] - phi[1]*n[0]] + pt_dict[pt] = [(wgt*(-n[2]*phixn[1]+n[1]*phixn[2]), (0, )), + (wgt*(n[2]*phixn[0]-n[0]*phixn[2]), (1, )), + (wgt*(-n[1]*phixn[0]+n[0]*phixn[1]), (2, ))] super().__init__(ref_el, (sd, ), pt_dict, {}, "IntegralMomentOfFaceTangentEvaluation") + class PointScaledNormalEvaluation(Functional): """Implements the evaluation of the normal component of a vector at a point on a facet of codimension 1, where the normal is scaled by @@ -497,7 +490,6 @@ def tostr(self): class IntegralMomentOfScaledNormalEvaluation(Functional): - r""" \int_F v\cdot n p ds diff --git a/FIAT/nedelec.py b/FIAT/nedelec.py index ed17159e..e4434c46 100644 --- a/FIAT/nedelec.py +++ b/FIAT/nedelec.py @@ -10,6 +10,7 @@ from itertools import chain import numpy + def NedelecSpace2D(ref_el, k): """Constructs a basis for the 2d H(curl) space of the first kind which is (P_k)^2 + P_k rot( x )""" @@ -240,8 +241,8 @@ def __init__(self, ref_el, degree, variant, quad_deg): t = ref_el.get_topology() if variant == "integral": - #edge nodes are \int_F v\cdot t p ds where p \in P_{q-1}(edge) - #degree is q - 1 + # edge nodes are \int_F v\cdot t p ds where p \in P_{q-1}(edge) + # degree is q - 1 edge = ref_el.get_facet_element().get_facet_element() Q = quadrature.make_quadrature(edge, quad_deg) Pq = polynomial_set.ONPolynomialSet(edge, degree) @@ -261,17 +262,16 @@ def __init__(self, ref_el, degree, variant, quad_deg): Pq_at_qpts = Pq.tabulate(Q.get_points())[tuple([0]*(2))] for f in range(len(t[2])): - n = ref_el.compute_scaled_normal(f) - #R is used to map [1,0,0] to tangent1 and [0,1,0] to tangent2 + # R is used to map [1,0,0] to tangent1 and [0,1,0] to tangent2 R = ref_el.compute_face_tangents(f) - #Skip last functionals because we only want p with p \cdot n = 0 + # Skip last functionals because we only want p with p \cdot n = 0 for i in range(int(Pq_at_qpts.shape[0]/3)*2): phi = Pq_at_qpts[i, ...] phi = numpy.matmul(phi[:-1, ...].T, R) nodes.append(functional.MonkIntegralMoment(ref_el, Q, phi, f)) - #internal nodes. These are \int_T v \cdot p dx where p \in P_{q-3}^3(T) + # internal nodes. These are \int_T v \cdot p dx where p \in P_{q-3}^3(T) if degree > 1: Q = quadrature.make_quadrature(ref_el, quad_deg) qpts = Q.get_points() @@ -356,11 +356,9 @@ def __init__(self, ref_el, q, variant=None): degree = q - 1 if variant is None: - variant = "point" - print('Warning: Variant of Nedelec element will change from point evaluation to integral evaluation.' - 'You should project into variant="integral"') - #Replace by the following in a month time - #variant = "integral" + variant = "point" + print('Warning: Variant of Nedelec element will change from point evaluation to integral evaluation.' + 'You should project into variant="integral"') if not (variant == "point" or "integral" in variant): raise ValueError('Choose either variant="point" or variant="integral"' @@ -372,7 +370,7 @@ def __init__(self, ref_el, q, variant=None): elif "integral" in variant: try: quad_deg = int(''.join(filter(str.isdigit, variant))) - except: + except ValueError: raise ValueError("Wrong format for variant") if quad_deg < degree + 1: raise ValueError("Warning, quadrature degree should be at least %s" % (degree + 1)) diff --git a/FIAT/nedelec_second_kind.py b/FIAT/nedelec_second_kind.py index 5eddefde..862b0de4 100644 --- a/FIAT/nedelec_second_kind.py +++ b/FIAT/nedelec_second_kind.py @@ -16,8 +16,7 @@ from FIAT.quadrature import make_quadrature, UFCTetrahedronFaceQuadratureRule from FIAT.reference_element import UFCTetrahedron -from FIAT import (polynomial_set, expansions, quadrature, dual_set, - finite_element, functional) +from FIAT import polynomial_set, quadrature, functional class NedelecSecondKindDual(DualSet): @@ -103,11 +102,11 @@ def _generate_edge_dofs(self, cell, degree, offset, variant, quad_deg): Pq = polynomial_set.ONPolynomialSet(edge, degree) Pq_at_qpts = Pq.tabulate(Q.get_points())[tuple([0]*(1))] for e in range(len(cell.get_topology()[1])): - for i in range(Pq_at_qpts.shape[0]): - phi = Pq_at_qpts[i, :] - dofs.append(functional.IntegralMomentOfEdgeTangentEvaluation(cell, Q, phi, e)) - jj = Pq_at_qpts.shape[0] * e - ids[e] = list(range(offset + jj, offset + jj + Pq_at_qpts.shape[0])) + for i in range(Pq_at_qpts.shape[0]): + phi = Pq_at_qpts[i, :] + dofs.append(functional.IntegralMomentOfEdgeTangentEvaluation(cell, Q, phi, e)) + jj = Pq_at_qpts.shape[0] * e + ids[e] = list(range(offset + jj, offset + jj + Pq_at_qpts.shape[0])) elif variant == "point": for edge in range(len(cell.get_topology()[1])): @@ -224,11 +223,9 @@ class NedelecSecondKind(CiarletElement): def __init__(self, cell, degree, variant=None): if variant is None: - variant = "point" - print('Warning: Variant of Nedelec 2nd kind element will change from point evaluation to integral evaluation.' - 'You should project into variant="integral"') - #Replace by the following in a month time - #variant = "integral" + variant = "point" + print('Warning: Variant of Nedelec 2nd kind element will change from point evaluation to integral evaluation.' + 'You should project into variant="integral"') if not (variant == "point" or "integral" in variant): raise ValueError('Choose either variant="point" or variant="integral"' @@ -240,7 +237,7 @@ def __init__(self, cell, degree, variant=None): elif "integral" in variant: try: quad_deg = int(''.join(filter(str.isdigit, variant))) - except: + except ValueError: raise ValueError("Wrong format for variant") if quad_deg < degree + 1: raise ValueError("Warning, quadrature degree should be at least %s" % (degree + 1)) diff --git a/FIAT/raviart_thomas.py b/FIAT/raviart_thomas.py index a28f63f3..935d17b0 100644 --- a/FIAT/raviart_thomas.py +++ b/FIAT/raviart_thomas.py @@ -150,11 +150,9 @@ def __init__(self, ref_el, q, variant=None): degree = q - 1 if variant is None: - variant = "point" - print('Warning: Variant of Raviart-Thomas element will change from point evaluation to integral evaluation.' - 'You should project into variant="integral"') - #Replace by the following in a month time - #variant = "integral" + variant = "point" + print('Warning: Variant of Raviart-Thomas element will change from point evaluation to integral evaluation.' + 'You should project into variant="integral"') if not (variant == "point" or "integral" in variant): raise ValueError('Choose either variant="point" or variant="integral"' @@ -166,7 +164,7 @@ def __init__(self, ref_el, q, variant=None): elif "integral" in variant: try: quad_deg = int(''.join(filter(str.isdigit, variant))) - except: + except ValueError: raise ValueError("Wrong format for variant") if quad_deg < degree + 1: raise ValueError("Warning, quadrature degree should be at least %s" % (degree + 1))