Skip to content

Fix argument block-size in Expressions#3429

Merged
jorgensd merged 4 commits into
mainfrom
dokken/fix-expression-argument-bs
Sep 21, 2024
Merged

Fix argument block-size in Expressions#3429
jorgensd merged 4 commits into
mainfrom
dokken/fix-expression-argument-bs

Conversation

@jorgensd

@jorgensd jorgensd commented Sep 21, 2024

Copy link
Copy Markdown
Member

Currently if an Expression gets a blocked test or trial function, we do not take into account this block size when accessing the underlying tabulate kernel.

The added test segfaults on the main branch

Background
A testfunction in a blocked space (say for instance bs=3) will be evaluated as
(v, 0, 0), (0,v,0), (0,0,v) in our expression kernels, where v is the basis function evaluated at a given point.

Example

import numpy as np
from mpi4py import MPI
import dolfinx
import ufl
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_SELF, 1, 1, cell_type=dolfinx.mesh.CellType.quadrilateral)
value_shape = (3,)
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 2, value_shape))
v = ufl.TestFunction(V)

points = np.array([[0.513, 0.317]], dtype=mesh.geometry.x.dtype)
expr = dolfinx.fem.Expression(v, points)

values = expr.eval(mesh, np.array([0], dtype=np.int32))
print(values)

should yield

[[-0.00316522  0.          0.          0.00333421  0.          0.
   0.00146907  0.          0.         -0.0015475   0.          0.
   0.24980901  0.          0.         -0.01096585  0.          0.
   0.01155129  0.          0.         -0.11594357  0.          0.
   0.86545855  0.          0.          0.         -0.00316522  0.
   0.          0.00333421  0.          0.          0.00146907  0.
   0.         -0.0015475   0.          0.          0.24980901  0.
   0.         -0.01096585  0.          0.          0.01155129  0.
   0.         -0.11594357  0.          0.          0.86545855  0.
   0.          0.         -0.00316522  0.          0.          0.00333421
   0.          0.          0.00146907  0.          0.         -0.0015475
   0.          0.          0.24980901  0.          0.         -0.01096585
   0.          0.          0.01155129  0.          0.         -0.11594357
   0.          0.          0.86545855]]

while main yields

[[-0.00316522  0.          0.          0.00333421  0.          0.
   0.00146907  0.          0.         -0.0015475   0.          0.
   0.24980901  0.          0.         -0.01096585  0.          0.
   0.01155129  0.          0.         -0.11594357  0.          0.
   0.86545855  0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.          0.          0.          0.
   0.          0.          0.        ]]

when it doesn't segfault

Comment thread cpp/dolfinx/fem/Expression.h Outdated
@jorgensd jorgensd added this pull request to the merge queue Sep 21, 2024
Merged via the queue into main with commit 8c65780 Sep 21, 2024
@jorgensd jorgensd deleted the dokken/fix-expression-argument-bs branch September 21, 2024 17:50
@michalhabera

Copy link
Copy Markdown
Contributor

Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants