1#ifndef INDEX_OPERATIONS_H
2#define INDEX_OPERATIONS_H
4#include <AMReX_Vector.H>
6#include <AMReX_RealBox.H>
7#include <AMReX_RealVect.H>
8#include <AMReX_Geometry.H>
14 const amrex::Vector<amrex::Real>& vec,
15 const amrex::Real value,
16 const amrex::Real tol = 0.0)
18 auto it = std::upper_bound(vec.begin(), vec.end(), value);
19 if (it == vec.end()) {
21 it = std::upper_bound(vec.begin(), vec.end(), value - tol);
23 AMREX_ALWAYS_ASSERT(it != vec.end());
25 const int idx =
static_cast<int>(std::distance(vec.begin(), it));
26 return std::max(idx - 1, 0);
30template <
typename T = amrex::GpuArray<
int, 2>>
41 amrex::Abort(
"Invalid normal value to determine perpendicular indices");
60 amrex::IntVect& shift_to_cc,
61 amrex::Box grown_interior_box,
62 const amrex::Box& domain_boundary_box,
63 const amrex::Orientation& ori)
65 shift_to_cc = {0, 0, 0};
66 const auto& field_location_vector = grown_interior_box.type();
67 if (!grown_interior_box.cellCentered()) {
68 grown_interior_box.enclosedCells();
70 auto bx = grown_interior_box & domain_boundary_box;
75 if (ori.isHigh() && field_location_vector[ori.coordDir()] == 1) {
76 bx.shift(field_location_vector);
77 shift_to_cc = -field_location_vector;
84 amrex::Box grown_interior_box,
85 const amrex::Box& domain_boundary_box,
86 const amrex::Orientation& ori)
88 amrex::IntVect shift_to_cc = {0, 0, 0};
90 shift_to_cc, grown_interior_box, domain_boundary_box, ori);
94AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool contains(
95 const amrex::Box& box,
96 const amrex::RealVect& pos,
97 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& prob_lo,
98 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxinv)
100 const amrex::IntVect iv(AMREX_D_DECL(
101 static_cast<int>(amrex::Math::floor((pos[0] - prob_lo[0]) * dxinv[0])),
102 static_cast<int>(amrex::Math::floor((pos[1] - prob_lo[1]) * dxinv[1])),
104 amrex::Math::floor((pos[2] - prob_lo[2]) * dxinv[2]))));
105 return box.contains(iv);
116realbox_to_box(
const amrex::RealBox& rbx,
const amrex::Geometry& geom);
Definition MultiParser.H:7
AMREX_FORCE_INLINE int closest_index(const amrex::Vector< amrex::Real > &vec, const amrex::Real value, const amrex::Real tol=0.0)
Return closest index (from lower) of value in vector.
Definition index_operations.H:13
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool contains(const amrex::Box &box, const amrex::RealVect &pos, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &prob_lo, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &dxinv)
Check if a point is inside a box.
Definition index_operations.H:94
amrex::Box face_aware_boundary_box_intersection(amrex::IntVect &shift_to_cc, amrex::Box grown_interior_box, const amrex::Box &domain_boundary_box, const amrex::Orientation &ori)
Definition index_operations.H:59
AMREX_FORCE_INLINE T perpendicular_idx(const int normal)
Return indices perpendicular to normal.
Definition index_operations.H:31
amrex::Box realbox_to_box(const amrex::RealBox &rbx, const amrex::Geometry &geom)
Definition index_operations.cpp:5