Skip to content

Commit

Permalink
Make facet optional return value
Browse files Browse the repository at this point in the history
  • Loading branch information
schnellerhase committed Aug 5, 2024
1 parent b34b090 commit c40d4f6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cpp/dolfinx/refinement/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace dolfinx::refinement::interval
template <std::floating_point T>
std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
std::array<std::size_t, 2>, std::optional<std::vector<std::int32_t>>,
std::vector<std::int8_t>>
std::optional<std::vector<std::int8_t>>>
compute_refinement_data(const mesh::Mesh<T>& mesh,
std::optional<std::span<const std::int32_t>> cells,
Option option)
Expand Down Expand Up @@ -183,7 +183,7 @@ compute_refinement_data(const mesh::Mesh<T>& mesh,
graph::AdjacencyList cell_adj(std::move(cell_topology), std::move(offsets));

return {std::move(cell_adj), std::move(new_vertex_coords), xshape,
std::move(parent_cell), {}};
std::move(parent_cell), std::nullopt};
}

} // namespace dolfinx::refinement::interval
21 changes: 12 additions & 9 deletions cpp/dolfinx/refinement/plaza.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ face_long_edge(const mesh::Mesh<T>& mesh)
template <std::floating_point T>
std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
std::array<std::size_t, 2>, std::optional<std::vector<std::int32_t>>,
std::vector<std::int8_t>>
std::optional<std::vector<std::int8_t>>>
compute_refinement(MPI_Comm neighbor_comm,
std::span<const std::int8_t> marked_edges,
const graph::AdjacencyList<int>& shared_edges,
Expand All @@ -309,7 +309,10 @@ compute_refinement(MPI_Comm neighbor_comm,
if (compute_parent_cell)
parent_cell.emplace();

std::vector<std::int8_t> parent_facet;
std::optional<std::vector<std::int8_t>> parent_facet(std::nullopt);
if (compute_facets)
parent_facet.emplace();

std::vector<std::int64_t> indices(num_cell_vertices + num_cell_edges);
std::vector<std::int32_t> simplex_set;

Expand Down Expand Up @@ -371,9 +374,9 @@ compute_refinement(MPI_Comm neighbor_comm,
if (compute_facets)
{
if (tdim == 3)
parent_facet.insert(parent_facet.end(), {0, 1, 2, 3});
parent_facet->insert(parent_facet->end(), {0, 1, 2, 3});
else
parent_facet.insert(parent_facet.end(), {0, 1, 2});
parent_facet->insert(parent_facet->end(), {0, 1, 2});
}
}
else
Expand Down Expand Up @@ -416,14 +419,14 @@ compute_refinement(MPI_Comm neighbor_comm,
if (tdim == 3)
{
auto npf = compute_parent_facets<3>(simplex_set);
parent_facet.insert(parent_facet.end(), npf.begin(),
std::next(npf.begin(), simplex_set.size()));
parent_facet->insert(parent_facet->end(), npf.begin(),
std::next(npf.begin(), simplex_set.size()));
}
else
{
auto npf = compute_parent_facets<2>(simplex_set);
parent_facet.insert(parent_facet.end(), npf.begin(),
std::next(npf.begin(), simplex_set.size()));
parent_facet->insert(parent_facet->end(), npf.begin(),
std::next(npf.begin(), simplex_set.size()));
}
}

Expand Down Expand Up @@ -457,7 +460,7 @@ compute_refinement(MPI_Comm neighbor_comm,
template <std::floating_point T>
std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<T>,
std::array<std::size_t, 2>, std::optional<std::vector<std::int32_t>>,
std::vector<std::int8_t>>
std::optional<std::vector<std::int8_t>>>
compute_refinement_data(const mesh::Mesh<T>& mesh,
std::optional<std::span<const std::int32_t>> edges,
Option option)
Expand Down
2 changes: 1 addition & 1 deletion cpp/dolfinx/refinement/refine.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ create_refined_mesh(const mesh::Mesh<T>& mesh,
/// @return New Mesh and optional parent cell index, parent facet indices
template <std::floating_point T>
std::tuple<mesh::Mesh<T>, std::optional<std::vector<std::int32_t>>,
std::vector<std::int8_t>>
std::optional<std::vector<std::int8_t>>>
refine(const mesh::Mesh<T>& mesh,
std::optional<std::span<const std::int32_t>> edges, bool redistribute,
mesh::GhostMode ghost_mode = mesh::GhostMode::shared_facet,
Expand Down
7 changes: 6 additions & 1 deletion python/dolfinx/wrappers/refinement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ void export_refinement_with_variable_mesh_type(nb::module_& m)
if (cell.has_value())
python_cell.emplace(as_nbarray(std::move(cell.value())));

std::optional<nb::ndarray<std::int8_t, nb::numpy>> python_facet(
std::nullopt);
if (facet.has_value())
python_facet.emplace(as_nbarray(std::move(facet.value())));

return std::tuple{std::move(mesh1), std::move(python_cell),
as_nbarray(std::move(facet))};
std::move(python_facet)};
},
nb::arg("mesh"), nb::arg("edges") = nb::none(), nb::arg("redistribute"),
nb::arg("ghost_mode"), nb::arg("option"));
Expand Down

0 comments on commit c40d4f6

Please sign in to comment.