Skip to content

Commit df1d68f

Browse files
authored
Make low-level default args not-default (#4082)
* Start fixing default args * Fixes * Fixes * Update tests * Lint * Type hint fixes * mypy updates * Small fix * Fixes * Fixes * Doc fixes * Small updates
1 parent 80afaf7 commit df1d68f

27 files changed

+156
-88
lines changed

cpp/dolfinx/mesh/generation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ Mesh<T> create_box(MPI_Comm comm, MPI_Comm subcomm,
117117
}
118118

119119
if (!partitioner and dolfinx::MPI::size(comm) > 1)
120-
partitioner = create_cell_partitioner();
120+
partitioner = create_cell_partitioner(mesh::GhostMode::none, 2);
121121

122122
switch (celltype)
123123
{
@@ -193,7 +193,7 @@ Mesh<T> create_rectangle(MPI_Comm comm, std::array<std::array<T, 2>, 2> p,
193193
}
194194

195195
if (!partitioner and dolfinx::MPI::size(comm) > 1)
196-
partitioner = create_cell_partitioner();
196+
partitioner = create_cell_partitioner(mesh::GhostMode::none, 2);
197197

198198
switch (celltype)
199199
{
@@ -262,7 +262,7 @@ Mesh<T> create_interval(MPI_Comm comm, std::int64_t n, std::array<T, 2> p,
262262
}
263263

264264
if (!partitioner and dolfinx::MPI::size(comm) > 1)
265-
partitioner = create_cell_partitioner(ghost_mode);
265+
partitioner = create_cell_partitioner(ghost_mode, 2);
266266

267267
fem::CoordinateElement<T> element(CellType::interval, 1);
268268
if (dolfinx::MPI::rank(comm) == 0)

cpp/dolfinx/mesh/graphbuild.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ enum class CellType : std::int8_t;
2929
/// matched facet is not connected any cells on other processes. All
3030
/// facets connected to less than `max_facet_to_cell_links` cells are
3131
/// considered *unmatched* and parallel communication will check for
32-
/// further connections. Defaults to `2`, which covers non-branching
33-
/// manifold meshes. Passing std::nullopt (no upper bound) corresponds
32+
/// further connections. Equal to `2` for non-branching manifold meshes.
33+
/// Passing std::nullopt (no upper bound) corresponds.
3434
/// to `max_facet_to_cell_links`=∞, i.e. every facet is considered
3535
/// unmatched.
3636
///
@@ -60,7 +60,7 @@ std::tuple<graph::AdjacencyList<std::int32_t>, std::vector<std::int64_t>,
6060
std::size_t, std::vector<std::int32_t>>
6161
build_local_dual_graph(std::span<const CellType> celltypes,
6262
const std::vector<std::span<const std::int64_t>>& cells,
63-
std::optional<std::int32_t> max_facet_to_cell_links = 2);
63+
std::optional<std::int32_t> max_facet_to_cell_links);
6464

6565
/// @brief Build distributed mesh dual graph (cell-cell connections via
6666
/// facets) from minimal mesh data.
@@ -96,6 +96,6 @@ build_local_dual_graph(std::span<const CellType> celltypes,
9696
graph::AdjacencyList<std::int64_t>
9797
build_dual_graph(MPI_Comm comm, std::span<const CellType> celltypes,
9898
const std::vector<std::span<const std::int64_t>>& cells,
99-
std::optional<std::int32_t> max_facet_to_cell_links = 2);
99+
std::optional<std::int32_t> max_facet_to_cell_links);
100100

101101
} // namespace dolfinx::mesh

cpp/dolfinx/mesh/utils.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ mesh::CellPartitionFunction mesh::create_cell_partitioner(
109109
spdlog::info("Compute partition of cells across ranks");
110110

111111
// Compute distributed dual graph (for the cells on this process)
112-
const graph::AdjacencyList dual_graph
112+
graph::AdjacencyList dual_graph
113113
= build_dual_graph(comm, cell_types, cells, max_facet_to_cell_links);
114114

115115
// Just flag any kind of ghosting for now
@@ -120,6 +120,14 @@ mesh::CellPartitionFunction mesh::create_cell_partitioner(
120120
};
121121
}
122122
//-----------------------------------------------------------------------------
123+
mesh::CellPartitionFunction mesh::create_cell_partitioner(
124+
mesh::GhostMode ghost_mode,
125+
std::optional<std::int32_t> max_facet_to_cell_links)
126+
{
127+
return create_cell_partitioner(ghost_mode, &graph::partition_graph,
128+
max_facet_to_cell_links);
129+
}
130+
//-----------------------------------------------------------------------------
123131
std::vector<std::int32_t>
124132
mesh::compute_incident_entities(const Topology& topology,
125133
std::span<const std::int32_t> entities, int d0,

cpp/dolfinx/mesh/utils.h

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,23 @@ using CellReorderFunction = std::function<std::vector<std::int32_t>(
227227
/// TODO: offload to cpp?
228228
inline auto
229229
create_boundary_vertices_fn(const CellReorderFunction& reorder_fn,
230-
std::optional<std::int32_t> max_facet_to_cell_links
231-
= 2)
230+
std::optional<std::int32_t> max_facet_to_cell_links)
232231
{
233-
/// brief Function that computes the process boundary vertices of a mesh
234-
/// during creation.
235-
/// param[in] celltypes List of celltypes in mesh.
236-
/// param[in] doflayouts List of DOF layouts in mesh.
237-
/// param[in] ghost_owners List of ghost owner per cell per celltype.
238-
/// param[out] cells List of cells per celltpye. Reorderd during call.
239-
/// param[out] cells_v List of vertices (no higher order nodes) of cell per
240-
/// celltype. Reordered during call.
241-
/// param[out] original_idx Contains the permutation applied to the cells per
242-
/// celltype.
243-
/// return Boundary vertices (for all cell types).
232+
/// @cond
233+
/// @brief Function that computes the process boundary vertices of a
234+
/// mesh during creation.
235+
///
236+
/// @param[in] celltypes List of celltypes in mesh.
237+
/// @param[in] doflayouts List of DOF layouts in mesh.
238+
/// @param[in] ghost_owners List of ghost owner per cell per celltype.
239+
/// @param[out] cells List of cells per celltpye. Reorderd during
240+
/// call.
241+
/// @param[out] cells_v List of vertices (no higher order nodes) of
242+
/// cell per celltype. Reordered during call.
243+
/// @param[out] original_idx Contains the permutation applied to the
244+
/// cells per celltype.
245+
/// @return Boundary vertices (for all cell types).
246+
/// @endcond
244247
return [&, max_facet_to_cell_links](
245248
const std::vector<CellType>& celltypes,
246249
const std::vector<fem::ElementDofLayout>& doflayouts,
@@ -955,17 +958,32 @@ entities_to_geometry(const Mesh<T>& mesh, int dim,
955958
/// @brief Create a function that computes destination rank for mesh
956959
/// cells on this rank by applying the default graph partitioner to the
957960
/// dual graph of the mesh.
961+
///
958962
/// @param[in] ghost_mode ghost mode of the created mesh, defaults to none
959963
/// @param[in] partfn Partitioning function for distributing cells
960964
/// across MPI ranks.
961965
/// @param[in] max_facet_to_cell_links Bound on the number of cells a
962-
/// facet needs to be connected to to be considered *matched* (not on boundary
963-
/// for non-branching meshes).
966+
/// facet needs to be connected to to be considered *matched* (not on
967+
/// boundary for non-branching meshes).
964968
/// @return Function that computes the destination ranks for each cell.
965-
CellPartitionFunction create_cell_partitioner(
966-
mesh::GhostMode ghost_mode = mesh::GhostMode::none,
967-
const graph::partition_fn& partfn = &graph::partition_graph,
968-
std::optional<std::int32_t> max_facet_to_cell_links = 2);
969+
CellPartitionFunction
970+
create_cell_partitioner(mesh::GhostMode ghost_mode,
971+
const graph::partition_fn& partfn,
972+
std::optional<std::int32_t> max_facet_to_cell_links);
973+
974+
/// @brief Create a function that computes destination rank for mesh
975+
/// cells on this rank by applying the default graph partitioner to the
976+
/// dual graph of the mesh.
977+
///
978+
/// @param[in] ghost_mode ghost mode of the created mesh, defaults to none
979+
/// @param[in] max_facet_to_cell_links Bound on the number of cells a
980+
/// facet needs to be connected to to be considered *matched* (not on
981+
/// boundary for non-branching meshes).
982+
/// @return Function that computes the destination ranks for each cell.
983+
CellPartitionFunction
984+
create_cell_partitioner(mesh::GhostMode ghost_mode,
985+
std::optional<std::int32_t> max_facet_to_cell_links
986+
= 2);
969987

970988
/// @brief Compute incident entities.
971989
/// @param[in] topology The topology.
@@ -1244,7 +1262,7 @@ Mesh<typename std::remove_reference_t<typename U::value_type>> create_mesh(
12441262
typename std::remove_reference_t<typename U::value_type>>& element,
12451263
MPI_Comm commg, const U& x, std::array<std::size_t, 2> xshape,
12461264
const CellPartitionFunction& partitioner,
1247-
std::optional<std::int32_t> max_facet_to_cell_links = 2,
1265+
std::optional<std::int32_t> max_facet_to_cell_links,
12481266
const CellReorderFunction& reorder_fn = graph::reorder_gps)
12491267
{
12501268
return create_mesh(comm, commt, std::vector{cells}, std::vector{element},
@@ -1287,9 +1305,10 @@ create_mesh(MPI_Comm comm, std::span<const std::int64_t> cells,
12871305
}
12881306
else
12891307
{
1290-
return create_mesh(comm, comm, std::vector{cells}, std::vector{elements},
1291-
comm, x, xshape, create_cell_partitioner(ghost_mode),
1292-
max_facet_to_cell_links);
1308+
return create_mesh(
1309+
comm, comm, std::vector{cells}, std::vector{elements}, comm, x, xshape,
1310+
create_cell_partitioner(ghost_mode, max_facet_to_cell_links),
1311+
max_facet_to_cell_links);
12931312
}
12941313
}
12951314

cpp/dolfinx/refinement/refine.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ create_identity_partitioner(const mesh::Mesh<T>& parent_mesh,
7474
if (comm == MPI_COMM_NULL)
7575
return graph::regular_adjacency_list(std::move(destinations), 1);
7676

77-
auto dual_graph = mesh::build_dual_graph(comm, cell_types, cells);
77+
auto dual_graph = mesh::build_dual_graph(comm, cell_types, cells, 2);
7878
std::vector<std::int32_t> node_disp(MPI::size(comm) + 1, 0);
7979
std::int32_t local_size = dual_graph.num_nodes();
8080
MPI_Allgather(&local_size, 1, dolfinx::MPI::mpi_t<std::int32_t>,
@@ -153,7 +153,7 @@ refine(const mesh::Mesh<T>& mesh,
153153
mesh::Mesh<T> mesh1 = mesh::create_mesh(
154154
mesh.comm(), mesh.comm(), cell_adj.array(), mesh.geometry().cmap(),
155155
mesh.comm(), new_vertex_coords, xshape,
156-
std::get<mesh::CellPartitionFunction>(partitioner));
156+
std::get<mesh::CellPartitionFunction>(partitioner), 2);
157157

158158
// Report the number of refined cells
159159
const int D = topology->dim();

cpp/dolfinx/refinement/uniform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ template <typename T>
1919
mesh::Mesh<T>
2020
uniform_refine(const mesh::Mesh<T>& mesh,
2121
const mesh::CellPartitionFunction& partitioner
22-
= mesh::create_cell_partitioner(mesh::GhostMode::none));
22+
= mesh::create_cell_partitioner(mesh::GhostMode::none, 2));
2323

2424
} // namespace dolfinx::refinement

cpp/test/matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace
3030
template <std::floating_point T>
3131
la::MatrixCSR<T> create_operator(MPI_Comm comm)
3232
{
33-
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none);
33+
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none, 2);
3434
auto mesh = std::make_shared<mesh::Mesh<T>>(
3535
mesh::create_box(comm, {{{0.0, 0.0, 0.0}, {1.0, 1.0, 1.0}}}, {12, 12, 12},
3636
mesh::CellType::tetrahedron, part));
@@ -66,7 +66,7 @@ void test_matrix_norm()
6666
void test_matrix_apply()
6767
{
6868
MPI_Comm comm = MPI_COMM_WORLD;
69-
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none);
69+
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none, 2);
7070
auto mesh = std::make_shared<mesh::Mesh<double>>(
7171
mesh::create_box(comm, {{{0.0, 0.0, 0.0}, {1.0, 1.0, 1.0}}}, {12, 12, 12},
7272
mesh::CellType::tetrahedron, part));

cpp/test/mesh/branching_manifold.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ TEST_CASE("dual_graph_branching")
4848
{
4949
// default
5050
auto [dual_graph, unmatched_facets, max_vertices_per_facet, cell_data]
51-
= mesh::build_local_dual_graph(celltypes, {cells});
51+
= mesh::build_local_dual_graph(celltypes, {cells}, 2);
5252

5353
CHECK(dual_graph.num_nodes() == 4);
5454

cpp/test/mesh/distributed_mesh.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void test_distributed_mesh(const mesh::CellPartitionFunction& partitioner)
139139

140140
// Build mesh
141141
mesh::Mesh mesh = mesh::create_mesh(comm, subset_comm, cells, cmap, comm, x,
142-
xshape, partitioner);
142+
xshape, partitioner, 2);
143143
auto t = mesh.topology();
144144
int tdim = t->dim();
145145
CHECK(t->index_map(tdim)->size_global() == 2 * N * N);
@@ -161,11 +161,11 @@ TEST_CASE("Create box", "[create_box]")
161161
{
162162
#ifdef HAS_PTSCOTCH
163163
CHECK_NOTHROW(test_create_box(mesh::create_cell_partitioner(
164-
mesh::GhostMode::none, graph::scotch::partitioner())));
164+
mesh::GhostMode::none, graph::scotch::partitioner(), 2)));
165165
#endif
166166
#ifdef HAS_PARMETIS
167167
CHECK_NOTHROW(test_create_box(mesh::create_cell_partitioner(
168-
mesh::GhostMode::none, graph::parmetis::partitioner())));
168+
mesh::GhostMode::none, graph::parmetis::partitioner(), 2)));
169169
#endif
170170
// #ifdef HAS_KAHIP
171171
// CHECK_NOTHROW(test_create_box(mesh::create_cell_partitioner(
@@ -183,14 +183,14 @@ TEST_CASE("Distributed Mesh", "[distributed_mesh]")
183183

184184
#ifdef HAS_PTSCOTCH
185185
CHECK_NOTHROW(test_distributed_mesh(mesh::create_cell_partitioner(
186-
mesh::GhostMode::none, graph::scotch::partitioner())));
186+
mesh::GhostMode::none, graph::scotch::partitioner(), 2)));
187187
#endif
188188
#ifdef HAS_PARMETIS
189189
CHECK_NOTHROW(test_distributed_mesh(mesh::create_cell_partitioner(
190-
mesh::GhostMode::none, graph::parmetis::partitioner())));
190+
mesh::GhostMode::none, graph::parmetis::partitioner(), 2)));
191191
#endif
192192
#ifdef HAS_KAHIP
193193
CHECK_NOTHROW(test_distributed_mesh(mesh::create_cell_partitioner(
194-
mesh::GhostMode::none, graph::kahip::partitioner(1, 1, 0.03, false))));
194+
mesh::GhostMode::none, graph::kahip::partitioner(1, 1, 0.03, false), 2)));
195195
#endif
196196
}

cpp/test/mesh/read_named_meshtags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void test_read_named_meshtags()
2929
constexpr std::int32_t material_value = 2;
3030

3131
// Create mesh
32-
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none);
32+
auto part = mesh::create_cell_partitioner(mesh::GhostMode::none, 2);
3333
auto mesh = std::make_shared<mesh::Mesh<double>>(
3434
mesh::create_rectangle(MPI_COMM_WORLD, {{{0.0, 0.0}, {1.0, 1.0}}}, {3, 3},
3535
mesh::CellType::triangle, part));

0 commit comments

Comments
 (0)