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>
14closest_index(
const amrex::Vector<amrex::Real>& vec,
const amrex::Real value)
16 auto const it = std::upper_bound(vec.begin(), vec.end(), value);
17 AMREX_ALWAYS_ASSERT(it != vec.end());
19 const int idx =
static_cast<int>(std::distance(vec.begin(), it));
20 return std::max(idx - 1, 0);
24template <
typename T = amrex::GpuArray<
int, 2>>
35 amrex::Abort(
"Invalid normal value to determine perpendicular indices");
54 amrex::IntVect& shift_to_cc,
55 amrex::Box grown_interior_box,
56 const amrex::Box& domain_boundary_box,
57 const amrex::Orientation& ori)
59 shift_to_cc = {0, 0, 0};
60 const auto& field_location_vector = grown_interior_box.type();
61 if (!grown_interior_box.cellCentered()) {
62 grown_interior_box.enclosedCells();
64 auto bx = grown_interior_box & domain_boundary_box;
69 if (ori.isHigh() && field_location_vector[ori.coordDir()] == 1) {
70 bx.shift(field_location_vector);
71 shift_to_cc = -field_location_vector;
78 amrex::Box grown_interior_box,
79 const amrex::Box& domain_boundary_box,
80 const amrex::Orientation& ori)
82 amrex::IntVect shift_to_cc = {0, 0, 0};
84 shift_to_cc, grown_interior_box, domain_boundary_box, ori);
88AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
bool contains(
89 const amrex::Box& box,
90 const amrex::RealVect& pos,
91 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& prob_lo,
92 const amrex::GpuArray<amrex::Real, AMREX_SPACEDIM>& dxinv)
94 const amrex::IntVect iv(AMREX_D_DECL(
95 static_cast<int>(amrex::Math::floor((pos[0] - prob_lo[0]) * dxinv[0])),
96 static_cast<int>(amrex::Math::floor((pos[1] - prob_lo[1]) * dxinv[1])),
98 amrex::Math::floor((pos[2] - prob_lo[2]) * dxinv[2]))));
99 return box.contains(iv);
110realbox_to_box(
const amrex::RealBox& rbx,
const amrex::Geometry& geom);
Definition MultiParser.H:7
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:88
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:53
AMREX_FORCE_INLINE int closest_index(const amrex::Vector< amrex::Real > &vec, const amrex::Real value)
Return closest index (from lower) of value in vector.
Definition index_operations.H:14
AMREX_FORCE_INLINE T perpendicular_idx(const int normal)
Return indices perpendicular to normal.
Definition index_operations.H:25
amrex::Box realbox_to_box(const amrex::RealBox &rbx, const amrex::Geometry &geom)
Definition index_operations.cpp:5