From 7cda1d3bf64ca69e88102b902d1017a44497761c Mon Sep 17 00:00:00 2001 From: ksagiyam Date: Wed, 11 Dec 2024 14:40:08 +0000 Subject: [PATCH] remove SingleValueRestricted --- .../firedrake/submesh/test_submesh_assemble.py | 12 ++++++------ tests/firedrake/submesh/test_submesh_solve.py | 6 +++--- tsfc/fem.py | 18 +----------------- tsfc/kernel_interface/common.py | 10 ++-------- tsfc/kernel_interface/firedrake_loopy.py | 6 ++---- tsfc/modified_terminals.py | 8 ++------ tsfc/ufl_utils.py | 2 -- 7 files changed, 16 insertions(+), 46 deletions(-) diff --git a/tests/firedrake/submesh/test_submesh_assemble.py b/tests/firedrake/submesh/test_submesh_assemble.py index dd99076aa8..2277590c40 100644 --- a/tests/firedrake/submesh/test_submesh_assemble.py +++ b/tests/firedrake/submesh/test_submesh_assemble.py @@ -50,7 +50,7 @@ def test_submesh_assemble_cell_cell_integral_facet(): v0, v1 = split(v) dS0 = Measure("dS", domain=mesh) ds1 = Measure("ds", domain=subm) - a = inner(u1('|'), v0('+')) * dS0 + inner(u0('+'), v1('|')) * ds1(5) + a = inner(u1, v0('+')) * dS0 + inner(u0('+'), v1) * ds1(5) A = assemble(a, mat_type="nest") assert np.allclose(A.M.sparsity[0][0].nnz, [1, 1, 1, 1, 1, 1, 1, 1]) # bc nodes assert np.allclose(A.M.sparsity[0][1].nnz, [4, 4, 4, 4, 4, 4, 4, 4]) @@ -62,7 +62,7 @@ def test_submesh_assemble_cell_cell_integral_facet(): [0., 0., 0., 0., 0., 0., 0., 0.]]) assert np.allclose(A.M[0][1].values, np.transpose(M10)) assert np.allclose(A.M[1][0].values, M10) - b = inner(u1('|'), v0('+')) * ds1(5) + inner(u0('+'), v1('|')) * dS0 + b = inner(u1, v0('+')) * ds1(5) + inner(u0('+'), v1) * dS0 B = assemble(b, mat_type="nest") assert np.allclose(B.M.sparsity[0][0].nnz, [1, 1, 1, 1, 1, 1, 1, 1]) # bc nodes assert np.allclose(B.M.sparsity[0][1].nnz, [4, 4, 4, 4, 4, 4, 4, 4]) @@ -126,7 +126,7 @@ def test_submesh_assemble_cell_cell_cell_cell_integral_various(): V = V_l * V_rl u_l, u_rl = TrialFunctions(V) v_l, v_rl = TestFunctions(V) - a = inner(u_rl('|'), v_l('|')) * ds_l(label_int) + inner(u_l('|'), v_rl('|')) * ds_rl(label_int) + a = inner(u_rl, v_l) * ds_l(label_int) + inner(u_l, v_rl) * ds_rl(label_int) A = assemble(a, mat_type="nest") assert np.allclose(A.M.sparsity[0][0].nnz, [1, 1, 1, 1, 1, 1, 1, 1]) # bc nodes assert np.allclose(A.M.sparsity[0][1].nnz, [4, 4, 4, 4, 0, 0, 0, 0]) @@ -138,7 +138,7 @@ def test_submesh_assemble_cell_cell_cell_cell_integral_various(): [0., 0., 0., 0., 0., 0., 0., 0.]]) assert np.allclose(A.M[0][1].values, np.transpose(M10)) assert np.allclose(A.M[1][0].values, M10) - b = inner(u_rl('|'), v_l('|')) * dS(label_int) + inner(u_l('|'), v_rl('|')) * dS(label_int) + b = inner(u_rl, v_l) * dS(label_int) + inner(u_l, v_rl) * dS(label_int) B = assemble(b, mat_type="nest") assert np.allclose(B.M.sparsity[0][0].nnz, [1, 1, 1, 1, 1, 1, 1, 1]) # bc nodes assert np.allclose(B.M.sparsity[0][1].nnz, [4, 4, 4, 4, 0, 0, 0, 0]) @@ -203,8 +203,8 @@ def test_submesh_assemble_cell_cell_cell_cell_integral_avg(): assert abs(assemble(cell_avg(x_l) * dx_rl) - 2.5) < 5.e-16 assert abs(assemble(facet_avg(y * y) * dS(label_int)) - 1. / 3.) < 5.e-16 assert abs(assemble(facet_avg(y('+') * y('-')) * ds_rl(label_int)) - 1. / 3.) < 5.e-16 - assert abs(assemble(facet_avg(y_rl('|') * y_rl('|')) * dS(label_int)) - 1. / 3.) < 5.e-16 - assert abs(assemble(facet_avg(y_rl('|') * y_rl('|')) * dS_l(label_int)) - 1. / 3.) < 5.e-16 + assert abs(assemble(facet_avg(y_rl * y_rl) * dS(label_int)) - 1. / 3.) < 5.e-16 + assert abs(assemble(facet_avg(y_rl * y_rl) * dS_l(label_int)) - 1. / 3.) < 5.e-16 assert abs(assemble(facet_avg(y_l('+') * y_l('-')) * ds_rl(label_int)) - 1. / 3.) < 5.e-16 diff --git a/tests/firedrake/submesh/test_submesh_solve.py b/tests/firedrake/submesh/test_submesh_solve.py index 361df30910..0c1cbd0384 100644 --- a/tests/firedrake/submesh/test_submesh_solve.py +++ b/tests/firedrake/submesh/test_submesh_solve.py @@ -271,13 +271,13 @@ def _mixed_poisson_solve_2d(nref, degree, quadrilateral, submesh_region): w = Function(W) sigma, u = split(w) a = (inner(sigma, tau) + inner(u, div(tau)) + inner(div(sigma), v)) * dx1 + inner(u - u_exact, v) * dx0(label_submesh_compl) - L = inner(f, v) * dx1 + inner((u('+') + u('-')) / 2., dot(tau('|'), nsub('|'))) * dS0(boun_int) + inner(u_exact('|'), dot(tau('|'), nsub('|'))) * ds0(boun_ext) + L = inner(f, v) * dx1 + inner((u('+') + u('-')) / 2., dot(tau, nsub)) * dS0(boun_int) + inner(u_exact, dot(tau, nsub)) * ds0(boun_ext) solve(a - L == 0, w, bcs=[bc]) # Change domains of integration. w_ = Function(W) sigma_, u_ = split(w_) a_ = (inner(sigma_, tau) + inner(u_, div(tau)) + inner(div(sigma_), v)) * dx1 + inner(u_ - u_exact, v) * dx0(label_submesh_compl) - L_ = inner(f, v) * dx0(label_submesh) + inner((u_('+') + u_('-')) / 2., dot(tau('|'), nsub('|'))) * ds1(boun_int) + inner(u_exact('|'), dot(tau('|'), nsub('|'))) * ds1(boun_ext) + L_ = inner(f, v) * dx0(label_submesh) + inner((u_('+') + u_('-')) / 2., dot(tau, nsub)) * ds1(boun_int) + inner(u_exact, dot(tau, nsub)) * ds1(boun_ext) solve(a_ - L_ == 0, w_, bcs=[bc]) assert assemble(inner(sigma_ - sigma, sigma_ - sigma) * dx1) < 1.e-20 assert assemble(inner(u_ - u, u_ - u) * dx0(label_submesh)) < 1.e-20 @@ -401,7 +401,7 @@ def _mixed_poisson_solve_3d(hexahedral, degree, submesh_region): w = Function(W) sigma, u = split(w) a = (inner(sigma, tau) + inner(u, div(tau)) + inner(div(sigma), v)) * dx1 + inner(u - u_exact, v) * dx0(label_submesh_compl) - L = inner(f, v) * dx1 + inner((u('+') + u('-')) / 2., dot(tau('|'), nsub('|'))) * ds1(boun_int) + inner(u_exact('|'), dot(tau('|'), nsub('|'))) * ds0(boun_ext) + L = inner(f, v) * dx1 + inner((u('+') + u('-')) / 2., dot(tau, nsub)) * ds1(boun_int) + inner(u_exact, dot(tau, nsub)) * ds0(boun_ext) solve(a - L == 0, w, bcs=[bc]) sigma_error = sqrt(assemble(inner(sigma - sigma_exact, sigma - sigma_exact) * dx1)) u_error = sqrt(assemble(inner(u - u_exact, u - u_exact) * dx0(label_submesh))) diff --git a/tsfc/fem.py b/tsfc/fem.py index 8f15d2d528..333d017a62 100644 --- a/tsfc/fem.py +++ b/tsfc/fem.py @@ -27,7 +27,7 @@ PositiveRestricted, QuadratureWeight, ReferenceCellEdgeVectors, ReferenceCellVolume, ReferenceFacetVolume, ReferenceNormal, - SingleValueRestricted, SpatialCoordinate) + SpatialCoordinate) from ufl.corealg.map_dag import map_expr_dag, map_expr_dags from ufl.corealg.multifunction import MultiFunction from ufl.domain import extract_unique_domain @@ -171,10 +171,6 @@ def jacobian_at(self, point): expr = PositiveRestricted(expr) elif self.mt.restriction == '-': expr = NegativeRestricted(expr) - elif self.mt.restriction == '|': - expr = SingleValueRestricted(expr) - elif self.mt.restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") config = {"point_set": PointSingleton(point)} config.update(self.config) context = PointSetContext(**config) @@ -187,10 +183,6 @@ def detJ_at(self, point): expr = PositiveRestricted(expr) elif self.mt.restriction == '-': expr = NegativeRestricted(expr) - elif self.mt.restriction == '|': - expr = SingleValueRestricted(expr) - elif self.mt.restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") config = {"point_set": PointSingleton(point)} config.update(self.config) context = PointSetContext(**config) @@ -234,10 +226,6 @@ def physical_edge_lengths(self): expr = PositiveRestricted(expr) elif self.mt.restriction == '-': expr = NegativeRestricted(expr) - elif self.mt.restriction == '|': - expr = SingleValueRestricted(expr) - elif self.mt.restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") cell = self.interface.fiat_cell sd = cell.get_spatial_dimension() @@ -262,10 +250,6 @@ def physical_points(self, point_set, entity=None): expr = PositiveRestricted(expr) elif self.mt.restriction == '-': expr = NegativeRestricted(expr) - elif self.mt.restriction == '|': - expr = SingleValueRestricted(expr) - elif self.mt.restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") config = {"point_set": point_set} config.update(self.config) if entity is not None: diff --git a/tsfc/kernel_interface/common.py b/tsfc/kernel_interface/common.py index 385b2f09dd..dcd389dd4e 100644 --- a/tsfc/kernel_interface/common.py +++ b/tsfc/kernel_interface/common.py @@ -54,13 +54,11 @@ def coordinate(self, domain): def coefficient(self, ufl_coefficient, restriction): """A function that maps :class:`ufl.Coefficient`s to GEM expressions.""" - if restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") kernel_arg = self.coefficient_map[ufl_coefficient] domain = extract_unique_domain(ufl_coefficient) if ufl_coefficient.ufl_element().family() == 'Real': return kernel_arg - elif not self._domain_integral_type_map[domain].startswith("interior_facet"): # '|' is for exterior_facet + elif not self._domain_integral_type_map[domain].startswith("interior_facet"): return kernel_arg else: return kernel_arg[{'+': 0, '-': 1}[restriction]] @@ -70,11 +68,9 @@ def constant(self, const): def cell_orientation(self, domain, restriction): """Cell orientation as a GEM expression.""" - if restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") if not hasattr(self, "_cell_orientations"): raise RuntimeError("Haven't called set_cell_orientations") - f = {None: 0, '|': 0, '+': 0, '-': 1}[restriction] + f = {None: 0, '+': 0, '-': 1}[restriction] co_int = self._cell_orientations[domain][f] return gem.Conditional(gem.Comparison("==", co_int, gem.Literal(1)), gem.Literal(-1), @@ -83,8 +79,6 @@ def cell_orientation(self, domain, restriction): gem.Literal(numpy.nan))) def cell_size(self, domain, restriction): - if restriction == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") if not hasattr(self, "_cell_sizes"): raise RuntimeError("Haven't called set_cell_sizes") if self._domain_integral_type_map[domain].startswith("interior_facet"): diff --git a/tsfc/kernel_interface/firedrake_loopy.py b/tsfc/kernel_interface/firedrake_loopy.py index fb522edcc2..78cd46ae02 100644 --- a/tsfc/kernel_interface/firedrake_loopy.py +++ b/tsfc/kernel_interface/firedrake_loopy.py @@ -311,8 +311,7 @@ def set_entity_numbers(self, domains): integral_type = self.integral_data_info.domain_integral_type_map[domain] if integral_type in ['exterior_facet', 'exterior_facet_vert']: facet = gem.Variable(f'facet_{i}', (1,), dtype=gem.uint_type) - self._entity_numbers[domain] = {None: gem.VariableIndex(gem.Indexed(facet, (0,))), - '|': gem.VariableIndex(gem.Indexed(facet, (0,)))} + self._entity_numbers[domain] = {None: gem.VariableIndex(gem.Indexed(facet, (0,))),} elif integral_type in ['interior_facet', 'interior_facet_vert']: facet = gem.Variable(f'facet_{i}', (2,), dtype=gem.uint_type) self._entity_numbers[domain] = { @@ -336,8 +335,7 @@ def set_entity_orientations(self, domains): integral_type = self.integral_data_info.domain_integral_type_map[domain] if integral_type in ['exterior_facet', 'exterior_facet_vert']: facet_orientation = gem.Variable(f'facet_orientation_{i}', (1,), dtype=gem.uint_type) - self._entity_orientations[domain] = {None: gem.OrientationVariableIndex(gem.Indexed(facet_orientation, (0,))), - '|': gem.OrientationVariableIndex(gem.Indexed(facet_orientation, (0,)))} + self._entity_orientations[domain] = {None: gem.OrientationVariableIndex(gem.Indexed(facet_orientation, (0,))),} elif integral_type in ['interior_facet', 'interior_facet_vert']: facet_orientation = gem.Variable(f'facet_orientation_{i}', (2,), dtype=gem.uint_type) self._entity_orientations[domain] = { diff --git a/tsfc/modified_terminals.py b/tsfc/modified_terminals.py index 9e694f2e69..8c5162bf97 100644 --- a/tsfc/modified_terminals.py +++ b/tsfc/modified_terminals.py @@ -21,7 +21,7 @@ """Definitions of 'modified terminals', a core concept in uflacs.""" from ufl.classes import (ReferenceValue, ReferenceGrad, - NegativeRestricted, PositiveRestricted, SingleValueRestricted, ToBeRestricted, + NegativeRestricted, PositiveRestricted, Restricted, ConstantValue, Jacobian, SpatialCoordinate, Zero) from ufl.checks import is_cellwise_constant @@ -39,7 +39,7 @@ class ModifiedTerminal(object): terminal - the underlying Terminal object local_derivatives - tuple of ints, each meaning derivative in that local direction reference_value - bool, whether this is represented in reference frame - restriction - None, '+', '-', '|', or '?' + restriction - None, '+' or '-' """ def __init__(self, expr, terminal, local_derivatives, restriction, reference_value): @@ -175,9 +175,5 @@ def construct_modified_terminal(mt, terminal): expr = PositiveRestricted(expr) elif mt.restriction == '-': expr = NegativeRestricted(expr) - elif mt.restriction == '|': - expr = SingleValueRestricted(expr) - elif mt.restriction == '?': - expr = ToBeRestricted(expr) return expr diff --git a/tsfc/ufl_utils.py b/tsfc/ufl_utils.py index 0d7413400c..9c6065c540 100644 --- a/tsfc/ufl_utils.py +++ b/tsfc/ufl_utils.py @@ -258,8 +258,6 @@ def modified_terminal(self, o): mt = analyse_modified_terminal(o) t = mt.terminal r = mt.restriction - if r == '?': - raise RuntimeError("Not expecting '?' restriction at this stage") if isinstance(t, Argument) and r in ['+', '-']: if r == self.restrictions[t.number()]: return o