Skip to content

Commit

Permalink
TODO: action and algorithms/formtransformation
Browse files Browse the repository at this point in the history
  • Loading branch information
ksagiyam committed Sep 14, 2023
1 parent 00aae76 commit 342a923
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
14 changes: 13 additions & 1 deletion ufl/algorithms/checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ufl.form import Form
from ufl.argument import Argument
from ufl.coefficient import Coefficient
from ufl.subspace import Subspace
from ufl.constantvalue import is_true_ufl_scalar

# UFL algorithms
Expand Down Expand Up @@ -52,9 +53,10 @@ def validate_form(form): # TODO: Can we make this return a list of errors inste
elif len(cells) > 1:
errors.append(f"Multiple cell definitions in form: {cells}")

# Check that no Coefficient or Argument instance have the same
# Check that no Coefficient/Subspace or Argument instance have the same
# count unless they are the same
coefficients = {}
subspaces = {}
arguments = {}
for e in iter_expressions(form):
for f in traverse_unique_terminals(e):
Expand All @@ -68,6 +70,16 @@ def validate_form(form): # TODO: Can we make this return a list of errors inste
else:
coefficients[c] = f

if isinstance(f, Subspace):
c = f.count()
if c in subspaces:
g = subspaces[c]
if f is not g:
errors.append("Found different Subspaces with "
f"same count: {f} and {g}.")
else:
subspaces[c] = f

elif isinstance(f, Argument):
n = f.number()
p = f.part()
Expand Down
5 changes: 4 additions & 1 deletion ufl/algorithms/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import hashlib
from ufl.classes import (Label,
Index, MultiIndex,
Coefficient, Argument,
Coefficient, Subspace, Argument,
GeometricQuantity, ConstantValue, Constant,
ExprList, ExprMapping)
from ufl.corealg.traversal import traverse_unique_terminals, unique_post_traversal
Expand Down Expand Up @@ -58,6 +58,9 @@ def compute_terminal_hashdata(expressions, renumbering):
elif isinstance(expr, Coefficient):
data = expr._ufl_signature_data_(renumbering)

elif isinstance(expr, Subspace):
data = expr._ufl_signature_data_(renumbering)

elif isinstance(expr, Constant):
data = expr._ufl_signature_data_(renumbering)

Expand Down
9 changes: 7 additions & 2 deletions ufl/algorithms/strip_terminal_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
data-carrying objects have been extracted to a mapping."""

from ufl.classes import Form, Integral
from ufl.classes import Argument, Coefficient, Constant
from ufl.classes import Argument, Coefficient, Subspace, Constant
from ufl.classes import FunctionSpace, TensorProductFunctionSpace, MixedFunctionSpace
from ufl.classes import Mesh, MeshView, TensorProductMesh
from ufl.algorithms.replace import replace
Expand All @@ -26,6 +26,11 @@ def coefficient(self, o):
o.count())
return self.mapping.setdefault(o, o_new)

def subspace(self, o):
o_new = Subspace(strip_function_space(o.ufl_function_space()),
o.count())
return self.mapping.setdefault(o, o_new)

def constant(self, o):
o_new = Constant(strip_domain(o.ufl_domain()), o.ufl_shape,
o.count())
Expand Down Expand Up @@ -118,4 +123,4 @@ def strip_domain(domain):
meshes = [strip_domain(mesh) for mesh in domain.ufl_meshes()]
return TensorProductMesh(meshes, domain.ufl_id())
else:
raise NotImplementedError(f"{type(domain)} cannot be stripped")
raise NotImplemen`tedError(f"{type(domain)} cannot be stripped")
4 changes: 3 additions & 1 deletion ufl/sorting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from ufl.core.expr import Expr
from ufl.argument import Argument
from ufl.coefficient import Coefficient
from ufl.subspace import Subspace
from ufl.core.multiindex import FixedIndex, MultiIndex
from ufl.variable import Label

Expand Down Expand Up @@ -61,7 +62,7 @@ def _cmp_label(a, b):


def _cmp_coefficient(a, b):
# It's ok to compare relative counts for Coefficients,
# It's ok to compare relative counts for Coefficients/Subspaces,
# since their ordering is a property of the form
x, y = a._count, b._count
if x < y:
Expand Down Expand Up @@ -97,6 +98,7 @@ def _cmp_terminal_by_repr(a, b):
_terminal_cmps[MultiIndex._ufl_typecode_] = _cmp_multi_index
_terminal_cmps[Argument._ufl_typecode_] = _cmp_argument
_terminal_cmps[Coefficient._ufl_typecode_] = _cmp_coefficient
_terminal_cmps[Subspace._ufl_typecode_] = _cmp_coefficient
_terminal_cmps[Label._ufl_typecode_] = _cmp_label


Expand Down
4 changes: 2 additions & 2 deletions ufl/split_functions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
"Algorithm for splitting a Coefficient or Argument into subfunctions."
"Algorithm for splitting a Coefficient/Subspace or Argument into subfunctions."

# Copyright (C) 2008-2016 Martin Sandve Alnæs
#
Expand All @@ -18,7 +18,7 @@


def split(v):
"""UFL operator: If v is a Coefficient or Argument in a mixed space, returns
"""UFL operator: If v is a Coefficient/Subspace or Argument in a mixed space, returns
a tuple with the function components corresponding to the subelements."""

# Default range is all of v
Expand Down

0 comments on commit 342a923

Please sign in to comment.