1 #ifndef AMREX_HABEC_2D_H_
2 #define AMREX_HABEC_2D_H_
3 #include <AMReX_Config.H>
16 Dim3 const& boxlo,
Dim3 const& boxhi,
25 sten[1] = -(sb / (dx[0]*dx[0])) *
b[0](i,j,k);
26 sten[2] = -(sb / (dx[0]*dx[0])) *
b[0](i+1,j,k);
27 sten[3] = -(sb / (dx[1]*dx[1])) *
b[1](i,j,k);
28 sten[4] = -(sb / (dx[1]*dx[1])) *
b[1](i,j+1,k);
29 sten[0] = -(sten[1] + sten[2] + sten[3] + sten[4]);
30 if (sa != Real(0.0)) {
31 sten[0] += sa * a(i,j,k);
37 if (msk[cdir](i-1,j,k) > 0) {
40 sten[0] += bf1 *
b[0](i,j,k);
42 sten[2] += bf2 *
b[0](i,j,k);
49 if (msk[cdir](i+1,j,k) > 0) {
52 sten[0] += bf1 *
b[0](i+1,j,k);
53 sten[1] += bf2 *
b[0](i+1,j,k);
61 if (msk[cdir](i,j-1,k) > 0) {
64 sten[0] += bf1 *
b[1](i,j,k);
66 sten[4] += bf2 *
b[1](i,j,k);
73 if (msk[cdir](i,j+1,k) > 0) {
76 sten[0] += bf1 *
b[1](i,j+1,k);
77 sten[3] += bf2 *
b[1](i,j+1,k);
82 diaginv(i,j,k) = Real(1.0) / sten[0];
84 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
85 sten[m] *= diaginv(i,j,k);
89 template <
typename Int>
101 if (!osm || osm(i,j,k) != 0) {
102 sten[1] = -(sb / (dx[0]*dx[0])) *
b[0](i,j,k);
103 sten[2] = -(sb / (dx[0]*dx[0])) *
b[0](i+1,j,k);
104 sten[3] = -(sb / (dx[1]*dx[1])) *
b[1](i,j,k);
105 sten[4] = -(sb / (dx[1]*dx[1])) *
b[1](i,j+1,k);
106 sten[0] = -(sten[1] + sten[2] + sten[3] + sten[4]);
107 if (sa != Real(0.0)) {
108 sten[0] += sa * a(i,j,k);
112 if (cell_id(i-1,j,k) < 0) {
116 sten[0] += bf1 *
b[0](i,j,k);
118 sten[2] += bf2 *
b[0](i,j,k);
122 if (cell_id(i+1,j,k) < 0) {
126 sten[0] += bf1 *
b[0](i+1,j,k);
127 sten[1] += bf2 *
b[0](i+1,j,k);
132 if (cell_id(i,j-1,k) < 0) {
136 sten[0] += bf1 *
b[1](i,j,k);
138 sten[4] += bf2 *
b[1](i,j,k);
142 if (cell_id(i,j+1,k) < 0) {
146 sten[0] += bf1 *
b[1](i,j+1,k);
147 sten[3] += bf2 *
b[1](i,j+1,k);
152 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
157 diaginv(i,j,k) = Real(1.0) / sten[0];
159 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
160 sten[m] *= diaginv(i,j,k);
164 for (
int m = 0; m < 2*AMREX_SPACEDIM+1; ++m) {
165 ncols(i,j,k) += (sten[m] != Real(0.0));
169 template <
typename Int>
174 sten[0] = cell_id(i ,j ,0);
175 sten[1] = cell_id(i-1,j ,0);
176 sten[2] = cell_id(i+1,j ,0);
177 sten[3] = cell_id(i ,j-1,0);
178 sten[4] = cell_id(i ,j+1,0);
183 template <
typename Int>
185 void habec_cols_eb (GpuArray<Int,9>& sten,
int i,
int j,
int ,
186 Array4<Int const>
const& cell_id)
188 sten[0] = cell_id(i-1,j-1,0);
189 sten[1] = cell_id(i ,j-1,0);
190 sten[2] = cell_id(i+1,j-1,0);
191 sten[3] = cell_id(i-1,j ,0);
192 sten[4] = cell_id(i ,j ,0);
193 sten[5] = cell_id(i+1,j ,0);
194 sten[6] = cell_id(i-1,j+1,0);
195 sten[7] = cell_id(i ,j+1,0);
196 sten[8] = cell_id(i+1,j+1,0);
199 template <
typename Int>
201 void habec_ijmat_eb (GpuArray<Real,9>& sten, Array4<Int>
const& ncols,
202 Array4<Real>
const& diaginv,
int i,
int j,
int k,
203 Array4<Int const>
const& cell_id,
204 Real sa, Array4<Real const>
const& a,
205 Real sb, GpuArray<Real,AMREX_SPACEDIM>
const& dx,
206 GpuArray<Array4<Real const>, AMREX_SPACEDIM>
const& b,
207 GpuArray<int,AMREX_SPACEDIM*2>
const& bctype,
208 GpuArray<Real,AMREX_SPACEDIM*2>
const& bcl,
int bho,
209 Array4<const EBCellFlag>
const& flag,
210 Array4<Real const>
const& vfrc,
211 Array4<Real const>
const& apx,
212 Array4<Real const>
const& apy,
213 Array4<Real const>
const& fcx,
214 Array4<Real const>
const& fcy,
215 Array4<Real const>
const& ba,
216 Array4<Real const>
const& bcen,
217 Array4<Real const>
const& beb)
219 for (
int m = 0; m < 9; ++m) {
223 auto& mat_tmp =
reinterpret_cast<Array2D<Real,-1,1,-1,1
>&>(sten);
225 GpuArray<Real,AMREX_SPACEDIM> fac{sb/(dx[0]*dx[0]), sb/(dx[1]*dx[1])};
227 if (flag(i,j,k).isRegular())
229 mat_tmp(0,0) = fac[0]*(
b[0](i,j,k)+b[0](i+1,j,k))
230 + fac[1]*(b[1](i,j,k)+
b[1](i,j+1,k));
231 mat_tmp(-1, 0) = -fac[0]*
b[0](i,j,k);
232 mat_tmp( 1, 0) = -fac[0]*
b[0](i+1,j,k);
233 mat_tmp( 0,-1) = -fac[1]*
b[1](i,j,k);
234 mat_tmp( 0, 1) = -fac[1]*
b[1](i,j+1,k);
236 if (cell_id(i-1,j,k) < 0) {
240 mat_tmp(0,0) += bf1*
b[0](i,j,k);
241 mat_tmp(-1,0) = Real(0.0);
242 mat_tmp(1,0) += bf2*
b[0](i,j,k);
245 if (cell_id(i+1,j,k) < 0) {
249 mat_tmp(0,0) += bf1*
b[0](i+1,j,k);
250 mat_tmp(1,0) = Real(0.0);
251 mat_tmp(-1,0) += bf2*
b[0](i+1,j,k);
254 if (cell_id(i,j-1,k) < 0) {
258 mat_tmp(0,0) += bf1*
b[1](i,j,k);
259 mat_tmp(0,-1) = Real(0.0);
260 mat_tmp(0,1) += bf2*
b[1](i,j,k);
263 if (cell_id(i,j+1,k) < 0) {
267 mat_tmp(0,0) += bf1*
b[1](i,j+1,k);
268 mat_tmp(0,1) = Real(0.0);
269 mat_tmp(0,-1) += bf2*
b[1](i,j+1,k);
272 if (sa != Real(0.0)) {
273 mat_tmp(0,0) += sa*a(i,j,k);
276 else if (flag(i,j,k).isSingleValued())
279 Real area = apx(i,j,k);
281 if (area > Real(0.0))
287 if (area != Real(1.0)) {
288 joff =
static_cast<int>(std::copysign(Real(1.0), fcx(i,j,k)));
290 if (cell_id(i-1,jj,k) < 0 && cell_id(i,jj,k) < 0) {
304 Real tmp = (Real(1.0)-fracy)*area*b[0](i,j,k);
305 if (cell_id(i-1,j,k) >= 0) {
306 mat_tmp( 0,0) += tmp*
f;
307 mat_tmp(-1,0) -= tmp*
f;
308 }
else if (cell_id(i+1,j,k) < 0 || apx(i+1,j,k) == Real(0.0)) {
309 mat_tmp(0,0) += tmp*(
f+bflo);
311 mat_tmp(0,0) += tmp*(
f+bf1);
312 mat_tmp(1,0) += tmp* bf2;
315 if (fracy > Real(0.0)) {
316 if (cell_id(i-1,jj,k) >= 0 && cell_id(i,jj,k) >= 0) {
317 mat_tmp(-1,joff) -= fracy*area*
b[0](i,jj,k)*
f;
318 mat_tmp( 0,joff) += fracy*area*
b[0](i,jj,k)*
f;
319 }
else if (cell_id(i+1,jj,k) < 0 || apx(i+1,jj,k) == Real(0.0)) {
320 mat_tmp( 0,joff) += tmp*(
f+bflo);
322 mat_tmp( 0,joff) += tmp*(
f+bf1);
323 mat_tmp( 1,joff) += tmp* bf2;
330 if (area > Real(0.0))
336 if (area != Real(1.0)) {
337 joff =
static_cast<int>(std::copysign(Real(1.0), fcx(i+1,j,k)));
339 if (cell_id(i,jj,k) < 0 && cell_id(i+1,jj,k) < 0) {
353 Real tmp = (Real(1.0)-fracy)*area*b[0](i+1,j,k);
354 if (cell_id(i+1,j,k) >= 0) {
355 mat_tmp(0,0) += tmp*
f;
356 mat_tmp(1,0) -= tmp*
f;
357 }
else if (cell_id(i-1,j,k) < 0 || apx(i,j,k) == Real(0.0)) {
358 mat_tmp(0,0) += tmp*(
f+bflo);
360 mat_tmp( 0,0) += tmp*(
f+bf1);
361 mat_tmp(-1,0) += tmp* bf2;
364 if (fracy > Real(0.0)) {
365 if (cell_id(i,jj,k) >= 0 && cell_id(i+1,jj,k) >= 0) {
366 mat_tmp(0,joff) += fracy*area*
b[0](i+1,jj,k)*
f;
367 mat_tmp(1,joff) -= fracy*area*
b[0](i+1,jj,k)*
f;
368 }
else if (cell_id(i-1,jj,k) < 0 || apx(i,jj,k) == Real(0.0)) {
369 mat_tmp(0,joff) += tmp*(
f+bflo);
371 mat_tmp( 0,joff) += tmp*(
f+bf1);
372 mat_tmp(-1,joff) += tmp* bf2;
379 if (area > Real(0.0))
385 if (area != Real(1.0)) {
386 ioff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j,k)));
388 if (cell_id(ii,j-1,k) < 0 && cell_id(ii,j,k) < 0) {
402 Real tmp = (Real(1.0)-fracx)*area*b[1](i,j,k);
403 if (cell_id(i,j-1,k) >= 0) {
404 mat_tmp(0, 0) += tmp*
f;
405 mat_tmp(0,-1) -= tmp*
f;
406 }
else if (cell_id(i,j+1,k) < 0 || apy(i,j+1,k) == Real(0.0)) {
407 mat_tmp(0,0) += tmp*(
f+bflo);
409 mat_tmp(0,0) += tmp*(
f+bf1);
410 mat_tmp(0,1) += tmp* bf2;
413 if (fracx > Real(0.0)) {
414 if (cell_id(ii,j-1,k) >= 0 && cell_id(ii,j,k) >= 0) {
415 mat_tmp(ioff,-1) -= fracx*area*
b[1](ii,j,k)*
f;
416 mat_tmp(ioff, 0) += fracx*area*
b[1](ii,j,k)*
f;
417 }
else if (cell_id(ii,j+1,k) < 0 || apy(ii,j+1,k) == Real(0.0)) {
418 mat_tmp(ioff,0) += tmp*(
f+bflo);
420 mat_tmp(ioff,0) += tmp*(
f+bf1);
421 mat_tmp(ioff,1) += tmp* bf2;
428 if (area > Real(0.0))
434 if (area != Real(1.0)) {
435 ioff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j+1,k)));
437 if (cell_id(ii,j,k) < 0 && cell_id(ii,j+1,k) < 0) {
451 Real tmp = (Real(1.0)-fracx)*area*b[1](i,j+1,k);
452 if (cell_id(i,j+1,k) >= 0) {
453 mat_tmp(0,0) += tmp*
f;
454 mat_tmp(0,1) -= tmp*
f;
455 }
else if (cell_id(i,j-1,k) < 0 || apy(i,j,k) == Real(0.0)) {
456 mat_tmp(0,0) += tmp*(
f+bflo);
458 mat_tmp(0, 0) += tmp*(
f+bf1);
459 mat_tmp(0,-1) += tmp* bf2;
462 if (fracx > Real(0.0)) {
463 if (cell_id(ii,j,k) >= 0 && cell_id(ii,j+1,k) >= 0) {
464 mat_tmp(ioff,0) += fracx*area*
b[1](ii,j+1,k)*
f;
465 mat_tmp(ioff,1) -= fracx*area*
b[1](ii,j+1,k)*
f;
466 }
else if (cell_id(ii,j-1,k) < 0 || apy(ii,j,k) == Real(0.0)) {
467 mat_tmp(ioff,0) += tmp*(
f+bflo);
469 mat_tmp(ioff, 0) += tmp*(
f+bf1);
470 mat_tmp(ioff,-1) += tmp* bf2;
476 Real anorm =
std::sqrt((apx(i,j,k) - apx(i+1,j,k))*(apx(i,j,k) - apx(i+1,j,k))
477 + (apy(i,j,k) - apy(i,j+1,k))*(apy(i,j,k) - apy(i,j+1,k)));
479 Real anorminv = Real(1.0)/anorm;
480 Real anrmx = (apx(i,j,k) - apx(i+1,j,k))*anorminv;
481 Real anrmy = (apy(i,j,k) - apy(i,j+1,k))*anorminv;
482 Real sx = std::copysign(Real(1.0),anrmx);
483 Real sy = std::copysign(Real(1.0),anrmy);
484 Real bctx = bcen(i,j,k,0);
485 Real bcty = bcen(i,j,k,1);
487 Real gx = bctx - dg*anrmx;
488 Real gy = bcty - dg*anrmy;
489 int ioff = -
static_cast<int>(sx);
490 int joff = -
static_cast<int>(sy);
491 Array1D<Real,0,3> phig1{Real(1.0) + gx*sx + gy*sy + gx*gy*sx*sy,
492 - gx*sx - gx*gy*sx*sy,
493 - gy*sy - gx*gy*sx*sy,
496 Array1D<Real,0,3> feb;
497 for (
int ii=0; ii<4; ii++){
498 feb(ii) = -phig1(ii) * (ba(i,j,k) * beb(i,j,k) / dg);
500 mat_tmp(0 , 0 ) -= feb(0)*fac[0];
501 mat_tmp(ioff, 0 ) -= feb(1)*fac[0];
502 mat_tmp(0 ,joff) -= feb(2)*fac[0];
503 mat_tmp(ioff,joff) -= feb(3)*fac[0];
506 for (
int jj=-1; jj<=1; jj++) {
507 for (
int ii=-1; ii<=1; ii++) {
508 mat_tmp(ii,jj) *= Real(1.0)/vfrc(i,j,k);
511 if (sa != Real(0.0)) {
512 mat_tmp(0,0) += sa*a(i,j,k);
517 for (
int jj=-1; jj<=1; jj++) {
518 for (
int ii=-1; ii<=1; ii++) {
519 mat_tmp(ii,jj) = Real(0.0);
521 mat_tmp(0,0) = Real(1.0);
524 diaginv(i,j,k) = Real(1.0) / mat_tmp(0,0);
525 for (
int jj=-1; jj<=1; jj++) {
526 for (
int ii=-1; ii<=1; ii++) {
527 mat_tmp(ii,jj) *= diaginv(i,j,k);
529 mat_tmp(0,0) = Real(1.0);
532 for (
int m = 0; m < 9; ++m) {
533 ncols(i,j,k) += (sten[m] != Real(0.0));
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
Encapsulation of the Orientation of the Faces of a Box.
Definition: AMReX_Orientation.H:29
@ low
Definition: AMReX_Orientation.H:34
@ high
Definition: AMReX_Orientation.H:34
static int f(amrex::Real t, N_Vector y_data, N_Vector y_rhs, void *user_data)
Definition: AMReX_SundialsIntegrator.H:44
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void comp_bf(Real &bf1, Real &bf2, Real sb, Real h, int bct, Real bcl, int bho)
Definition: AMReX_Habec_K.H:11
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void comp_bflo(Real &bf1, Real &bf2, Real &bflo, Real sb, Real h, int bct, Real bcl, int bho)
Definition: AMReX_Habec_K.H:34
Definition: AMReX_Amr.cpp:49
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void habec_ijmat(GpuArray< Real, 2 *AMREX_SPACEDIM+1 > &sten, Array4< Int > const &ncols, Array4< Real > const &diaginv, int i, int j, int k, Array4< Int const > const &cell_id, Real sa, Array4< Real const > const &a, Real sb, GpuArray< Real, AMREX_SPACEDIM > const &dx, GpuArray< Array4< Real const >, AMREX_SPACEDIM > const &b, GpuArray< int, AMREX_SPACEDIM *2 > const &bctype, GpuArray< Real, AMREX_SPACEDIM *2 > const &bcl, int bho, Array4< int const > const &osm)
Definition: AMReX_Habec_2D_K.H:91
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 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 habec_cols(GpuArray< Int, 2 *AMREX_SPACEDIM+1 > &sten, int i, int j, int, Array4< Int const > const &cell_id)
Definition: AMReX_Habec_2D_K.H:171
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void habec_mat(GpuArray< Real, 2 *AMREX_SPACEDIM+1 > &sten, int i, int j, int k, Dim3 const &boxlo, Dim3 const &boxhi, Real sa, Array4< Real const > const &a, Real sb, GpuArray< Real, AMREX_SPACEDIM > const &dx, GpuArray< Array4< Real const >, AMREX_SPACEDIM > const &b, GpuArray< int, AMREX_SPACEDIM *2 > const &bctype, GpuArray< Real, AMREX_SPACEDIM *2 > const &bcl, int bho, GpuArray< Array4< int const >, AMREX_SPACEDIM *2 > const &msk, Array4< Real > const &diaginv)
Definition: AMReX_Habec_2D_K.H:15
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
Return the square root of a complex number.
Definition: AMReX_GpuComplex.H:373
Definition: AMReX_Array4.H:61
Definition: AMReX_Dim3.H:12
int x
Definition: AMReX_Dim3.H:12
int y
Definition: AMReX_Dim3.H:12
Definition: AMReX_Array.H:34