Block-Structured AMR Software Framework
Loading...
Searching...
No Matches
AMReX_EBData.H
Go to the documentation of this file.
1#ifndef AMREX_EB_DATA_H_
2#define AMREX_EB_DATA_H_
3#include <AMReX_Config.H>
4
5#include <AMReX_EBCellFlag.H>
6#include <AMReX_Random.H>
7
8namespace amrex
9{
10
11enum struct EBData_t : int
12{
13 levelset, // level set
14 volfrac, // volume fraction
15 centroid, // volume centroid
16 bndrycent, // boundary centroid
17 bndrynorm, // boundary normal
18 bndryarea, // boundary area
19 AMREX_D_DECL(apx, apy, apz), // area fraction
20 AMREX_D_DECL(fcx, fcy, fcz), // face centroid
21 AMREX_D_DECL(ecx, ecy, ecz), // edge centroid
22 cellflag // EBCellFlag
23};
24
25struct EBData
26{
27 template <EBData_t T>
29 auto get (int i, int j, int k) const noexcept
30 {
31 if constexpr (T == EBData_t::cellflag) {
32 return (*m_cell_flag)(i,j,k);
33 } else {
34 return m_real_data[static_cast<int>(T)](i,j,k);
35 }
36 }
37
38 template <EBData_t T>
40 const auto& get () const noexcept
41 {
42 if constexpr (T == EBData_t::cellflag) {
43 return *m_cell_flag;
44 } else {
45 return m_real_data[static_cast<int>(T)];
46 }
47 }
48
49 template <EBData_t T, std::enable_if_t< T == EBData_t::centroid
53 || T==EBData_t::fcy,
54 || T==EBData_t::fcz), int> = 0>
56 auto get (int i, int j, int k, int n) const noexcept
57 {
58 return m_real_data[static_cast<int>(T)](i,j,k,n);
59 }
60
63 randomPointOnEB (int i, int j, int k, RandomEngine const& engine) const
64 {
65 Real nx = this->get<EBData_t::bndrynorm>(i,j,k,0);
66 Real ny = this->get<EBData_t::bndrynorm>(i,j,k,1);
67 Real bcx = this->get<EBData_t::bndrycent>(i,j,k,0);
68 Real bcy = this->get<EBData_t::bndrycent>(i,j,k,1);
69 int dir = (std::abs(nx) >= std::abs(ny)) ? 0 : 1;
70#if (AMREX_SPACEDIM == 2)
71 auto f = [&] (Real n0, Real n1, Real bc0, Real bc1)
72 {
73 Real rn = amrex::Random(engine);
74 if (n1 == 0) {
75 return amrex::makeTuple(bc0, rn-Real(0.5));
76 } else {
77 Real nn = n0/n1; // Note that we have n0 >= n1. So nn != 0.
78 Real ym = bc1+nn*(bc0-Real(-0.5)); // where x=-0.5 and EB intersects
79 Real yp = bc1+nn*(bc0-Real( 0.5)); // where x= 0.5 and EB intersects
80 Real ymin = std::min(ym,yp);
81 Real ymax = std::max(ym,yp);
82 ymin = std::max(ymin, Real(-0.5));
83 ymax = std::min(ymax, Real( 0.5));
84 Real y = rn*(ymax-ymin) + ymin;
85 Real x = bc0 - (y-bc1)*n1/n0;
86 return amrex::makeTuple(x,y);
87 }
88 };
89
90 if (dir == 0) {
91 auto [x,y] = f( nx, ny,
92 bcx,bcy);
93 return GpuArray<Real,2>{x,y};
94 } else {
95 auto [y,x] = f( ny, nx,
96 bcy,bcx);
97 return GpuArray<Real,2>{x,y};
98 }
99#else
100 Real nz = this->get<EBData_t::bndrynorm>(i,j,k,2);
101 Real bcz = this->get<EBData_t::bndrycent>(i,j,k,2);
102 if (std::abs(nz) > std::abs(nx) && std::abs(nz) > std::abs(ny)) {
103 dir = 2;
104 }
105 auto f = [&] (Real n0, Real n1, Real n2, Real bc0, Real bc1, Real bc2)
106 { // Note that n0 >= n1 >= n2;
107 if (n1 == 0 && n2 == 0) {
108 return amrex::makeTuple(bc0,
109 amrex::Random(engine)-Real(0.5),
110 amrex::Random(engine)-Real(0.5));
111 } else if (n2 == 0) {
112 Real nn = n0/n1;
113 Real ym = bc1+nn*(bc0-Real(-0.5));
114 Real yp = bc1+nn*(bc0-Real( 0.5));
115 Real ymin = std::min(ym,yp);
116 Real ymax = std::max(ym,yp);
117 ymin = std::max(ymin, Real(-0.5));
118 ymax = std::min(ymax, Real( 0.5));
119 Real y = amrex::Random(engine)*(ymax-ymin) + ymin;
120 Real z = amrex::Random(engine) - Real(0.5);
121 Real x = bc0 - ((y-bc1)*n1+(z-bc2)*n2)/n0;
122 return amrex::makeTuple(x,y,z);
123 } else {
124 Real y0 = bc1 - ((Real(-0.5)-bc0)*n0+(Real(-0.5)-bc2)*n2)/n1;
125 Real y1 = bc1 - ((Real( 0.5)-bc0)*n0+(Real(-0.5)-bc2)*n2)/n1;
126 Real y2 = bc1 - ((Real(-0.5)-bc0)*n0+(Real( 0.5)-bc2)*n2)/n1;
127 Real y3 = bc1 - ((Real( 0.5)-bc0)*n0+(Real( 0.5)-bc2)*n2)/n1;
128 Real ymin = amrex::min(y0,y1,y2,y3);
129 Real ymax = amrex::max(y0,y1,y2,y3);
130 ymin = std::max(ymin, Real(-0.5));
131 ymax = std::min(ymax, Real( 0.5));
132 Real z0 = bc2 - ((Real(-0.5)-bc0)*n0+(Real(-0.5)-bc1)*n1)/n2;
133 Real z1 = bc2 - ((Real( 0.5)-bc0)*n0+(Real(-0.5)-bc1)*n1)/n2;
134 Real z2 = bc2 - ((Real(-0.5)-bc0)*n0+(Real( 0.5)-bc1)*n1)/n2;
135 Real z3 = bc2 - ((Real( 0.5)-bc0)*n0+(Real( 0.5)-bc1)*n1)/n2;
136 Real zmin = amrex::min(z0,z1,z2,z3);
137 Real zmax = amrex::max(z0,z1,z2,z3);
138 zmin = std::max(zmin, Real(-0.5));
139 zmax = std::min(zmax, Real( 0.5));
140 Real x, y, z;
141 do {
142 y = amrex::Random(engine)*(ymax-ymin) + ymin;
143 z = amrex::Random(engine)*(zmax-zmin) + zmin;
144 x = bc0 - ((y-bc1)*n1+(z-bc2)*n2)/n0;
145 } while (x > Real(0.5) || x < Real(-0.5));
146 return amrex::makeTuple(x,y,z);
147 }
148 };
149 if (dir == 0) {
150 if (std::abs(ny) >= std::abs(nz)) {
151 auto [x,y,z] = f( nx, ny, nz,
152 bcx,bcy,bcz);
153 return GpuArray<Real,3>{x, y, z};
154 } else {
155 auto [x,z,y] = f( nx, nz, ny,
156 bcx,bcz,bcy);
157 return GpuArray<Real,3>{x, y, z};
158 }
159 } else if (dir == 1) {
160 if (std::abs(nx) >= std::abs(nz)) {
161 auto [y,x,z] = f( ny, nx, nz,
162 bcy,bcx,bcz);
163 return GpuArray<Real,3>{x, y, z};
164 } else {
165 auto [y,z,x] = f( ny, nz, nx,
166 bcy,bcz,bcx);
167 return GpuArray<Real,3>{x, y, z};
168 }
169 } else {
170 if (std::abs(nx) >= std::abs(ny)) {
171 auto [z,x,y] = f( nz, nx, ny,
172 bcz,bcx,bcy);
173 return GpuArray<Real,3>{x, y, z};
174 } else {
175 auto [z,y,x] = f( nz, ny, nx,
176 bcz,bcy,bcx);
177 return GpuArray<Real,3>{x, y, z};
178 }
179 }
180#endif
181 }
182
183 static constexpr int real_data_size = static_cast<int>(EBData_t::cellflag);
184
187};
188
190{
191 template <EBData_t T>
193 auto get (int box_no, int i, int j, int k) const noexcept
194 {
195 if constexpr (T == EBData_t::cellflag) {
196 return m_cell_flag[box_no](i,j,k);
197 } else {
198 return m_real_data[(box_no*real_data_size) + static_cast<int>(T)](i,j,k);
199 }
200 }
201
202 template <EBData_t T, std::enable_if_t< T == EBData_t::centroid
203 || T == EBData_t::bndrycent
204 || T == EBData_t::bndrynorm
206 || T==EBData_t::fcy,
207 || T==EBData_t::fcz), int> = 0>
209 auto get (int box_no, int i, int j, int k, int n) const noexcept
210 {
211 return m_real_data[(box_no*real_data_size) + static_cast<int>(T)](i,j,k,n);
212 }
213
215 EBData get (int box_no) const noexcept
216 {
217 return EBData{m_cell_flag + box_no, m_real_data + (box_no * real_data_size)};
218 }
219
220 static constexpr int real_data_size = static_cast<int>(EBData_t::cellflag);
221
224};
225
226}
227#endif
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition AMReX_Extension.H:32
#define AMREX_GPU_HOST_DEVICE
Definition AMReX_GpuQualifiers.H:20
#define AMREX_D_TERM(a, b, c)
Definition AMReX_SPACE.H:172
#define AMREX_D_DECL(a, b, c)
Definition AMReX_SPACE.H:171
amrex_real Real
Floating Point Type for Fields.
Definition AMReX_REAL.H:79
Real Random()
Generate a psuedo-random real from uniform distribution.
Definition AMReX_Random.cpp:123
Definition AMReX_Amr.cpp:49
__host__ __device__ constexpr GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition AMReX_Tuple.H:263
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:24
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:44
EBData_t
Definition AMReX_EBData.H:12
A multidimensional array accessor.
Definition AMReX_Array4.H:283
Definition AMReX_EBData.H:190
Array4< Real const > const *__restrict__ m_real_data
Definition AMReX_EBData.H:223
__host__ __device__ auto get(int box_no, int i, int j, int k, int n) const noexcept
Definition AMReX_EBData.H:209
static constexpr int real_data_size
Definition AMReX_EBData.H:220
Array4< EBCellFlag const > const *__restrict__ m_cell_flag
Definition AMReX_EBData.H:222
__host__ __device__ auto get(int box_no, int i, int j, int k) const noexcept
Definition AMReX_EBData.H:193
__host__ __device__ EBData get(int box_no) const noexcept
Definition AMReX_EBData.H:215
Definition AMReX_EBData.H:26
__host__ __device__ GpuArray< Real, 3 > randomPointOnEB(int i, int j, int k, RandomEngine const &engine) const
Definition AMReX_EBData.H:63
__host__ __device__ const auto & get() const noexcept
Definition AMReX_EBData.H:40
Array4< EBCellFlag const > const * m_cell_flag
Definition AMReX_EBData.H:185
static constexpr int real_data_size
Definition AMReX_EBData.H:183
Array4< Real const > const * m_real_data
Definition AMReX_EBData.H:186
__host__ __device__ auto get(int i, int j, int k, int n) const noexcept
Definition AMReX_EBData.H:56
__host__ __device__ auto get(int i, int j, int k) const noexcept
Definition AMReX_EBData.H:29
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:43
Definition AMReX_RandomEngine.H:72