Skip to content

Commit 3c871bd

Browse files
Merge branch 'main' into schnellerhase/clang-tidy-2.0
2 parents b921c4d + e908d7e commit 3c871bd

22 files changed

+68
-127
lines changed

.github/workflows/ccpp.yml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,6 @@ on:
1313
branches:
1414
- main
1515
workflow_dispatch:
16-
inputs:
17-
ffcx_ref:
18-
description: "FFCx branch or tag"
19-
default: "main"
20-
type: string
21-
basix_ref:
22-
description: "Basix branch or tag"
23-
default: "main"
24-
type: string
25-
ufl_ref:
26-
description: "UFL branch or tag"
27-
default: "main"
28-
type: string
2916

3017
jobs:
3118

@@ -108,18 +95,11 @@ jobs:
10895
run: |
10996
pip install --upgrade -r python/build-requirements.txt
11097
111-
- name: Install FEniCS Python components (default branches/tags)
112-
if: github.event_name != 'workflow_dispatch'
98+
- name: Install FEniCS Python components
11399
run: |
114100
pip install git+https://github.com/fenics/ufl.git@${{ env.ufl_ref }}
115101
pip install git+https://github.com/fenics/basix.git@${{ env.basix_ref }}
116102
pip install git+https://github.com/fenics/ffcx.git@${{ env.ffcx_ref }}
117-
- name: Install FEniCS Python components
118-
if: github.event_name == 'workflow_dispatch'
119-
run: |
120-
pip install git+https://github.com/FEniCS/ufl.git@${{ env.ufl_ref }}
121-
pip install git+https://github.com/FEniCS/basix.git@${{ env.basix_ref }}
122-
pip install git+https://github.com/FEniCS/ffcx.git@${{ env.ffcx_ref }}
123103
124104
- name: Configure and install C++
125105
run: |
@@ -195,15 +175,7 @@ jobs:
195175
- name: Load environment variables
196176
run: cat .github/workflows/fenicsx-refs.env >> $GITHUB_ENV
197177

198-
- name: Install FEniCS Python components (default branches/tags)
199-
if: github.event_name != 'workflow_dispatch'
200-
run: |
201-
pip install git+https://github.com/FEniCS/ufl.git@${{ env.ufl_ref }}
202-
pip install git+https://github.com/FEniCS/basix.git@${{ env.basix_ref }}
203-
pip install git+https://github.com/FEniCS/ffcx.git@${{ env.ffcx_ref }}
204-
205178
- name: Install FEniCS Python components
206-
if: github.event_name == 'workflow_dispatch'
207179
run: |
208180
pip install git+https://github.com/FEniCS/ufl.git@${{ env.ufl_ref }}
209181
pip install git+https://github.com/FEniCS/basix.git@${{ env.basix_ref }}
@@ -290,14 +262,7 @@ jobs:
290262
- name: Load environment variables
291263
run: cat .github/workflows/fenicsx-refs.env >> $GITHUB_ENV
292264

293-
- name: Install FEniCS Python components (default branches/tags)
294-
if: github.event_name != 'workflow_dispatch'
295-
run: |
296-
pip install git+https://github.com/FEniCS/ufl.git@${{ env.ufl_ref }}
297-
pip install git+https://github.com/FEniCS/basix.git@${{ env.basix_ref }}
298-
pip install git+https://github.com/FEniCS/ffcx.git@${{ env.ffcx_ref }}
299265
- name: Install FEniCS Python components
300-
if: github.event_name == 'workflow_dispatch'
301266
run: |
302267
pip install git+https://github.com/FEniCS/ufl.git@${{ env.ufl_ref }}
303268
pip install git+https://github.com/FEniCS/basix.git@${{ env.basix_ref }}

