1 #ifndef ERF_EB_CUT_CELL_H_
2 #define ERF_EB_CUT_CELL_H_
4 #include <AMReX_REAL.H>
5 #include <AMReX_Array.H>
6 #include <AMReX_RealBox.H>
7 #include <AMReX_RealVect.H>
8 #include <AMReX_Algorithm.H>
9 #include <AMReX_EBCellFlag.H>
20 amrex::RealBox
const& a_rbox,
21 amrex::RealVect
const& a_point,
22 amrex::RealVect
const& a_normal );
24 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
27 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
30 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
33 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
38 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
56 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
59 if (
m_flag.isCovered() ) {
return 0.; }
65 amrex::RealVect v0(lo[0], lo[1], lo[2]);
77 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
79 AMREX_ASSERT( a_idim >=0 && a_idim < AMREX_SPACEDIM );
80 if (
m_flag.isCovered() ) {
return 0.; }
86 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
88 AMREX_ASSERT( a_idim >= 0 && a_idim < AMREX_SPACEDIM );
89 if (
m_flag.isCovered() ) {
return 0.; }
95 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
100 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
101 amrex::RealVect
centLo (
int const a_idim )
const noexcept {
102 AMREX_ASSERT( a_idim >=0 && a_idim < AMREX_SPACEDIM );
108 if (amrex::almostEqual(area_R,0.0) || amrex::almostEqual(area_R,
m_rbox_area[a_idim]) ){
111 amrex::RealVect cent_O = cent;
112 amrex::RealVect cent_R =
m_lo_faces[a_idim]->get_centroid();
114 cent =
m_invert * cent_R + (1.-
m_invert) * ((1.+area_R/area_C)*cent_O - area_R/area_C*cent_R);
120 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
121 amrex::RealVect
centHi (
int const a_idim )
const noexcept {
122 AMREX_ASSERT( a_idim >=0 && a_idim < AMREX_SPACEDIM );
128 if (amrex::almostEqual(area_R,0.0) || amrex::almostEqual(area_R,
m_rbox_area[a_idim]) ){
131 amrex::RealVect cent_O = cent;
132 amrex::RealVect cent_R =
m_hi_faces[a_idim]->get_centroid();
134 cent =
m_invert * cent_R + (1.-
m_invert) * ((1.+area_R/area_C)*cent_O - area_R/area_C*cent_R);
140 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
142 amrex::RealVect cent{0.,0.,0.};
143 if (
m_flag.isSingleValued()) {
149 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
151 amrex::RealVect normal{0.,0.,0.};
152 if (
m_flag.isSingleValued()) {
158 [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
161 if (
m_flag.isSingleValued()) {
181 vcent[0] = 0.5 * ( - xm * xm * axm + xp * xp * axp + bcent[0] * bcent[0] *
m_eb_normal[0] * barea ) / vol;
182 vcent[1] = 0.5 * ( - ym * ym * aym + yp * yp * ayp + bcent[1] * bcent[1] *
m_eb_normal[1] * barea ) / vol;
183 vcent[2] = 0.5 * ( - zm * zm * azm + zp * zp * azp + bcent[2] * bcent[2] *
m_eb_normal[2] * barea ) / vol;
188 void debug (
int const a_face = -1 );
225 AMREX_GPU_HOST_DEVICE
228 AMREX_GPU_HOST_DEVICE
232 AMREX_GPU_HOST_DEVICE
236 amrex::RealBox
const& a_rbox,
237 amrex::RealVect
const& a_point,
238 amrex::RealVect
const& a_normal )
240 , m_eb_point(a_point)
241 , m_eb_normal(a_normal)
243 , m_F1(a_point, a_normal)
244 , m_F2(a_point, a_normal)
245 , m_F3(a_point, a_normal)
246 , m_F4(a_point, a_normal)
247 , m_F5(a_point, a_normal)
248 , m_F6(a_point, a_normal)
249 , m_cellface_cent({amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.),
250 amrex::RealVect(0.), amrex::RealVect(0.), amrex::RealVect(0.)})
252 using namespace amrex;
254 m_rbox_area[0] = m_rbox.length(1)*m_rbox.length(2);
255 m_rbox_area[1] = m_rbox.length(0)*m_rbox.length(2);
256 m_rbox_area[2] = m_rbox.length(0)*m_rbox.length(1);
258 RealVect v0(m_rbox.lo(0), m_rbox.lo(1), m_rbox.lo(2));
259 RealVect v1(m_rbox.hi(0), m_rbox.lo(1), m_rbox.lo(2));
260 RealVect v2(m_rbox.lo(0), m_rbox.hi(1), m_rbox.lo(2));
261 RealVect v3(m_rbox.lo(0), m_rbox.lo(1), m_rbox.hi(2));
262 RealVect v4(m_rbox.hi(0), m_rbox.lo(1), m_rbox.hi(2));
263 RealVect v5(m_rbox.hi(0), m_rbox.hi(1), m_rbox.lo(2));
264 RealVect v6(m_rbox.lo(0), m_rbox.hi(1), m_rbox.hi(2));
265 RealVect v7(m_rbox.hi(0), m_rbox.hi(1), m_rbox.hi(2));
269 m_cellface_cent[0] = 0.25 * ( v0 + v2 + v5 + v1 );
270 m_cellface_cent[1] = 0.25 * ( v1 + v5 + v7 + v4 );
271 m_cellface_cent[2] = 0.25 * ( v3 + v4 + v7 + v6 );
272 m_cellface_cent[3] = 0.25 * ( v0 + v3 + v6 + v2 );
273 m_cellface_cent[4] = 0.25 * ( v0 + v1 + v4 + v3 );
274 m_cellface_cent[5] = 0.25 * ( v2 + v5 + v7 + v6 );
278 m_cell_cent[0] = 0.5 * ( m_rbox.lo(0) + m_rbox.hi(0) );
279 m_cell_cent[1] = 0.5 * ( m_rbox.lo(1) + m_rbox.hi(1) );
280 m_cell_cent[2] = 0.5 * ( m_rbox.lo(2) + m_rbox.hi(2) );
284 m_dx[0] = m_rbox.hi(0) - m_rbox.lo(0);
285 m_dx[1] = m_rbox.hi(1) - m_rbox.lo(1);
286 m_dx[2] = m_rbox.hi(2) - m_rbox.lo(2);
288 if (a_flag.isCovered() ) {
292 }
else if (a_flag.isRegular() ) {
298 RealVect c = 0.5*(v0 + v7);
301 Real r = e[0]*amrex::Math::abs(a_normal[0]) +
302 e[1]*amrex::Math::abs(a_normal[1]) +
303 e[2]*amrex::Math::abs(a_normal[2]);
305 Real s = amrex::Math::abs(c.dotProduct(a_normal)
306 - a_point.dotProduct(a_normal));
309 if ((a_normal.dotProduct(v0) - a_normal.dotProduct(a_point)) > 0.)
310 { set_covered(); }
else { set_regular(); }
311 }
else { m_flag.setSingleValued(); }
314 if ( m_flag.isSingleValued() ) {
316 m_invert = ((m_eb_normal.dotProduct(v0) - m_eb_normal.dotProduct(m_eb_point)) > 0.) ? 0.0 : 1.0;
318 calc_edge_intersections();
331 if ( !m_flag.isSingleValued() ) {
332 set_covered_regular_cell_vertices();
337 AMREX_GPU_HOST_DEVICE
343 using namespace amrex;
354 #ifndef AMREX_USE_GPU
355 constexpr
bool print_F1 =
false;
356 constexpr
bool print_F2 =
false;
357 constexpr
bool print_F3 =
false;
358 constexpr
bool print_F4 =
false;
359 constexpr
bool print_F5 =
false;
360 constexpr
bool print_F6 =
false;
361 constexpr
bool print_F7 =
false;
378 constexpr
Real tol = 1.e-15;
380 amrex::Array<bool, 8> vertex_intersected{};
385 for (
int i = 0; i < 8; ++i) vertex_intersected[i] =
false;
391 if ( Math::abs(distIP) < tol ) {
403 if (!vertex_intersected[0]) {
404 vertex_intersected[0] =
true;
407 }
else if ( Math::abs(distIP - length) < tol ) {
419 if (!vertex_intersected[1]) {
420 vertex_intersected[1] =
true;
444 m_F1.
add_vertex(v1,
"Path 1: after v0--v1, cuts%2 == 0: add v1 -> F1",print_F1);
445 m_F2.
add_vertex(v1,
"Path 1: after v0--v1, cuts%2 == 0: add v1 -> F2",print_F2);
446 m_F5.
add_vertex(v1,
"Path 1: after v0--v1, cuts%2 == 0: add v1 -> F5",print_F5);
454 if ( Math::abs(distIP) < tol ) {
466 if (!vertex_intersected[1]) {
467 vertex_intersected[1] =
true;
470 }
else if ( Math::abs(distIP - length) < tol ) {
482 if (!vertex_intersected[4]) {
483 vertex_intersected[4] =
true;
507 m_F2.
add_vertex(v4,
"Path 1: after v1--v4, cuts%2 == 0: add v4 -> F2",print_F2);
508 m_F3.
add_vertex(v4,
"Path 1: after v1--v4, cuts%2 == 0: add v4 -> F3",print_F3);
509 m_F5.
add_vertex(v4,
"Path 1: after v1--v4, cuts%2 == 0: add v4 -> F5",print_F5);
517 if ( Math::abs(distIP) < tol) {
529 if (!vertex_intersected[4]) {
530 vertex_intersected[4] =
true;
533 }
else if ( Math::abs(distIP - length) < tol) {
545 if (!vertex_intersected[7]) {
546 vertex_intersected[7] =
true;
564 if (cuts == 2 && add_v7) {
571 m_F2.
add_vertex(v7,
"Path 1: after v4--v7, cuts == 2 && add_v7: add v7 -> F2",print_F2);
572 m_F3.
add_vertex(v7,
"Path 1: after v4--v7, cuts == 2 && add_v7: add v7 -> F3",print_F3);
573 m_F6.
add_vertex(v7,
"Path 1: after v4--v7, cuts == 2 && add_v7: add v7 -> F6",print_F6);
585 if ( Math::abs(distIP) < tol) {
597 }
else if ( Math::abs(distIP - length) < tol) {
624 for (
int i = 0; i < 8; ++i) vertex_intersected[i] =
false;
630 if ( Math::abs(distIP) < tol ) {
642 if (!vertex_intersected[0]) {
643 vertex_intersected[0] =
true;
646 }
else if ( Math::abs(distIP - length) < tol ) {
658 if (!vertex_intersected[2]) {
659 vertex_intersected[2] =
true;
683 m_F1.
add_vertex(v2,
"Path 2: after v0--v2, cuts%2 == 0: add v2 -> F1",print_F1);
684 m_F4.
add_vertex(v2,
"Path 2: after v0--v2, cuts%2 == 0: add v2 -> F4",print_F4);
685 m_F6.
add_vertex(v2,
"Path 2: after v0--v2, cuts%2 == 0: add v2 -> F6",print_F6);
693 if ( Math::abs(distIP) < tol) {
705 if (!vertex_intersected[2]) {
706 vertex_intersected[2] =
true;
709 }
else if ( Math::abs(distIP - length) < tol) {
721 if (!vertex_intersected[5]) {
722 vertex_intersected[5] =
true;
745 m_F1.
add_vertex(v5,
"Path 2: after v2--v5, cuts%2 == 0: add v5 -> F1",print_F1);
746 m_F2.
add_vertex(v5,
"Path 2: after v2--v5, cuts%2 == 0: add v5 -> F2",print_F2);
747 m_F6.
add_vertex(v5,
"Path 2: after v2--v5, cuts%2 == 0: add v5 -> F6",print_F6);
755 if ( Math::abs(distIP) < tol) {
767 if (!vertex_intersected[5]) {
768 vertex_intersected[5] =
true;
771 }
else if ( Math::abs(distIP - length) < tol) {
783 if (!vertex_intersected[7]) {
784 vertex_intersected[7] =
true;
801 if (cuts == 2 && add_v7) {
808 m_F2.
add_vertex(v7,
"Path 2: after v5--v7, cuts == 2 && add_v7: add v7 -> F2",print_F2);
809 m_F3.
add_vertex(v7,
"Path 2: after v5--v7, cuts == 2 && add_v7: add v7 -> F3",print_F3);
810 m_F6.
add_vertex(v7,
"Path 2: after v5--v7, cuts == 2 && add_v7: add v7 -> F6",print_F6);
823 if ( Math::abs(distIP) < tol) {
835 }
else if ( Math::abs(distIP - length) < tol) {
863 for (
int i = 0; i < 8; ++i) vertex_intersected[i] =
false;
869 if ( Math::abs(distIP) < tol) {
881 if (!vertex_intersected[0]) {
882 vertex_intersected[0] =
true;
885 }
else if ( Math::abs(distIP - length) < tol) {
897 if (!vertex_intersected[3]) {
898 vertex_intersected[3] =
true;
922 m_F3.
add_vertex(v3,
"Path 3: after v0--v3, cuts%2 == 0: add v3 -> F3",print_F3);
923 m_F4.
add_vertex(v3,
"Path 3: after v0--v3, cuts%2 == 0: add v3 -> F4",print_F4);
924 m_F5.
add_vertex(v3,
"Path 3: after v0--v3, cuts%2 == 0: add v3 -> F5",print_F5);
932 if ( Math::abs(distIP) < tol) {
944 if (!vertex_intersected[3]) {
945 vertex_intersected[3] =
true;
948 }
else if ( Math::abs(distIP - length) < tol) {
960 if (!vertex_intersected[6]) {
961 vertex_intersected[6] =
true;
985 m_F3.
add_vertex(v6,
"Path 3: after v3--v6, cuts%2 == 0: add v6 -> F3",print_F3);
986 m_F4.
add_vertex(v6,
"Path 3: after v3--v6, cuts%2 == 0: add v6 -> F4",print_F4);
987 m_F6.
add_vertex(v6,
"Path 3: after v3--v6, cuts%2 == 0: add v6 -> F6",print_F6);
995 if ( Math::abs(distIP) < tol) {
1007 if (!vertex_intersected[6]) {
1008 vertex_intersected[6] =
true;
1011 }
else if ( Math::abs(distIP - length) < tol) {
1012 #ifdef AMREX_USE_GPU
1023 if (!vertex_intersected[7]) {
1024 vertex_intersected[7] =
true;
1028 #ifdef AMREX_USE_GPU
1041 if (cuts == 2 && add_v7) {
1043 #ifdef AMREX_USE_GPU
1048 m_F2.
add_vertex(v7,
"Path 3: after v6--v7, cuts == 2 && add_v7: add v7 -> F2",print_F2);
1049 m_F3.
add_vertex(v7,
"Path 3: after v6--v7, cuts == 2 && add_v7: add v7 -> F3",print_F3);
1050 m_F6.
add_vertex(v7,
"Path 3: after v6--v7, cuts == 2 && add_v7: add v7 -> F6",print_F6);
1063 if ( Math::abs(distIP) < tol) {
1064 #ifdef AMREX_USE_GPU
1075 }
else if ( Math::abs(distIP - length) < tol) {
1076 #ifdef AMREX_USE_GPU
1088 #ifdef AMREX_USE_GPU
1100 #ifndef AMREX_USE_GPU
1101 if (print_F1 || print_F2 || print_F3 || print_F4 || print_F5 || print_F6 || print_F7){
1102 amrex::Print()<<
"\n";
1110 AMREX_GPU_HOST_DEVICE
1116 using namespace amrex;
amrex::Real Real
Definition: ERF_ShocInterface.H:19
Definition: ERF_EBCutCell.H:14
AMREX_GPU_HOST_DEVICE void calc_edge_intersections()
Definition: ERF_EBCutCell.H:341
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real volume() const
Definition: ERF_EBCutCell.H:57
polygon_ m_F6
Definition: ERF_EBCutCell.H:209
amrex::Array< polygon_ const *const, 3 > m_lo_faces
Definition: ERF_EBCutCell.H:219
amrex::RealVect m_rbox_area
Definition: ERF_EBCutCell.H:198
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool isRegular() const noexcept
Definition: ERF_EBCutCell.H:28
amrex::RealVect m_cell_cent
Definition: ERF_EBCutCell.H:213
amrex::RealVect m_dx
Definition: ERF_EBCutCell.H:214
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real areaHi(int const a_idim) const noexcept
Definition: ERF_EBCutCell.H:87
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real areaLo(int const a_idim) const noexcept
Definition: ERF_EBCutCell.H:78
amrex::RealVect const m_eb_point
Definition: ERF_EBCutCell.H:193
amrex::Real m_invert
Definition: ERF_EBCutCell.H:196
amrex::RealBox const m_rbox
Definition: ERF_EBCutCell.H:192
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect centBoun() const noexcept
Definition: ERF_EBCutCell.H:141
AMREX_GPU_HOST_DEVICE void set_covered_regular_cell_vertices()
Definition: ERF_EBCutCell.H:1114
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_regular()
Definition: ERF_EBCutCell.H:39
polygon_ m_F1
Definition: ERF_EBCutCell.H:204
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real areaBoun() const noexcept
Definition: ERF_EBCutCell.H:96
polygon_ m_F3
Definition: ERF_EBCutCell.H:206
amrex::EBCellFlag m_flag
Definition: ERF_EBCutCell.H:200
polygon_ m_F5
Definition: ERF_EBCutCell.H:208
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect centLo(int const a_idim) const noexcept
Definition: ERF_EBCutCell.H:101
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect centVol() const noexcept
Definition: ERF_EBCutCell.H:159
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_covered()
Definition: ERF_EBCutCell.H:34
polygon_ m_F7
Definition: ERF_EBCutCell.H:217
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect normBoun() const noexcept
Definition: ERF_EBCutCell.H:150
amrex::Array< int const, 3 > m_hi_faces_id
Definition: ERF_EBCutCell.H:223
AMREX_GPU_HOST_DEVICE eb_cut_cell_(amrex::EBCellFlag const &a_flag, amrex::RealBox const &a_rbox, amrex::RealVect const &a_point, amrex::RealVect const &a_normal)
Definition: ERF_EBCutCell.H:235
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool isSingleValued() const noexcept
Definition: ERF_EBCutCell.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool isCovered() const noexcept
Definition: ERF_EBCutCell.H:25
void debug(int const a_face=-1)
Definition: ERF_EBCutCell.cpp:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect centHi(int const a_idim) const noexcept
Definition: ERF_EBCutCell.H:121
static constexpr int m_max_faces
Definition: ERF_EBCutCell.H:211
amrex::RealVect const m_eb_normal
Definition: ERF_EBCutCell.H:194
amrex::Array< int const, 3 > m_lo_faces_id
Definition: ERF_EBCutCell.H:222
polygon_ m_F2
Definition: ERF_EBCutCell.H:205
amrex::Array< polygon_ const *const, 3 > m_hi_faces
Definition: ERF_EBCutCell.H:220
polygon_ m_F4
Definition: ERF_EBCutCell.H:207
amrex::Array< amrex::RealVect, m_max_faces > m_cellface_cent
Definition: ERF_EBCutCell.H:212
Definition: ERF_EBPolygon.H:9
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::RealVect get_centroid() const noexcept
Definition: ERF_EBPolygon.H:179
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int ok() const noexcept
Definition: ERF_EBPolygon.H:160
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real distance(amrex::RealVect const &a_point) const noexcept
Definition: ERF_EBPolygon.H:171
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::Real area() const noexcept
Definition: ERF_EBPolygon.H:164
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void set_area(amrex::Real const &a_area)
Definition: ERF_EBPolygon.H:72
AMREX_GPU_HOST void add_vertex(amrex::RealVect const &a_v, const std::string &msg, bool print_msg=false)
Definition: ERF_EBPolygon.H:43
Definition: ERF_ConsoleIO.cpp:12
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE int intersect_plane_edge(amrex::RealVect const &a_plane_point, amrex::RealVect const &a_plane_normal, amrex::RealVect const &a_edge_point0, amrex::RealVect const &a_edge_point1, amrex::RealVect &a_intersection_point, amrex::Real &a_intersection_dist)
Definition: ERF_EBUtils.H:30