Skip to content

Separate cpp.Expression and ufl.Coefficient #1

@garth-wells

Description

@garth-wells

From @blechta

Expressions have element associated with them. That enables any expression to be used immediately in integrals. This poses several problems:

  1. Not all expressions are intended to be used in integrals. Why should they have element.
  2. Attached element does not have any relevance apart of integrals. This is confusing
  3. degree kwarg being shortcut for Lagrange element is overly confusing.

Proposal is to separate Expression from ufl.Coefficient in a following spirit

expression = Expression("x[0]*x[0]")
expression.eval(...)  # ok
u = interpolate(expression, some_function_space)  # ok
bc = DirichletBC(space, expression, where)  # ok
expression*dx  # failure: is not ufl expression

Expression(expression, element=...)*dx  # ok
create_pointwise_expression(expression, ...)*dx  # ok

The last two lines could be renamed to something more sensible, e.g.,

Coefficient(expression, element)*dx  # ok

See #2 for discussion about pointwise expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalSuggested change or addition

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions