FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
779 stars 181 forks source link

Cell-partitioning function with ghost mode in python interface #2591

Closed jorgensd closed 1 year ago

jorgensd commented 1 year ago

Describe new/missing feature

In C++ we can choose the partitioner and ghost mode:


#ifdef HAS_PARMETIS
  auto graph_part = dolfinx::graph::parmetis::partitioner();
#elif HAS_PTSCOTCH
  auto graph_part = dolfinx::graph::scotch::partitioner(
      dolfinx::graph::scotch::strategy::scalability);
#elif HAS_KAHIP
  auto graph_part = dolfinx::graph::kahip::partitioner();
#else
#error "No mesh partitioner has been selected"
#endif

  auto cell_part = dolfinx::mesh::create_cell_partitioner(
      dolfinx::mesh::GhostMode::none, graph_part);

This is not possible in Python, as we only have two interfaces:

In [2]: dolfinx.mesh.create_cell_partitioner??
Docstring:
create_cell_partitioner(*args, **kwargs)
Overloaded function.

1. create_cell_partitioner(arg0: dolfinx.cpp.mesh.GhostMode) -> Callable[[MPICommWrapper, int, int, dolfinx::graph::AdjacencyList<long>], dolfinx::graph::AdjacencyList<int>]

2. create_cell_partitioner(part: Callable[[MPICommWrapper, int, dolfinx::graph::AdjacencyList<long>, bool], dolfinx::graph::AdjacencyList<int>]) -> Callable[[MPICommWrapper, int, int, dolfinx::graph::AdjacencyList<long>], dolfinx::graph::AdjacencyList<int>]
Type:      builtin_function_or_method

where the first one only vies you the option to chose ghost mode. The second one lets you send in a graph partitioner, but not the ghost mode (it assumes ghost mode none).

Adding the optional input argument ghost-mode to the latter function, i.e changing: https://github.com/FEniCS/dolfinx/blob/362f241e63052c2c320026498ae404c2c2702d0b/python/dolfinx/wrappers/mesh.cpp#L376-L388 to

  m.def(
      "create_cell_partitioner",
      [](dolfinx::mesh::GhostMode ghost_mode, const std::function<dolfinx::graph::AdjacencyList<std::int32_t>(
             MPICommWrapper comm, int nparts,
             const dolfinx::graph::AdjacencyList<std::int64_t>& local_graph,
             bool ghosting)>& part) -> PythonCellPartitionFunction
      {
        return create_cell_partitioner_py(
            dolfinx::mesh::create_cell_partitioner(
                dolfinx::mesh::GhostMode::none,
                create_cell_partitioner_cpp(part)));
      }, py::arg("ghost_mode")=dolfinx::mesh::GhostMode::none, py::arg("local_graph"))

we would be able to chose partitioner and ghost mode at the same time from C++

Suggestion user interface

No response

garth-wells commented 1 year ago

@jorgensd is this fixed by #2598?