Skip to content

Commit e95ea93

Browse files
authored
Use ruff formatting. (#109)
* Use ruff formatting. Fix sparsity pattern creation after API change in FEniCS/dolfinx#3079 * Using numba typing inside numba modules for sake of clarity * Update mdspan, ref FEniCS/dolfinx#3086
1 parent 01723af commit e95ea93

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2148
-1272
lines changed

.github/workflows/test_mpc.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ jobs:
7070
- name: upgrade pip
7171
run: python3 -m pip install --upgrade setuptools pip
7272

73-
- name: Flake8 code
74-
run: flake8 python/
73+
- name: Check formatting
74+
run: |
75+
ruff check
76+
ruff format
7577
76-
- name: Mypy check
78+
- name: Check typing
7779
run: |
7880
python3 -m pip install mypy
7981
cd python

cpp/assemble_matrix.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,9 @@ void assemble_exterior_facets(
337337
const int local_facet = facets[l + 1];
338338

339339
// Get cell vertex coordinates
340-
namespace stdex = std::experimental;
341-
auto x_dofs = stdex::submdspan(x_dofmap, cell,
342-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
340+
341+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
342+
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
343343
for (std::size_t i = 0; i < x_dofs.size(); ++i)
344344
{
345345
std::copy_n(std::next(x_g.begin(), 3 * x_dofs[i]), 3,
@@ -466,13 +466,13 @@ void assemble_cells_impl(
466466
Ae(Aeb.data(), ndim0, ndim1);
467467
const std::span<T> _Ae(Aeb);
468468
std::vector<T> scratch_memory(2 * ndim0 * ndim1 + ndim0 + ndim1);
469-
namespace stdex = std::experimental;
469+
470470
for (std::size_t c = 0; c < active_cells.size(); c++)
471471
{
472472
const std::int32_t cell = active_cells[c];
473473
// Get cell coordinates/geometry
474-
auto x_dofs = stdex::submdspan(x_dofmap, cell,
475-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
474+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
475+
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
476476
for (std::size_t i = 0; i < x_dofs.size(); ++i)
477477
{
478478
std::copy_n(std::next(x_g.begin(), 3 * x_dofs[i]), 3,

cpp/assemble_vector.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void _assemble_vector(
9292
std::span<T> b, const dolfinx::fem::Form<T>& L,
9393
const std::shared_ptr<const dolfinx_mpc::MultiPointConstraint<T, U>>& mpc)
9494
{
95-
namespace stdex = std::experimental;
95+
9696
const auto mesh = L.mesh();
9797
assert(mesh);
9898

@@ -153,7 +153,7 @@ void _assemble_vector(
153153
auto cell = entity.front();
154154

155155
// Fetch the coordinates of the cell
156-
auto x_dofs = stdex::submdspan(
156+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
157157
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
158158
for (std::size_t i = 0; i < x_dofs.size(); ++i)
159159
{
@@ -202,7 +202,7 @@ void _assemble_vector(
202202
// Fetch the coordinates of the cell
203203
const std::int32_t cell = entity[0];
204204
const int local_facet = entity[1];
205-
auto x_dofs = stdex::submdspan(
205+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
206206
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
207207
for (std::size_t i = 0; i < x_dofs.size(); ++i)
208208
{

cpp/lifting.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void apply_lifting(
182182
auto mesh = a->function_spaces()[0]->mesh();
183183

184184
// Prepare cell geometry
185-
namespace stdex = std::experimental;
185+
186186
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
187187
const std::int32_t,
188188
MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
@@ -231,7 +231,7 @@ void apply_lifting(
231231
auto cell = entity.front();
232232

233233
// Fetch the coordinates of the cell
234-
auto x_dofs = stdex::submdspan(
234+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
235235
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
236236
for (std::size_t i = 0; i < x_dofs.size(); ++i)
237237
{
@@ -315,7 +315,7 @@ void apply_lifting(
315315
const int local_facet = entity[1];
316316

317317
// Fetch the coordinates of the cell
318-
auto x_dofs = stdex::submdspan(
318+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
319319
x_dofmap, cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
320320
for (std::size_t i = 0; i < x_dofs.size(); ++i)
321321
{

cpp/utils.h

+56-45
Original file line numberDiff line numberDiff line change
@@ -282,13 +282,16 @@ void build_standard_pattern(dolfinx::la::SparsityPattern& pattern,
282282
throw std::runtime_error(
283283
"Cannot create sparsity pattern. Form is not a bilinear.");
284284
}
285-
286285
// Get dof maps and mesh
287286
std::array<std::reference_wrapper<const dolfinx::fem::DofMap>, 2> dofmaps{
288287
*a.function_spaces().at(0)->dofmap(),
289288
*a.function_spaces().at(1)->dofmap()};
290289
std::shared_ptr mesh = a.mesh();
291290
assert(mesh);
291+
std::shared_ptr mesh0 = a.function_spaces().at(0)->mesh();
292+
assert(mesh0);
293+
std::shared_ptr mesh1 = a.function_spaces().at(1)->mesh();
294+
assert(mesh1);
292295

293296
const std::set<dolfinx::fem::IntegralType> types = a.integral_types();
294297
if (types.find(dolfinx::fem::IntegralType::interior_facet) != types.end()
@@ -300,6 +303,16 @@ void build_standard_pattern(dolfinx::la::SparsityPattern& pattern,
300303
mesh->topology_mutable()->create_connectivity(tdim - 1, tdim);
301304
}
302305

306+
auto extract_cells = [](std::span<const std::int32_t> facets)
307+
{
308+
assert(facets.size() % 2 == 0);
309+
std::vector<std::int32_t> cells;
310+
cells.reserve(facets.size() / 2);
311+
for (std::size_t i = 0; i < facets.size(); i += 2)
312+
cells.push_back(facets[i]);
313+
return cells;
314+
};
315+
303316
for (auto type : types)
304317
{
305318
std::vector<int> ids = a.integral_ids(type);
@@ -308,33 +321,29 @@ void build_standard_pattern(dolfinx::la::SparsityPattern& pattern,
308321
case dolfinx::fem::IntegralType::cell:
309322
for (int id : ids)
310323
{
311-
std::span<const std::int32_t> cells = a.domain(type, id);
312-
dolfinx::fem::sparsitybuild::cells(pattern, cells,
313-
{{dofmaps[0], dofmaps[1]}});
324+
dolfinx::fem::sparsitybuild::cells(
325+
pattern, {a.domain(type, id, *mesh0), a.domain(type, id, *mesh1)},
326+
{{dofmaps[0], dofmaps[1]}});
314327
}
315328
break;
316329
case dolfinx::fem::IntegralType::interior_facet:
317330
for (int id : ids)
318331
{
319-
std::span<const std::int32_t> facets = a.domain(type, id);
320-
std::vector<std::int32_t> f;
321-
f.reserve(facets.size() / 2);
322-
for (std::size_t i = 0; i < facets.size(); i += 4)
323-
f.insert(f.end(), {facets[i], facets[i + 2]});
324332
dolfinx::fem::sparsitybuild::interior_facets(
325-
pattern, f, {{dofmaps[0], dofmaps[1]}});
333+
pattern,
334+
{extract_cells(a.domain(type, id, *mesh0)),
335+
extract_cells(a.domain(type, id, *mesh1))},
336+
{{dofmaps[0], dofmaps[1]}});
326337
}
327338
break;
328339
case dolfinx::fem::IntegralType::exterior_facet:
329340
for (int id : ids)
330341
{
331-
std::span<const std::int32_t> facets = a.domain(type, id);
332-
std::vector<std::int32_t> cells;
333-
cells.reserve(facets.size() / 2);
334-
for (std::size_t i = 0; i < facets.size(); i += 2)
335-
cells.push_back(facets[i]);
336-
dolfinx::fem::sparsitybuild::cells(pattern, cells,
337-
{{dofmaps[0], dofmaps[1]}});
342+
dolfinx::fem::sparsitybuild::cells(
343+
pattern,
344+
{extract_cells(a.domain(type, id, *mesh0)),
345+
extract_cells(a.domain(type, id, *mesh1))},
346+
{{dofmaps[0], dofmaps[1]}});
338347
}
339348
break;
340349
default:
@@ -985,7 +994,7 @@ evaluate_basis_functions(const dolfinx::fem::FunctionSpace<U>& V,
985994
auto map = mesh->topology()->index_map(tdim);
986995

987996
// Get geometry data
988-
namespace stdex = std::experimental;
997+
989998
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
990999
const std::int32_t,
9911000
MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>
@@ -1054,17 +1063,19 @@ evaluate_basis_functions(const dolfinx::fem::FunctionSpace<U>& V,
10541063
std::reduce(phi0_shape.begin(), phi0_shape.end(), 1, std::multiplies{}));
10551064
cmdspan4_t phi0(phi0_b.data(), phi0_shape);
10561065
cmap.tabulate(1, std::vector<U>(tdim, 0), {1, tdim}, phi0_b);
1057-
auto dphi0 = stdex::submdspan(phi0, std::pair(1, tdim + 1), 0,
1058-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
1066+
auto dphi0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1067+
phi0, std::pair(1, tdim + 1), 0,
1068+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
10591069

10601070
// Data structure for evaluating geometry basis at specific points.
10611071
// Used in non-affine case.
10621072
std::array<std::size_t, 4> phi_shape = cmap.tabulate_shape(1, 1);
10631073
std::vector<U> phi_b(
10641074
std::reduce(phi_shape.begin(), phi_shape.end(), 1, std::multiplies{}));
10651075
cmdspan4_t phi(phi_b.data(), phi_shape);
1066-
auto dphi = stdex::submdspan(phi, std::pair(1, tdim + 1), 0,
1067-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
1076+
auto dphi = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1077+
phi, std::pair(1, tdim + 1), 0,
1078+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
10681079

10691080
// Reference coordinates for each point
10701081
std::vector<U> Xb(num_points * tdim);
@@ -1088,8 +1099,8 @@ evaluate_basis_functions(const dolfinx::fem::FunctionSpace<U>& V,
10881099
continue;
10891100

10901101
// Get cell geometry (coordinate dofs)
1091-
auto x_dofs = stdex::submdspan(x_dofmap, cell_index,
1092-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1102+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1103+
x_dofmap, cell_index, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
10931104
for (std::size_t i = 0; i < num_dofs_g; ++i)
10941105
{
10951106
const int pos = 3 * x_dofs[i];
@@ -1100,12 +1111,12 @@ evaluate_basis_functions(const dolfinx::fem::FunctionSpace<U>& V,
11001111
for (std::size_t j = 0; j < gdim; ++j)
11011112
xp(0, j) = x[3 * p + j];
11021113

1103-
auto _J
1104-
= stdex::submdspan(J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1105-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1106-
auto _K
1107-
= stdex::submdspan(K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1108-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1114+
auto _J = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1115+
J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1116+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1117+
auto _K = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1118+
K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1119+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
11091120

11101121
std::array<U, 3> Xpb = {0, 0, 0};
11111122
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
@@ -1184,15 +1195,15 @@ evaluate_basis_functions(const dolfinx::fem::FunctionSpace<U>& V,
11841195
apply_dof_transformation(basis_valuesb, cell_info, cell_index,
11851196
(int)reference_value_size);
11861197

1187-
auto _U = stdex::submdspan(full_basis, p,
1188-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1189-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1190-
auto _J
1191-
= stdex::submdspan(J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1192-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1193-
auto _K
1194-
= stdex::submdspan(K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1195-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1198+
auto _U = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1199+
full_basis, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1200+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1201+
auto _J = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1202+
J, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1203+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1204+
auto _K = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1205+
K, p, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1206+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
11961207
push_forward_fn(_U, basis_values, _J, detJ[p], _K);
11971208
}
11981209
return {output_basis, reference_shape};
@@ -1262,7 +1273,7 @@ std::pair<std::vector<U>, std::array<std::size_t, 2>> tabulate_dof_coordinates(
12621273
const std::size_t num_dofs_g = x_dofmap.extent(1);
12631274

12641275
// Array to hold coordinates to return
1265-
namespace stdex = std::experimental;
1276+
12661277
std::array<std::size_t, 2> coord_shape = {dofs.size(), 3};
12671278
if (transposed)
12681279
coord_shape = {3, dofs.size()};
@@ -1298,9 +1309,9 @@ std::pair<std::vector<U>, std::array<std::size_t, 2>> tabulate_dof_coordinates(
12981309
MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
12991310
const U, MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 4>>
13001311
phi_full(phi_b.data(), bsize);
1301-
auto phi = stdex::submdspan(phi_full, 0,
1302-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1303-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
1312+
auto phi = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1313+
phi_full, 0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent,
1314+
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent, 0);
13041315

13051316
// Create insertion function
13061317
std::function<void(std::size_t, std::size_t, std::ptrdiff_t)> inserter;
@@ -1320,8 +1331,8 @@ std::pair<std::vector<U>, std::array<std::size_t, 2>> tabulate_dof_coordinates(
13201331
for (std::size_t c = 0; c < cells.size(); ++c)
13211332
{
13221333
// Fetch the coordinates of the cell
1323-
auto x_dofs = stdex::submdspan(x_dofmap, cells[c],
1324-
MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
1334+
auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
1335+
x_dofmap, cells[c], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
13251336
for (std::size_t i = 0; i < num_dofs_g; ++i)
13261337
{
13271338
const int pos = 3 * x_dofs[i];

python/.isort.cfg

-8
This file was deleted.

0 commit comments

Comments
 (0)