python/dolfinx/io/gmshio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def model_to_mesh(
366366
if comm.rank != rank:
367367
x = np.empty([0, gdim], dtype=dtype) # No nodes on other than root rank
368368
mesh = create_mesh(
369-
comm, cell_connectivity, x[:, :gdim].astype(dtype, copy=False), ufl_domain, partitioner
369+
comm, cell_connectivity, ufl_domain, x[:, :gdim].astype(dtype, copy=False), partitioner
370370
)
371371
assert tdim == mesh.topology.dim, (
372372
f"{mesh.topology.dim=} does not match Gmsh model dimension {tdim}"

python/dolfinx/io/utils.py

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@
2626
__all__ = ["VTKFile", "XDMFFile", "cell_perm_gmsh", "cell_perm_vtk", "distribute_entity_data"]
2727

2828

29-
def _extract_cpp_objects(functions: typing.Union[Mesh, Function, tuple[Function], list[Function]]):
30-
"""Extract C++ objects"""
31-
if isinstance(functions, (list, tuple)):
32-
return [getattr(u, "_cpp_object", u) for u in functions]
33-
else:
34-
return [getattr(functions, "_cpp_object", functions)]
35-
36-
3729
# VTXWriter requires ADIOS2
3830
if _cpp.common.has_adios2:
3931
from dolfinx.cpp.io import VTXMeshPolicy # F401
@@ -81,27 +73,29 @@ def __init__(
8173
have the same element type.
8274
"""
8375
# Get geometry type
84-
try:
85-
dtype = output.geometry.x.dtype # type: ignore
86-
except AttributeError:
87-
try:
88-
dtype = output.function_space.mesh.geometry.x.dtype # type: ignore
89-
except AttributeError:
90-
dtype = output[0].function_space.mesh.geometry.x.dtype # type: ignore
76+
if isinstance(output, Mesh):
77+
dtype = output.geometry.x.dtype
78+
elif isinstance(output, Function):
79+
dtype = output.function_space.mesh.geometry.x.dtype
80+
else:
81+
dtype = output[0].function_space.mesh.geometry.x.dtype
9182

9283
if np.issubdtype(dtype, np.float32):
9384
_vtxwriter = _cpp.io.VTXWriter_float32
9485
elif np.issubdtype(dtype, np.float64):
9586
_vtxwriter = _cpp.io.VTXWriter_float64
87+
else:
88+
raise RuntimeError(f"VTXWriter does not support dtype={dtype}.")
9689

97-
try:
98-
# Input is a mesh
90+
if isinstance(output, Mesh):
9991
self._cpp_object = _vtxwriter(comm, filename, output._cpp_object, engine) # type: ignore[union-attr]
100-
except (NotImplementedError, TypeError, AttributeError):
101-
# Input is a single function or a list of functions
102-
self._cpp_object = _vtxwriter(
103-
comm, filename, _extract_cpp_objects(output), engine, mesh_policy
104-
) # type: ignore[arg-type]
92+
else:
93+
cpp_objects = (
94+
[output._cpp_object]
95+
if isinstance(output, Function)
96+
else [o._cpp_object for o in output]
97+
)
98+
self._cpp_object = _vtxwriter(comm, filename, cpp_objects, engine, mesh_policy)
10599

106100
def __enter__(self):
107101
return self
@@ -137,7 +131,8 @@ def write_mesh(self, mesh: Mesh, t: float = 0.0) -> None:
137131
def write_function(self, u: typing.Union[list[Function], Function], t: float = 0.0) -> None:
138132
"""Write a single function or a list of functions to file for a
139133
given time (default 0.0)"""
140-
super().write(_extract_cpp_objects(u), t)
134+
cpp_objects = [u._cpp_object] if isinstance(u, Function) else [_u._cpp_object for _u in u]
135+
super().write(cpp_objects, t)
141136

142137

143138
class XDMFFile(_cpp.io.XDMFFile):

python/dolfinx/mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,13 @@ def refine(
683683
def create_mesh(
684684
comm: _MPI.Comm,
685685
cells: npt.NDArray[np.int64],
686-
x: npt.NDArray[np.floating],
687686
e: typing.Union[
688687
ufl.Mesh,
689688
basix.finite_element.FiniteElement,
690689
basix.ufl._BasixElement,
691690
_CoordinateElement,
692691
],
692+
x: npt.NDArray[np.floating],
693693
partitioner: typing.Optional[Callable] = None,
694694
) -> Mesh:
695695
"""Create a mesh from topology and geometry arrays.

python/test/unit/fem/test_assembler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def test_petsc_assemble_manifold(self):
274274
dtype=default_real_type,
275275
)
276276
)
277-
mesh = create_mesh(MPI.COMM_WORLD, cells, points, domain)
277+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, points)
278278
assert mesh.geometry.dim == 2
279279
assert mesh.topology.dim == 1
280280

@@ -1306,7 +1306,7 @@ def partitioner(comm, nparts, local_graph, num_ghost_nodes):
13061306
cells = np.empty((0, 3), dtype=np.int64)
13071307
x = np.empty((0, 2), dtype=default_real_type)
13081308

1309-
mesh = create_mesh(comm, cells, x, domain, partitioner)
1309+
mesh = create_mesh(comm, cells, domain, x, partitioner)
13101310

13111311
V = functionspace(mesh, ("Lagrange", 2))
13121312
u, v = ufl.TrialFunction(V), ufl.TestFunction(V)

python/test/unit/fem/test_dof_permuting.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,35 +108,35 @@ def randomly_ordered_mesh(cell_type):
108108

109109
# On process 0, input mesh data and distribute to other
110110
# processes
111-
return create_mesh(MPI.COMM_WORLD, cells, points, domain)
111+
return create_mesh(MPI.COMM_WORLD, cells, domain, points)
112112
else:
113113
if cell_type == "triangle":
114114
return create_mesh(
115115
MPI.COMM_WORLD,
116116
np.ndarray((0, 3)),
117-
np.ndarray((0, 2), dtype=default_real_type),
118117
domain,
118+
np.ndarray((0, 2), dtype=default_real_type),
119119
)
120120
elif cell_type == "quadrilateral":
121121
return create_mesh(
122122
MPI.COMM_WORLD,
123123
np.ndarray((0, 4)),
124-
np.ndarray((0, 2), dtype=default_real_type),
125124
domain,
125+
np.ndarray((0, 2), dtype=default_real_type),
126126
)
127127
elif cell_type == "tetrahedron":
128128
return create_mesh(
129129
MPI.COMM_WORLD,
130130
np.ndarray((0, 4)),
131-
np.ndarray((0, 3), dtype=default_real_type),
132131
domain,
132+
np.ndarray((0, 3), dtype=default_real_type),
133133
)
134134
elif cell_type == "hexahedron":
135135
return create_mesh(
136136
MPI.COMM_WORLD,
137137
np.ndarray((0, 8)),
138-
np.ndarray((0, 3), dtype=default_real_type),
139138
domain,
139+
np.ndarray((0, 3), dtype=default_real_type),
140140
)
141141

142142

@@ -276,7 +276,7 @@ def random_evaluation_mesh(cell_type):
276276
cell_order += [c + diff for c in cell_order]
277277

278278
cells.append([order[cell[i]] for i in cell_order])
279-
return create_mesh(MPI.COMM_WORLD, np.array(cells), points, domain)
279+
return create_mesh(MPI.COMM_WORLD, np.array(cells), domain, points)
280280

281281

282282
@pytest.mark.skip_in_parallel

python/test/unit/fem/test_dofmap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def test_higher_order_coordinate_map(points, celltype, order):
324324
domain = ufl.Mesh(
325325
element("Lagrange", celltype.name, order, shape=(points.shape[1],), dtype=default_real_type)
326326
)
327-
mesh = create_mesh(MPI.COMM_WORLD, cells, points, domain)
327+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, points)
328328

329329
V = functionspace(mesh, ("Lagrange", 2))
330330
X = V.element.interpolation_points
@@ -400,7 +400,7 @@ def test_higher_order_tetra_coordinate_map(order):
400400
domain = ufl.Mesh(
401401
element("Lagrange", celltype.name, order, shape=(3,), dtype=default_real_type)
402402
)
403-
mesh = create_mesh(MPI.COMM_WORLD, cells, points, domain)
403+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, points)
404404
V = functionspace(mesh, ("Lagrange", order))
405405
X = V.element.interpolation_points
406406
x_dofs = mesh.geometry.dofmap
@@ -439,7 +439,7 @@ def self_partitioner(comm: MPI.Intracomm, n, m, topo):
439439
# TODO: can we improve on this interface? I.e. warp to do cpp type conversion automatically
440440
return dolfinx.graph.adjacencylist(dests, offsets)._cpp_object
441441

442-
mesh = create_mesh(MPI.COMM_WORLD, cells, nodes, c_el, partitioner=self_partitioner)
442+
mesh = create_mesh(MPI.COMM_WORLD, cells, c_el, nodes, partitioner=self_partitioner)
443443

