Block-Structured AMR Software Framework
AMReX_EBFluxRegister_3D_C.H
Go to the documentation of this file.
1 #ifndef AMREX_EB_FLUXREGISTER_3D_C_H_
2 #define AMREX_EB_FLUXREGISTER_3D_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& fz,
11  Array4<Real const> const& vfrac, Array4<Real const> const& ax,
12  Array4<Real const> const& ay, Array4<Real const> const& az,
13  Real dtdx, Real dtdy, Real dtdz, int ncomp)
14 {
16  && vfrac(i,j,k) > Real(1.e-14))
17  {
18  Real volinv = Real(1.0)/vfrac(i,j,k);
19 
20  if (flag(i-1,j,k) == amrex_yafluxreg_fine_cell) {
21  Real tmp = dtdx*ax(i,j,k)*volinv;
22  for (int n = 0; n < ncomp; ++n) {
23  d(i,j,k,n) -= tmp*fx(i,j,k,n);
24  }
25  } else if (flag(i+1,j,k) == amrex_yafluxreg_fine_cell) {
26  Real tmp = dtdx*ax(i+1,j,k)*volinv;
27  for (int n = 0; n < ncomp; ++n) {
28  d(i,j,k,n) += tmp*fx(i+1,j,k,n);
29  }
30  }
31 
32  if (flag(i,j-1,k) == amrex_yafluxreg_fine_cell) {
33  Real tmp = dtdy*ay(i,j,k)*volinv;
34  for (int n = 0; n < ncomp; ++n) {
35  d(i,j,k,n) -= tmp*fy(i,j,k,n);
36  }
37  } else if (flag(i,j+1,k) == amrex_yafluxreg_fine_cell) {
38  Real tmp = dtdy*ay(i,j+1,k)*volinv;
39  for (int n = 0; n < ncomp; ++n) {
40  d(i,j,k,n) += tmp*fy(i,j+1,k,n);
41  }
42  }
43 
44  if (flag(i,j,k-1) == amrex_yafluxreg_fine_cell) {
45  Real tmp = dtdz*az(i,j,k)*volinv;
46  for (int n = 0; n < ncomp; ++n) {
47  d(i,j,k,n) -= tmp*fz(i,j,k,n);
48  }
49  } else if (flag(i,j,k+1) == amrex_yafluxreg_fine_cell) {
50  Real tmp = dtdz*az(i,j,k+1)*volinv;
51  for (int n = 0; n < ncomp; ++n) {
52  d(i,j,k,n) += tmp*fz(i,j,k+1,n);
53  }
54  }
55  }
56 }
57 
59 Real eb_flux_reg_cvol (int i, int j, int k, Array4<Real const> const& vfrac,
60  Dim3 const& ratio, Real small) noexcept
61 {
62  Real cvol = Real(0.0);
63  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
64  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
65  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
66  cvol += vfrac(ii,jj,kk);
67  }
68  }
69  }
70  return (cvol > small) ? Real(1.0)/cvol : Real(0.0);
71 }
72 
74 void eb_flux_reg_fineadd_va_xlo (int i, int j, int k, int n, Array4<Real> const& d,
75  Array4<Real const> const& f, Array4<Real const> const& vfrac,
76  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
77 {
78  int ii = (i+1)*ratio.x;
79  Real fa = Real(0.0);
80  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
81  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
82  if (f.contains(ii,jj,kk)) {
83  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
84  }
85  }
86  }
87  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
88  fa *= -fac*cvol;
89  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
90 }
91 
93 void eb_flux_reg_fineadd_va_xhi (int i, int j, int k, int n, Array4<Real> const& d,
94  Array4<Real const> const& f, Array4<Real const> const& vfrac,
95  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
96 {
97  int ii = i*ratio.x;
98  Real fa = Real(0.0);
99  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
100  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
101  if (f.contains(ii,jj,kk)) {
102  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
103  }
104  }
105  }
106  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
107  fa *= fac*cvol;
108  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
109 }
110 
112 void eb_flux_reg_fineadd_va_ylo (int i, int j, int k, int n, Array4<Real> const& d,
113  Array4<Real const> const& f, Array4<Real const> const& vfrac,
114  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
115 {
116  int jj = (j+1)*ratio.y;
117  Real fa = Real(0.0);
118  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
119  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
120  if (f.contains(ii,jj,kk)) {
121  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
122  }
123  }
124  }
125  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
126  fa *= -fac*cvol;
127  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
128 }
129 
131 void eb_flux_reg_fineadd_va_yhi (int i, int j, int k, int n, Array4<Real> const& d,
132  Array4<Real const> const& f, Array4<Real const> const& vfrac,
133  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
134 {
135  int jj = j*ratio.y;
136  Real fa = Real(0.0);
137  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
138  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
139  if (f.contains(ii,jj,kk)) {
140  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
141  }
142  }
143  }
144  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
145  fa *= fac*cvol;
146  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
147 }
148 
150 void eb_flux_reg_fineadd_va_zlo (int i, int j, int k, int n, Array4<Real> const& d,
151  Array4<Real const> const& f, Array4<Real const> const& vfrac,
152  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
153 {
154  int kk = (k+1)*ratio.z;
155  Real fa = Real(0.0);
156  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
157  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
158  if (f.contains(ii,jj,kk)) {
159  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
160  }
161  }
162  }
163  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
164  fa *= -fac*cvol;
165  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
166 }
167 
169 void eb_flux_reg_fineadd_va_zhi (int i, int j, int k, int n, Array4<Real> const& d,
170  Array4<Real const> const& f, Array4<Real const> const& vfrac,
171  Array4<Real const> const& a, Real fac, Dim3 const& ratio)
172 {
173  int kk = k*ratio.z;
174  Real fa = Real(0.0);
175  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
176  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
177  if (f.contains(ii,jj,kk)) {
178  fa += f(ii,jj,kk,n) * a(ii,jj,kk);
179  }
180  }
181  }
182  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,Real(1.e-14));
183  fa *= fac*cvol;
184  HostDevice::Atomic::Add(d.ptr(i,j,k,n), fa);
185 }
186 
188 void eb_flux_reg_fineadd_dm (int i, int j, int k, int n, Box const& dmbx, Array4<Real> const& d,
189  Array4<Real const> const& dm, Array4<Real const> const& vfrac,
190  Dim3 const& ratio, Real threshold)
191 {
192  Real dmtot = Real(0.0);
193  for (int kk = k*ratio.z; kk < (k+1)*ratio.z; ++kk) {
194  for (int jj = j*ratio.y; jj < (j+1)*ratio.y; ++jj) {
195  for (int ii = i*ratio.x; ii < (i+1)*ratio.x; ++ii) {
196  if (dmbx.contains(IntVect(ii,jj,kk))) {
197  dmtot += dm(ii,jj,kk,n);
198  }
199  }
200  }
201  }
202  Real cvol = eb_flux_reg_cvol(i,j,k,vfrac,ratio,threshold);
203  dmtot *= cvol;
204  HostDevice::Atomic::Add(d.ptr(i,j,k,n), dmtot);
205 }
206 
208 void eb_rereflux_from_crse (int i, int j, int k, int n, Box const& bx, Array4<Real> const& d,
209  Array4<Real const> const& s, Array4<int const> const& amrflg,
210  Array4<EBCellFlag const> const& ebflg, Array4<Real const> const& vfrac)
211 {
212  if (amrflg(i,j,k) == amrex_yafluxreg_crse_fine_boundary_cell)
213  {
214  auto flag = ebflg(i,j,k);
215  if (flag.isRegular())
216  {
217  if (bx.contains(IntVect(i,j,k)))
218  {
219  HostDevice::Atomic::Add(d.ptr(i,j,k,n), s(i,j,k,n));
220  }
221  }
222  else if (flag.isSingleValued())
223  {
224  Real dm = s(i,j,k,n) * vfrac(i,j,k);
225  if (bx.contains(IntVect(i,j,k))) {
226  HostDevice::Atomic::Add(d.ptr(i,j,k,n), dm);
227  }
228 
229  Real wtot = Real(0.0);
230  for (int kk = -1; kk <= 1; ++kk) {
231  for (int jj = -1; jj <= 1; ++jj) {
232  for (int ii = -1; ii <= 1; ++ii) {
233  if ((ii != 0 || jj != 0 || kk != 0) && flag.isConnected(ii,jj,kk)) {
234  wtot += vfrac(i+ii,j+jj,k+kk);
235  }
236  }}}
237 
238  Real drho = dm * ((Real(1.0)-vfrac(i,j,k))/wtot);
239  for (int kk = -1; kk <= 1; ++kk) {
240  for (int jj = -1; jj <= 1; ++jj) {
241  for (int ii = -1; ii <= 1; ++ii) {
242  if ((ii != 0 || jj != 0 || kk != 0) && flag.isConnected(ii,jj,kk)) {
243  if (bx.contains(IntVect(i+ii,j+jj,k+kk))) {
244  HostDevice::Atomic::Add(d.ptr(i+ii,j+jj,k+kk,n), drho);
245  }
246  }
247  }}}
248  }
249  }
250 }
251 
253 void eb_rereflux_to_fine (int i, int j, int k, int n, Array4<Real> const& d,
254  Array4<Real const> const& s, Array4<int const> const& msk, Dim3 ratio)
255 {
256  int ic = amrex::coarsen(i,ratio.x);
257  int jc = amrex::coarsen(j,ratio.y);
258  int kc = amrex::coarsen(k,ratio.z);
259  if (msk(ic,jc,kc) == 1) {
260  d(i,j,k,n) += s(ic,jc,kc,n);
261  }
262 }
263 
264 }
265 
266 #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 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
BoxND< AMREX_SPACEDIM > Box
Definition: AMReX_BaseFwd.H:27
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void eb_flux_reg_fineadd_va_zlo(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_3D_C.H:150
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
IntVectND< AMREX_SPACEDIM > IntVect
Definition: AMReX_BaseFwd.H:30
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_fineadd_va_zhi(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_3D_C.H:169
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 z
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12