Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create alias for elements #547

Open
massimiliano-leoni opened this issue Dec 14, 2022 · 0 comments
Open

Create alias for elements #547

massimiliano-leoni opened this issue Dec 14, 2022 · 0 comments

Comments

@massimiliano-leoni
Copy link

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::FunctionSpace>(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::FunctionSpace>(
        fem::create_functionspace(functionspace_DG1T, "", mesh));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant