FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
743 stars 178 forks source link

Manifold meshes from XDMF broken #2389

Open jorgensd opened 2 years ago

jorgensd commented 2 years ago

Broken by PR #2301 Reported at: https://fenicsproject.discourse.group/t/triangle-elements-in-3d-broken-in-dolfinx/9426 MWE: XDMFFile:

<Xdmf Version="3.0">
  <Domain>
    <Grid Name="Grid">
      <Geometry GeometryType="XYZ">
        <DataItem DataType="Float" Dimensions="3 2" Format="XML" Precision="8">
          0.0 0.0 0.0
          1.0 0.0 0.0
          0.0 1.0 0.0
        </DataItem>
      </Geometry>
      <Topology NodesPerElement="3" NumberOfElements="1" TopologyType="triangle">
        <DataItem DataType="Int" Dimensions="1 3" Format="XML" Precision="4">
          0 1 2
        </DataItem>
      </Topology>
    </Grid>
  </Domain>
</Xdmf>

and code

#!/usr/bin/env python3
from mpi4py import MPI
from dolfinx import fem, io
import ufl

comm = MPI.COMM_WORLD

meshname = 'mesh.xdmf'

with io.XDMFFile(comm, meshname, 'r', encoding=io.XDMFFile.Encoding.ASCII) as infile:

    mesh = infile.read_mesh(name="Grid")

V_s = fem.FunctionSpace(mesh, ("P", 1))
V_v = fem.VectorFunctionSpace(mesh, ("P", 1))
V_t = fem.TensorFunctionSpace(mesh, ("P", 1))
print(mesh.geometry.dim, mesh.topology.dim)

yields error:

Non-matching cell of finite element and domain.
ERROR:UFL:Non-matching cell of finite element and domain.
Traceback (most recent call last):
  File "/root/shared/debug/mwe_gmsh.py", line 15, in <module>
    V_v = fem.VectorFunctionSpace(mesh, ("P", 1))
  File "/root/shared/dolfinx/python/dolfinx/fem/function.py", line 578, in VectorFunctionSpace
    return FunctionSpace(mesh, ufl_element)
  File "/root/shared/dolfinx/python/dolfinx/fem/function.py", line 452, in __init__
    super().__init__(mesh.ufl_domain(), element)
  File "/root/shared/ufl/ufl/functionspace.py", line 45, in __init__
    error("Non-matching cell of finite element and domain.")
  File "/root/shared/ufl/ufl/log.py", line 158, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Non-matching cell of finite element and domain.
jpdean commented 2 years ago

I suspect this issue might be fixed by https://github.com/FEniCS/dolfinx/pull/2386

jorgensd commented 2 years ago

This is not fixed yet. There are issues with the sub-spaces, i.e. V.sub(i) does not work.

jpdean commented 2 years ago

Is the issue related to this by any chance? i.e. does specifying dim=mesh.geometry.dim when creating the vector function space fix the problem?

mscroggs commented 2 years ago

Is the issue related to this by any chance? i.e. does specifying dim=mesh.geometry.dim when creating the vector function space fix the problem?

I've opened a PR in Basix to fix that and maybe fix this

jorgensd commented 1 year ago

@mscroggs is this resolved?

garth-wells commented 1 year ago

@mscroggs, @jorgensd is this fixed now?

jorgensd commented 1 year ago

No, this is still not resolved. You get the issue by adding V_v.sub(i) i being 0, 1 or 2 to the example above. You then get issues when creating the sub function space, as the sub elements are using the wrong cell type

mscroggs commented 1 year ago

Is there a sensible test we can add to DOLFINx that will check that we don't break this in future?

mscroggs commented 1 year ago

This may have been fixed by https://github.com/FEniCS/basix/pull/617

jorgensd commented 1 year ago

Is there a sensible test we can add to DOLFINx that will check that we don't break this in future?

Good question, maybe we need to solve a PDE on a manifold, or do something similar to what we do above. I guess we could use locate_dofs_topological on a subspace to compare it to what one gets on the collapsed sub space.

garth-wells commented 5 months ago

This may have been fixed by FEniCS/basix#617

Is this issue now fixed?