include/pops/numerics/spatial/embedded_boundary/domain.hpp Source FileΒΆ

adc_cpp: include/pops/numerics/spatial/embedded_boundary/domain.hpp Source File
adc_cpp 0.3.0
Model-free C++23 core for coupled hyperbolic-elliptic systems on adaptive (AMR) meshes, with MPI and GPU (Kokkos) backends
domain.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pops/core/foundation/types.hpp> // Real, POPS_HD
4
5#include <cmath> // std::hypot
6#include <concepts> // std::convertible_to (diagnostics only)
7
37
38namespace pops {
39
43template <class D>
44concept LevelSetDomain = requires(const D d, Real x, Real y) {
45 { d.level_set(x, y) } -> std::convertible_to<Real>;
46 { d(x, y) } -> std::convertible_to<Real>;
47 { d.cell_active(x, y) } -> std::convertible_to<bool>;
48};
49
50namespace detail {
51
69struct DiscDomain {
70 double cx = 0.0;
71 double cy = 0.0;
72 double R = 0.0;
73
76 static DiscDomain centered_in_box(double L, double radius) {
77 return DiscDomain{0.5 * L, 0.5 * L, radius};
78 }
79
83 return static_cast<Real>(std::hypot(static_cast<double>(x) - cx, static_cast<double>(y) - cy) -
84 R);
85 }
86
88 POPS_HD Real operator()(Real x, Real y) const { return level_set(x, y); }
89
91 POPS_HD bool cell_active(Real x, Real y) const { return level_set(x, y) < Real(0); }
92};
93
98 double a = 0.0;
99 double b = 0.0;
100 double c = 0.0;
101
104 return static_cast<Real>(a * static_cast<double>(x) + b * static_cast<double>(y) - c);
105 }
106
108 POPS_HD Real operator()(Real x, Real y) const { return level_set(x, y); }
109
111 POPS_HD bool cell_active(Real x, Real y) const { return level_set(x, y) < Real(0); }
112};
113
114} // namespace detail
115} // namespace pops
Definition domain.hpp:44
Definition amr_hierarchy.hpp:29
double Real
Definition types.hpp:30
CIRCLE / DISC level-set domain: the canonical instance of the contract and the SINGLE SOURCE of truth...
Definition domain.hpp:69
static DiscDomain centered_in_box(double L, double radius)
Disc centered in a square box [0, L]^2 with radius radius (same center as wall_predicate("circle",...
Definition domain.hpp:76
double cy
center y (default L/2 when built from L)
Definition domain.hpp:71
POPS_HD bool cell_active(Real x, Real y) const
ACTIVE cell: its center (x, y) is inside the disc (ls < 0). Same inside test as GeometricMG.
Definition domain.hpp:91
double cx
center x (default L/2 when built from L)
Definition domain.hpp:70
POPS_HD Real level_set(Real x, Real y) const
Level set ls(x, y) = hypot(x - cx, y - cy) - R: < 0 inside, 0 at the boundary, > 0 outside.
Definition domain.hpp:82
double R
disc radius
Definition domain.hpp:72
POPS_HD Real operator()(Real x, Real y) const
Callable form (the LevelSet argument of cut_fraction / assemble_rhs_eb); forwards to level_set.
Definition domain.hpp:88
HALF-PLANE level-set domain: ls(x, y) = a*x + b*y - c, ACTIVE on the side a*x + b*y < c.
Definition domain.hpp:97
POPS_HD Real operator()(Real x, Real y) const
Callable form (forwards to level_set), so the domain is directly usable as a LevelSet argument.
Definition domain.hpp:108
double b
y coefficient
Definition domain.hpp:99
double a
x coefficient of the linear level set
Definition domain.hpp:98
POPS_HD bool cell_active(Real x, Real y) const
ACTIVE cell: its center (x, y) is on the active side (ls < 0).
Definition domain.hpp:111
POPS_HD Real level_set(Real x, Real y) const
Level set ls(x, y) = a*x + b*y - c: < 0 inside (active side), 0 on the line, > 0 outside.
Definition domain.hpp:103
double c
offset: active where a*x + b*y - c < 0
Definition domain.hpp:100
Base scalar types and the POPS_HD macro (host+device portability).
#define POPS_HD
Definition types.hpp:25