FEniCS / FEniCS/ffcx

Create alias for elements

Open
#547 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
192
Forks
45
Avg merge
1d 11h
Merged PRs (30d)
16

Description

I ran into this shortcoming while elaborating on the hyperelasticity demo.
There, in the UFL/py file, we export an expression `sigma`

```
expressions = [(sigma, [[0.25, 0.25, 0.25]])]
```
and then create a function space for it via `basix` with
```
const basix::FiniteElement S_element =
basix::create_element(family, cell_type, k, variant, discontinuous);
auto S = std::make_shared(fem::create_functionspace(
problem.getMesh(),
S_element,
pow(problem.getMesh()->geometry().dim(), 2)));
```

Now, since saving a DG0 tensor function is currently unsupported [see https://gitlab.kitware.com/vtk/vtk/-/issues/18458 and https://github.com/FEniCS/dolfinx/issues/2298 ] but -- and I say BUT -- writing a DG1 tensor works with ADIOS2, I thought I'd do that.
Unfortunately, this doesn't work because `basix` only creates elements with a value shape of `{}` [see https://github.com/FEniCS/basix/issues/626 ] and then `dolfinx` mistakenly assigns a vector value shape

```
// dolfinx/fem/FiniteElement.cpp:266
if (_value_shape.empty() and bs > 1)
_value_shape = {1};
std::transform(_value_shape.cbegin(), _value_shape.cend(),
_value_shape.begin(), [bs](auto s) { return bs * s; }); // is {9}, should be {3, 3}
```
and ultimately, down the line,
```
// dolfinx/io/ADIOS2Writers.cpp:91
const int rank = u.function_space()->element()->value_shape().size(); // is 1, should be 2
const std::uint32_t num_comp = std::pow(3, rank); // is 3, should be 9
```

which eventually yields a segfault in ADIOS2.

So fine, I'll export the function space from UFL instead of creating it with `basix`:
```
DG1T = TensorElement("DG", tetrahedron, 1)
elements = [(DG1T)]
```
but then `DG1T` is nowhere to be found in the generated code. I see that the element is being exported to the C file but there is no alias or handle to instantiate it.
Ideally I would expect to be able to do something like
```
auto S = std::make_shared(
fem::create_functionspace(functionspace_DG1T, "", mesh));
```

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.