/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#ifndef DirectionSelector_H
2#define DirectionSelector_H
3
4#include "AMReX_Box.H"
5#include "AMReX_Gpu.H"
6
8template <int Index>
10{
11 int operator()(int i, int j, int k) const;
12};
13
14template <>
15struct DirectionSelector<0>
16{
17 AMREX_GPU_DEVICE int operator()(int i, int /*unused*/, int /*unused*/) const
18 {
19 return i;
20 };
21 int odir1 = 1;
22 int odir2 = 2;
23};
24
25template <>
26struct DirectionSelector<1>
27{
28 AMREX_GPU_DEVICE int operator()(int /*unused*/, int j, int /*unused*/) const
29 {
30 return j;
31 };
32 int odir1 = 0;
33 int odir2 = 2;
34};
35
36template <>
37struct DirectionSelector<2>
38{
39 AMREX_GPU_DEVICE int operator()(int /*unused*/, int /*unused*/, int k) const
40 {
41 return k;
42 };
43 int odir1 = 0;
44 int odir2 = 1;
45};
46
50
51// Given a box, return a 2D box perpendicular to the selected axis.
52// For example, if we're using ZDir, return a box covering the x-y plane.
53// The IntVect is used to set the constant index in the parallel direction.
54template <typename IndexSelector>
55AMREX_GPU_HOST_DEVICE amrex::Box
56perpendicular_box(const amrex::Box& bx, const amrex::IntVect& iv)
57{
58 amrex::IntVect plane_lo, plane_hi;
59
60 if (std::is_same_v<IndexSelector, XDir>) {
61 plane_lo = {iv[0], bx.smallEnd(1), bx.smallEnd(2)};
62 plane_hi = {iv[0], bx.bigEnd(1), bx.bigEnd(2)};
63 } else if (std::is_same_v<IndexSelector, YDir>) {
64 plane_lo = {bx.smallEnd(0), iv[1], bx.smallEnd(2)};
65 plane_hi = {bx.bigEnd(0), iv[1], bx.bigEnd(2)};
66 } else {
67 plane_lo = {bx.smallEnd(0), bx.smallEnd(1), iv[2]};
68 plane_hi = {bx.bigEnd(0), bx.bigEnd(1), iv[2]};
69 }
70
71 amrex::Box pbx(plane_lo, plane_hi);
72
73 return pbx;
74}
75
76// Given a box, return a 1D box parallel to the selected axis.
77// For example, if we're using ZDir, return a box covering the z axis.
78// The IntVect is used to set the constant indices in the perpendicular
79// direction.
80template <typename IndexSelector>
81AMREX_GPU_DEVICE amrex::Box
82parallel_box(const amrex::Box& bx, const amrex::IntVect& iv)
83{
84 amrex::IntVect line_lo, line_hi;
85
86 if (std::is_same_v<IndexSelector, XDir>) {
87 line_lo = {bx.smallEnd(0), iv[1], iv[2]};
88 line_hi = {bx.bigEnd(0), iv[1], iv[2]};
89 } else if (std::is_same_v<IndexSelector, YDir>) {
90 line_lo = {iv[0], bx.smallEnd(1), iv[2]};
91 line_hi = {iv[0], bx.bigEnd(1), iv[2]};
92 } else {
93 line_lo = {iv[0], iv[1], bx.smallEnd(2)};
94 line_hi = {iv[0], iv[1], bx.bigEnd(2)};
95 }
96
97 amrex::Box lbx(line_lo, line_hi);
98
99 return lbx;
100}
101
102namespace amr_wind {
103
104AMREX_GPU_DEVICE AMREX_FORCE_INLINE int
105direction_selector(const int i, const int j, const int k, const int dir)
106{
107 return (dir == 0) ? i : (dir == 1) ? j : k;
108}
109
110} /* namespace amr_wind */
111#endif /* DirectionSelector_H */
AMREX_GPU_HOST_DEVICE amrex::Box perpendicular_box(const amrex::Box &bx, const amrex::IntVect &iv)
Definition DirectionSelector.H:56
DirectionSelector< 0 > XDir
Definition DirectionSelector.H:47
DirectionSelector< 1 > YDir
Definition DirectionSelector.H:48
DirectionSelector< 2 > ZDir
Definition DirectionSelector.H:49
AMREX_GPU_DEVICE amrex::Box parallel_box(const amrex::Box &bx, const amrex::IntVect &iv)
Definition DirectionSelector.H:82
This test case is intended as an evaluation of the momentum advection scheme.
Definition BCInterface.cpp:10
AMREX_GPU_DEVICE AMREX_FORCE_INLINE int direction_selector(const int i, const int j, const int k, const int dir)
Definition DirectionSelector.H:105
Definition DirectionSelector.H:10
int operator()(int i, int j, int k) const