Block-Structured AMR Software Framework
AMReX_EB_StateRedistSlopeLimiter_K.H
Go to the documentation of this file.
1 #ifndef AMREX_EB_STATE_REDIST_SLOPE_LIMITER_K_H_
2 #define AMREX_EB_STATE_REDIST_SLOPE_LIMITER_K_H_
3 
4 namespace amrex {
5 
7 amrex::Real
8 amrex_calc_alpha_stencil(Real q_hat, Real q_max, Real q_min, Real state) noexcept
9 {
10 #ifdef AMREX_USE_FLOAT
11  constexpr Real epsilon = amrex::Real(1.e-6);
12 #else
13  constexpr Real epsilon = 1.e-12;
14 #endif
15 
16  const Real small = epsilon*amrex::max(amrex::Math::abs(q_max),amrex::Math::abs(q_min));
17  Real alpha;
18 
19  if ((q_hat-state) > small) {
20  alpha = amrex::min(1.0_rt,(q_max-state)/(q_hat-state));
21  } else if ((q_hat-state) < -small) {
22  alpha = amrex::min(1.0_rt,(q_min-state)/(q_hat-state));
23  } else {
24  alpha = 1.0_rt;
25  }
26  return alpha;
27 }
28 
31 amrex_calc_centroid_limiter(int i, int j, int k, int n,
35  amrex::Array4<amrex::Real const> const& ccent) noexcept
36 {
37 #ifdef AMREX_USE_FLOAT
38  constexpr Real epsilon = amrex::Real(1.e-6);
39 #else
40  constexpr Real epsilon = 1.e-12;
41 #endif
42 
43  AMREX_D_TERM(amrex::Real xalpha = 1.0;,
44  amrex::Real yalpha = 1.0;,
45  amrex::Real zalpha = 1.0;);
46 
47  // Compute the limiters needed to keep the predicted q_hat between the max and min
48 #if (AMREX_SPACEDIM == 2)
49  int kk = 0;
50 #elif (AMREX_SPACEDIM == 3)
51  for(int kk(-1); kk<=1; kk++)
52 #endif
53  {
54  for(int jj(-1); jj<=1; jj++){
55  for(int ii(-1); ii<=1; ii++){
56  Real alpha = amrex::max(xalpha,yalpha);
57 #if (AMREX_SPACEDIM == 3)
58  alpha = amrex::max(alpha,zalpha);
59 #endif
60  if (flag(i,j,k).isConnected(ii,jj,kk) && alpha > 0.0)
61  {
62  AMREX_D_TERM(Real delta_x = ccent(i+ii,j+jj,k+kk,0) - ccent(i,j,k,0) + static_cast<Real>(ii);,
63  Real delta_y = ccent(i+ii,j+jj,k+kk,1) - ccent(i,j,k,1) + static_cast<Real>(jj);,
64  Real delta_z = ccent(i+ii,j+jj,k+kk,2) - ccent(i,j,k,2) + static_cast<Real>(kk););
65 
66  Real q_hat = state(i,j,k,n) + AMREX_D_TERM( delta_x * slopes[0],
67  + delta_y * slopes[1],
68  + delta_z * slopes[2]);
69 
70  Real q_max = amrex::max(state(i+ii,j+jj,k+kk,n),state(i,j,k,n));
71  Real q_min = amrex::min(state(i+ii,j+jj,k+kk,n),state(i,j,k,n));
72 
73  if ( q_hat-q_max > amrex::Math::abs(epsilon*q_max) || q_hat-q_min < -1.0*amrex::Math::abs(epsilon*q_min) )
74  {
75  Real new_lim = amrex_calc_alpha_stencil(q_hat, q_max, q_min, state(i,j,k,n));
76 
77  if (amrex::Math::abs(delta_x) > epsilon) { xalpha = amrex::min(xalpha,new_lim); }
78  if (amrex::Math::abs(delta_y) > epsilon) { yalpha = amrex::min(yalpha,new_lim); }
79 #if (AMREX_SPACEDIM == 3)
80  if (amrex::Math::abs(delta_z) > epsilon) { zalpha = amrex::min(zalpha,new_lim); }
81 #endif
82  }
83  }
84  }
85  }
86  }
87 
88  return {AMREX_D_DECL(xalpha,yalpha,zalpha)};
89 }
90 
91 }
92 
93 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_DEVICE
Definition: AMReX_GpuQualifiers.H:18
#define AMREX_D_TERM(a, b, c)
Definition: AMReX_SPACE.H:129
#define AMREX_D_DECL(a, b, c)
Definition: AMReX_SPACE.H:104
#define abs(x)
Definition: complex-type.h:85
Definition: AMReX_Amr.cpp:49
AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > amrex_calc_centroid_limiter(int i, int j, int k, int n, amrex::Array4< amrex::Real const > const &state, amrex::Array4< amrex::EBCellFlag const > const &flag, const amrex::GpuArray< amrex::Real, AMREX_SPACEDIM > &slopes, amrex::Array4< amrex::Real const > const &ccent) noexcept
Definition: AMReX_EB_StateRedistSlopeLimiter_K.H:31
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_DEVICE AMREX_FORCE_INLINE amrex::Real amrex_calc_alpha_stencil(Real q_hat, Real q_max, Real q_min, Real state) noexcept
Definition: AMReX_EB_StateRedistSlopeLimiter_K.H:8
Definition: AMReX_Array4.H:61
Definition: AMReX_Array.H:33