core
Shared MPI block decomposition + asynchronous ghost-layer exchange (header-only C++20)
Loading...
Searching...
No Matches
refine.hpp
Go to the documentation of this file.
1// core — refinement criteria for a BlockOctree.
2//
3// Topology-mutation helpers that drive BlockOctree::refineIf from a geometric
4// criterion. The headline one is SDF-driven: refine leaves the solid surface
5// passes through (plus a band) down to a target level, leaving the interior /
6// far field coarse — the usual AMR pattern for the suite's cut-cell IBM. Reuses
7// the shared peclet::core::geom SDF (any callable returning a signed distance at a world
8// point) and the AmrGeometry world mapping.
9//
10// Header-only, guarded by PECLET_CORE_HAVE_MORTON.
11#ifndef PECLET_CORE_AMR_REFINE_HPP
12#define PECLET_CORE_AMR_REFINE_HPP
13
14#ifdef PECLET_CORE_HAVE_MORTON
15
16#include <algorithm>
17#include <cmath>
18#include <vector>
19
23
24namespace peclet::core::amr {
25
34template <int Dim, unsigned Bits, class SdfFn>
36 unsigned targetLevel, Real band = 1.0, bool balance = true) {
37 using Code = typename BlockOctree<Dim, Bits>::Code;
38 const Real halfDiagFactor = 0.5 * std::sqrt(static_cast<Real>(Dim));
39 Index total = 0;
40 for (;;) {
41 std::vector<Code> toRefine;
42 for (Index i = 0; i < t.numLeaves(); ++i) {
43 const unsigned L = t.level(i);
44 if (L <= targetLevel)
45 continue;
46 auto b = t.bounds(i);
47 Vec<Dim> c = geo.center(b);
48 const Real width = geo.leafSize(L);
49 if (std::fabs(static_cast<Real>(sdf(c))) <= halfDiagFactor * width + band * geo.h0)
50 toRefine.push_back(t.code(i));
51 }
52 if (toRefine.empty())
53 break;
54 std::sort(toRefine.begin(), toRefine.end());
55 toRefine.erase(std::unique(toRefine.begin(), toRefine.end()), toRefine.end());
56 total += t.refineIf(
57 [&](Code c, unsigned) { return std::binary_search(toRefine.begin(), toRefine.end(), c); });
58 }
59 if (balance)
60 total += t.balance2to1();
61 return total;
62}
63
64} // namespace peclet::core::amr
65
66#endif // PECLET_CORE_HAVE_MORTON
67#endif // PECLET_CORE_AMR_REFINE_HPP
typename M::code_type Code
Index refineToSdf(BlockOctree< Dim, Bits > &t, const AmrGeometry< Dim > &geo, SdfFn &&sdf, unsigned targetLevel, Real band=1.0, bool balance=true)
Refine leaves near an SDF interface down to targetLevel.
Definition refine.hpp:35
Kokkos::View< T *, MemSpace > View
1D device array.
Definition view.hpp:26
double Real
Default host floating type. Device kernels may use float; conversions happen at the boundary.
Definition types.hpp:18
std::int64_t Index
Signed index type for grids and particles (supersedes block_decomposer's long int IndxT).
Definition types.hpp:15