Block-Structured AMR Software Framework
AMReX_InterpFaceReg_3D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_INTERP_FACE_REG_3D_C_H_
2 #define AMREX_INTERP_FACE_REG_3D_C_H_
3 
4 namespace amrex {
5 
7 void interp_face_reg (int i, int j, int k, IntVect const& rr, Array4<Real> const& fine, int scomp,
8  Array4<Real const> const& crse, Array4<Real> const& slope, int ncomp,
9  Box const& domface, int idim)
10 {
11  int ic = amrex::coarsen(i,rr[0]);
12  int jc = amrex::coarsen(j,rr[1]);
13  int kc = amrex::coarsen(k,rr[2]);
14  if (idim == 0) {
15  for (int n = 0; n < ncomp; ++n) {
16  fine(i,j,k,n+scomp) = crse(ic,jc,kc,n);
17  }
18  if (jc != domface.smallEnd(1) && jc != domface.bigEnd(1) && rr[1] > 1) {
19  Real sfy = Real(1.0);
20  for (int n = 0; n < ncomp; ++n) {
21  Real dc = Real(0.5) * (crse(ic,jc+1,kc,n) - crse(ic,jc-1,kc,n));
22  Real df = Real(2.0) * (crse(ic,jc+1,kc,n) - crse(ic,jc ,kc,n));
23  Real db = Real(2.0) * (crse(ic,jc ,kc,n) - crse(ic,jc-1,kc,n));
24  Real sy = (df*db >= Real(0.0)) ?
25  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
26  sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc));
27  if (dc != Real(0.0)) {
28  sfy = amrex::min(sfy, sy / dc);
29  }
30  slope(i,j,k,n) = dc;
31  }
32  Real yoff = (static_cast<Real>(j - jc*rr[1]) + Real(0.5)) / Real(rr[1]) - Real(0.5);
33  for (int n = 0; n < ncomp; ++n) {
34  fine(i,j,k,n+scomp) += yoff * slope(i,j,k,n) * sfy;
35  }
36  }
37 
38  if (kc != domface.smallEnd(2) && kc != domface.bigEnd(2) && rr[2] > 1) {
39  Real sfz = Real(1.0);
40  for (int n = 0; n < ncomp; ++n) {
41  Real dc = Real(0.5) * (crse(ic,jc,kc+1,n) - crse(ic,jc,kc-1,n));
42  Real df = Real(2.0) * (crse(ic,jc,kc+1,n) - crse(ic,jc,kc ,n));
43  Real db = Real(2.0) * (crse(ic,jc,kc ,n) - crse(ic,jc,kc-1,n));
44  Real sz = (df*db >= Real(0.0)) ?
45  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
46  sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc));
47  if (dc != Real(0.0)) {
48  sfz = amrex::min(sfz, sz / dc);
49  }
50  slope(i,j,k,n) = dc;
51  }
52  Real zoff = (static_cast<Real>(k - kc*rr[2]) + Real(0.5)) / Real(rr[2]) - Real(0.5);
53  for (int n = 0; n < ncomp; ++n) {
54  fine(i,j,k,n+scomp) += zoff * slope(i,j,k,n) * sfz;
55  }
56  }
57  } else if (idim == 1) {
58  for (int n = 0; n < ncomp; ++n) {
59  fine(i,j,k,n+scomp) = crse(ic,jc,kc,n);
60  }
61  if (ic != domface.smallEnd(0) && ic != domface.bigEnd(0) && rr[0] > 1) {
62  Real sfx = Real(1.0);
63  for (int n = 0; n < ncomp; ++n) {
64  Real dc = Real(0.5) * (crse(ic+1,jc,kc,n) - crse(ic-1,jc,kc,n));
65  Real df = Real(2.0) * (crse(ic+1,jc,kc,n) - crse(ic ,jc,kc,n));
66  Real db = Real(2.0) * (crse(ic ,jc,kc,n) - crse(ic-1,jc,kc,n));
67  Real sx = (df*db >= Real(0.0)) ?
68  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
69  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
70  if (dc != Real(0.0)) {
71  sfx = amrex::min(sfx, sx / dc);
72  }
73  slope(i,j,k,n) = dc;
74  }
75  Real xoff = (static_cast<Real>(i - ic*rr[0]) + Real(0.5)) / Real(rr[0]) - Real(0.5);
76  for (int n = 0; n < ncomp; ++n) {
77  fine(i,j,k,n+scomp) += xoff * slope(i,j,k,n) * sfx;
78  }
79  }
80 
81  if (kc != domface.smallEnd(2) && kc != domface.bigEnd(2) && rr[2] > 1) {
82  Real sfz = Real(1.0);
83  for (int n = 0; n < ncomp; ++n) {
84  Real dc = Real(0.5) * (crse(ic,jc,kc+1,n) - crse(ic,jc,kc-1,n));
85  Real df = Real(2.0) * (crse(ic,jc,kc+1,n) - crse(ic,jc,kc ,n));
86  Real db = Real(2.0) * (crse(ic,jc,kc ,n) - crse(ic,jc,kc-1,n));
87  Real sz = (df*db >= Real(0.0)) ?
88  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
89  sz = std::copysign(Real(1.),dc)*amrex::min(sz,std::abs(dc));
90  if (dc != Real(0.0)) {
91  sfz = amrex::min(sfz, sz / dc);
92  }
93  slope(i,j,k,n) = dc;
94  }
95  Real zoff = (static_cast<Real>(k - kc*rr[2]) + Real(0.5)) / Real(rr[2]) - Real(0.5);
96  for (int n = 0; n < ncomp; ++n) {
97  fine(i,j,k,n+scomp) += zoff * slope(i,j,k,n) * sfz;
98  }
99  }
100  } else {
101  for (int n = 0; n < ncomp; ++n) {
102  fine(i,j,k,n+scomp) = crse(ic,jc,kc,n);
103  }
104  if (ic != domface.smallEnd(0) && ic != domface.bigEnd(0) && rr[0] > 1) {
105  Real sfx = Real(1.0);
106  for (int n = 0; n < ncomp; ++n) {
107  Real dc = Real(0.5) * (crse(ic+1,jc,kc,n) - crse(ic-1,jc,kc,n));
108  Real df = Real(2.0) * (crse(ic+1,jc,kc,n) - crse(ic ,jc,kc,n));
109  Real db = Real(2.0) * (crse(ic ,jc,kc,n) - crse(ic-1,jc,kc,n));
110  Real sx = (df*db >= Real(0.0)) ?
111  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
112  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
113  if (dc != Real(0.0)) {
114  sfx = amrex::min(sfx, sx / dc);
115  }
116  slope(i,j,k,n) = dc;
117  }
118  Real xoff = (static_cast<Real>(i - ic*rr[0]) + Real(0.5)) / Real(rr[0]) - Real(0.5);
119  for (int n = 0; n < ncomp; ++n) {
120  fine(i,j,k,n+scomp) += xoff * slope(i,j,k,n) * sfx;
121  }
122  }
123 
124  if (jc != domface.smallEnd(1) && jc != domface.bigEnd(1) && rr[1] > 1) {
125  Real sfy = Real(1.0);
126  for (int n = 0; n < ncomp; ++n) {
127  Real dc = Real(0.5) * (crse(ic,jc+1,kc,n) - crse(ic,jc-1,kc,n));
128  Real df = Real(2.0) * (crse(ic,jc+1,kc,n) - crse(ic,jc ,kc,n));
129  Real db = Real(2.0) * (crse(ic,jc ,kc,n) - crse(ic,jc-1,kc,n));
130  Real sy = (df*db >= Real(0.0)) ?
131  amrex::min(std::abs(df),std::abs(db)) : Real(0.);
132  sy = std::copysign(Real(1.),dc)*amrex::min(sy,std::abs(dc));
133  if (dc != Real(0.0)) {
134  sfy = amrex::min(sfy, sy / dc);
135  }
136  slope(i,j,k,n) = dc;
137  }
138  Real yoff = (static_cast<Real>(j - jc*rr[1]) + Real(0.5)) / Real(rr[1]) - Real(0.5);
139  for (int n = 0; n < ncomp; ++n) {
140  fine(i,j,k,n+scomp) += yoff * slope(i,j,k,n) * sfy;
141  }
142  }
143  }
144 }
145 
146 }
147 
148 #endif
#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
Box domface
Definition: AMReX_InterpFaceRegister.cpp:94
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & smallEnd() const &noexcept
Get the smallend of the BoxND.
Definition: AMReX_Box.H:105
AMREX_GPU_HOST_DEVICE const IntVectND< dim > & bigEnd() const &noexcept
Get the bigend.
Definition: AMReX_Box.H:116
Definition: AMReX_Amr.cpp:49
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 T abs(const GpuComplex< T > &a_z) noexcept
Return the absolute value of a complex number.
Definition: AMReX_GpuComplex.H:356
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 void interp_face_reg(int i, int j, IntVect const &rr, Array4< Real > const &fine, int scomp, Array4< Real const > const &crse, Array4< Real > const &slope, int ncomp, Box const &domface, int idim)
Definition: AMReX_InterpFaceReg_2D_C.H:7
Definition: AMReX_Array4.H:61