DOLFINx 0.11.0.0
DOLFINx C++
Loading...
Searching...
No Matches
mark.h
1// Copyright (C) 2026 Paul T. Kühner
2//
3// This file is part of DOLFINX (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include <algorithm>
10#include <cassert>
11#include <concepts>
12#include <cstdint>
13#include <limits>
14#include <mpi.h>
15#include <spdlog/spdlog.h>
16#include <vector>
17
18#include "dolfinx/common/MPI.h"
19
20namespace dolfinx::refinement
21{
22
31template <std::floating_point T>
32std::vector<std::int32_t> mark_maximum(std::span<const T> marker, T theta,
33 MPI_Comm comm)
34{
35 if ((theta <= 0) || (theta >= 1))
36 throw std::invalid_argument("Theta needs to fullfill 0 < θ < 1.");
37
38 T max = marker.empty() ? std::numeric_limits<T>::lowest()
39 : std::ranges::max(marker);
40 MPI_Allreduce(MPI_IN_PLACE, &max, 1, dolfinx::MPI::mpi_t<T>, MPI_MAX, comm);
41
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 }
52
53 spdlog::info("Marking (max) {} / {} (local) entities.", indices.size(),
54 marker.size());
55
56 return indices;
57}
58
59} // namespace dolfinx::refinement
MPI_Datatype mpi_t
Retrieves the MPI data type associated to the provided type.
Definition MPI.h:280
Mesh refinement algorithms.
Definition dolfinx_refinement.h:8
std::vector< std::int32_t > mark_maximum(std::span< const T > marker, T theta, MPI_Comm comm)
Maximum marking of a marker.
Definition mark.h:32