444444
el = element("Lagrange", "interval", 1, shape=(2,))
445445
V = functionspace(mesh, el)

python/test/unit/fem/test_element_integrals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def unit_cell(cell_type, dtype, random_order=True):
104104
domain = ufl.Mesh(
105105
element("Lagrange", cell_type.name, 1, shape=(ordered_points.shape[1],), dtype=dtype)
106106
)
107-
mesh = create_mesh(MPI.COMM_WORLD, cells, ordered_points, domain)
107+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, ordered_points)
108108
return mesh
109109

110110

@@ -188,7 +188,7 @@ def two_unit_cells(cell_type, dtype, agree=False, random_order=True, return_orde
188188
domain = ufl.Mesh(
189189
element("Lagrange", cell_type.name, 1, shape=(ordered_points.shape[1],), dtype=dtype)
190190
)
191-
mesh = create_mesh(MPI.COMM_WORLD, ordered_cells, ordered_points, domain)
191+
mesh = create_mesh(MPI.COMM_WORLD, ordered_cells, domain, ordered_points)
192192
if return_order:
193193
return mesh, order
194194
return mesh
@@ -525,7 +525,7 @@ def test_curl(space_type, order, dtype):
525525
for i in range(5):
526526
random.shuffle(cell)
527527
domain = ufl.Mesh(element("Lagrange", "tetrahedron", 1, shape=(3,), dtype=dtype))
528-
mesh = create_mesh(MPI.COMM_WORLD, [cell], points, domain)
528+
mesh = create_mesh(MPI.COMM_WORLD, [cell], domain, points)
529529
V = functionspace(mesh, (space_type, order))
530530
v = ufl.TestFunction(V)
531531
f = ufl.as_vector(tuple(1 if i == 0 else 0 for i in range(tdim)))
@@ -576,7 +576,7 @@ def create_quad_mesh(offset, dtype):
576576
x = np.array([[0, 0], [1, 0], [0, 0.5 + offset], [1, 0.5 - offset]], dtype=dtype)
577577
cells = np.array([[0, 1, 2, 3]])
578578
ufl_mesh = ufl.Mesh(element("Lagrange", "quadrilateral", 1, shape=(2,), dtype=dtype))
579-
mesh = create_mesh(MPI.COMM_WORLD, cells, x, ufl_mesh)
579+
mesh = create_mesh(MPI.COMM_WORLD, cells, ufl_mesh, x)
580580
return mesh
581581

582582

python/test/unit/fem/test_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_eval_manifold():
107107
)
108108
cells = [(0, 1, 2), (0, 1, 3)]
109109
domain = ufl.Mesh(element("Lagrange", "triangle", 1, shape=(2,), dtype=default_real_type))
110-
mesh = create_mesh(MPI.COMM_WORLD, cells, vertices, domain)
110+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, vertices)
111111
Q = functionspace(mesh, ("Lagrange", 1))
112112
u = Function(Q)
113113
u.interpolate(lambda x: x[0] + x[1])

python/test/unit/fem/test_function_space.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ def test_vector_function_space_cell_type():
272272
domain = Mesh(element("Lagrange", "interval", 1, shape=(1,), dtype=default_real_type))
273273
cells = np.array([[0, 1]], dtype=np.int64)
274274
x = np.array([[0.0, 0.0], [1.0, 1.0]])
275-
mesh = create_mesh(comm, cells, x, domain)
275+
mesh = create_mesh(comm, cells, domain, x)
276276

277277
# Create functions space over mesh, and check element cell
278278
# is correct
@@ -288,7 +288,7 @@ def test_manifold_spaces():
288288
)
289289
cells = [(0, 1, 2), (0, 1, 3)]
290290
domain = Mesh(element("Lagrange", "triangle", 1, shape=(2,), dtype=default_real_type))
291-
mesh = create_mesh(MPI.COMM_WORLD, cells, vertices, domain)
291+
mesh = create_mesh(MPI.COMM_WORLD, cells, domain, vertices)
292292
gdim = mesh.geometry.dim
293293
QV = functionspace(mesh, ("Lagrange", 1, (gdim,)))
294294
QT = functionspace(mesh, ("Lagrange", 1, (gdim, gdim)))

0 commit comments

Comments
 (0)