2020namespace dolfinx ::refinement
2121{
2222
23+ namespace impl
24+ {
25+
26+ // / @brief Threshold marking helper
27+ // /
28+ // / @param[in] marker Input marker
29+ // / @param[in] threshold Lower bound for values to mark
30+ // /
31+ // / @returns indices i which satisfy e_i > threshold.
32+ template <std::floating_point T>
33+ std::vector<std::int32_t > mark_threshold (std::span<const T> marker, T threshold)
34+ {
35+ auto mark = [=](T e) { return e > threshold; };
36+
37+ std::vector<std::int32_t > indices;
38+ indices.reserve (std::ranges::count_if (marker, mark));
39+
40+ for (std::int32_t i = 0 ; i < static_cast <std::int32_t >(marker.size ()); ++i)
41+ {
42+ if (mark (marker[i]))
43+ indices.push_back (i);
44+ }
45+
46+ return indices;
47+ }
48+
49+ } // namespace impl
50+
2351// / @brief Maximum marking of a marker.
2452// /
2553// / @param[in] marker Input marker (local) - usually an error indicator per
@@ -39,16 +67,7 @@ std::vector<std::int32_t> mark_maximum(std::span<const T> marker, T theta,
3967 : std::ranges::max (marker);
4068 MPI_Allreduce (MPI_IN_PLACE, &max, 1 , dolfinx::MPI::mpi_t <T>, MPI_MAX, comm);
4169
42- auto mark = [=](T e) { return e > theta * max; };
43-
44- std::vector<std::int32_t > indices;
45- indices.reserve (std::ranges::count_if (marker, mark));
46-
47- for (std::int32_t i = 0 ; i < static_cast <std::int32_t >(marker.size ()); ++i)
48- {
49- if (mark (marker[i]))
50- indices.push_back (i);
51- }
70+ auto indices = impl::mark_threshold<T>(marker, theta * max);
5271
5372 spdlog::info (" Marking (max) {} / {} (local) entities." , indices.size (),
5473 marker.size ());
@@ -83,16 +102,7 @@ std::vector<std::int32_t> mark_equidistribution(std::span<const T> marker,
83102 MPI_Allreduce (MPI_IN_PLACE, &count, 1 , dolfinx::MPI::mpi_t <std::int32_t >,
84103 MPI_SUM, comm);
85104
86- auto mark = [=](T e) { return e > theta * norm / std::sqrt (count); };
87-
88- std::vector<std::int32_t > indices;
89- indices.reserve (std::ranges::count_if (marker, mark));
90-
91- for (std::int32_t i = 0 ; i < static_cast <std::int32_t >(marker.size ()); ++i)
92- {
93- if (mark (marker[i]))
94- indices.push_back (i);
95- }
105+ auto indices = impl::mark_threshold<T>(marker, theta * norm / std::sqrt (count));
96106
97107 spdlog::info (" Marking (equi) {} / {} (local) entities." , indices.size (),
98108 marker.size ());
0 commit comments