Skip to content

Commit

Permalink
remove SingleValueRestricted
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Dec 11, 2024
1 parent 3224da5 commit 7cda1d3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 46 deletions.
12 changes: 6 additions & 6 deletions tests/firedrake/submesh/test_submesh_assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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


Expand Down
6 changes: 3 additions & 3 deletions tests/firedrake/submesh/test_submesh_solve.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down
18 changes: 1 addition & 17 deletions tsfc/fem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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:
Expand Down
10 changes: 2 additions & 8 deletions tsfc/kernel_interface/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand All @@ -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),
Expand All @@ -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"):
Expand Down
6 changes: 2 additions & 4 deletions tsfc/kernel_interface/firedrake_loopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,))),}

Check failure on line 314 in tsfc/kernel_interface/firedrake_loopy.py

View workflow job for this annotation

GitHub Actions / Run linter

E231

tsfc/kernel_interface/firedrake_loopy.py:314:98: E231 missing whitespace after ','
elif integral_type in ['interior_facet', 'interior_facet_vert']:
facet = gem.Variable(f'facet_{i}', (2,), dtype=gem.uint_type)
self._entity_numbers[domain] = {
Expand All @@ -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,))),}

Check failure on line 338 in tsfc/kernel_interface/firedrake_loopy.py

View workflow job for this annotation

GitHub Actions / Run linter

E231

tsfc/kernel_interface/firedrake_loopy.py:338:126: E231 missing whitespace after ','
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] = {
Expand Down
8 changes: 2 additions & 6 deletions tsfc/modified_terminals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions tsfc/ufl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7cda1d3

Please sign in to comment.