Skip to content

Commit

Permalink
remove_indices
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Apr 10, 2024
1 parent bc1a5e0 commit ddc1759
Showing 1 changed file with 0 additions and 94 deletions.
94 changes: 0 additions & 94 deletions tsfc/ufl_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,97 +496,3 @@ class TSFCConstantMixin:

def __init__(self):
pass


class FixedIndexRemover(MultiFunction):

def __init__(self, fimap):
MultiFunction.__init__(self)
self.fimap = fimap

expr = MultiFunction.reuse_if_untouched

def zero(self, o):
free_indices = []
index_dimensions = []
for i, d in zip(o.ufl_free_indices, o.ufl_index_dimensions):
if Index(i) in self.fimap:
ind_j = self.fimap[Index(i)]
if not isinstance(ind_j, FixedIndex):
free_indices.append(ind_j.count())
index_dimensions.append(d)
else:
free_indices.append(i)
index_dimensions.append(d)
return Zero(shape=o.ufl_shape, free_indices=tuple(free_indices), index_dimensions=tuple(index_dimensions))

def list_tensor(self, o):
rule = FixedIndexRemover(self.fimap)
cc = []
for o1 in o.ufl_operands:
comp = map_expr_dag(rule, o1)
cc.append(comp)
return ListTensor(*cc)

def multi_index(self, o):
return MultiIndex(tuple(self.fimap.get(i, i) for i in o.indices()))


class IndexRemover(MultiFunction):

def __init__(self):
MultiFunction.__init__(self)

expr = MultiFunction.reuse_if_untouched

def _zero_simplify(self, o):
operand, = o.ufl_operands
rule = IndexRemover()
operand = map_expr_dag(rule, operand)
if isinstance(operand, Zero):
return Zero(shape=o.ufl_shape, free_indices=o.ufl_free_indices, index_dimensions=o.ufl_index_dimensions)
else:
return o._ufl_expr_reconstruct_(operand)

def indexed(self, o):
o1, i1 = o.ufl_operands
if isinstance(o1, ComponentTensor):
o2, i2 = o1.ufl_operands
fimap = dict(zip(i2.indices(), i1.indices(), strict=True))
rule = FixedIndexRemover(fimap)
v = map_expr_dag(rule, o2)
rule = IndexRemover()
return map_expr_dag(rule, v)
elif isinstance(o1, ListTensor):
if isinstance(i1[0], FixedIndex):
o1 = o1.ufl_operands[i1[0]._value]
rule = IndexRemover()
if len(i1) > 1:
i1 = MultiIndex(i1[1:])
return map_expr_dag(rule, Indexed(o1, i1))
else:
return map_expr_dag(rule, o1)
rule = IndexRemover()
o1 = map_expr_dag(rule, o1)
return Indexed(o1, i1)

# Do something nicer
positive_restricted = _zero_simplify
negative_restricted = _zero_simplify
single_value_restricted = _zero_simplify
to_be_restricted = _zero_simplify
reference_grad = _zero_simplify
reference_value = _zero_simplify


def remove_indices(o):
if isinstance(o, Form):
integrals = []
for integral in o.integrals():
integrand = remove_indices(integral.integrand())
if not isinstance(integrand, Zero):
integrals.append(integral.reconstruct(integrand=integrand))
return o._ufl_expr_reconstruct_(integrals)
else:
rule = IndexRemover()
return map_expr_dag(rule, o)

0 comments on commit ddc1759

Please sign in to comment.