Block-Structured AMR Software Framework
AMReX_Interp_1D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_INTERP_1D_C_H_
2 #define AMREX_INTERP_1D_C_H_
3 #include <AMReX_Config.H>
4 
5 #include <AMReX_FArrayBox.H>
6 #include <AMReX_BCRec.H>
7 #include <AMReX_Vector.H>
8 #include <AMReX_Array.H>
9 #include <cmath>
10 
11 namespace amrex {
12 
14 pcinterp_interp (Box const& bx,
15  Array4<Real> const& fine, const int fcomp, const int ncomp,
16  Array4<Real const> const& crse, const int ccomp,
17  IntVect const& ratio) noexcept
18 {
19  const auto lo = amrex::lbound(bx);
20  const auto hi = amrex::ubound(bx);
21 
22  for (int n = 0; n < ncomp; ++n) {
24  for (int i = lo.x; i <= hi.x; ++i) {
25  const int ic = amrex::coarsen(i,ratio[0]);
26  fine(i,0,0,n+fcomp) = crse(ic,0,0,n+ccomp);
27  }
28  }
29 }
30 
31 template<typename T>
33 nodebilin_slopes (Box const& bx, Array4<T> const& slope, Array4<T const> const& u,
34  const int icomp, const int ncomp, IntVect const& ratio) noexcept
35 {
36  const auto lo = amrex::lbound(bx);
37  const auto hi = amrex::ubound(bx);
38 
39  const Real rx = Real(1.)/Real(ratio[0]);
40 
41  for (int n = 0; n < ncomp; ++n) {
43  for (int i = lo.x; i <= hi.x; ++i) {
44  T dx0 = u(i+1,0,0,n+icomp) - u(i,0,0,n+icomp);
45  slope(i,0,0,n) = rx*dx0;
46  }
47  }
48 }
49 
50 template<typename T>
52 nodebilin_interp (Box const& bx, Array4<T> const& fine, const int fcomp, const int ncomp,
54  const int ccomp, IntVect const& ratio) noexcept
55 {
56  const auto lo = amrex::lbound(bx);
57  const auto hi = amrex::ubound(bx);
58  const auto chi = amrex::ubound(slope);
59 
60  for (int n = 0; n < ncomp; ++n) {
62  for (int i = lo.x; i <= hi.x; ++i) {
63  const int ic = amrex::min(amrex::coarsen(i,ratio[0]),chi.x);
64  const Real fx = i - ic*ratio[0];
65  fine(i,0,0,n+fcomp) = crse(ic,0,0,n+ccomp) + fx*slope(ic,0,0,0);
66  }
67  }
68 }
69 
70 // Or, compile time error this?
71 // Remove these functions in a way that gives a good error message?
72 
73 template<typename T>
75 facediv_face_interp (int /*ci*/, int /*cj*/, int /*ck*/,
76  int /*nc*/, int /*nf*/, int /*idir*/,
77  Array4<T const> const& /*crse*/,
78  Array4<T> const& /*fine*/,
79  Array4<const int> const& /*mask*/,
80  IntVect const& /*ratio*/) noexcept
81 {
82  amrex::Abort("No 1D version of FaceDiv exists.\n");
83 }
84 
85 template<typename T>
87 facediv_int (int /*ci*/, int /*cj*/, int /*ck*/, int /*nf*/,
88  GpuArray<Array4<T>, AMREX_SPACEDIM> const& /*fine*/,
89  IntVect const& /*ratio*/,
90  GpuArray<Real, AMREX_SPACEDIM> const& /*cellSize*/) noexcept
91 {
92  amrex::Abort("No 1D version of FaceDiv exists.\n");
93 }
94 
95 template<typename T>
97 face_linear_interp_x (int i, int /*j*/, int /*k*/, int n, Array4<T> const& fine,
98  Array4<T const> const& crse, IntVect const& ratio) noexcept
99 {
100  const int ii = amrex::coarsen(i,ratio[0]);
101  if (i-ii*ratio[0] == 0) {
102  fine(i,0,0,n) = crse(ii,0,0,n);
103  } else {
104  Real const w = static_cast<Real>(i-ii*ratio[0]) * (Real(1.)/Real(ratio[0]));
105  fine(i,0,0,n) = (Real(1.)-w) * crse(ii,0,0,n) + w * crse(ii+1,0,0,n);
106  }
107 }
108 
110 void ccquartic_interp (int i, int /*j*/, int /*k*/, int n,
111  Array4<Real const> const& crse,
112  Array4<Real> const& fine ) noexcept
113 
114 {
115  // Note: there are asserts in CellConservativeQuartic::interp()
116  // to check whether ratio is all equal to 2.
117 
118  constexpr Array1D<Real, -2, 2> cL = { -0.01171875_rt, 0.0859375_rt, 0.5_rt, -0.0859375_rt, 0.01171875_rt };
119 
120  int ic = amrex::coarsen(i,2);
121  int irx = i - 2*ic; // = abs(i % 2)
122 
123  Real ftmp = 2.0_rt * ( cL(-2)*crse(ic-2,0,0,n)
124  + cL(-1)*crse(ic-1,0,0,n)
125  + cL( 0)*crse(ic ,0,0,n)
126  + cL( 1)*crse(ic+1,0,0,n)
127  + cL( 2)*crse(ic+2,0,0,n) );
128  if (irx) {
129  ftmp = 2.0_rt * crse(ic,0,0,n) - ftmp;
130  }
131 
132  fine(i,0,0,n) = ftmp;
133 
134 }
135 
136 } // namespace amrex
137 
138 #endif
#define AMREX_PRAGMA_SIMD
Definition: AMReX_Extension.H:80
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Array4< Real > fine
Definition: AMReX_InterpFaceRegister.cpp:90
Array4< Real > slope
Definition: AMReX_InterpFaceRegister.cpp:91
Array4< Real const > crse
Definition: AMReX_InterpFaceRegister.cpp:92
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void nodebilin_interp(Box const &bx, Array4< T > const &fine, const int fcomp, const int ncomp, Array4< T const > const &slope, Array4< T const > const &crse, const int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:52
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & min(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:21
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 ubound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:315
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Dim3 lbound(Array4< T > const &a) noexcept
Definition: AMReX_Array4.H:308
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void facediv_face_interp(int, int, int, int, int, int, Array4< T const > const &, Array4< T > const &, Array4< const int > const &, IntVect const &) noexcept
Definition: AMReX_Interp_1D_C.H:75
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void facediv_int(int, int, int, int, GpuArray< Array4< T >, AMREX_SPACEDIM > const &, IntVect const &, GpuArray< Real, AMREX_SPACEDIM > const &) noexcept
Definition: AMReX_Interp_1D_C.H:87
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ccquartic_interp(int i, int, int, int n, Array4< Real const > const &crse, Array4< Real > const &fine) noexcept
Definition: AMReX_Interp_1D_C.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void face_linear_interp_x(int i, int, int, int n, Array4< T > const &fine, Array4< T const > const &crse, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:97
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void pcinterp_interp(Box const &bx, Array4< Real > const &fine, const int fcomp, const int ncomp, Array4< Real const > const &crse, const int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:14
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void nodebilin_slopes(Box const &bx, Array4< T > const &slope, Array4< T const > const &u, const int icomp, const int ncomp, IntVect const &ratio) noexcept
Definition: AMReX_Interp_1D_C.H:33
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE BoxND< dim > coarsen(const BoxND< dim > &b, int ref_ratio) noexcept
Coarsen BoxND by given (positive) refinement ratio. NOTE: if type(dir) = CELL centered: lo <- lo/rati...
Definition: AMReX_Box.H:1304
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
Definition: AMReX_Array.H:161
Definition: AMReX_Array4.H:61
Definition: AMReX_Array.H:34