FEniCS / ffcx

Next generation FEniCS Form Compiler for finite element forms
https://fenicsproject.org
Other
146 stars 39 forks source link

Support CellVolume for Expressions on non-simplex geometries #550

Open jorgensd opened 1 year ago

jorgensd commented 1 year ago

MWE.

import ufl
import numpy as np

cmap = ufl.VectorElement("Lagrange", ufl.quadrilateral, 1)
mesh = ufl.Mesh(cmap)
el = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), 1)

elmVol_ufl = ufl.CellVolume(mesh)
expressions = [(elmVol_ufl, np.array([[0.5, 0.5]]))]

returns

WARNING:py.warnings:/root/shared/ufl/ufl/algorithms/apply_geometry_lowering.py:193: UserWarning: Only know how to compute the cell volume of an affine cell.
  warnings.warn("Only know how to compute the cell volume of an affine cell.")

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/root/shared/ffcx/ffcx/__main__.py", line 12, in <module>
    sys.exit(main())
  File "/root/shared/ffcx/ffcx/main.py", line 67, in main
    code_h, code_c = compiler.compile_ufl_objects(
  File "/root/shared/ffcx/ffcx/compiler.py", line 107, in compile_ufl_objects
    code = generate_code(ir, options)
  File "/root/shared/ffcx/ffcx/codegeneration/codegeneration.py", line 52, in generate_code
    code_expressions = [expression_generator(expression_ir, options) for expression_ir in ir.expressions]
  File "/root/shared/ffcx/ffcx/codegeneration/codegeneration.py", line 52, in <listcomp>
    code_expressions = [expression_generator(expression_ir, options) for expression_ir in ir.expressions]
  File "/root/shared/ffcx/ffcx/codegeneration/expressions.py", line 43, in generator
    parts = eg.generate()
  File "/root/shared/ffcx/ffcx/codegeneration/expressions.py", line 159, in generate
    parts += self.generate_piecewise_partition()
  File "/root/shared/ffcx/ffcx/codegeneration/expressions.py", line 273, in generate_piecewise_partition
    parts = self.generate_partition(arraysymbol, F, "piecewise")
  File "/root/shared/ffcx/ffcx/codegeneration/expressions.py", line 460, in generate_partition
    vaccess = self.backend.access.get(mt.terminal, mt, tabledata, 0)
  File "/root/shared/ffcx/ffcx/codegeneration/access.py", line 64, in get
    raise RuntimeError(f"Not handled: {type(e)}")
RuntimeError: Not handled: <class 'ufl.geometry.CellVolume'>

related to https://github.com/FEniCS/ufl/issues/140 and vaguely to: https://github.com/FEniCS/ffcx/pull/501