Block-Structured AMR Software Framework
AMReX_MFInterp_1D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_MF_INTERP_1D_C_H_
2 #define AMREX_MF_INTERP_1D_C_H_
3 
4 namespace amrex {
5 
8  Array4<Real const> const& u, int scomp, int ncomp,
9  Box const& domain, IntVect const& ratio, BCRec const* bc) noexcept
10 {
11  Real sfx = Real(1.0);
12 
13  for (int ns = 0; ns < ncomp; ++ns) {
14  int nu = ns + scomp;
15 
16  // x-direction
17  Real dc = mf_compute_slopes_x(i, 0, 0, u, nu, domain, bc[ns]);
18  Real df = Real(2.0) * (u(i+1,0,0,nu) - u(i ,0,0,nu));
19  Real db = Real(2.0) * (u(i ,0,0,nu) - u(i-1,0,0,nu));
20  Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.);
21  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
22  slope(i,0,0,ns) = dc;
23 
24  // additional limiting is unnecessary in 1D
25 
26  if (dc != Real(0.0)) {
27  sfx = amrex::min(sfx, sx / dc);
28  }
29  }
30 
31  for (int ns = 0; ns < ncomp; ++ns) {
32  slope(i,0,0,ns) *= sfx;
33  }
34 
35  amrex::ignore_unused(ratio);
36 }
37 
39 void mf_cell_cons_lin_interp_llslope (int i, int, int, Array4<Real> const& slope,
40  Array4<Real const> const& u, int scomp, int ncomp,
41  Box const& domain, IntVect const& /*ratio*/, BCRec const* bc) noexcept
42 {
43  Real sfx = Real(1.0);
44 
45  for (int ns = 0; ns < ncomp; ++ns) {
46  int nu = ns + scomp;
47 
48  // x-direction
49  Real dc = mf_compute_slopes_x(i, 0, 0, u, nu, domain, bc[ns]);
50  Real df = Real(2.0) * (u(i+1,0,0,nu) - u(i ,0,0,nu));
51  Real db = Real(2.0) * (u(i ,0,0,nu) - u(i-1,0,0,nu));
52  Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.);
53  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
54  if (dc != Real(0.0)) {
55  sfx = amrex::min(sfx, sx / dc);
56  }
57  slope(i,0,0,ns) = dc;
58  }
59 
60  for (int ns = 0; ns < ncomp; ++ns) {
61  slope(i,0,0,ns) *= sfx;
62  }
63 }
64 
66 void mf_cell_cons_lin_interp_mcslope (int i, int /*j*/, int /*k*/, int ns,
67  Array4<Real> const& slope,
68  Array4<Real const> const& u, int scomp, int /*ncomp*/,
69  Box const& domain, IntVect const& ratio,
70  BCRec const* bc) noexcept
71 {
72  int nu = ns + scomp;
73 
74  // x-direction
75  Real dc = mf_compute_slopes_x(i, 0, 0, u, nu, domain, bc[ns]);
76  Real df = Real(2.0) * (u(i+1,0,0,nu) - u(i ,0,0,nu));
77  Real db = Real(2.0) * (u(i ,0,0,nu) - u(i-1,0,0,nu));
78  Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.);
79  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
80 
81  Real alpha = Real(1.0);
82  if (sx != Real(0.0)) {
83  Real dumax = std::abs(sx) * Real(ratio[0]-1)/Real(2*ratio[0]);
84  Real umax = u(i,0,0,nu);
85  Real umin = u(i,0,0,nu);
86  for (int ioff = -1; ioff <= 1; ++ioff) {
87  umin = amrex::min(umin, u(i+ioff,0,0,nu));
88  umax = amrex::max(umax, u(i+ioff,0,0,nu));
89  }
90  if (dumax * alpha > (umax - u(i,0,0,nu))) {
91  alpha = (umax - u(i,0,0,nu)) / dumax;
92  }
93  if (dumax * alpha > (u(i,0,0,nu) - umin)) {
94  alpha = (u(i,0,0,nu) - umin) / dumax;
95  }
96  }
97 
98  slope(i,0,0,ns) = sx * alpha;
99 }
100 
102 void mf_cell_cons_lin_interp (int i, int /*j*/, int /*k*/, int ns,
103  Array4<Real> const& fine, int fcomp,
105  int ccomp, int /*ncomp*/, IntVect const& ratio) noexcept
106 {
107  const int ic = amrex::coarsen(i, ratio[0]);
108  const Real xoff = (static_cast<Real>(i - ic*ratio[0]) + Real(0.5)) / Real(ratio[0]) - Real(0.5);
109  fine(i,0,0,fcomp+ns) = crse(ic,0,0,ccomp+ns)
110  + xoff * slope(ic,0,0,ns);
111 }
112 
115  Array4<Real const> const& u, int scomp, int /*ncomp*/,
116  Box const& domain, IntVect const& ratio,
117  BCRec const* bc, Real drf, Real rlo) noexcept
118 {
119  int nu = ns + scomp;
120 
121  // x-direction
122  Real dc = mf_compute_slopes_x(i, 0, 0, u, nu, domain, bc[ns]);
123  Real df = Real(2.0) * (u(i+1,0,0,nu) - u(i ,0,0,nu));
124  Real db = Real(2.0) * (u(i ,0,0,nu) - u(i-1,0,0,nu));
125  Real sx = (df*db >= Real(0.0)) ? amrex::min(std::abs(df),std::abs(db)) : Real(0.);
126  sx = std::copysign(Real(1.),dc)*amrex::min(sx,std::abs(dc));
127 
128  Real alpha = Real(1.0);
129  if (sx != Real(0.0)) {
130  const Real drc = drf * ratio[0];
131  const Real rcm = i * drc + rlo;
132  const Real rcp = (i+1) * drc + rlo;
133  const Real vcm = rcm*rcm*rcm;
134  const Real vcp = rcp*rcp*rcp;
135  Real rfm = i*ratio[0] * drf + rlo;
136  Real rfp = (i*ratio[0] + 1) * drf + rlo;
137  Real vfm = rfm*rfm*rfm;
138  Real vfp = rfp*rfp*rfp;
139  Real xlo = Real(0.5) * ((vfm+vfp) - (vcm+vcp)) / (vcp - vcm);
140  rfm = ((i+1)*ratio[0] - 1) * drf + rlo;
141  rfp = (i+1)*ratio[0] * drf + rlo;
142  vfm = rfm*rfm*rfm;
143  vfp = rfp*rfp*rfp;
144  Real xhi = Real(0.5) * ((vfm+vfp) - (vcm+vcp)) / (vcp - vcm);
145  Real dumax = amrex::max(sx*xlo, sx*xhi);
146  Real dumin = -amrex::min(sx*xlo, sx*xhi);
147  Real umax = u(i,0,0,nu);
148  Real umin = u(i,0,0,nu);
149  for (int ioff = -1; ioff <= 1; ++ioff) {
150  umin = amrex::min(umin, u(i+ioff,0,0,nu));
151  umax = amrex::max(umax, u(i+ioff,0,0,nu));
152  }
153  if (dumax * alpha > (umax - u(i,0,0,nu))) {
154  alpha = (umax - u(i,0,0,nu)) / dumax;
155  }
156  if (dumin * alpha > (u(i,0,0,nu) - umin)) {
157  alpha = (u(i,0,0,nu) - umin) / dumin;
158  }
159  }
160 
161  slope(i,0,0,ns) = sx * alpha;
162 }
163 
165 void mf_cell_cons_lin_interp_sph (int i, int ns, Array4<Real> const& fine, int fcomp,
167  int ccomp, int /*ncomp*/, IntVect const& ratio, Real drf, Real rlo) noexcept
168 {
169  const int ic = amrex::coarsen(i, ratio[0]);
170  const Real drc = drf * ratio[0];
171  const Real rcm = ic * drc + rlo;
172  const Real rcp = (ic+1) * drc + rlo;
173  const Real rfm = i * drf + rlo;
174  const Real rfp = (i +1) * drf + rlo;
175  const Real vcm = rcm*rcm*rcm;
176  const Real vcp = rcp*rcp*rcp;
177  const Real vfm = rfm*rfm*rfm;
178  const Real vfp = rfp*rfp*rfp;
179  const Real xoff = Real(0.5) * ((vfm+vfp) - (vcm+vcp)) / (vcp - vcm);
180  fine(i,0,0,fcomp+ns) = crse(ic,0,0,ccomp+ns)
181  + xoff * slope(ic,0,0,ns);
182 }
183 
184 template<typename T>
186 void mf_cell_bilin_interp (int i, int, int, int n, Array4<T> const& fine, int fcomp,
187  Array4<T const> const& crse, int ccomp, IntVect const& ratio) noexcept
188 {
189  int ic = amrex::coarsen(i,ratio[0]);
190  int ioff = i - ic*ratio[0];
191  int sx;
192  Real wx;
193  if (ioff*2 < ratio[0]) {
194  sx = -1;
195  wx = Real(ratio[0]+1+2*ioff) / Real(2*ratio[0]);
196  } else {
197  sx = 1;
198  wx = Real(3*ratio[0]-1-2*ioff) / Real(2*ratio[0]);
199  }
200  fine(i,0,0,n+fcomp) =
201  crse(ic ,0,0,n+ccomp)* wx +
202  crse(ic+sx,0,0,n+ccomp)*(Real(1.0)-wx);
203 }
204 
206 void mf_nodebilin_interp (int i, int, int, int n, Array4<Real> const& fine, int fcomp,
207  Array4<Real const> const& crse, int ccomp, IntVect const& ratio) noexcept
208 {
209  int ic = amrex::coarsen(i,ratio[0]);
210  int ioff = i - ic*ratio[0];
211  if (ioff != 0) {
212  Real rxinv = Real(1.0) / Real(ratio[0]);
213  fine(i,0,0,n+fcomp) = rxinv*(static_cast<Real>(ratio[0]-ioff)*crse(ic ,0,0,n+ccomp) +
214  static_cast<Real>( ioff)*crse(ic+1,0,0,n+ccomp));
215  } else {
216  fine(i,0,0,n+fcomp) = crse(ic,0,0,n+ccomp);
217  }
218 }
219 
220 }
221 
222 #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
Boundary Condition Records. Necessary information and functions for computing boundary conditions.
Definition: AMReX_BCRec.H:17
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_cons_lin_interp_mcslope_sph(int i, int ns, Array4< Real > const &slope, Array4< Real const > const &u, int scomp, int, Box const &domain, IntVect const &ratio, BCRec const *bc, Real drf, Real rlo) noexcept
Definition: AMReX_MFInterp_1D_C.H:114
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_bilin_interp(int i, int, int, int n, Array4< T > const &fine, int fcomp, Array4< T const > const &crse, int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_MFInterp_1D_C.H:186
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_cons_lin_interp_llslope(int i, int, int, Array4< Real > const &slope, Array4< Real const > const &u, int scomp, int ncomp, Box const &domain, IntVect const &, BCRec const *bc) noexcept
Definition: AMReX_MFInterp_1D_C.H:39
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
Definition: AMReX_Algorithm.H:35
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 void mf_cell_cons_lin_interp_limit_minmax_llslope(int i, int, int, Array4< Real > const &slope, Array4< Real const > const &u, int scomp, int ncomp, Box const &domain, IntVect const &ratio, BCRec const *bc) noexcept
Definition: AMReX_MFInterp_1D_C.H:7
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 void mf_cell_cons_lin_interp_mcslope(int i, int, int, int ns, Array4< Real > const &slope, Array4< Real const > const &u, int scomp, int, Box const &domain, IntVect const &ratio, BCRec const *bc) noexcept
Definition: AMReX_MFInterp_1D_C.H:66
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_cons_lin_interp(int i, int, int, int ns, Array4< Real > const &fine, int fcomp, Array4< Real const > const &slope, Array4< Real const > const &crse, int ccomp, int, IntVect const &ratio) noexcept
Definition: AMReX_MFInterp_1D_C.H:102
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void ignore_unused(const Ts &...)
This shuts up the compiler about unused variables.
Definition: AMReX.H:111
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_nodebilin_interp(int i, int, int, int n, Array4< Real > const &fine, int fcomp, Array4< Real const > const &crse, int ccomp, IntVect const &ratio) noexcept
Definition: AMReX_MFInterp_1D_C.H:206
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real mf_compute_slopes_x(int i, int j, int k, Array4< Real const > const &u, int nu, Box const &domain, BCRec const &bc)
Definition: AMReX_MFInterp_C.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void mf_cell_cons_lin_interp_sph(int i, int ns, Array4< Real > const &fine, int fcomp, Array4< Real const > const &slope, Array4< Real const > const &crse, int ccomp, int, IntVect const &ratio, Real drf, Real rlo) noexcept
Definition: AMReX_MFInterp_1D_C.H:165
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
Definition: AMReX_Array4.H:61