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

AMR-Wind API: /home/runner/work/amr-wind/amr-wind/amr-wind/utilities/DirectionSelector.H Source File
AMR-Wind API v0.1.0
CFD solver for wind plant simulations
Loading...
Searching...
No Matches
DirectionSelector.H
Go to the documentation of this file.
1//
2// DirectionSelector.H
3// amr-wind
4//
5//
6
7#ifndef DirectionSelector_H
8#define DirectionSelector_H
9
10#include "AMReX_Box.H"
11#include "AMReX_Gpu.H"
12
14template <int Index>
16{
17 int operator()(int i, int j, int k) const;
18};
19
20template <>
22{
23 AMREX_GPU_DEVICE int operator()(int i, int /*unused*/, int /*unused*/) const
24 {
25 return i;
26 };
27 int odir1 = 1;
28 int odir2 = 2;
29};
30
31template <>
33{
34 AMREX_GPU_DEVICE int operator()(int /*unused*/, int j, int /*unused*/) const
35 {
36 return j;
37 };
38 int odir1 = 0;
39 int odir2 = 2;
40};
41
42template <>
44{
45 AMREX_GPU_DEVICE int operator()(int /*unused*/, int /*unused*/, int k) const
46 {
47 return k;
48 };
49 int odir1 = 0;
50 int odir2 = 1;
51};
52
56
57// Given a box, return a 2D box perpendicular to the selected axis.
58// For example, if we're using ZDir, return a box covering the x-y plane.
59// The IntVect is used to set the constant index in the parallel direction.
60template <typename IndexSelector>
61AMREX_GPU_HOST_DEVICE amrex::Box
62perpendicular_box(const amrex::Box& bx, const amrex::IntVect& iv)
63{
64 amrex::IntVect plane_lo, plane_hi;
65
66 if (std::is_same_v<IndexSelector, XDir>) {
67 plane_lo = {iv[0], bx.smallEnd(1), bx.smallEnd(2)};
68 plane_hi = {iv[0], bx.bigEnd(1), bx.bigEnd(2)};
69 } else if (std::is_same_v<IndexSelector, YDir>) {
70 plane_lo = {bx.smallEnd(0), iv[1], bx.smallEnd(2)};
71 plane_hi = {bx.bigEnd(0), iv[1], bx.bigEnd(2)};
72 } else {
73 plane_lo = {bx.smallEnd(0), bx.smallEnd(1), iv[2]};
74 plane_hi = {bx.bigEnd(0), bx.bigEnd(1), iv[2]};
75 }
76
77 amrex::Box pbx(plane_lo, plane_hi);
78
79 return pbx;
80}
81
82// Given a box, return a 1D box parallel to the selected axis.
83// For example, if we're using ZDir, return a box covering the z axis.
84// The IntVect is used to set the constant indices in the perpendicular
85// direction.
86template <typename IndexSelector>
87AMREX_GPU_DEVICE amrex::Box
88parallel_box(const amrex::Box& bx, const amrex::IntVect& iv)
89{
90 amrex::IntVect line_lo, line_hi;
91
92 if (std::is_same_v<IndexSelector, XDir>) {
93 line_lo = {bx.smallEnd(0), iv[1], iv[2]};
94 line_hi = {bx.bigEnd(0), iv[1], iv[2]};
95 } else if (std::is_same_v<IndexSelector, YDir>) {
96 line_lo = {iv[0], bx.smallEnd(1), iv[2]};
97 line_hi = {iv[0], bx.bigEnd(1), iv[2]};
98 } else {
99 line_lo = {iv[0], iv[1], bx.smallEnd(2)};
100 line_hi = {iv[0], iv[1], bx.bigEnd(2)};
101 }
102
103 amrex::Box lbx(line_lo, line_hi);
104
105 return lbx;
106}
107
108namespace amr_wind {
109
110AMREX_GPU_DEVICE AMREX_FORCE_INLINE int
111direction_selector(const int i, const int j, const int k, const int dir)
112{
113 return (dir == 0) ? i : (dir == 1) ? j : k;
114}
115
116} /* namespace amr_wind */
117#endif /* DirectionSelector_H */
AMREX_GPU_HOST_DEVICE amrex::Box perpendicular_box(const amrex::Box &bx, const amrex::IntVect &iv)
Definition DirectionSelector.H:62
AMREX_GPU_DEVICE amrex::Box parallel_box(const amrex::Box &bx, const amrex::IntVect &iv)
Definition DirectionSelector.H:88
Definition BCInterface.cpp:7
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int direction_selector(const int i, const int j, const int k, const int dir)
Definition DirectionSelector.H:111
Definition DirectionSelector.H:22
AMREX_GPU_DEVICE int operator()(int i, int, int) const
Definition DirectionSelector.H:23
Definition DirectionSelector.H:33
AMREX_GPU_DEVICE int operator()(int, int j, int) const
Definition DirectionSelector.H:34
Definition DirectionSelector.H:44
AMREX_GPU_DEVICE int operator()(int, int, int k) const
Definition DirectionSelector.H:45
Definition DirectionSelector.H:16
int operator()(int i, int j, int k) const