/home/runner/work/amr-wind/amr-wind/amr-wind/utilities/index_operations.H Source File

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/utilities/index_operations.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
index_operations.H
Go to the documentation of this file.
1#ifndef INDEX_OPERATIONS_H
2#define INDEX_OPERATIONS_H
3#include <AMReX_REAL.H>
4#include <AMReX_Vector.H>
5#include <AMReX_Box.H>
6#include <AMReX_RealBox.H>
7#include <AMReX_RealVect.H>
8#include <AMReX_Geometry.H>
9
10namespace amr_wind::utils {
11
13AMREX_FORCE_INLINE int
14closest_index(const amrex::Vector<amrex::Real>& vec, const amrex::Real value)
15{
16 auto const it = std::upper_bound(vec.begin(), vec.end(), value);
17 AMREX_ALWAYS_ASSERT(it != vec.end());
18
19 const int idx = static_cast<int>(std::distance(vec.begin(), it));
20 return std::max(idx - 1, 0);
21}
22
24template <typename T = amrex::GpuArray<int, 2>>
25AMREX_FORCE_INLINE T perpendicular_idx(const int normal)
26{
27 switch (normal) {
28 case 0:
29 return T{1, 2};
30 case 1:
31 return T{0, 2};
32 case 2:
33 return T{0, 1};
34 default:
35 amrex::Abort("Invalid normal value to determine perpendicular indices");
36 }
37 return T{-1, -1};
38}
39
54 amrex::IntVect& shift_to_cc,
55 amrex::Box grown_interior_box,
56 const amrex::Box& domain_boundary_box,
57 const amrex::Orientation& ori)
58{
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();
63 }
64 auto bx = grown_interior_box & domain_boundary_box;
65 if (bx.isEmpty()) {
66 return bx;
67 }
68
69 if (ori.isHigh() && field_location_vector[ori.coordDir()] == 1) {
70 bx.shift(field_location_vector);
71 shift_to_cc = -field_location_vector;
72 }
73 return bx;
74}
75
76// This version omits the shift to cell-centered data, often not needed
78 amrex::Box grown_interior_box,
79 const amrex::Box& domain_boundary_box,
80 const amrex::Orientation& ori)
81{
82 amrex::IntVect shift_to_cc = {0, 0, 0};
84 shift_to_cc, grown_interior_box, domain_boundary_box, ori);
85}
86
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)
93{
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])),
97 static_cast<int>(
98 amrex::Math::floor((pos[2] - prob_lo[2]) * dxinv[2]))));
99 return box.contains(iv);
100}
101
109amrex::Box
110realbox_to_box(const amrex::RealBox& rbx, const amrex::Geometry& geom);
111
112} // namespace amr_wind::utils
113
114#endif /* INDEX_OPERATIONS_H */
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