FEniCS / FEniCS/ufl

External ufl types.

Open
#127 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
150
Forks
79
Avg merge
1d 16h
Merged PRs (30d)
10

Description

When adding an UFL type using the `@ufl_type` decorator this seems to lead to errors in, for example, the `Transformer` class from `ufl.algorithms`. Example, somewhere in some external (to ufl) code:
```
import ufl
from ufl.core.ufl_type import ufl_type
@ufl_type(is_scalar=True)
class BoundaryId(ufl.geometry.GeometricFacetQuantity):
"""UFL boundary id: can be used in a conditional to fix the desired boundary id."""
__slots__ = ()
name = "facetid"
```

This leads to an index error in https://github.com/FEniCS/ufl/blob/4e3868dee951504484b7f85e2c0e477ef7894c23/ufl/algorithms/transformer.py#L89 It can be fixed by adding the new class manually to `all_ufl_classes`:
```
from ufl.classes import all_ufl_classes
all_ufl_classes.add(BoundaryId)
```

However, this can cause problems when other Python modules using UFL are included before these two lines, because it can mess up the index order in `all_ufl_classes`. So the result is, that all other modules using UFL should be included after this statement.

**So the question is**: What is the correct way of adding external UFL types (besides using `@ufl_type`)? Or is this a bug and the modification of the UFL internal lists and sets should be done inside the `@ufl_type` functions?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.