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

Fix facet and cell averages #501

Closed
wants to merge 7 commits into from
Closed

Fix facet and cell averages #501

wants to merge 7 commits into from

Conversation

jorgensd
Copy link
Member

Currently we do not support FacetAvg or CellAvg in ufl forms, as the following mwe illustrates:

import ufl

cell = ufl.triangle
c_el = ufl.VectorElement("Lagrange", cell, 1)
mesh = ufl.Mesh(c_el)
el = ufl.FiniteElement("Lagrange", cell, 1)
V = ufl.FunctionSpace(mesh, el)
u = ufl.Coefficient(V)

a = ufl.cell_avg(u) * ufl.dx
L = ufl.facet_avg(u) * ufl.ds
forms = [a, L]
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 68, in main
    code_h, code_c = compiler.compile_ufl_objects(
  File "/root/shared/ffcx/ffcx/compiler.py", line 102, in compile_ufl_objects
    ir = compute_ir(analysis, object_names, prefix, parameters, visualise)
  File "/root/shared/ffcx/ffcx/ir/representation.py", line 197, in compute_ir
    irs = [
  File "/root/shared/ffcx/ffcx/ir/representation.py", line 198, in <listcomp>
    _compute_integral_ir(fd, i, analysis.element_numbers, integral_names, finite_element_names,
  File "/root/shared/ffcx/ffcx/ir/representation.py", line 487, in _compute_integral_ir
    integral_ir = compute_integral_ir(itg_data.domain.ufl_cell(), itg_data.integral_type,
  File "/root/shared/ffcx/ffcx/ir/integral.py", line 71, in compute_integral_ir
    S = build_scalar_graph(expression)
  File "/root/shared/ffcx/ffcx/ir/analysis/graph.py", line 79, in build_scalar_graph
    scalar_expressions = rebuild_with_scalar_subexpressions(G)
  File "/root/shared/ffcx/ffcx/ir/analysis/graph.py", line 179, in rebuild_with_scalar_subexpressions
    ws = reconstruct(expr, wops)
  File "/root/shared/ffcx/ffcx/ir/analysis/reconstruct.py", line 168, in reconstruct
    raise RuntimeError("Not expecting expression of type %s in here." % type(o))
RuntimeError: Not expecting expression of type <class 'ufl.averaging.CellAvg'> in here.

This is due to: https://bitbucket.org/fenics-project/ufl/pull-requests/89
which never got fixed in old DOLFIN.

@jorgensd jorgensd requested a review from IgorBaratta June 22, 2022 16:17
@michalhabera
Copy link
Contributor

Substitution CellAvg(u) --> u / CellVolume does not look correct to me, these things have also different units (u-units vs. u-units/volume). And it is also wrong for constant functions, since CellAvg(u) = u for u in DG0.

@jorgensd
Copy link
Member Author

Substitution CellAvg(u) --> u / CellVolume does not look correct to me, these things have also different units (u-units vs. u-units/volume). And it is also wrong for constant functions, since CellAvg(u) = u for u in DG0.

Im then not sure what a cell_avg should be. As far as I can tell this is what they do in tsfc (firedrakeproject/tsfc#158)

I see that this is wrong for DG 0. I guess what we actually want is cell_avg(var)*dx->(var/CellVolume*dx)*dx

@michalhabera do we support such operations in ffcx?

@michalhabera
Copy link
Contributor

michalhabera commented Jun 27, 2022 via email

@wence-
Copy link

wence- commented Jan 9, 2023

As far as I can tell this is what they do in tsfc (firedrakeproject/tsfc#158)

TSFC implements CellAvg(expr)*dx (and FacetAvg) as cellwise_integral(expr/CellVolume *dx) * dx as @michalhabera is advocating for

@jorgensd jorgensd closed this May 3, 2024
@jorgensd jorgensd deleted the dokken/facetcellavg branch May 22, 2024 06:10
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

Successfully merging this pull request may close these issues.

3 participants