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
14namespace amrex
15{
16
18enum struct EBData_t : int
19{
20 levelset, // level set
21 volfrac, // volume fraction
22 centroid, // volume centroid
23 bndrycent, // boundary centroid
24 bndrynorm, // boundary normal
25 bndryarea, // boundary area
26 AMREX_D_DECL(apx, apy, apz), // area fraction
27 AMREX_D_DECL(fcx, fcy, fcz), // face centroid
28 AMREX_D_DECL(ecx, ecy, ecz), // edge centroid
29 cellflag // EBCellFlag
30};
31
33struct EBData
34{
35 template <EBData_t T>
38 auto get (int i, int j, int k) const noexcept
39 {
40 if constexpr (T == EBData_t::cellflag) {
41 return (*m_cell_flag)(i,j,k);
42 } else {
43 return m_real_data[static_cast<int>(T)](i,j,k);
44 }
45 }
46
47 template <EBData_t T>
50 const auto& get () const noexcept
51 {
52 if constexpr (T == EBData_t::cellflag) {
53 return *m_cell_flag;
54 } else {
55 return m_real_data[static_cast<int>(T)];
56 }
57 }
58
59 template <EBData_t T>
60 requires ( T == EBData_t::centroid
64 || T==EBData_t::fcy,
65 || T==EBData_t::fcz) )
68 auto get (int i, int j, int k, int n) const noexcept
69 {
70 return m_real_data[static_cast<int>(T)](i,j,k,n);
71 }
72
84 randomPointOnEB (int i, int j, int k, RandomEngine const& engine,
85 GpuArray<Real,AMREX_SPACEDIM> const& dx) const
86 {
87 Real nx = this->get<EBData_t::bndrynorm>(i,j,k,0) * dx[0];
88 Real ny = this->get<EBData_t::bndrynorm>(i,j,k,1) * dx[1];
89 Real bcx = this->get<EBData_t::bndrycent>(i,j,k,0);
90 Real bcy = this->get<EBData_t::bndrycent>(i,j,k,1);
91 int dir = (std::abs(nx) >= std::abs(ny)) ? 0 : 1;
92#if (AMREX_SPACEDIM == 2)
93 auto f = [&] (Real n0, Real n1, Real bc0, Real bc1)
94 {
95 Real rn = amrex::Random(engine);
96 if (n1 == 0) {
97 return amrex::makeTuple(bc0, rn-Real(0.5));
98 } else {
99 Real nn = n0/n1; // Note that we have n0 >= n1. So nn != 0.
100 Real ym = bc1+nn*(bc0-Real(-0.5)); // where x=-0.5 and EB intersects
101 Real yp = bc1+nn*(bc0-Real( 0.5)); // where x= 0.5 and EB intersects
102 Real ymin = std::min(ym,yp);
103 Real ymax = std::max(ym,yp);
104 ymin = std::max(ymin, Real(-0.5));
105 ymax = std::min(ymax, Real( 0.5));
106 Real y = rn*(ymax-ymin) + ymin;
107 Real x = bc0 - (y-bc1)*n1/n0;
108 return amrex::makeTuple(x,y);
109 }
110 };
111
112 if (dir == 0) {
113 auto [x,y] = f( nx, ny,
114 bcx,bcy);
115 return GpuArray<Real,2>{x,y};
116 } else {
117 auto [y,x] = f( ny, nx,
118 bcy,bcx);
119 return GpuArray<Real,2>{x,y};
120 }
121#else
122 Real nz = this->get<EBData_t::bndrynorm>(i,j,k,2) * dx[2];
123 Real bcz = this->get<EBData_t::bndrycent>(i,j,k,2);
124 if (std::abs(nz) > std::abs(nx) && std::abs(nz) > std::abs(ny)) {
125 dir = 2;
126 }
127 auto f = [&] (Real n0, Real n1, Real n2, Real bc0, Real bc1, Real bc2)
128 { // Note that n0 >= n1 >= n2;
129 if (n1 == 0 && n2 == 0) {
130 return amrex::makeTuple(bc0,
131 amrex::Random(engine)-Real(0.5),
132 amrex::Random(engine)-Real(0.5));
133 } else if (n2 == 0) {
134 Real nn = n0/n1;
135 Real ym = bc1+nn*(bc0-Real(-0.5));
136 Real yp = bc1+nn*(bc0-Real( 0.5));
137 Real ymin = std::min(ym,yp);
138 Real ymax = std::max(ym,yp);
139 ymin = std::max(ymin, Real(-0.5));
140 ymax = std::min(ymax, Real( 0.5));
141 Real y = amrex::Random(engine)*(ymax-ymin) + ymin;
142 Real z = amrex::Random(engine) - Real(0.5);
143 Real x = bc0 - ((y-bc1)*n1+(z-bc2)*n2)/n0;
144 return amrex::makeTuple(x,y,z);
145 } else {
146 Real y0 = bc1 - ((Real(-0.5)-bc0)*n0+(Real(-0.5)-bc2)*n2)/n1;
147 Real y1 = bc1 - ((Real( 0.5)-bc0)*n0+(Real(-0.5)-bc2)*n2)/n1;
148 Real y2 = bc1 - ((Real(-0.5)-bc0)*n0+(Real( 0.5)-bc2)*n2)/n1;
149 Real y3 = bc1 - ((Real( 0.5)-bc0)*n0+(Real( 0.5)-bc2)*n2)/n1;
150 Real ymin = amrex::min(y0,y1,y2,y3);
151 Real ymax = amrex::max(y0,y1,y2,y3);
152 ymin = std::max(ymin, Real(-0.5));
153 ymax = std::min(ymax, Real( 0.5));
154 Real z0 = bc2 - ((Real(-0.5)-bc0)*n0+(Real(-0.5)-bc1)*n1)/n2;
155 Real z1 = bc2 - ((Real( 0.5)-bc0)*n0+(Real(-0.5)-bc1)*n1)/n2;
156 Real z2 = bc2 - ((Real(-0.5)-bc0)*n0+(Real( 0.5)-bc1)*n1)/n2;
157 Real z3 = bc2 - ((Real( 0.5)-bc0)*n0+(Real( 0.5)-bc1)*n1)/n2;
158 Real zmin = amrex::min(z0,z1,z2,z3);
159 Real zmax = amrex::max(z0,z1,z2,z3);
160 zmin = std::max(zmin, Real(-0.5));
161 zmax = std::min(zmax, Real( 0.5));
162 Real x, y, z;
163 do {
164 y = amrex::Random(engine)*(ymax-ymin) + ymin;
165 z = amrex::Random(engine)*(zmax-zmin) + zmin;
166 x = bc0 - ((y-bc1)*n1+(z-bc2)*n2)/n0;
167 } while (x > Real(0.5) || x < Real(-0.5));
168 return amrex::makeTuple(x,y,z);
169 }
170 };
171 if (dir == 0) {
172 if (std::abs(ny) >= std::abs(nz)) {
173 auto [x,y,z] = f( nx, ny, nz,
174 bcx,bcy,bcz);
175 return GpuArray<Real,3>{x, y, z};
176 } else {
177 auto [x,z,y] = f( nx, nz, ny,
178 bcx,bcz,bcy);
179 return GpuArray<Real,3>{x, y, z};
180 }
181 } else if (dir == 1) {
182 if (std::abs(nx) >= std::abs(nz)) {
183 auto [y,x,z] = f( ny, nx, nz,
184 bcy,bcx,bcz);
185 return GpuArray<Real,3>{x, y, z};
186 } else {
187 auto [y,z,x] = f( ny, nz, nx,
188 bcy,bcz,bcx);
189 return GpuArray<Real,3>{x, y, z};
190 }
191 } else {
192 if (std::abs(nx) >= std::abs(ny)) {
193 auto [z,x,y] = f( nz, nx, ny,
194 bcz,bcx,bcy);
195 return GpuArray<Real,3>{x, y, z};
196 } else {
197 auto [z,y,x] = f( nz, ny, nx,
198 bcz,bcy,bcx);
199 return GpuArray<Real,3>{x, y, z};
200 }
201 }
202#endif
203 }
204
205 static constexpr int real_data_size = static_cast<int>(EBData_t::cellflag);
206
209};
210
213{
214 template <EBData_t T>
217 auto get (int box_no, int i, int j, int k) const noexcept
218 {
219 if constexpr (T == EBData_t::cellflag) {
220 return m_cell_flag[box_no](i,j,k);
221 } else {
222 return m_real_data[(box_no*real_data_size) + static_cast<int>(T)](i,j,k);
223 }
224 }
225
226 template <EBData_t T>
227 requires ( T == EBData_t::centroid
228 || T == EBData_t::bndrycent
229 || T == EBData_t::bndrynorm
231 || T==EBData_t::fcy,
232 || T==EBData_t::fcz))
235 auto get (int box_no, int i, int j, int k, int n) const noexcept
236 {
237 return m_real_data[(box_no*real_data_size) + static_cast<int>(T)](i,j,k,n);
238 }
239
242 EBData get (int box_no) const noexcept
243 {
244 return EBData{.m_cell_flag = m_cell_flag + box_no,
245 .m_real_data = m_real_data + (box_no * real_data_size)};
246 }
247
248 static constexpr int real_data_size = static_cast<int>(EBData_t::cellflag);
249
252};
253
254}
255#endif
#define AMREX_FORCE_INLINE
Definition AMReX_Extension.H:124
#define AMREX_RESTRICT
Definition AMReX_Extension.H:37
#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:80
Real Random()
Generate a psuedo-random real from uniform distribution.
Definition AMReX_Random.cpp:155
__host__ __device__ constexpr const T & min(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:31
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition AMReX_Algorithm.H:53
Definition AMReX_Amr.cpp:50
__host__ __device__ constexpr GpuTuple< detail::tuple_decay_t< Ts >... > makeTuple(Ts &&... args)
Definition AMReX_Tuple.H:275
EBData_t
Tags that index into EB data arrays stored in EBData/EBDataArrays.
Definition AMReX_EBData.H:19
A multidimensional array accessor.
Definition AMReX_Array4.H:289
Views aggregating EBData for multiple boxes.
Definition AMReX_EBData.H:213
Array4< Real const > const *__restrict__ m_real_data
Definition AMReX_EBData.H:251
static constexpr int real_data_size
Definition AMReX_EBData.H:248
Array4< EBCellFlag const > const *__restrict__ m_cell_flag
Definition AMReX_EBData.H:250
__host__ __device__ auto get(int box_no, int i, int j, int k) const noexcept
Access scalar EB data for box box_no at (i,j,k).
Definition AMReX_EBData.H:217
__host__ __device__ EBData get(int box_no) const noexcept
Return an EBData wrapper anchored at box box_no.
Definition AMReX_EBData.H:242
Set of Array4 views to EB data for a single box (plus helpers).
Definition AMReX_EBData.H:34
__host__ __device__ GpuArray< Real, 3 > randomPointOnEB(int i, int j, int k, RandomEngine const &engine, GpuArray< Real, 3 > const &dx) const
Generate a uniformly random point on the EB face inside cell (i,j,k).
Definition AMReX_EBData.H:84
__host__ __device__ const auto & get() const noexcept
Access the Array4 backing EB data T.
Definition AMReX_EBData.H:50
Array4< EBCellFlag const > const * m_cell_flag
Definition AMReX_EBData.H:207
static constexpr int real_data_size
Definition AMReX_EBData.H:205
Array4< Real const > const * m_real_data
Definition AMReX_EBData.H:208
__host__ __device__ auto get(int i, int j, int k) const noexcept
Access scalar EB data entries at cell (i,j,k).
Definition AMReX_EBData.H:38
Fixed-size array that can be used on GPU.
Definition AMReX_Array.H:52
Definition AMReX_RandomEngine.H:72