|
9 | 9 | import finat |
10 | 10 | import firedrake |
11 | 11 | import numpy |
| 12 | +from pyadjoint.tape import annotate_tape |
12 | 13 | from tsfc import kernel_args |
13 | 14 | from tsfc.finatinterface import create_element |
14 | 15 | import ufl |
15 | | -from firedrake import (assemble_expressions, extrusion_utils as eutils, matrix, parameters, solving, |
| 16 | +from firedrake import (extrusion_utils as eutils, matrix, parameters, solving, |
16 | 17 | tsfc_interface, utils) |
17 | 18 | from firedrake.adjoint import annotate_assemble |
18 | 19 | from firedrake.bcs import DirichletBC, EquationBC, EquationBCSplit |
@@ -100,7 +101,7 @@ def assemble(expr, *args, **kwargs): |
100 | 101 | if isinstance(expr, (ufl.form.Form, slate.TensorBase)): |
101 | 102 | return _assemble_form(expr, *args, **kwargs) |
102 | 103 | elif isinstance(expr, ufl.core.expr.Expr): |
103 | | - return assemble_expressions.assemble_expression(expr) |
| 104 | + return _assemble_expr(expr) |
104 | 105 | else: |
105 | 106 | raise TypeError(f"Unable to assemble: {expr}") |
106 | 107 |
|
@@ -290,6 +291,20 @@ def _assemble_form(form, tensor=None, bcs=None, *, |
290 | 291 | return assembler.assemble() |
291 | 292 |
|
292 | 293 |
|
| 294 | +def _assemble_expr(expr): |
| 295 | + """Assemble a pointwise expression. |
| 296 | +
|
| 297 | + :arg expr: The :class:`ufl.core.expr.Expr` to be evaluated. |
| 298 | + :returns: A :class:`firedrake.Function` containing the result of this evaluation. |
| 299 | + """ |
| 300 | + try: |
| 301 | + coefficients = ufl.algorithms.extract_coefficients(expr) |
| 302 | + V, = set(c.function_space() for c in coefficients) - {None} |
| 303 | + except ValueError: |
| 304 | + raise ValueError("Cannot deduce correct target space from pointwise expression") |
| 305 | + return firedrake.Function(V).assign(expr) |
| 306 | + |
| 307 | + |
293 | 308 | def _check_inputs(form, tensor, bcs, diagonal): |
294 | 309 | # Ensure mesh is 'initialised' as we could have got here without building a |
295 | 310 | # function space (e.g. if integrating a constant). |
|
0 commit comments