Block-Structured AMR Software Framework
AMReX_OpenBC_K.H
Go to the documentation of this file.
1 #ifndef AMREX_OPENBC_K_H_
2 #define AMREX_OPENBC_K_H_
3 
4 #include <AMReX_OpenBC.H>
5 #include <AMReX_LOUtil_K.H>
6 
7 namespace amrex::openbc {
8 
11 { // p!*q! in the order of 0!*0!, 1!*0!, ..., 7!*0!, 0!*1!, 1!*1!, 2!*1!, ..., 6!*1!, 0!*2!, ..., 0!*7!.
12  mom[ 2] *= Real(0.5);
13  mom[ 3] *= Real(1./6.);
14  mom[ 4] *= Real(1./24.);
15  mom[ 5] *= Real(1./120.);
16  mom[ 6] *= Real(1./720.);
17  mom[ 7] *= Real(1./5040.);
18  mom[10] *= Real(0.5);
19  mom[11] *= Real(1./6.);
20  mom[12] *= Real(1./24.);
21  mom[13] *= Real(1./120.);
22  mom[14] *= Real(1./720.);
23  mom[15] *= Real(0.5);
24  mom[16] *= Real(0.5);
25  mom[17] *= Real(0.25);
26  mom[18] *= Real(1./12.);
27  mom[19] *= Real(1./48.);
28  mom[20] *= Real(1./240.);
29  mom[21] *= Real(1./6.);
30  mom[22] *= Real(1./6.);
31  mom[23] *= Real(1./12.);
32  mom[24] *= Real(1./36.);
33  mom[25] *= Real(1./144.);
34  mom[26] *= Real(1./24.);
35  mom[27] *= Real(1./24.);
36  mom[28] *= Real(1./48.);
37  mom[29] *= Real(1./144.);
38  mom[30] *= Real(1./120.);
39  mom[31] *= Real(1./120.);
40  mom[32] *= Real(1./240.);
41  mom[33] *= Real(1./720.);
42  mom[34] *= Real(1./720.);
43  mom[35] *= Real(1./5040.);
44 }
45 
47 Real block_potential (openbc::Moments const& mom, Real xb, Real yb, Real zb)
48 {
49  constexpr Real oneover4pi = Real(1.)/Real(4.*3.1415926535897932);
50 
51  xb -= mom.x;
52  yb -= mom.y;
53  zb -= mom.z;
54  Real ri = Real(1.)/std::sqrt(xb*xb+yb*yb+zb*zb);
55  Real ri2 = ri*ri;
56  Real ri3 = ri2*ri;
57  Real ri4 = ri3*ri;
58  Real xr, yr;
59  if (mom.face.coordDir() == 0) {
60  xr = yb*ri;
61  yr = zb*ri;
62  } else if (mom.face.coordDir() == 1) {
63  xr = xb*ri;
64  yr = zb*ri;
65  } else {
66  xr = xb*ri;
67  yr = yb*ri;
68  }
69  Real xr2 = xr *xr;
70  Real xr4 = xr2*xr2;
71  Real xr6 = xr4*xr2;
72  Real yr2 = yr *yr;
73  Real yr4 = yr2*yr2;
74  Real yr6 = yr4*yr2;
75  Real phi = ri * mom.mom[0]
76  + ri2*(xr*mom.mom[1] + yr*mom.mom[8])
77  + ri3*((Real(3.) * xr2 - Real(1.)) * mom.mom[2] +
78  (Real(3.) * xr * yr ) * mom.mom[9] +
79  (Real(3.) * yr2 - Real(1.)) * mom.mom[15])
80  + ri4 * (xr * (Real(15.) * xr2 - Real(9.)) * mom.mom[3] +
81  yr * (Real(15.) * xr2 - Real(3.)) * mom.mom[10] +
82  xr * (Real(15.) * yr2 - Real(3.)) * mom.mom[16] +
83  yr * (Real(15.) * yr2 - Real(9.)) * mom.mom[21])
84  + ri4*ri * ((Real(105.) * xr4 - Real(90.) * xr2 + Real(9.)) * mom.mom[4] +
85  (xr * yr * (Real(105.) * xr2 - Real(45.))) * mom.mom[11] +
86  (Real(105.) * xr2 * yr2 - Real(15.) * xr2 - Real(15.) * yr2 + Real(3.)) * mom.mom[17] +
87  (xr * yr * (Real(105.) * yr2 - Real(45.))) * mom.mom[22] +
88  (Real(105.) * yr4 - Real(90.) * yr2 + Real(9.)) * mom.mom[26])
89  + ri4*ri2 * (xr * (Real(945.)*xr4 - Real(1050.)*xr2 + Real(225.)) * mom.mom[5] +
90  yr * (Real(945.)*xr4 - Real(630.)*xr2 + Real(45.)) * mom.mom[12] +
91  xr * (Real(945.)*xr2*yr2 - Real(105.)*xr2 - Real(315.)*yr2 + Real(45.)) * mom.mom[18] +
92  yr * (Real(945.)*xr2*yr2 - Real(315.)*xr2 - Real(105.)*yr2 + Real(45.)) * mom.mom[23] +
93  xr * (Real(945.)*yr4 - Real(630.)*yr2 + Real(45.)) * mom.mom[27] +
94  yr * (Real(945.)*yr4 - Real(1050.)*yr2 + Real(225.)) * mom.mom[30])
95  + ri4*ri3 * (Real(45.) * (Real(231.)*xr6 - Real(315.)*xr4 + Real(105.)*xr2 - Real(5.)) * mom.mom[6] +
96  Real(315.)*xr*yr * (Real(33.)*xr4 - Real(30.)*xr2 + Real(5.)) * mom.mom[13] +
97  Real(45.) * (Real(231.)*xr4*yr2 - Real(21.)*xr4 - Real(126.)*xr2*yr2 + Real(14.)*xr2 + Real(7.)*yr2 - Real(1.)) * mom.mom[19] +
98  Real(945.)*xr*yr * (Real(11.)*xr2*yr2 - Real(3.)*xr2 - Real(3.)*yr2 + Real(1.)) * mom.mom[24] +
99  Real(45.) * (Real(231.)*xr2*yr4 - Real(126.)*xr2*yr2 + Real(7.)*xr2 - Real(21.)*yr4 + Real(14.)*yr2 - Real(1.)) * mom.mom[28] +
100  Real(315.)*xr*yr * (Real(33.)*yr4 - Real(30.)*yr2 + Real(5.)) * mom.mom[31] +
101  Real(45.) * (Real(231.)*yr6 - Real(315.)*yr4 + Real(105.)*yr2 - Real(5.)) * mom.mom[33])
102  + ri4*ri4*(Real(315.)*xr*(Real(429.)*xr6 - Real(693.)*xr4 + Real(315.)*xr2 - Real(35.)) * mom.mom[7] +
103  Real(315.)*yr*(Real(429.)*xr6 - Real(495.)*xr4 + Real(135.)*xr2 - Real(5.)) * mom.mom[14] +
104  Real(315.)*xr*(Real(429.)*xr4*yr2 - Real(33.)*xr4 - Real(330.)*xr2*yr2 + Real(30.)*xr2 + Real(45.)*yr2 - Real(5.)) * mom.mom[20] +
105  Real(945.)*yr*(Real(143.)*xr4*yr2 - Real(33.)*xr4 - Real(66.)*xr2*yr2 + Real(18.)*xr2 + Real(3.)*yr2 - Real(1.)) * mom.mom[25] +
106  Real(945.)*xr*(Real(143.)*xr2*yr4 - Real(66.)*xr2*yr2 + Real(3.)*xr2 - Real(33.)*yr4 + Real(18.)*yr2 - Real(1.)) * mom.mom[29] +
107  Real(315.)*yr*(Real(429.)*xr2*yr4 - Real(330.)*xr2*yr2 + Real(45.)*xr2 - Real(33.)*yr4 + Real(30.)*yr2 - Real(5.)) * mom.mom[32] +
108  Real(315.)*xr*(Real(429.)*yr6 - Real(495.)*yr4 + Real(135.)*yr2 - Real(5.)) * mom.mom[34] +
109  Real(315.)*yr*(Real(429.)*yr6 - Real(693.)*yr4 + Real(315.)*yr2 - Real(35.)) * mom.mom[35]);
110  return phi*(-oneover4pi);
111 }
112 
114 void interp_coef (int i, int ii, Real* AMREX_RESTRICT c, int crse_ratio)
115 {
116  static_assert(openbc::P == 3, "openbc::P is assumed to be 3 here");
117  Real xint = (static_cast<Real>(ii-i*crse_ratio) + Real(0.5))/static_cast<Real>(crse_ratio);
118  constexpr Real x[] = {-3._rt, -2._rt, -1._rt, 0._rt, 1._rt, 2._rt, 3._rt, 4._rt};
119  poly_interp_coeff<8>(xint, x, c);
120 }
121 
123 Real interpccx (int ii, int j, int k, Array4<Real const> const& phi, int crse_ratio)
124 {
125  int i = amrex::coarsen(ii,crse_ratio);
126  Real c[8];
127  interp_coef(i,ii,c,crse_ratio);
128 
129  Real p = Real(0.);
130  for (int n = 0; n < 8; ++n) {
131  p += c[n] * phi(i-3+n,j,k);
132  }
133  return p;
134 }
135 
137 Real interpccy (int i, int jj, int k, Array4<Real const> const& phi, int crse_ratio)
138 {
139  int j = amrex::coarsen(jj,crse_ratio);
140  Real c[8];
141  interp_coef(j,jj,c,crse_ratio);
142 
143  Real p = Real(0.);
144  for (int n = 0; n < 8; ++n) {
145  p += c[n] * phi(i,j-3+n,k);
146  }
147  return p;
148 }
149 
151 Real interpccz (int i, int j, int kk, Array4<Real const> const& phi, int crse_ratio)
152 {
153  int k = amrex::coarsen(kk,crse_ratio);
154  Real c[8];
155  interp_coef(k,kk,c,crse_ratio);
156 
157  Real p = Real(0.);
158  for (int n = 0; n < 8; ++n) {
159  p += c[n] * phi(i,j,k-3+n);
160  }
161  return p;
162 }
163 
164 }
165 
166 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_RESTRICT
Definition: AMReX_Extension.H:37
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
AMREX_GPU_HOST_DEVICE int coordDir() const noexcept
Returns the coordinate direction.
Definition: AMReX_Orientation.H:83
Definition: AMReX_OpenBC.cpp:866
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void scale_moments(openbc::Moments::array_type &mom)
Definition: AMReX_OpenBC_K.H:10
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real interpccy(int i, int jj, int k, Array4< Real const > const &phi, int crse_ratio)
Definition: AMReX_OpenBC_K.H:137
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real interpccz(int i, int j, int kk, Array4< Real const > const &phi, int crse_ratio)
Definition: AMReX_OpenBC_K.H:151
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real interpccx(int ii, int j, int k, Array4< Real const > const &phi, int crse_ratio)
Definition: AMReX_OpenBC_K.H:123
AMREX_GPU_DEVICE AMREX_FORCE_INLINE Real block_potential(openbc::Moments const &mom, Real xb, Real yb, Real zb)
Definition: AMReX_OpenBC_K.H:47
AMREX_GPU_DEVICE AMREX_FORCE_INLINE void interp_coef(int i, int ii, Real *AMREX_RESTRICT c, int crse_ratio)
Definition: AMReX_OpenBC_K.H:114
static constexpr int P
Definition: AMReX_OpenBC.H:14
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
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
Definition: AMReX_Array4.H:61
Definition: AMReX_OpenBC.H:17
Real z
Definition: AMReX_OpenBC.H:20
array_type mom
Definition: AMReX_OpenBC.H:19
Orientation face
Definition: AMReX_OpenBC.H:21
Real y
Definition: AMReX_OpenBC.H:20
Real x
Definition: AMReX_OpenBC.H:20