Block-Structured AMR Software Framework
AMReX_EBFluxRegister_2D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_EB_FLUXREGISTER_2D_C_H_
2 #define AMREX_EB_FLUXREGISTER_2D_C_H_
3 #include <AMReX_Config.H>
4 
5 namespace amrex {
6 
8 void eb_flux_reg_crseadd_va(int i, int j, int k, Array4<Real> const& d,
9  Array4<int const> const& flag, Array4<Real const> const& fx,
10  Array4<Real const> const& fy, Array4<Real const> const& vfrac,
11  Array4<Real const> const& ax, Array4<Real const> const& ay,
12  Real dtdx, Real dtdy, int ncomp)
13 {
15  && vfrac(i,j,k) > Real(1.e-14))
16  {
17  Real volinv = Real(1.0)/vfrac(i,j,k);
18 
19  if (flag(i-1,j,k) == amrex_yafluxreg_fine_cell) {
20  Real tmp = dtdx*ax(i,j,k)*volinv;
21  for (int n = 0; n < ncomp; ++n) {
22  d(i,j,k,n) -= tmp*fx(i,j,k,n);
23  }
24  } else if (flag(i+1,j,k) == amrex_yafluxreg_fine_cell) {
25  Real tmp = dtdx*ax(i+1,j,k)*volinv;
26  for (int n = 0; n < ncomp; ++n) {
27  d(i,j,k,n) += tmp*fx(i+1,j,k,n);
28  }
29  }
30 
31  if (flag(i,j-1,k) == amrex_yafluxreg_fine_cell) {
32  Real tmp = dtdy*ay(i,j,k)*volinv;
33  for (int n = 0; n < ncomp; ++n) {
34  d(i,j,k,n) -= tmp*fy(i,j,k,n);
35  }
36  } else if (flag(i,j+1,k) == amrex_yafluxreg_fine_cell) {
37  Real tmp = dtdy*ay(i,j+1,k)*volinv;
38  for (int n = 0; n < ncomp; ++n) {
39  d(i,j,k,n) += tmp*fy(i,j+1,k,n);
40  }
41  }
42  }
43 }
44 
46 Real eb_flux_reg_cvol (int i, int j, Array4<Real const> const& vfrac,
47  Dim3 const& ratio, Real threshold) noexcept
48 {
49  Real cvol = Real(0.0);
50  constexpr int kk = 0;
51  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
52  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
53  cvol += vfrac(ii,jj,kk);
54  }
55  }
56  return (cvol > threshold) ? Real(1.0)/cvol : Real(0.0);
57 }
58 
60 void eb_flux_reg_fineadd_va_xlo (int i, int j, int k, int n, Array4<Real> const& d,
61  Array4<Real const> const& f, Array4<Real const> const& vfrac,
62  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
63 {
64  constexpr int kk = 0;
65  int ii = (i+1)*ratio.x;
66  Real fa = Real(0.0);
67  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
68  if (f.contains(ii,jj,kk)) {
69  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
70  }
71  }
72  Real cvol = eb_flux_reg_cvol(i,j,vfrac,ratio,Real(1.e-14));
73  fa *= -fac*cvol;
74  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
75 }
76 
78 void eb_flux_reg_fineadd_va_xhi (int i, int j, int k, int n, Array4<Real> const& d,
79  Array4<Real const> const& f, Array4<Real const> const& vfrac,
80  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
81 {
82  constexpr int kk = 0;
83  int ii = i*ratio.x;
84  Real fa = Real(0.0);
85  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
86  if (f.contains(ii,jj,kk)) {
87  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
88  }
89  }
90  Real cvol = eb_flux_reg_cvol(i,j,vfrac,ratio,Real(1.e-14));
91  fa *= fac*cvol;
92  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
93 }
94 
96 void eb_flux_reg_fineadd_va_ylo (int i, int j, int k, int n, Array4<Real> const& d,
97  Array4<Real const> const& f, Array4<Real const> const& vfrac,
98  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
99 {
100  constexpr int kk = 0;
101  int jj = (j+1)*ratio.y;
102  Real fa = Real(0.0);
103  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
104  if (f.contains(ii,jj,kk)) {
105  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
106  }
107  }
108  Real cvol = eb_flux_reg_cvol(i,j,vfrac,ratio,Real(1.e-14));
109  fa *= -fac*cvol;
110  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
111 }
112 
114 void eb_flux_reg_fineadd_va_yhi (int i, int j, int k, int n, Array4<Real> const& d,
115  Array4<Real const> const& f, Array4<Real const> const& vfrac,
116  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
117 {
118  constexpr int kk = 0;
119  int jj = j*ratio.y;
120  Real fa = Real(0.0);
121  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
122  if (f.contains(ii,jj,kk)) {
123  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
124  }
125  }
126  Real cvol = eb_flux_reg_cvol(i,j,vfrac,ratio,Real(1.e-14));
127  fa *= fac*cvol;
128  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
129 }
130 
132 void eb_flux_reg_fineadd_dm (int i, int j, int k, int n, Box const& dmbx, Array4<Real> const& d,
133  Array4<Real const> const& dm, Array4<Real const> const& vfrac,
134  Dim3 const& ratio, Real threshold)
135 {
136  Real dmtot = Real(0.0);
137  constexpr int kk = 0;
138  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
139  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
140  if (dmbx.contains(IntVect(ii,jj))) {
141  dmtot += dm(ii,jj,kk,n);
142  }
143  }
144  }
145  Real cvol = eb_flux_reg_cvol(i,j,vfrac,ratio,threshold);
146  dmtot *= cvol;
147  HostDevice::Atomic::Add(d.ptr(i,j,k,n), dmtot);
148 }
149 
151 void eb_rereflux_from_crse (int i, int j, int k, int n, Box const& bx, Array4<Real> const& d,
152  Array4<Real const> const& s, Array4<int const> const& amrflg,
153  Array4<EBCellFlag const> const& ebflg, Array4<Real const> const& vfrac)
154 {
155  if (amrflg(i,j,k) == amrex_yafluxreg_crse_fine_boundary_cell)
156  {
157  auto flag = ebflg(i,j,k);
158  if (flag.isRegular())
159  {
160  if (bx.contains(IntVect(i,j)))
161  {
162  HostDevice::Atomic::Add(d.ptr(i,j,k,n), s(i,j,k,n));
163  }
164  }
165  else if (flag.isSingleValued())
166  {
167  Real dm = s(i,j,k,n) * vfrac(i,j,k);
168  if (bx.contains(IntVect(i,j))) {
169  HostDevice::Atomic::Add(d.ptr(i,j,k,n), dm);
170  }
171 
172  Real wtot = Real(0.0);
173  for (int jj = -1; jj <= 1; ++jj) {
174  for (int ii = -1; ii <= 1; ++ii) {
175  if ((ii != 0 || jj != 0) && flag.isConnected(ii,jj,0)) {
176  wtot += vfrac(i+ii,j+jj,k);
177  }
178  }}
179 
180  Real drho = dm * ((Real(1.0)-vfrac(i,j,k))/wtot);
181  for (int jj = -1; jj <= 1; ++jj) {
182  for (int ii = -1; ii <= 1; ++ii) {
183  if ((ii != 0 || jj != 0) && flag.isConnected(ii,jj,0)) {
184  if (bx.contains(IntVect(i+ii,j+jj))) {
185  HostDevice::Atomic::Add(d.ptr(i+ii,j+jj,k,n), drho);
186  }
187  }
188  }}
189  }
190  }
191 }
192 
194 void eb_rereflux_to_fine (int i, int j, int /*k*/, int n, Array4<Real> const& d,
195  Array4<Real const> const& s, Array4<int const> const& msk, Dim3 ratio)
196 {
197  int ic = amrex::coarsen(i,ratio.x);
198  int jc = amrex::coarsen(j,ratio.y);
199  if (msk(ic,jc,0) == 1) {
200  d(i,j,0,n) += s(ic,jc,0,n);
201  }
202 }
203 
204 }
205 
206 #endif
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
constexpr int amrex_yafluxreg_fine_cell
Definition: AMReX_YAFluxRegister_K.H:8
constexpr int amrex_yafluxreg_crse_fine_boundary_cell
Definition: AMReX_YAFluxRegister_K.H:7
AMREX_GPU_HOST_DEVICE bool contains(const IntVectND< dim > &p) const noexcept
Returns true if argument is contained within BoxND.
Definition: AMReX_Box.H:204
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void Add(T *const sum, T const value) noexcept
Definition: AMReX_GpuAtomic.H:619
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_rereflux_to_fine(int i, int j, int, int n, Array4< Real > const &d, Array4< Real const > const &s, Array4< int const > const &msk, Dim3 ratio)
Definition: AMReX_EBFluxRegister_2D_C.H:194
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_va_xlo(int i, int j, int k, int n, Array4< Real > const &d, Array4< Real const > const &f, Array4< Real const > const &vfrac, Array4< Real const > const &a, Real fac, Dim3 const &ratio)
Definition: AMReX_EBFluxRegister_2D_C.H:60
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_va_yhi(int i, int j, int k, int n, Array4< Real > const &d, Array4< Real const > const &f, Array4< Real const > const &vfrac, Array4< Real const > const &a, Real fac, Dim3 const &ratio)
Definition: AMReX_EBFluxRegister_2D_C.H:114
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE Real eb_flux_reg_cvol(int i, int j, Array4< Real const > const &vfrac, Dim3 const &ratio, Real threshold) noexcept
Definition: AMReX_EBFluxRegister_2D_C.H:46
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_dm(int i, int j, int k, int n, Box const &dmbx, Array4< Real > const &d, Array4< Real const > const &dm, Array4< Real const > const &vfrac, Dim3 const &ratio, Real threshold)
Definition: AMReX_EBFluxRegister_2D_C.H:132
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_va_ylo(int i, int j, int k, int n, Array4< Real > const &d, Array4< Real const > const &f, Array4< Real const > const &vfrac, Array4< Real const > const &a, Real fac, Dim3 const &ratio)
Definition: AMReX_EBFluxRegister_2D_C.H:96
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_va_xhi(int i, int j, int k, int n, Array4< Real > const &d, Array4< Real const > const &f, Array4< Real const > const &vfrac, Array4< Real const > const &a, Real fac, Dim3 const &ratio)
Definition: AMReX_EBFluxRegister_2D_C.H:78
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_rereflux_from_crse(int i, int j, int k, int n, Box const &bx, Array4< Real > const &d, Array4< Real const > const &s, Array4< int const > const &amrflg, Array4< EBCellFlag const > const &ebflg, Array4< Real const > const &vfrac)
Definition: AMReX_EBFluxRegister_2D_C.H:151
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 eb_flux_reg_crseadd_va(int i, int j, int k, Array4< Real > const &d, Array4< int const > const &flag, Array4< Real const > const &fx, Array4< Real const > const &fy, Array4< Real const > const &vfrac, Array4< Real const > const &ax, Array4< Real const > const &ay, Real dtdx, Real dtdy, int ncomp)
Definition: AMReX_EBFluxRegister_2D_C.H:8
Definition: AMReX_Array4.H:61
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T * ptr(int i, int j, int k) const noexcept
Definition: AMReX_Array4.H:149
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12