1 #ifndef AMREX_HABEC_3D_H_
2 #define AMREX_HABEC_3D_H_
3 #include <AMReX_Config.H>
15 void habec_mat (GpuArray<Real,2*AMREX_SPACEDIM+1>& sten,
int i,
int j,
int k,
16 Dim3
const& boxlo, Dim3
const& boxhi,
17 Real sa, Array4<Real const>
const& a,
18 Real sb, GpuArray<Real,AMREX_SPACEDIM>
const& dx,
19 GpuArray<Array4<Real const>, AMREX_SPACEDIM>
const& b,
20 GpuArray<int,AMREX_SPACEDIM*2>
const& bctype,
21 GpuArray<Real,AMREX_SPACEDIM*2>
const& bcl,
int bho,
22 GpuArray<Array4<int const>, AMREX_SPACEDIM*2>
const& msk,
23 Array4<Real>
const& diaginv)
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[5] = -(sb / (dx[2]*dx[2])) *
b[2](i,j,k);
30 sten[6] = -(sb / (dx[2]*dx[2])) *
b[2](i,j,k+1);
31 sten[0] = -(sten[1] + sten[2] + sten[3] + sten[4] + sten[5] + sten[6]);
32 if (sa != Real(0.0)) {
33 sten[0] += sa * a(i,j,k);
39 if (msk[cdir](i-1,j,k) > 0) {
42 sten[0] += bf1 *
b[0](i,j,k);
44 sten[2] += bf2 *
b[0](i,j,k);
51 if (msk[cdir](i+1,j,k) > 0) {
54 sten[0] += bf1 *
b[0](i+1,j,k);
55 sten[1] += bf2 *
b[0](i+1,j,k);
63 if (msk[cdir](i,j-1,k) > 0) {
66 sten[0] += bf1 *
b[1](i,j,k);
68 sten[4] += bf2 *
b[1](i,j,k);
75 if (msk[cdir](i,j+1,k) > 0) {
78 sten[0] += bf1 *
b[1](i,j+1,k);
79 sten[3] += bf2 *
b[1](i,j+1,k);
87 if (msk[cdir](i,j,k-1) > 0) {
90 sten[0] += bf1 *
b[2](i,j,k);
92 sten[6] += bf2 *
b[2](i,j,k);
99 if (msk[cdir](i,j,k+1) > 0) {
102 sten[0] += bf1 *
b[2](i,j,k+1);
103 sten[5] += bf2 *
b[2](i,j,k+1);
108 diaginv(i,j,k) = Real(1.0) / sten[0];
110 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
111 sten[m] *= diaginv(i,j,k);
115 template <
typename Int>
117 void habec_ijmat (GpuArray<Real,2*AMREX_SPACEDIM+1>& sten, Array4<Int>
const& ncols,
118 Array4<Real>
const& diaginv,
int i,
int j,
int k,
119 Array4<Int const>
const& cell_id,
120 Real sa, Array4<Real const>
const& a,
121 Real sb, GpuArray<Real,AMREX_SPACEDIM>
const& dx,
122 GpuArray<Array4<Real const>, AMREX_SPACEDIM>
const& b,
123 GpuArray<int,AMREX_SPACEDIM*2>
const& bctype,
124 GpuArray<Real,AMREX_SPACEDIM*2>
const& bcl,
int bho,
125 Array4<int const>
const& osm)
127 if (!osm || osm(i,j,k) != 0) {
128 sten[1] = -(sb / (dx[0]*dx[0])) *
b[0](i,j,k);
129 sten[2] = -(sb / (dx[0]*dx[0])) *
b[0](i+1,j,k);
130 sten[3] = -(sb / (dx[1]*dx[1])) *
b[1](i,j,k);
131 sten[4] = -(sb / (dx[1]*dx[1])) *
b[1](i,j+1,k);
132 sten[5] = -(sb / (dx[2]*dx[2])) *
b[2](i,j,k);
133 sten[6] = -(sb / (dx[2]*dx[2])) *
b[2](i,j,k+1);
134 sten[0] = -(sten[1] + sten[2] + sten[3] + sten[4] + sten[5] + sten[6]);
135 if (sa != Real(0.0)) {
136 sten[0] += sa * a(i,j,k);
140 if (cell_id(i-1,j,k) < 0) {
144 sten[0] += bf1 *
b[0](i,j,k);
146 sten[2] += bf2 *
b[0](i,j,k);
150 if (cell_id(i+1,j,k) < 0) {
154 sten[0] += bf1 *
b[0](i+1,j,k);
155 sten[1] += bf2 *
b[0](i+1,j,k);
160 if (cell_id(i,j-1,k) < 0) {
164 sten[0] += bf1 *
b[1](i,j,k);
166 sten[4] += bf2 *
b[1](i,j,k);
170 if (cell_id(i,j+1,k) < 0) {
174 sten[0] += bf1 *
b[1](i,j+1,k);
175 sten[3] += bf2 *
b[1](i,j+1,k);
180 if (cell_id(i,j,k-1) < 0) {
184 sten[0] += bf1 *
b[2](i,j,k);
186 sten[6] += bf2 *
b[2](i,j,k);
190 if (cell_id(i,j,k+1) < 0) {
194 sten[0] += bf1 *
b[2](i,j,k+1);
195 sten[5] += bf2 *
b[2](i,j,k+1);
200 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
205 diaginv(i,j,k) = Real(1.0) / sten[0];
207 for (
int m = 1; m < 2*AMREX_SPACEDIM+1; ++m) {
208 sten[m] *= diaginv(i,j,k);
212 for (
int m = 0; m < 2*AMREX_SPACEDIM+1; ++m) {
213 ncols(i,j,k) += (sten[m] != Real(0.0));
217 template <
typename Int>
219 void habec_cols (GpuArray<Int,2*AMREX_SPACEDIM+1>& sten,
int i,
int j,
int k,
220 Array4<Int const>
const& cell_id)
222 sten[0] = cell_id(i ,j ,k );
223 sten[1] = cell_id(i-1,j ,k );
224 sten[2] = cell_id(i+1,j ,k );
225 sten[3] = cell_id(i ,j-1,k );
226 sten[4] = cell_id(i ,j+1,k );
227 sten[5] = cell_id(i ,j ,k-1);
228 sten[6] = cell_id(i ,j ,k+1);
233 template <
typename Int>
235 void habec_cols_eb (GpuArray<Int,27>& sten,
int i,
int j,
int k,
236 Array4<Int const>
const& cell_id)
238 sten[0 ] = cell_id(i-1,j-1,k-1);
239 sten[1 ] = cell_id(i ,j-1,k-1);
240 sten[2 ] = cell_id(i+1,j-1,k-1);
241 sten[3 ] = cell_id(i-1,j ,k-1);
242 sten[4 ] = cell_id(i ,j ,k-1);
243 sten[5 ] = cell_id(i+1,j ,k-1);
244 sten[6 ] = cell_id(i-1,j+1,k-1);
245 sten[7 ] = cell_id(i ,j+1,k-1);
246 sten[8 ] = cell_id(i+1,j+1,k-1);
247 sten[9 ] = cell_id(i-1,j-1,k );
248 sten[10] = cell_id(i ,j-1,k );
249 sten[11] = cell_id(i+1,j-1,k );
250 sten[12] = cell_id(i-1,j ,k );
251 sten[13] = cell_id(i ,j ,k );
252 sten[14] = cell_id(i+1,j ,k );
253 sten[15] = cell_id(i-1,j+1,k );
254 sten[16] = cell_id(i ,j+1,k );
255 sten[17] = cell_id(i+1,j+1,k );
256 sten[18] = cell_id(i-1,j-1,k+1);
257 sten[19] = cell_id(i ,j-1,k+1);
258 sten[20] = cell_id(i+1,j-1,k+1);
259 sten[21] = cell_id(i-1,j ,k+1);
260 sten[22] = cell_id(i ,j ,k+1);
261 sten[23] = cell_id(i+1,j ,k+1);
262 sten[24] = cell_id(i-1,j+1,k+1);
263 sten[25] = cell_id(i ,j+1,k+1);
264 sten[26] = cell_id(i+1,j+1,k+1);
267 template <
typename Int>
269 void habec_ijmat_eb (GpuArray<Real,27>& sten, Array4<Int>
const& ncols,
270 Array4<Real>
const& diaginv,
int i,
int j,
int k,
271 Array4<Int const>
const& cell_id,
272 Real sa, Array4<Real const>
const& a,
273 Real sb, GpuArray<Real,AMREX_SPACEDIM>
const& dx,
274 GpuArray<Array4<Real const>, AMREX_SPACEDIM>
const& b,
275 GpuArray<int,AMREX_SPACEDIM*2>
const& bctype,
276 GpuArray<Real,AMREX_SPACEDIM*2>
const& bcl,
int bho,
277 Array4<const EBCellFlag>
const& flag,
278 Array4<Real const>
const& vfrc,
279 Array4<Real const>
const& apx,
280 Array4<Real const>
const& apy,
281 Array4<Real const>
const& apz,
282 Array4<Real const>
const& fcx,
283 Array4<Real const>
const& fcy,
284 Array4<Real const>
const& fcz,
285 Array4<Real const>
const& ba,
286 Array4<Real const>
const& bcen,
287 Array4<Real const>
const& beb)
289 for (
int m = 0; m < 27; ++m) {
293 auto& mat_tmp =
reinterpret_cast<Array3D<Real,-1,1,-1,1,-1,1
>&>(sten);
295 GpuArray<Real,AMREX_SPACEDIM> fac{sb/(dx[0]*dx[0]), sb/(dx[1]*dx[1]), sb/(dx[2]*dx[2])};
297 if (flag(i,j,k).isRegular())
299 mat_tmp(0,0,0) = fac[0]*(
b[0](i,j,k)+b[0](i+1,j,k))
300 + fac[1]*(b[1](i,j,k)+
b[1](i,j+1,k))
301 + fac[2]*(
b[2](i,j,k)+b[2](i,j,k+1));
302 mat_tmp(-1, 0, 0) = -fac[0]*
b[0](i,j,k);
303 mat_tmp( 1, 0, 0) = -fac[0]*
b[0](i+1,j,k);
304 mat_tmp( 0,-1, 0) = -fac[1]*
b[1](i,j,k);
305 mat_tmp( 0, 1, 0) = -fac[1]*
b[1](i,j+1,k);
306 mat_tmp( 0, 0,-1) = -fac[2]*
b[2](i,j,k);
307 mat_tmp( 0, 0, 1) = -fac[2]*
b[2](i,j,k+1);
309 if (cell_id(i-1,j,k) < 0) {
313 mat_tmp(0,0,0) += bf1*
b[0](i,j,k);
314 mat_tmp(-1,0,0) = Real(0.0);
315 mat_tmp(1,0,0) += bf2*
b[0](i,j,k);
318 if (cell_id(i+1,j,k) < 0) {
322 mat_tmp(0,0,0) += bf1*
b[0](i+1,j,k);
323 mat_tmp(1,0,0) = Real(0.0);
324 mat_tmp(-1,0,0) += bf2*
b[0](i+1,j,k);
327 if (cell_id(i,j-1,k) < 0) {
331 mat_tmp(0,0,0) += bf1*
b[1](i,j,k);
332 mat_tmp(0,-1,0) = Real(0.0);
333 mat_tmp(0,1,0) += bf2*
b[1](i,j,k);
336 if (cell_id(i,j+1,k) < 0) {
340 mat_tmp(0,0,0) += bf1*
b[1](i,j+1,k);
341 mat_tmp(0,1,0) = Real(0.0);
342 mat_tmp(0,-1,0) += bf2*
b[1](i,j+1,k);
345 if (cell_id(i,j,k-1) < 0) {
349 mat_tmp(0,0,0) += bf1*
b[2](i,j,k);
350 mat_tmp(0,0,-1) = Real(0.0);
351 mat_tmp(0,0,1) += bf2*
b[2](i,j,k);
354 if (cell_id(i,j,k+1) < 0) {
358 mat_tmp(0,0,0) += bf1*
b[2](i,j,k+1);
359 mat_tmp(0,0,1) = Real(0.0);
360 mat_tmp(0,0,-1) += bf2*
b[2](i,j,k+1);
363 if (sa != Real(0.0)) {
364 mat_tmp(0,0,0) += sa*a(i,j,k);
367 else if (flag(i,j,k).isSingleValued())
370 Real area = apx(i,j,k);
372 if (area > Real(0.0))
374 int joff, koff, jj, kk;
378 if (area != Real(1.0)) {
379 joff =
static_cast<int>(std::copysign(Real(1.0), fcx(i,j,k,0)));
380 koff =
static_cast<int>(std::copysign(Real(1.0), fcx(i,j,k,1)));
383 if (cell_id(i-1,jj,k) < 0 && cell_id(i,jj,k) < 0) {
388 if (cell_id(i-1,j,kk) < 0 && cell_id(i,j,kk) < 0) {
393 if (cell_id(i-1,jj,kk) < 0 && cell_id(i,jj,kk) < 0 && (fracy*fracz) > Real(0.0)) {
409 Real tmp = (Real(1.0)-fracy)*(1.0-fracz)*area*
b[0](i,j,k);
411 if (cell_id(i-1,j,k) >= 0) {
412 mat_tmp( 0,0,0) += tmp*
f;
413 mat_tmp(-1,0,0) -= tmp*
f;
414 }
else if (cell_id(i+1,j,k) < 0 || apx(i+1,j,k) == Real(0.0)) {
415 mat_tmp(0,0,0) += tmp*(
f+bflo);
417 mat_tmp(0,0,0) += tmp*(
f+bf1);
418 mat_tmp(1,0,0) += tmp* bf2;
421 if (fracy > Real(0.0)) {
422 tmp = fracy*(Real(1.0)-fracz)*area*b[0](i,jj,k);
423 if (cell_id(i-1,jj,k) >= 0 && cell_id(i,jj,k) >= 0) {
424 mat_tmp(-1,joff,0) -= tmp*
f;
425 mat_tmp( 0,joff,0) += tmp*
f;
426 }
else if (cell_id(i+1,jj,k) < 0 || apx(i+1,jj,k) == Real(0.0)) {
427 mat_tmp( 0,joff,0) += tmp*(
f+bflo);
429 mat_tmp( 0,joff,0) += tmp*(
f+bf1);
430 mat_tmp( 1,joff,0) += tmp* bf2;
434 if (fracz > Real(0.0)) {
435 tmp = fracz*(Real(1.0)-fracy)*area*b[0](i,j,kk);
436 if (cell_id(i-1,j,kk) >= 0 && cell_id(i,j,kk) >= 0) {
437 mat_tmp(-1,0,koff) -= tmp*
f;
438 mat_tmp( 0,0,koff) += tmp*
f;
439 }
else if (cell_id(i+1,j,kk) < 0 || apx(i+1,j,kk) == Real(0.0)) {
440 mat_tmp( 0,0,koff) += tmp*(
f+bflo);
442 mat_tmp( 0,0,koff) += tmp*(
f+bf1);
443 mat_tmp( 1,0,koff) += tmp* bf2;
447 if (fracy > Real(0.0) && fracz > Real(0.0)) {
448 tmp = fracy*fracz*area*
b[0](i,jj,kk);
449 if (cell_id(i-1,jj,kk) >= 0 && cell_id(i,jj,kk) >= 0) {
450 mat_tmp(-1,joff,koff) -= tmp*
f;
451 mat_tmp( 0,joff,koff) += tmp*
f;
452 }
else if (cell_id(i+1,jj,kk) < 0 || apx(i+1,jj,kk) == Real(0.0)) {
453 mat_tmp( 0,joff,koff) += tmp*(
f+bflo);
455 mat_tmp( 0,joff,koff) += tmp*(
f+bf1);
456 mat_tmp( 1,joff,koff) += tmp* bf2;
464 if (area > Real(0.0))
466 int joff, koff, jj, kk;
470 if (area != Real(1.0)) {
471 joff =
static_cast<int>(std::copysign(Real(1.0), fcx(i+1,j,k,0)));
472 koff =
static_cast<int>(std::copysign(Real(1.0), fcx(i+1,j,k,1)));
475 if (cell_id(i,jj,k) < 0 && cell_id(i+1,jj,k) < 0) {
480 if (cell_id(i,j,kk) < 0 && cell_id(i+1,j,kk) < 0) {
485 if (cell_id(i,jj,kk) < 0 && cell_id(i+1,jj,kk) < 0 && (fracy*fracz) > Real(0.0)) {
501 Real tmp = (Real(1.0)-fracy)*(Real(1.0)-fracz)*area*b[0](i+1,j,k);
502 if (cell_id(i+1,j,k) >= 0) {
503 mat_tmp(0,0,0) += tmp*
f;
504 mat_tmp(1,0,0) -= tmp*
f;
505 }
else if (cell_id(i-1,j,k) < 0 || apx(i-1,j,k) == Real(0.0)) {
506 mat_tmp(0,0,0) += tmp*(
f+bflo);
508 mat_tmp( 0,0,0) += tmp*(
f+bf1);
509 mat_tmp(-1,0,0) += tmp* bf2;
512 if (fracy > Real(0.0)) {
513 tmp = fracy*(Real(1.0)-fracz)*area*b[0](i+1,jj,k);
514 if (cell_id(i,jj,k) >= 0 && cell_id(i+1,jj,k) >= 0) {
515 mat_tmp(0,joff,0) += tmp*
f;
516 mat_tmp(1,joff,0) -= tmp*
f;
517 }
else if (cell_id(i-1,jj,k) < 0 || apx(i-1,jj,k) == Real(0.0)) {
518 mat_tmp(0,joff,0) += tmp*(
f+bflo);
520 mat_tmp( 0,joff,0) += tmp*(
f+bf1);
521 mat_tmp(-1,joff,0) += tmp* bf2;
525 if (fracz > Real(0.0)) {
526 tmp = fracz*(Real(1.0)-fracy)*area*b[0](i+1,j,kk);
527 if (cell_id(i,j,kk) >= 0 && cell_id(i+1,j,kk) >= 0) {
528 mat_tmp(0,0,koff) += tmp*
f;
529 mat_tmp(1,0,koff) -= tmp*
f;
530 }
else if (cell_id(i-1,j,kk) < 0 || apx(i-1,j,kk) == Real(0.0)) {
531 mat_tmp(0,0,koff) += tmp*(
f+bflo);
533 mat_tmp( 0,0,koff) += tmp*(
f+bf1);
534 mat_tmp(-1,0,koff) += tmp* bf2;
538 if (fracy > Real(0.0) && fracz > Real(0.0)) {
539 tmp = fracy*fracz*area*
b[0](i+1,jj,kk);
540 if (cell_id(i,jj,kk) >= 0 && cell_id(i+1,jj,kk) >= 0) {
541 mat_tmp(0,joff,koff) += tmp*
f;
542 mat_tmp(1,joff,koff) -= tmp*
f;
543 }
else if (cell_id(i-1,jj,kk) < 0 || apx(i-1,jj,kk) == Real(0.0)) {
544 mat_tmp(0,joff,koff) += tmp*(
f+bflo);
546 mat_tmp( 0,joff,koff) += tmp*(
f+bf1);
547 mat_tmp(-1,joff,koff) += tmp* bf2;
555 if (area > Real(0.0))
557 int ioff, koff, ii, kk;
561 if (area != Real(1.0)) {
562 ioff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j,k,0)));
563 koff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j,k,1)));
566 if (cell_id(ii,j-1,k) < 0 && cell_id(ii,j,k) < 0) {
571 if (cell_id(i,j-1,kk) < 0 && cell_id(i,j,kk) < 0) {
576 if (cell_id(ii,j-1,kk) < 0 && cell_id(ii,j,kk) < 0 && fracx*fracz > Real(0.0)) {
592 Real tmp = (Real(1.0)-fracx)*(Real(1.0)-fracz)*area*b[1](i,j,k);
593 if (cell_id(i,j-1,k) >= 0) {
594 mat_tmp(0, 0,0) += tmp*
f;
595 mat_tmp(0,-1,0) -= tmp*
f;
596 }
else if (cell_id(i,j+1,k) < 0 || apy(i,j+1,k) == Real(0.0)) {
597 mat_tmp(0,0,0) += tmp*(
f+bflo);
599 mat_tmp(0,0,0) += tmp*(
f+bf1);
600 mat_tmp(0,1,0) += tmp* bf2;
603 if (fracx > Real(0.0)) {
604 tmp = fracx*(Real(1.0)-fracz)*area*b[1](ii,j,k);
605 if (cell_id(ii,j-1,k) >= 0 && cell_id(ii,j,k) >= 0) {
606 mat_tmp(ioff,-1,0) -= tmp*
f;
607 mat_tmp(ioff, 0,0) += tmp*
f;
608 }
else if (cell_id(ii,j+1,k) < 0 || apy(ii,j+1,k) == Real(0.0)) {
609 mat_tmp(ioff,0,0) += tmp*(
f+bflo);
611 mat_tmp(ioff,0,0) += tmp*(
f+bf1);
612 mat_tmp(ioff,1,0) += tmp* bf2;
616 if (fracz > Real(0.0)) {
617 tmp = fracz*(Real(1.0)-fracx)*area*b[1](i,j,kk);
618 if (cell_id(i,j-1,kk) >= 0 && cell_id(i,j,kk) >= 0) {
619 mat_tmp(0,-1,koff) -= tmp*
f;
620 mat_tmp(0, 0,koff) += tmp*
f;
621 }
else if (cell_id(i,j+1,kk) < 0 || apy(i,j+1,kk) == Real(0.0)) {
622 mat_tmp(0,0,koff) += tmp*(
f+bflo);
624 mat_tmp(0,0,koff) += tmp*(
f+bf1);
625 mat_tmp(0,1,koff) += tmp* bf2;
629 if (fracx > Real(0.0) && fracz > Real(0.0)) {
630 tmp = fracx*fracz*area*
b[1](ii,j,kk);
631 if (cell_id(ii,j-1,kk) >= 0 && cell_id(ii,j,kk) >= 0) {
632 mat_tmp(ioff,-1,koff) -= tmp*
f;
633 mat_tmp(ioff, 0,koff) += tmp*
f;
634 }
else if (cell_id(ii,j+1,kk) < 0 || apy(ii,j+1,kk) == Real(0.0)) {
635 mat_tmp(ioff,0,koff) += tmp*(
f+bflo);
637 mat_tmp(ioff,0,koff) += tmp*(
f+bf1);
638 mat_tmp(ioff,1,koff) += tmp* bf2;
646 if (area > Real(0.0))
648 int ioff, koff, ii, kk;
652 if (area != Real(1.0)) {
653 ioff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j+1,k,0)));
654 koff =
static_cast<int>(std::copysign(Real(1.0), fcy(i,j+1,k,1)));
657 if (cell_id(ii,j,k) < 0 && cell_id(ii,j+1,k) < 0) {
662 if (cell_id(i,j,kk) < 0 && cell_id(i,j+1,kk) < 0) {
667 if (cell_id(ii,j,kk) < 0 && cell_id(ii,j+1,kk) < 0 && fracx*fracz > Real(0.0)) {
683 Real tmp = (Real(1.0)-fracx)*(Real(1.0)-fracz)*area*b[1](i,j+1,k);
684 if (cell_id(i,j+1,k) >= 0) {
685 mat_tmp(0,0,0) += tmp*
f;
686 mat_tmp(0,1,0) -= tmp*
f;
687 }
else if (cell_id(i,j-1,k) < 0 || apy(i,j-1,k) == Real(0.0)) {
688 mat_tmp(0,0,0) += tmp*(
f+bflo);
690 mat_tmp(0, 0,0) += tmp*(
f+bf1);
691 mat_tmp(0,-1,0) += tmp* bf2;
694 if (fracx > Real(0.0)) {
695 tmp = fracx*(Real(1.0)-fracz)*area*b[1](ii,j+1,k);
696 if (cell_id(ii,j,k) >= 0 && cell_id(ii,j+1,k) >= 0) {
697 mat_tmp(ioff,0,0) += tmp*
f;
698 mat_tmp(ioff,1,0) -= tmp*
f;
699 }
else if (cell_id(ii,j-1,k) < 0 || apy(ii,j-1,k) == Real(0.0)) {
700 mat_tmp(ioff,0,0) += tmp*(
f+bflo);
702 mat_tmp(ioff, 0,0) += tmp*(
f+bf1);
703 mat_tmp(ioff,-1,0) += tmp* bf2;
707 if (fracz > Real(0.0)) {
708 tmp = fracz*(Real(1.0)-fracx)*area*b[1](i,j+1,kk);
709 if (cell_id(i,j,kk) >= 0 && cell_id(i,j+1,kk) >= 0) {
710 mat_tmp(0,0,koff) += tmp*
f;
711 mat_tmp(0,1,koff) -= tmp*
f;
712 }
else if (cell_id(i,j-1,kk) < 0 || apy(i,j-1,kk) == Real(0.0)) {
713 mat_tmp(0,0,koff) += tmp*(
f+bflo);
715 mat_tmp(0, 0,koff) += tmp*(
f+bf1);
716 mat_tmp(0,-1,koff) += tmp* bf2;
720 if (fracx > Real(0.0) && fracz > Real(0.0)) {
721 tmp = fracx*fracz*area*
b[1](ii,j+1,kk);
722 if (cell_id(ii,j,kk) >= 0 && cell_id(ii,j+1,kk) >= 0) {
723 mat_tmp(ioff,1,koff) -= tmp*
f;
724 mat_tmp(ioff,0,koff) += tmp*
f;
725 }
else if (cell_id(ii,j-1,kk) < 0 || apy(ii,j-1,kk) == Real(0.0)) {
726 mat_tmp(ioff,0,koff) += tmp*(
f+bflo);
728 mat_tmp(ioff, 0,koff) += tmp*(
f+bf1);
729 mat_tmp(ioff,-1,koff) += tmp* bf2;
737 if (area > Real(0.0))
739 int ioff, joff, ii, jj;
743 if (area != Real(1.0)) {
744 ioff =
static_cast<int>(std::copysign(Real(1.0), fcz(i,j,k,0)));
745 joff =
static_cast<int>(std::copysign(Real(1.0), fcz(i,j,k,1)));
748 if (cell_id(ii,j,k-1) < 0 && cell_id(ii,j,k) < 0) {
753 if (cell_id(i,jj,k-1) < 0 && cell_id(i,jj,k) < 0) {
758 if (cell_id(ii,jj,k-1) < 0 && cell_id(ii,jj,k) < 0 && fracx*fracy > Real(0.0)) {
774 Real tmp = (Real(1.0)-fracx)*(Real(1.0)-fracy)*area*b[2](i,j,k);
775 if (cell_id(i,j,k-1) >= 0) {
776 mat_tmp(0,0, 0) += tmp*
f;
777 mat_tmp(0,0,-1) -= tmp*
f;
778 }
else if (cell_id(i,j,k+1) < 0 || apz(i,j,k+1) == Real(0.0)) {
779 mat_tmp(0,0,0) += tmp*(
f+bflo);
781 mat_tmp(0,0,0) += tmp*(
f+bf1);
782 mat_tmp(0,0,1) += tmp* bf2;
785 if (fracx > Real(0.0)) {
786 tmp = fracx*(Real(1.0)-fracy)*area*b[2](ii,j,k);
787 if (cell_id(ii,j,k-1) >= 0 && cell_id(ii,j,k) >= 0) {
788 mat_tmp(ioff,0,-1) -= tmp*
f;
789 mat_tmp(ioff,0, 0) += tmp*
f;
790 }
else if (cell_id(ii,j,k+1) < 0 || apz(ii,j,k+1) == Real(0.0)) {
791 mat_tmp(ioff,0,0) += tmp*(
f+bflo);
793 mat_tmp(ioff,0,0) += tmp*(
f+bf1);
794 mat_tmp(ioff,0,1) += tmp* bf2;
798 if (fracy > Real(0.0)) {
799 tmp = fracy*(Real(1.0)-fracx)*area*b[2](i,jj,k);
800 if (cell_id(i,jj,k-1) >= 0 && cell_id(i,jj,k) >= 0) {
801 mat_tmp(0,joff,-1) -= tmp*
f;
802 mat_tmp(0,joff, 0) += tmp*
f;
803 }
else if (cell_id(i,jj,k+1) < 0 || apz(i,jj,k+1) == Real(0.0)) {
804 mat_tmp(0,joff,0) += tmp*(
f+bflo);
806 mat_tmp(0,joff,0) += tmp*(
f+bf1);
807 mat_tmp(0,joff,1) += tmp* bf2;
811 if (fracx > Real(0.0) && fracy > Real(0.0)) {
812 tmp = fracx*fracy*area*
b[2](ii,jj,k);
813 if (cell_id(ii,jj,k-1) >= 0 && cell_id(ii,jj,k) >= 0) {
814 mat_tmp(ioff,joff,-1) -= tmp*
f;
815 mat_tmp(ioff,joff, 0) += tmp*
f;
816 }
else if (cell_id(ii,jj,k+1) < 0 || apz(ii,jj,k+1) == Real(0.0)) {
817 mat_tmp(ioff,joff,0) += tmp*(
f+bflo);
819 mat_tmp(ioff,joff,0) += tmp*(
f+bf1);
820 mat_tmp(ioff,joff,1) += tmp* bf2;
828 if (area > Real(0.0))
830 int ioff, joff, ii, jj;
834 if (area != Real(1.0)) {
835 ioff =
static_cast<int>(std::copysign(Real(1.0), fcz(i,j,k+1,0)));
836 joff =
static_cast<int>(std::copysign(Real(1.0), fcz(i,j,k+1,1)));
839 if (cell_id(ii,j,k) < 0 && cell_id(ii,j,k+1) < 0) {
844 if (cell_id(i,jj,k) < 0 && cell_id(i,jj,k+1) < 0) {
849 if (cell_id(ii,jj,k) < 0 && cell_id(ii,jj,k+1) < 0 && fracx*fracy > Real(0.0)) {
865 Real tmp = (Real(1.0)-fracx)*(Real(1.0)-fracy)*area*b[2](i,j,k+1);
866 if (cell_id(i,j,k+1) >= 0) {
867 mat_tmp(0,0,0) += tmp*
f;
868 mat_tmp(0,0,1) -= tmp*
f;
869 }
else if (cell_id(i,j,k-1) < 0 || apz(i,j,k-1) == Real(0.0)) {
870 mat_tmp(0,0,0) += tmp*(
f+bflo);
872 mat_tmp(0,0, 0) += tmp*(
f+bf1);
873 mat_tmp(0,0,-1) += tmp* bf2;
876 if (fracx > Real(0.0)) {
877 tmp = fracx*(Real(1.0)-fracy)*area*b[2](ii,j,k+1);
878 if (cell_id(ii,j,k) >= 0 && cell_id(ii,j,k+1) >= 0) {
879 mat_tmp(ioff,0,0) += tmp*
f;
880 mat_tmp(ioff,0,1) -= tmp*
f;
881 }
else if (cell_id(ii,j,k-1) < 0 || apz(ii,j,k-1) == Real(0.0)) {
882 mat_tmp(ioff,0,0) += tmp*(
f+bflo);
884 mat_tmp(ioff,0, 0) += tmp*(
f+bf1);
885 mat_tmp(ioff,0,-1) += tmp* bf2;
889 if (fracy > Real(0.0)) {
890 tmp = fracy*(Real(1.0)-fracx)*area*b[2](i,jj,k+1);
891 if (cell_id(i,jj,k) >= 0 && cell_id(i,jj,k+1) >= 0) {
892 mat_tmp(0,joff,0) += tmp*
f;
893 mat_tmp(0,joff,1) -= tmp*
f;
894 }
else if (cell_id(i,jj,k-1) < 0 || apz(i,jj,k-1) == Real(0.0)) {
895 mat_tmp(0,joff,0) += tmp*(
f+bflo);
897 mat_tmp(0,joff, 0) += tmp*(
f+bf1);
898 mat_tmp(0,joff,-1) += tmp* bf2;
902 if (fracx > Real(0.0) && fracy > Real(0.0)) {
903 tmp = fracx*fracy*area*
b[2](ii,jj,k+1);
904 if (cell_id(ii,jj,k+1) >= 0 && cell_id(ii,jj,k) >= 0) {
905 mat_tmp(ioff,joff,1) -= tmp*
f;
906 mat_tmp(ioff,joff,0) += tmp*
f;
907 }
else if (cell_id(ii,jj,k-1) < 0 || apz(ii,jj,k-1) == Real(0.0)) {
908 mat_tmp(ioff,joff,0) += tmp*(
f+bflo);
910 mat_tmp(ioff,joff, 0) += tmp*(
f+bf1);
911 mat_tmp(ioff,joff,-1) += tmp* bf2;
917 Real anorm =
std::sqrt((apx(i,j,k) - apx(i+1,j,k))*(apx(i,j,k) - apx(i+1,j,k))
918 + (apy(i,j,k) - apy(i,j+1,k))*(apy(i,j,k) - apy(i,j+1,k))
919 + (apz(i,j,k) - apz(i,j,k+1))*(apz(i,j,k) - apz(i,j,k+1)));
921 Real anorminv = Real(1.0)/anorm;
922 Real anrmx = (apx(i,j,k) - apx(i+1,j,k))*anorminv;
923 Real anrmy = (apy(i,j,k) - apy(i,j+1,k))*anorminv;
924 Real anrmz = (apz(i,j,k) - apz(i,j,k+1))*anorminv;
925 Real sx = std::copysign(Real(1.0),anrmx);
926 Real sy = std::copysign(Real(1.0),anrmy);
927 Real sz = std::copysign(Real(1.0),anrmz);
928 Real bctx = bcen(i,j,k,0);
929 Real bcty = bcen(i,j,k,1);
930 Real bctz = bcen(i,j,k,2);
932 Real gx = bctx - dg*anrmx;
933 Real gy = bcty - dg*anrmy;
934 Real gz = bctz - dg*anrmz;
935 int ioff = -
static_cast<int>(sx);
936 int joff = -
static_cast<int>(sy);
937 int koff = -
static_cast<int>(sz);
944 Real gxyz = gx*gy*gz;
945 Array1D<Real,0,7> phig1{Real(1.0) + gx + gy + gz + gxy + gxz + gyz + gxyz,
946 - gx - gxy - gxz - gxyz,
947 - gy - gxy - gyz - gxyz,
948 - gz - gxz - gyz - gxyz,
953 Array1D<Real,0,7> feb;
954 for (
int ii=0; ii<8; ii++) {
955 feb(ii) = -phig1(ii) * (ba(i,j,k) * beb(i,j,k) / dg);
957 mat_tmp(0 , 0 , 0 ) -= feb(0)*fac[0];
958 mat_tmp(ioff, 0 , 0 ) -= feb(1)*fac[0];
959 mat_tmp(0 ,joff, 0 ) -= feb(2)*fac[0];
960 mat_tmp(0 , 0 ,koff) -= feb(3)*fac[0];
961 mat_tmp(ioff,joff, 0 ) -= feb(4)*fac[0];
962 mat_tmp(ioff, 0 ,koff) -= feb(5)*fac[0];
963 mat_tmp(0 ,joff,koff) -= feb(6)*fac[0];
964 mat_tmp(ioff,joff,koff) -= feb(7)*fac[0];
967 for (
int kk=-1; kk<=1; kk++) {
968 for (
int jj=-1; jj<=1; jj++) {
969 for (
int ii=-1; ii<=1; ii++) {
970 mat_tmp(ii,jj,kk) *= Real(1.0)/vfrc(i,j,k);
973 if (sa != Real(0.0)) {
974 mat_tmp(0,0,0) += sa*a(i,j,k);
979 for (
int kk=-1; kk<=1; kk++) {
980 for (
int jj=-1; jj<=1; jj++) {
981 for (
int ii=-1; ii<=1; ii++) {
982 mat_tmp(ii,jj,kk) = Real(0.0);
984 mat_tmp(0,0,0) = Real(1.0);
987 diaginv(i,j,k) = Real(1.0)/mat_tmp(0,0,0);
988 for (
int kk=-1; kk<=1; kk++) {
989 for (
int jj=-1; jj<=1; jj++) {
990 for (
int ii=-1; ii<=1; ii++) {
991 mat_tmp(ii,jj,kk) *= diaginv(i,j,k);
993 mat_tmp(0,0,0) = Real(1.0);
996 for (
int m = 0; m < 27; ++m) {
997 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
@ 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