From f6917240bc5d26053edb7188ec71e8744ad282bc Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Sun, 17 May 2026 15:51:27 -0700 Subject: [PATCH 01/18] wrap numbers in Real() --- BDS/hydro_bds_edge_state_2D.cpp | 178 ++-- BDS/hydro_bds_edge_state_3D.cpp | 810 +++++++++--------- Diagnostics/Redistribution/CMakeLists.txt | 15 + .../FOR_PAPER/hydro_redistribution.cpp | 407 +++++++++ .../FOR_PAPER/hydro_redistribution.cpp.hack | 466 ++++++++++ Diagnostics/Redistribution/Make.package | 7 + .../hydro_create_itracker_2d.cpp | 223 +++++ .../hydro_create_itracker_3d.cpp | 500 +++++++++++ .../Redistribution/hydro_redistribution.H | 122 +++ .../Redistribution/hydro_redistribution.cpp | 446 ++++++++++ .../Redistribution/hydro_slope_limiter_K.H | 86 ++ .../hydro_state_redistribute.cpp | 324 +++++++ .../Redistribution/hydro_state_utils.cpp | 208 +++++ Diagnostics/hydro_ebgodunov.cpp | 660 ++++++++++++++ Diagnostics/hydro_ebmol.cpp | 613 +++++++++++++ Godunov/hydro_godunov_edge_state_2D.cpp | 66 +- Godunov/hydro_godunov_edge_state_3D.cpp | 150 ++-- .../hydro_godunov_extrap_vel_to_faces_2D.cpp | 78 +- Godunov/hydro_godunov_plm.cpp | 24 +- Godunov/hydro_godunov_ppm.H | 152 ++-- MOL/hydro_mol_edge_state_K.H | 60 +- 21 files changed, 4836 insertions(+), 759 deletions(-) create mode 100644 Diagnostics/Redistribution/CMakeLists.txt create mode 100644 Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp create mode 100644 Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack create mode 100644 Diagnostics/Redistribution/Make.package create mode 100644 Diagnostics/Redistribution/hydro_create_itracker_2d.cpp create mode 100644 Diagnostics/Redistribution/hydro_create_itracker_3d.cpp create mode 100644 Diagnostics/Redistribution/hydro_redistribution.H create mode 100644 Diagnostics/Redistribution/hydro_redistribution.cpp create mode 100644 Diagnostics/Redistribution/hydro_slope_limiter_K.H create mode 100644 Diagnostics/Redistribution/hydro_state_redistribute.cpp create mode 100644 Diagnostics/Redistribution/hydro_state_utils.cpp create mode 100644 Diagnostics/hydro_ebgodunov.cpp create mode 100644 Diagnostics/hydro_ebmol.cpp diff --git a/BDS/hydro_bds_edge_state_2D.cpp b/BDS/hydro_bds_edge_state_2D.cpp index 814803aa2..ecae4fc30 100644 --- a/BDS/hydro_bds_edge_state_2D.cpp +++ b/BDS/hydro_bds_edge_state_2D.cpp @@ -10,7 +10,7 @@ using namespace amrex; -constexpr amrex::Real eps = 1.0e-8; +constexpr amrex::Real eps = Real(1e-8); /** * Uses the Bell-Dawson-Shubin (BDS) algorithm, a higher order Godunov @@ -128,19 +128,19 @@ BDS::ComputeSlopes ( Box const& bx, // set node values equal to the average of the ghost cell values since they store the physical condition on the boundary if ( i<=dlo.x && lo_x_physbc ) { - sint(i,j,k) = 0.5*(s(dlo.x-1,j,k,icomp) + s(dlo.x-1,j-1,k,icomp)); + sint(i,j,k) = Real(0.5)*(s(dlo.x-1,j,k,icomp) + s(dlo.x-1,j-1,k,icomp)); return; } if ( i>=dhi.x+1 && hi_x_physbc ) { - sint(i,j,k) = 0.5*(s(dhi.x+1,j,k,icomp) + s(dhi.x+1,j-1,k,icomp)); + sint(i,j,k) = Real(0.5)*(s(dhi.x+1,j,k,icomp) + s(dhi.x+1,j-1,k,icomp)); return; } if ( j<=dlo.y && lo_y_physbc ) { - sint(i,j,k) = 0.5*(s(i,dlo.y-1,k,icomp) + s(i-1,dlo.y-1,k,icomp)); + sint(i,j,k) = Real(0.5)*(s(i,dlo.y-1,k,icomp) + s(i-1,dlo.y-1,k,icomp)); return; } if ( j>=dhi.y+1 && hi_y_physbc ) { - sint(i,j,k) = 0.5*(s(i,dhi.y+1,k,icomp) + s(i-1,dhi.y+1,k,icomp)); + sint(i,j,k) = Real(0.5)*(s(i,dhi.y+1,k,icomp) + s(i-1,dhi.y+1,k,icomp)); return; } @@ -150,14 +150,14 @@ BDS::ComputeSlopes ( Box const& bx, (j==dlo.y+1 && lo_y_physbc) || (j==dhi.y && hi_y_physbc) ) { - sint(i,j,k) = 0.25* (s(i,j,k,icomp) + s(i-1,j,k,icomp) + s(i,j-1,k,icomp) + s(i-1,j-1,k,icomp)); + sint(i,j,k) = Real(0.25)* (s(i,j,k,icomp) + s(i-1,j,k,icomp) + s(i,j-1,k,icomp) + s(i-1,j-1,k,icomp)); return; } sint(i,j,k) = (s(i-2,j-2,k,icomp) + s(i-2,j+1,k,icomp) + s(i+1,j-2,k,icomp) + s(i+1,j+1,k,icomp) - - 7.0*(s(i-2,j-1,k,icomp) + s(i-2,j ,k,icomp) + s(i-1,j-2,k,icomp) + s(i ,j-2,k,icomp) + - s(i-1,j+1,k,icomp) + s(i ,j+1,k,icomp) + s(i+1,j-1,k,icomp) + s(i+1,j ,k,icomp)) - + 49.0*(s(i-1,j-1,k,icomp) + s(i ,j-1,k,icomp) + s(i-1,j ,k,icomp) + s(i ,j ,k,icomp)) ) / 144.0; + - Real(7)*(s(i-2,j-1,k,icomp) + s(i-2,j ,k,icomp) + s(i-1,j-2,k,icomp) + s(i ,j-2,k,icomp) + + s(i-1,j+1,k,icomp) + s(i ,j+1,k,icomp) + s(i+1,j-1,k,icomp) + s(i+1,j ,k,icomp)) + + Real(49)*(s(i-1,j-1,k,icomp) + s(i ,j-1,k,icomp) + s(i-1,j ,k,icomp) + s(i ,j ,k,icomp)) ) / Real(144); }); ParallelFor(gbx, [=] AMREX_GPU_DEVICE (int i, int j, int k){ @@ -173,25 +173,25 @@ BDS::ComputeSlopes ( Box const& bx, // compute initial estimates of slopes from unlimited corner points // sx - slopes(i,j,k,0) = 0.5*(sint(i+1,j+1,k) + sint(i+1,j,k) - sint(i,j+1,k) - sint(i,j,k)) / hx; + slopes(i,j,k,0) = Real(0.5)*(sint(i+1,j+1,k) + sint(i+1,j,k) - sint(i,j+1,k) - sint(i,j,k)) / hx; // sy - slopes(i,j,k,1) = 0.5*(sint(i+1,j+1,k) - sint(i+1,j,k) + sint(i,j+1,k) - sint(i,j,k)) / hy; + slopes(i,j,k,1) = Real(0.5)*(sint(i+1,j+1,k) - sint(i+1,j,k) + sint(i,j+1,k) - sint(i,j,k)) / hy; // sxy slopes(i,j,k,2) = (sint(i+1,j+1,k) - sint(i+1,j,k) - sint(i,j+1,k) + sint(i,j,k)) / (hx*hy); if (bds_limiter_type > 0) { // ++ / sint(i+1,j+1) - sc(4) = s(i,j,k,icomp) + 0.5*(hx*slopes(i,j,k,0) + hy*slopes(i,j,k,1)) + 0.25*hx*hy*slopes(i,j,k,2); + sc(4) = s(i,j,k,icomp) + Real(0.5)*(hx*slopes(i,j,k,0) + hy*slopes(i,j,k,1)) + Real(0.25)*hx*hy*slopes(i,j,k,2); // +- / sint(i+1,j ) - sc(3) = s(i,j,k,icomp) + 0.5*(hx*slopes(i,j,k,0) - hy*slopes(i,j,k,1)) - 0.25*hx*hy*slopes(i,j,k,2); + sc(3) = s(i,j,k,icomp) + Real(0.5)*(hx*slopes(i,j,k,0) - hy*slopes(i,j,k,1)) - Real(0.25)*hx*hy*slopes(i,j,k,2); // -+ / sint(i ,j+1) - sc(2) = s(i,j,k,icomp) - 0.5*(hx*slopes(i,j,k,0) - hy*slopes(i,j,k,1)) - 0.25*hx*hy*slopes(i,j,k,2); + sc(2) = s(i,j,k,icomp) - Real(0.5)*(hx*slopes(i,j,k,0) - hy*slopes(i,j,k,1)) - Real(0.25)*hx*hy*slopes(i,j,k,2); // -- / sint(i ,j ) - sc(1) = s(i,j,k,icomp) - 0.5*(hx*slopes(i,j,k,0) + hy*slopes(i,j,k,1)) + 0.25*hx*hy*slopes(i,j,k,2); + sc(1) = s(i,j,k,icomp) - Real(0.5)*(hx*slopes(i,j,k,0) + hy*slopes(i,j,k,1)) + Real(0.25)*hx*hy*slopes(i,j,k,2); // enforce max/min bounds smin(4) = amrex::min(s(i,j,k,icomp), s(i+1,j,k,icomp), s(i,j+1,k,icomp), s(i+1,j+1,k,icomp)); @@ -214,11 +214,11 @@ BDS::ComputeSlopes ( Box const& bx, for(int ll=1; ll<=3; ++ll){ // compute the amount by which the average of the nodal values differs from cell-center value - sumloc = 0.25*(sc(4) + sc(3) + sc(2) + sc(1)); - sumdif = (sumloc - s(i,j,k,icomp))*4.0; + sumloc = Real(0.25)*(sc(4) + sc(3) + sc(2) + sc(1)); + sumdif = (sumloc - s(i,j,k,icomp))*Real(4); // sgndif = +(-)1 if the node average is too large(small) - sgndif = std::copysign(1.0,sumdif); + sgndif = std::copysign(Real(1),sumdif); // compute how much each node is larger(smaller) than the cell-centered value for(int mm=1; mm<=4; ++mm){ @@ -241,7 +241,7 @@ BDS::ComputeSlopes ( Box const& bx, // how many node values are left to potentially adjust if (kdp<1) { - div = 1.0; + div = Real(1); } else { div = kdp; } @@ -295,9 +295,9 @@ BDS::ComputeSlopes ( Box const& bx, // final slopes // sx - slopes(i,j,k,0) = 0.5*( sc(4) + sc(3) -sc(1) - sc(2) )/hx; + slopes(i,j,k,0) = Real(0.5)*( sc(4) + sc(3) -sc(1) - sc(2) )/hx; // sy - slopes(i,j,k,1) = 0.5*( sc(4) + sc(2) -sc(1) - sc(3) )/hy; + slopes(i,j,k,1) = Real(0.5)*( sc(4) + sc(2) -sc(1) - sc(3) )/hy; // sxy slopes(i,j,k,2) = ( sc(1) + sc(4) -sc(2) - sc(3) )/(hx*hy); } @@ -376,8 +376,8 @@ BDS::ComputeConc (Box const& bx, Real hx = dx[0]; Real hy = dx[1]; - Real dt2 = dt/2.0; - Real dt3 = dt/3.0; + Real dt2 = dt/Real(2); + Real dt3 = dt/Real(3); Box const& domain = geom.Domain(); const auto dlo = amrex::lbound(domain); @@ -445,10 +445,10 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// if (umac(i,j,k) > 0) { - isign = 1.; + isign = Real(1); ioff = -1; } else { - isign = -1.; + isign = -Real(1); ioff = 0; } @@ -457,15 +457,15 @@ BDS::ComputeConc (Box const& bx, } // centroid of rectangular volume - del(1) = isign*0.5*hx - 0.5*umac(i,j,k)*dt; + del(1) = isign*Real(0.5)*hx - Real(0.5)*umac(i,j,k)*dt; del(2) = 0.; xedge_tmp = eval(s(i+ioff,j,k,icomp),slope_tmp,del); // source term if (iconserv[icomp]) { - xedge_tmp = xedge_tmp*(1. - dt2*ux(i+ioff,j,k)); + xedge_tmp = xedge_tmp*(Real(1)- dt2*ux(i+ioff,j,k)); } else { - xedge_tmp = xedge_tmp*(1. + dt2*vy(i+ioff,j,k)); + xedge_tmp = xedge_tmp*(Real(1)+ dt2*vy(i+ioff,j,k)); } if (force) { xedge_tmp += dt2*force(i+ioff,j,k,icomp); @@ -476,10 +476,10 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// if (vmac(i+ioff,j+1,k) > 0.) { - jsign = 1.; + jsign = Real(1); joff = 0; } else { - jsign = -1.; + jsign = -Real(1); joff = 1; } @@ -488,40 +488,40 @@ BDS::ComputeConc (Box const& bx, u = umac(i,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; - p3(1) = isign*0.5*hx - u*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k)*dt; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k)*dt; for(int n=1; n<=3; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); } for (int ll=1; ll<=2; ++ll) { - del(ll) = (p2(ll)+p3(ll))/2.; + del(ll) = (p2(ll)+p3(ll))/Real(2); } val1 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p3(ll))/2.; + del(ll) = (p1(ll)+p3(ll))/Real(2); } val2 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p2(ll))/2.; + del(ll) = (p1(ll)+p2(ll))/Real(2); } val3 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { - gamma = gamma*(1. - dt3*divu(i+ioff,j+joff,k)); + gamma = gamma*(Real(1)- dt3*divu(i+ioff,j+joff,k)); } /////////////////////////////////////////////// @@ -530,17 +530,17 @@ BDS::ComputeConc (Box const& bx, gamma = gamma * vmac(i+ioff,j+1,k); - xedge_tmp = xedge_tmp - dt*gamma/(2.*hy); + xedge_tmp = xedge_tmp - dt*gamma/(Real(2)*hy); /////////////////////////////////////////////// // compute \Gamma^{y-} /////////////////////////////////////////////// if (vmac(i+ioff,j,k) > 0.) { - jsign = 1.; + jsign = Real(1); joff = -1; } else { - jsign = -1.; + jsign = -Real(1); joff = 0; } @@ -549,40 +549,40 @@ BDS::ComputeConc (Box const& bx, u = umac(i,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; - p3(1) = isign*0.5*hx - u*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j,k)*dt; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k)*dt; for(int n=1; n<=3; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); } for (int ll=1; ll<=2; ++ll) { - del(ll) = (p2(ll)+p3(ll))/2.; + del(ll) = (p2(ll)+p3(ll))/Real(2); } val1 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p3(ll))/2.; + del(ll) = (p1(ll)+p3(ll))/Real(2); } val2 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p2(ll))/2.; + del(ll) = (p1(ll)+p2(ll))/Real(2); } val3 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { - gamma = gamma*(1. - dt3*divu(i+ioff,j+joff,k)); + gamma = gamma*(Real(1)- dt3*divu(i+ioff,j+joff,k)); } /////////////////////////////////////////////// @@ -590,7 +590,7 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// gamma = gamma * vmac(i+ioff,j,k); - sedgex(i,j,k,icomp) = xedge_tmp + dt*gamma/(2.*hy); + sedgex(i,j,k,icomp) = xedge_tmp + dt*gamma/(Real(2)*hy); }); // compute sedgey on y-faces @@ -640,10 +640,10 @@ BDS::ComputeConc (Box const& bx, // centroid of rectangular volume if (vmac(i,j,k) > 0.) { - jsign = 1.; + jsign = Real(1); joff = -1; } else { - jsign = -1.; + jsign = -Real(1); joff = 0; } @@ -652,14 +652,14 @@ BDS::ComputeConc (Box const& bx, } del(1) = 0.; - del(2) = jsign*0.5*hy - 0.5*vmac(i,j,k)*dt; + del(2) = jsign*Real(0.5)*hy - Real(0.5)*vmac(i,j,k)*dt; yedge_tmp = eval(s(i,j+joff,k,icomp),slope_tmp,del); // source term if (iconserv[icomp]) { - yedge_tmp = yedge_tmp*(1. - dt2*vy(i,j+joff,k)); + yedge_tmp = yedge_tmp*(Real(1)- dt2*vy(i,j+joff,k)); } else { - yedge_tmp = yedge_tmp*(1. + dt2*ux(i,j+joff,k)); + yedge_tmp = yedge_tmp*(Real(1)+ dt2*ux(i,j+joff,k)); } if (force) { yedge_tmp += dt2*force(i,j+joff,k,icomp); @@ -670,10 +670,10 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// if (umac(i+1,j+joff,k) > 0.) { - isign = 1.; + isign = Real(1); ioff = 0; } else { - isign = -1.; + isign = -Real(1); ioff = 1; } @@ -682,40 +682,40 @@ BDS::ComputeConc (Box const& bx, v = vmac(i+ioff,j,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; - p3(1) = isign*0.5*hx - umac(i+1,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - v*dt; + p3(1) = isign*Real(0.5)*hx - umac(i+1,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - v*dt; for(int n=1; n<=3; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); } for (int ll=1; ll<=2; ++ll) { - del(ll) = (p2(ll)+p3(ll))/2.; + del(ll) = (p2(ll)+p3(ll))/Real(2); } val1 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p3(ll))/2.; + del(ll) = (p1(ll)+p3(ll))/Real(2); } val2 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p2(ll))/2.; + del(ll) = (p1(ll)+p2(ll))/Real(2); } val3 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { - gamma = gamma*(1. - dt3*divu(i+ioff,j+joff,k)); + gamma = gamma*(Real(1)- dt3*divu(i+ioff,j+joff,k)); } /////////////////////////////////////////////// @@ -723,17 +723,17 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// gamma = gamma * umac(i+1,j+joff,k); - yedge_tmp = yedge_tmp - dt*gamma/(2.*hx); + yedge_tmp = yedge_tmp - dt*gamma/(Real(2)*hx); /////////////////////////////////////////////// // compute \Gamma^{x-} /////////////////////////////////////////////// if (umac(i,j+joff,k) > 0.) { - isign = 1.; + isign = Real(1); ioff = -1; } else { - isign = -1.; + isign = -Real(1); ioff = 0; } @@ -742,40 +742,40 @@ BDS::ComputeConc (Box const& bx, v = vmac(i+ioff,j,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; - p3(1) = isign*0.5*hx - umac(i,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - v*dt; + p3(1) = isign*Real(0.5)*hx - umac(i,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - v*dt; for(int n=1; n<=3; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); } for (int ll=1; ll<=2; ++ll) { - del(ll) = (p2(ll)+p3(ll))/2.; + del(ll) = (p2(ll)+p3(ll))/Real(2); } val1 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p3(ll))/2.; + del(ll) = (p1(ll)+p3(ll))/Real(2); } val2 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for (int ll=1; ll<=2; ++ll) { - del(ll) = (p1(ll)+p2(ll))/2.; + del(ll) = (p1(ll)+p2(ll))/Real(2); } val3 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { - gamma = gamma*(1. - dt3*divu(i+ioff,j+joff,k)); + gamma = gamma*(Real(1)- dt3*divu(i+ioff,j+joff,k)); } /////////////////////////////////////////////// @@ -783,7 +783,7 @@ BDS::ComputeConc (Box const& bx, /////////////////////////////////////////////// gamma = gamma * umac(i,j+joff,k); - sedgey(i,j,k,icomp) = yedge_tmp + dt*gamma/(2.*hx); + sedgey(i,j,k,icomp) = yedge_tmp + dt*gamma/(Real(2)*hx); }); } diff --git a/BDS/hydro_bds_edge_state_3D.cpp b/BDS/hydro_bds_edge_state_3D.cpp index 15aafa190..6dc2efe2b 100644 --- a/BDS/hydro_bds_edge_state_3D.cpp +++ b/BDS/hydro_bds_edge_state_3D.cpp @@ -214,39 +214,39 @@ BDS::ComputeSlopes ( Box const& bx, // compute initial estimates of slopes from unlimited corner points // sx - slopes(i,j,k,0) = 0.25*(( sint(i+1,j ,k ) + sint(i+1,j+1,k ) - +sint(i+1,j ,k+1) + sint(i+1,j+1,k+1) ) - -( sint(i ,j ,k ) + sint(i ,j+1,k ) - +sint(i ,j ,k+1) + sint(i ,j+1,k+1) )) / hx; + slopes(i,j,k,0) = Real(0.25)*(( sint(i+1,j ,k ) + sint(i+1,j+1,k ) + +sint(i+1,j ,k+1) + sint(i+1,j+1,k+1) ) + -( sint(i ,j ,k ) + sint(i ,j+1,k ) + +sint(i ,j ,k+1) + sint(i ,j+1,k+1) )) / hx; // sy - slopes(i,j,k,1) = 0.25*(( sint(i ,j+1,k ) + sint(i+1,j+1,k ) - +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) - -( sint(i ,j ,k ) + sint(i+1,j ,k ) - +sint(i ,j ,k+1) + sint(i+1,j ,k+1) )) / hy; + slopes(i,j,k,1) = Real(0.25)*(( sint(i ,j+1,k ) + sint(i+1,j+1,k ) + +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) + -( sint(i ,j ,k ) + sint(i+1,j ,k ) + +sint(i ,j ,k+1) + sint(i+1,j ,k+1) )) / hy; // sz - slopes(i,j,k,2) = 0.25*(( sint(i ,j ,k+1) + sint(i+1,j ,k+1) - +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) - -( sint(i ,j ,k ) + sint(i+1,j ,k ) - +sint(i ,j+1,k ) + sint(i+1,j+1,k ) )) / hz; + slopes(i,j,k,2) = Real(0.25)*(( sint(i ,j ,k+1) + sint(i+1,j ,k+1) + +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) + -( sint(i ,j ,k ) + sint(i+1,j ,k ) + +sint(i ,j+1,k ) + sint(i+1,j+1,k ) )) / hz; // sxy - slopes(i,j,k,3) = 0.5*( ( sint(i ,j ,k ) + sint(i ,j ,k+1) - +sint(i+1,j+1,k ) + sint(i+1,j+1,k+1) ) - -( sint(i+1,j ,k ) + sint(i+1,j ,k+1) - +sint(i ,j+1,k ) + sint(i ,j+1,k+1) )) / (hx*hy); + slopes(i,j,k,3) = Real(0.5)*( ( sint(i ,j ,k ) + sint(i ,j ,k+1) + +sint(i+1,j+1,k ) + sint(i+1,j+1,k+1) ) + -( sint(i+1,j ,k ) + sint(i+1,j ,k+1) + +sint(i ,j+1,k ) + sint(i ,j+1,k+1) )) / (hx*hy); // sxz - slopes(i,j,k,4) = 0.5*( ( sint(i ,j ,k ) + sint(i ,j+1,k ) - +sint(i+1,j ,k+1) + sint(i+1,j+1,k+1) ) - -( sint(i+1,j ,k ) + sint(i+1,j+1,k ) - +sint(i ,j ,k+1) + sint(i ,j+1,k+1) )) / (hx*hz); + slopes(i,j,k,4) = Real(0.5)*( ( sint(i ,j ,k ) + sint(i ,j+1,k ) + +sint(i+1,j ,k+1) + sint(i+1,j+1,k+1) ) + -( sint(i+1,j ,k ) + sint(i+1,j+1,k ) + +sint(i ,j ,k+1) + sint(i ,j+1,k+1) )) / (hx*hz); // syz - slopes(i,j,k,5) = 0.5*( ( sint(i ,j ,k ) + sint(i+1,j ,k ) - +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) - -( sint(i ,j ,k+1) + sint(i+1,j ,k+1) - +sint(i ,j+1,k ) + sint(i+1,j+1,k ) )) / (hy*hz); + slopes(i,j,k,5) = Real(0.5)*( ( sint(i ,j ,k ) + sint(i+1,j ,k ) + +sint(i ,j+1,k+1) + sint(i+1,j+1,k+1) ) + -( sint(i ,j ,k+1) + sint(i+1,j ,k+1) + +sint(i ,j+1,k ) + sint(i+1,j+1,k ) )) / (hy*hz); // sxyz slopes(i,j,k,6) = (-sint(i ,j ,k ) + sint(i+1,j ,k ) + sint(i ,j+1,k ) @@ -257,51 +257,51 @@ BDS::ComputeSlopes ( Box const& bx, // +++ / sint(i+1,j+1,k+1) sc(8) = s(i,j,k,icomp) - +0.5 *( hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) - +0.25 *( hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) - +0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) + +Real(0.25 )*( hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) + +Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // ++- / sint(i+1,j+1,k ) sc(7) = s(i,j,k,icomp) - +0.5 *( hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) - +0.25 *( hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) - -0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) + +Real(0.25 )*( hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) + -Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // +-+ / sint(i+1,j ,k+1) sc(6) = s(i,j,k,icomp) - +0.5 *( hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) - +0.25 *( -hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) - -0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) + +Real(0.25 )*( -hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) + -Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // +-- / sint(i+1,j ,k ) sc(5) = s(i,j,k,icomp) - +0.5 *( hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) - +0.25 *( -hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) - +0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) + +Real(0.25 )*( -hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) + +Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // -++ / sint(i ,j+1,k+1) sc(4) = s(i,j,k,icomp) - +0.5 *( -hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) - +0.25 *( -hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) - -0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( -hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) + +Real(0.25 )*( -hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) + -Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // -+- / sint(i ,j+1,k ) sc(3) = s(i,j,k,icomp) - +0.5 *( -hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) - +0.25 *( -hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) - +0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( -hx*slopes(i,j,k,0)+ hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) + +Real(0.25 )*( -hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) + +Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // --+ / sint(i ,j ,k+1) sc(2) = s(i,j,k,icomp) - +0.5 *( -hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) - +0.25 *( hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) - +0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( -hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)+ hz*slopes(i,j,k,2)) + +Real(0.25 )*( hx*hy*slopes(i,j,k,3)-hx*hz*slopes(i,j,k,4)-hy*hz*slopes(i,j,k,5)) + +Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // ---/ sint(i ,j ,k ) sc(1) = s(i,j,k,icomp) - +0.5 *( -hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) - +0.25 *( hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) - -0.125*hx*hy*hz*slopes(i,j,k,6); + +Real(0.5 )*( -hx*slopes(i,j,k,0)- hy*slopes(i,j,k,1)- hz*slopes(i,j,k,2)) + +Real(0.25 )*( hx*hy*slopes(i,j,k,3)+hx*hz*slopes(i,j,k,4)+hy*hz*slopes(i,j,k,5)) + -Real(0.125)*hx*hy*hz*slopes(i,j,k,6); // enforce max/min bounds smin(8) = min(s(i ,j ,k ,icomp),s(i+1,j ,k ,icomp),s(i ,j+1,k ,icomp),s(i ,j ,k+1,icomp), @@ -434,40 +434,40 @@ BDS::ComputeSlopes ( Box const& bx, // final slopes // sx - slopes(i,j,k,0) = 0.25*( ( sc(5) + sc(7) - +sc(6) + sc(8)) - -( sc(1) + sc(3) - +sc(2) + sc(4)) ) / hx; + slopes(i,j,k,0) = Real(0.25)*( ( sc(5) + sc(7) + +sc(6) + sc(8)) + -( sc(1) + sc(3) + +sc(2) + sc(4)) ) / hx; // sy - slopes(i,j,k,1) = 0.25*( ( sc(3) + sc(7) - +sc(4) + sc(8)) - -( sc(1) + sc(5) - +sc(2) + sc(6)) ) / hy; + slopes(i,j,k,1) = Real(0.25)*( ( sc(3) + sc(7) + +sc(4) + sc(8)) + -( sc(1) + sc(5) + +sc(2) + sc(6)) ) / hy; // sz - slopes(i,j,k,2) = 0.25*( ( sc(2) + sc(6) - +sc(4) + sc(8)) - -( sc(1) + sc(5) - +sc(3) + sc(7)) ) / hz; + slopes(i,j,k,2) = Real(0.25)*( ( sc(2) + sc(6) + +sc(4) + sc(8)) + -( sc(1) + sc(5) + +sc(3) + sc(7)) ) / hz; // sxy - slopes(i,j,k,3) = 0.5*( ( sc(1) + sc(2) - +sc(7) + sc(8)) - -( sc(5) + sc(6) - +sc(3) + sc(4)) ) / (hx*hy); + slopes(i,j,k,3) = Real(0.5)*( ( sc(1) + sc(2) + +sc(7) + sc(8)) + -( sc(5) + sc(6) + +sc(3) + sc(4)) ) / (hx*hy); // sxz - slopes(i,j,k,4) = 0.5*( ( sc(1) + sc(3) - +sc(6) + sc(8)) - -( sc(5) + sc(7) - +sc(2) + sc(4)) ) / (hx*hz); + slopes(i,j,k,4) = Real(0.5)*( ( sc(1) + sc(3) + +sc(6) + sc(8)) + -( sc(5) + sc(7) + +sc(2) + sc(4)) ) / (hx*hz); // syz - slopes(i,j,k,5) = 0.5*( ( sc(1) + sc(5) - +sc(4) + sc(8)) - -( sc(2) + sc(6) - +sc(3) + sc(7)) ) / (hy*hz); + slopes(i,j,k,5) = Real(0.5)*( ( sc(1) + sc(5) + +sc(4) + sc(8)) + -( sc(2) + sc(6) + +sc(3) + sc(7)) ) / (hy*hz); // sxyz slopes(i,j,k,6) = (-sc(1) + sc(5) + sc(3) @@ -650,7 +650,7 @@ BDS::ComputeConc (Box const& bx, // centroid of rectangular volume - del(1) = isign*0.5*hx - 0.5*umac(i,j,k)*dt; + del(1) = isign*Real(0.5)*hx - Real(0.5)*umac(i,j,k)*dt; del(2) = 0.0; del(3) = 0.0; xedge_tmp = eval(s(i+ioff,j,k,icomp),slope_tmp,del); @@ -683,16 +683,16 @@ BDS::ComputeConc (Box const& bx, u = umac(i,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; p1(3) = 0.0; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; p2(3) = 0.0; - p3(1) = isign*0.5*hx - u*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k)*dt; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k)*dt; p3(3) = 0.0; for(int n=1; n<=7; ++n){ @@ -746,52 +746,52 @@ BDS::ComputeConc (Box const& bx, vv = vmac(i+ioff,j+1,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k+1)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k+1)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/Real(4); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -800,76 +800,76 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * wmac(i+ioff,j+joff,k+1); - gamma = gamma - dt*gamma2/(3.0*hz); + gamma = gamma - dt*gamma2/(Real(3)*hz); //////////////////////////////////////////////// // correct \Gamma^{y+} with \Gamma^{y+,z-} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k) > 0.0) { - ksign = 1.0; + if (wmac(i+ioff,j+joff,k) > Real(0)) { + ksign = Real(1); koff = -1; } else { - ksign = -1.0; + ksign = -Real(1); koff = 0; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - vv = 0.0; - if (vmac(i+ioff,j+1,k)*vmac(i+ioff,j+1,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i+ioff,j+1,k)*vmac(i+ioff,j+1,k+koff) > Real(0)) { vv = vmac(i+ioff,j+1,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/Real(4); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -878,65 +878,65 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * wmac(i+ioff,j+joff,k); - gamma = gamma + dt*gamma2/(3.0*hz); + gamma = gamma + dt*gamma2/(Real(3)*hz); //////////////////////////////////////////////// // correct sedgex with \Gamma^{y+} //////////////////////////////////////////////// gamma = gamma * vmac(i+ioff,j+1,k); - xedge_tmp = xedge_tmp - dt*gamma/(2.0*hy); + xedge_tmp = xedge_tmp - dt*gamma/(Real(2)*hy); //////////////////////////////////////////////// // compute \Gamma^{y-} without corner corrections //////////////////////////////////////////////// - if (vmac(i+ioff,j,k) > 0.0) { - jsign = 1.0; + if (vmac(i+ioff,j,k) > Real(0)) { + jsign = Real(1); joff = -1; } else { - jsign = -1.0; + jsign = -Real(1); joff = 0; } - u = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k) > 0.0) { + u = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k) > Real(0)) { u = umac(i,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = 0.0; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = Real(0); - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = 0.0; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = Real(0); - p3(1) = isign*0.5*hx - u*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j,k)*dt; - p3(3) = 0.0; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k)*dt; + p3(3) = Real(0); for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p2(ll)+p3(ll))/2.0; + del(ll) = (p2(ll)+p3(ll))*Real(0.5); } val1 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p3(ll))/2.0; + del(ll) = (p1(ll)+p3(ll))*Real(0.5); } val2 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll))/2.0; + del(ll) = (p1(ll)+p2(ll))*Real(0.5); } val3 = eval(s(i+ioff,j+joff,k,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.0; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { @@ -949,70 +949,70 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{y-} with \Gamma^{y-,z+} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k+1) > 0.0) { - ksign = 1.0; + if (wmac(i+ioff,j+joff,k+1) > Real(0)) { + ksign = Real(1); koff = 0; } else { - ksign = -1.0; + ksign = -Real(1); koff = 1; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - vv = 0.0; - if (vmac(i+ioff,j,k)*vmac(i+ioff,j,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i+ioff,j,k)*vmac(i+ioff,j,k+koff) > Real(0)) { vv = vmac(i+ioff,j,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k+1)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k+1)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/Real(4) } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1021,76 +1021,76 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * wmac(i+ioff,j+joff,k+1); - gamma = gamma - dt*gamma2/(3.0*hz); + gamma = gamma - dt*gamma2/(Real(3)*hz); //////////////////////////////////////////////// // correct \Gamma^{y-} with \Gamma^{y-,z-} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k) > 0.0) { - ksign = 1.0; + if (wmac(i+ioff,j+joff,k) > Real(0)) { + ksign = Real(1); koff = -1; } else { - ksign = -1.0; + ksign = -Real(1); koff = 0; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - vv = 0.0; - if (vmac(i+ioff,j,k)*vmac(i+ioff,j,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i+ioff,j,k)*vmac(i+ioff,j,k+koff) > Real(0)) { vv = vmac(i+ioff,j,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i+ioff,j,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))*Real(0.25); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1099,141 +1099,141 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * wmac(i+ioff,j+joff,k); - gamma = gamma + dt*gamma2/(3.0*hz); + gamma = gamma + dt*gamma2/(Real(3)*hz); //////////////////////////////////////////////// // correct sedgex with \Gamma^{y-} //////////////////////////////////////////////// gamma = gamma * vmac(i+ioff,j,k); - xedge_tmp = xedge_tmp + dt*gamma/(2.0*hy); + xedge_tmp = xedge_tmp + dt*gamma/(Real(2)*hy); //////////////////////////////////////////////// // compute \Gamma^{z+} without corner corrections //////////////////////////////////////////////// - if (wmac(i+ioff,j,k+1) > 0.0) { - ksign = 1.0; + if (wmac(i+ioff,j,k+1) > Real(0)) { + ksign = Real(1); koff = 0; } else { - ksign = -1.0; + ksign = -Real(1); koff = 1; } - u = 0.0; - if (umac(i,j,k)*umac(i,j,k+koff) > 0.0) { + u = Real(0); + if (umac(i,j,k)*umac(i,j,k+koff) > Real(0)) { u = umac(i,j,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = 0.0; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = Real(0); + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = 0.0; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = Real(0); + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - u*dt; - p3(2) = 0.0; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k+1)*dt; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = Real(0); + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k+1)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p2(ll)+p3(ll))/2.0; + del(ll) = (p2(ll)+p3(ll))*Real(0.5); } val1 = eval(s(i+ioff,j,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p3(ll))/2.0; + del(ll) = (p1(ll)+p3(ll))*Real(0.5); } val2 = eval(s(i+ioff,j,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll))/2.0; + del(ll) = (p1(ll)+p2(ll))*Real(0.5); } val3 = eval(s(i+ioff,j,k+koff,icomp),slope_tmp,del); // average these centroid values to get the average value - gamma = (val1+val2+val3)/3.0; + gamma = (val1+val2+val3)/Real(3); // source term if (iconserv[icomp]) { - gamma = gamma*(1. - dt3*(ux(i+ioff,j,k+koff)+wz(i+ioff,j,k+koff))); + gamma = gamma*(Real(1) - dt3*(ux(i+ioff,j,k+koff)+wz(i+ioff,j,k+koff))); } else { - gamma = gamma*(1. + dt3*vy(i+ioff,j,k+koff)); + gamma = gamma*(Real(1) + dt3*vy(i+ioff,j,k+koff)); } //////////////////////////////////////////////// // correct \Gamma^{z+} with \Gamma^{z+,y+} //////////////////////////////////////////////// - if (vmac(i+ioff,j+1,k+koff) > 0.0) { - jsign = 1.0; + if (vmac(i+ioff,j+1,k+koff) > Real(0)) { + jsign = Real(1); joff = 0; } else { - jsign = -1.0; + jsign = -Real(1); joff = 1; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - ww = 0.0; + ww = Real(0); if (wmac(i+ioff,j,k+1)*wmac(i+ioff,j+joff,k+1) > 0.0) { ww = wmac(i+ioff,j+joff,k+1); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k+1)*dt; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy; + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k+1)*dt; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k+koff)*dt; - p4(3) = ksign*0.5*hz - ww*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k+koff)*dt; + p4(3) = ksign*Real(0.5)*hz - ww*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))*Real(0.25); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1242,76 +1242,76 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * vmac(i+ioff,j+1,k+koff); - gamma = gamma - dt*gamma2/(3.0*hy); + gamma = gamma - dt*gamma2/(Real(3)*hy); //////////////////////////////////////////////// // correct \Gamma^{z+} with \Gamma^{z+,y-} //////////////////////////////////////////////// - if (vmac(i+ioff,j,k+koff) > 0.0) { - jsign = 1.0; + if (vmac(i+ioff,j,k+koff) > Real(0)) { + jsign = Real(1); joff = -1; } else { - jsign = -1.0; + jsign = -Real(1); joff = 0; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - ww = 0.0; - if (wmac(i+ioff,j,k+1)*wmac(i+ioff,j+joff,k+1) > 0.0) { + ww = Real(0); + if (wmac(i+ioff,j,k+1)*wmac(i+ioff,j+joff,k+1) > Real(0)) { ww = wmac(i+ioff,j+joff,k+1); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k+1)*dt; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy; + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k+1)*dt; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vmac(i+ioff,j,k+koff)*dt; - p4(3) = ksign*0.5*hz - ww*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k+koff)*dt; + p4(3) = ksign*Real(0.5)*hz - ww*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/4.0; + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))*Real(0.25); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1320,43 +1320,43 @@ BDS::ComputeConc (Box const& bx, gamma2 = gamma2 * vmac(i+ioff,j,k+koff); - gamma = gamma + dt*gamma2/(3.0*hy); + gamma = gamma + dt*gamma2/(Real(3)*hy); //////////////////////////////////////////////// // correct sedgex with \Gamma^{z+} //////////////////////////////////////////////// gamma = gamma * wmac(i+ioff,j,k+1); - xedge_tmp = xedge_tmp - dt*gamma/(2.0*hz); + xedge_tmp = xedge_tmp - dt*gamma/(Real(2)*hz); //////////////////////////////////////////////// // compute \Gamma^{z-} without corner corrections //////////////////////////////////////////////// - if (wmac(i+ioff,j,k) > 0.0) { - ksign = 1.0; + if (wmac(i+ioff,j,k) > Real(0)) { + ksign = Real(1); koff = -1; } else { - ksign = -1.0; + ksign = -Real(1); koff = 0; } - u = 0.0; - if (umac(i,j,k)*umac(i,j,k+koff) > 0.0) { + u = Real(0); + if (umac(i,j,k)*umac(i,j,k+koff) > Real(0)) { u = umac(i,j,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = 0.0; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = Real(0); + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = 0.0; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = Real(0); + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - u*dt; - p3(2) = 0.0; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k)*dt; + p3(1) = isign*Real(0.5)*hx - u*dt; + p3(2) = Real(0); + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j,k+koff,n-1); @@ -1391,7 +1391,7 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{z-} with \Gamma^{z-,y+} //////////////////////////////////////////////// - if (vmac(i+ioff,j+1,k+koff) > 0.0) { + if (vmac(i+ioff,j+1,k+koff) > Real(0)) { jsign = 1.0; joff = 0; } else { @@ -1399,31 +1399,31 @@ BDS::ComputeConc (Box const& bx, joff = 1; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - ww = 0.0; - if (wmac(i+ioff,j,k)*wmac(i+ioff,j+joff,k) > 0.0) { + ww = Real(0); + if (wmac(i+ioff,j,k)*wmac(i+ioff,j+joff,k) > Real(0)) { ww = wmac(i+ioff,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k)*dt; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy; + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k)*dt; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vmac(i+ioff,j+1,k+koff)*dt; - p4(3) = ksign*0.5*hz - ww*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j+1,k+koff)*dt; + p4(3) = ksign*Real(0.5)*hz - ww*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); @@ -1435,26 +1435,26 @@ BDS::ComputeConc (Box const& bx, val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1469,7 +1469,7 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{z-} with \Gamma^{z-,y-} //////////////////////////////////////////////// - if (vmac(i+ioff,j,k+koff) > 0.0) { + if (vmac(i+ioff,j,k+koff) > Real(0)) { jsign = 1.0; joff = -1; } else { @@ -1477,31 +1477,31 @@ BDS::ComputeConc (Box const& bx, joff = 0; } - uu = 0.0; - if (umac(i,j,k)*umac(i,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i,j,k)*umac(i,j+joff,k+koff) > Real(0)) { uu = umac(i,j+joff,k+koff); } - ww = 0.0; - if (wmac(i+ioff,j,k)*wmac(i+ioff,j+joff,k) > 0.0) { + ww = Real(0); + if (wmac(i+ioff,j,k)*wmac(i+ioff,j+joff,k) > Real(0)) { ww = wmac(i+ioff,j+joff,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx - umac(i,j,k)*dt; - p2(2) = jsign*0.5*hy; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p2(2) = jsign*Real(0.5)*hy; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i,j,k)*dt; - p3(2) = jsign*0.5*hy; - p3(3) = ksign*0.5*hz - wmac(i+ioff,j,k)*dt; + p3(1) = isign*Real(0.5)*hx - umac(i,j,k)*dt; + p3(2) = jsign*Real(0.5)*hy; + p3(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j,k)*dt; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vmac(i+ioff,j,k+koff)*dt; - p4(3) = ksign*0.5*hz - ww*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vmac(i+ioff,j,k+koff)*dt; + p4(3) = ksign*Real(0.5)*hz - ww*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); @@ -1513,26 +1513,26 @@ BDS::ComputeConc (Box const& bx, val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1562,7 +1562,7 @@ BDS::ComputeConc (Box const& bx, sedgey(i,j,k,icomp) = s(i,j-1,k,icomp); if (is_velocity && icomp == YVEL && (bc.lo(1) == BCType::foextrap || bc.lo(1) == BCType::hoextrap) ) { // make sure velocity is not blowing inward - sedgey(i,j,k,icomp) = amrex::min(0._rt,sedgey(i,j,k,icomp)); + sedgey(i,j,k,icomp) = amrex::min(Real(0),sedgey(i,j,k,icomp)); } return; } @@ -1570,7 +1570,7 @@ BDS::ComputeConc (Box const& bx, sedgey(i,j,k,icomp) = s(i,j,k,icomp); if (is_velocity && icomp == YVEL && (bc.hi(1) == BCType::foextrap || bc.hi(1) == BCType::hoextrap) ) { // make sure velocity is not blowing inward - sedgey(i,j,k,icomp) = amrex::max(0._rt,sedgey(i,j,k,icomp)); + sedgey(i,j,k,icomp) = amrex::max(Real(0),sedgey(i,j,k,icomp)); } return; } @@ -1600,7 +1600,7 @@ BDS::ComputeConc (Box const& bx, //////////////////////////////////////////////// // centroid of rectangular volume - if (vmac(i,j,k) > 0.0) { + if (vmac(i,j,k) > Real(0)) { jsign = 1.0; joff = -1; } else { @@ -1608,9 +1608,9 @@ BDS::ComputeConc (Box const& bx, joff = 0; } - del(1) = 0.0; - del(2) = jsign*0.5*hy - 0.5*vmac(i,j,k)*dt; - del(3) = 0.0; + del(1) = Real(0); + del(2) = jsign*Real(0.5)*hy - Real(0.5)*vmac(i,j,k)*dt; + del(3) = Real(0); for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i,j+joff,k,n-1); @@ -1632,7 +1632,7 @@ BDS::ComputeConc (Box const& bx, // compute \Gamma^{x+} without corner corrections //////////////////////////////////////////////// - if (umac(i+1,j+joff,k) > 0.0) { + if (umac(i+1,j+joff,k) > Real(0)) { isign = 1.0; ioff = 0; } else { @@ -1640,22 +1640,22 @@ BDS::ComputeConc (Box const& bx, ioff = 1; } - v = 0.0; - if (vmac(i,j,k)*vmac(i+ioff,j,k) > 0.0) { + v = Real(0); + if (vmac(i,j,k)*vmac(i+ioff,j,k) > Real(0)) { v = vmac(i+ioff,j,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = 0.0; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = Real(0); - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p2(3) = 0.0; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p2(3) = Real(0); - p3(1) = isign*0.5*hx - umac(i+1,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - v*dt; - p3(3) = 0.0; + p3(1) = isign*Real(0.5)*hx - umac(i+1,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - v*dt; + p3(3) = Real(0); for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); @@ -1690,7 +1690,7 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{x+} with \Gamma^{x+,z+} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k+1) > 0.0) { + if (wmac(i+ioff,j+joff,k+1) > Real(0)) { ksign = 1.0; koff = 0; } else { @@ -1698,31 +1698,31 @@ BDS::ComputeConc (Box const& bx, koff = 1; } - vv = 0.0; - if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > Real(0)) { vv = vmac(i+ioff,j,k+koff); } - uu = 0.0; - if (umac(i+1,j+joff,k)*umac(i+1,j+joff,k+koff) > 0.0) { + uu = Real(0); + if (umac(i+1,j+joff,k)*umac(i+1,j+joff,k+koff) > Real(0)) { uu = umac(i+1,j+joff,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i+1,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i+1,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k+1)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k+1)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); @@ -1734,26 +1734,26 @@ BDS::ComputeConc (Box const& bx, val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1768,7 +1768,7 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{x+} with \Gamma^{x+,z-} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k) > 0.0) { + if (wmac(i+ioff,j+joff,k) > Real(0)) { ksign = 1.0; koff = -1; } else { @@ -1776,31 +1776,31 @@ BDS::ComputeConc (Box const& bx, koff = 0; } - vv = 0.0; - if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > Real(0)) { vv = vmac(i+ioff,j,k+koff); } - uu = 0.0; + uu = Real(0); if (umac(i+1,j+joff,k)*umac(i+1,j+joff,k+koff) > 0.0) { uu = umac(i+1,j+joff,k+koff); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = ksign*0.5*hz; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = ksign*Real(0.5)*hz; - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p2(3) = ksign*0.5*hz; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p2(3) = ksign*Real(0.5)*hz; - p3(1) = isign*0.5*hx - umac(i+1,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p3(3) = ksign*0.5*hz; + p3(1) = isign*Real(0.5)*hx - umac(i+1,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p3(3) = ksign*Real(0.5)*hz; - p4(1) = isign*0.5*hx - uu*dt; - p4(2) = jsign*0.5*hy - vv*dt; - p4(3) = ksign*0.5*hz - wmac(i+ioff,j+joff,k)*dt; + p4(1) = isign*Real(0.5)*hx - uu*dt; + p4(2) = jsign*Real(0.5)*hy - vv*dt; + p4(3) = ksign*Real(0.5)*hz - wmac(i+ioff,j+joff,k)*dt; for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k+koff,n-1); @@ -1812,26 +1812,26 @@ BDS::ComputeConc (Box const& bx, val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p1(ll) + sixth*(p2(ll)+p3(ll)+p4(ll)); } val2 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); + del(ll) = Real(0.5)*p2(ll) + sixth*(p1(ll)+p3(ll)+p4(ll)); } val3 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); + del(ll) = Real(0.5)*p3(ll) + sixth*(p2(ll)+p1(ll)+p4(ll)); } val4 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); for(int ll=1; ll<=3; ++ll ){ - del(ll) = 0.5*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); + del(ll) = Real(0.5)*p4(ll) + sixth*(p2(ll)+p3(ll)+p1(ll)); } val5 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); - gamma2 = -0.8*val1 + 0.45*(val2+val3+val4+val5); + gamma2 = -Real(0.8)*val1 + Real(0.45)*(val2+val3+val4+val5); // divu source term if (iconserv[icomp]) { @@ -1853,30 +1853,30 @@ BDS::ComputeConc (Box const& bx, // compute \Gamma^{x-} without corner corrections //////////////////////////////////////////////// - if (umac(i,j+joff,k) > 0.0) { - isign = 1.0; + if (umac(i,j+joff,k) > Real(0)) { + isign = Real(1); ioff = -1; } else { - isign = -1.0; + isign = -Real(1); ioff = 0; } - v = 0.0; - if (vmac(i,j,k)*vmac(i+ioff,j,k) > 0.0) { + v = Real(0); + if (vmac(i,j,k)*vmac(i+ioff,j,k) > Real(0)) { v = vmac(i+ioff,j,k); } - p1(1) = isign*0.5*hx; - p1(2) = jsign*0.5*hy; - p1(3) = 0.0; + p1(1) = isign*Real(0.5)*hx; + p1(2) = jsign*Real(0.5)*hy; + p1(3) = Real(0); - p2(1) = isign*0.5*hx; - p2(2) = jsign*0.5*hy - vmac(i,j,k)*dt; - p2(3) = 0.0; + p2(1) = isign*Real(0.5)*hx; + p2(2) = jsign*Real(0.5)*hy - vmac(i,j,k)*dt; + p2(3) = Real(0); - p3(1) = isign*0.5*hx - umac(i,j+joff,k)*dt; - p3(2) = jsign*0.5*hy - v*dt; - p3(3) = 0.0; + p3(1) = isign*Real(0.5)*hx - umac(i,j+joff,k)*dt; + p3(2) = jsign*Real(0.5)*hy - v*dt; + p3(3) = Real(0); for(int n=1; n<=7; ++n){ slope_tmp(n) = slopes(i+ioff,j+joff,k,n-1); @@ -1911,7 +1911,7 @@ BDS::ComputeConc (Box const& bx, // correct \Gamma^{x-} with \Gamma^{x-,z+} //////////////////////////////////////////////// - if (wmac(i+ioff,j+joff,k+1) > 0.0) { + if (wmac(i+ioff,j+joff,k+1) > Real(0)) { ksign = 1.0; koff = 0; } else { @@ -1919,12 +1919,12 @@ BDS::ComputeConc (Box const& bx, koff = 1; } - vv = 0.0; - if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > 0.0) { + vv = Real(0); + if (vmac(i,j,k)*vmac(i+ioff,j,k+koff) > Real(0)) { vv = vmac(i+ioff,j,k+koff); } - uu = 0.0; + uu = Real(0); if (umac(i,j+joff,k)*umac(i,j+joff,k+koff) > 0.0) { uu = umac(i,j+joff,k+koff); } diff --git a/Diagnostics/Redistribution/CMakeLists.txt b/Diagnostics/Redistribution/CMakeLists.txt new file mode 100644 index 000000000..ab2c5109d --- /dev/null +++ b/Diagnostics/Redistribution/CMakeLists.txt @@ -0,0 +1,15 @@ +target_include_directories( + amrex_hydro + PUBLIC + $ + ) + +target_sources( + amrex_hydro + PRIVATE + hydro_redistribution.H + hydro_redistribution.cpp + hydro_create_itracker_${HYDRO_SPACEDIM}d.cpp + hydro_state_redistribute.cpp + hydro_state_utils.cpp + ) diff --git a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp new file mode 100644 index 000000000..9e0c45fc9 --- /dev/null +++ b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp @@ -0,0 +1,407 @@ +/** + * \file hydro_redistribution.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include +#include + +using namespace amrex; + +void Redistribution::Apply ( Box const& bx, int ncomp, + Array4 const& dUdt_out, + Array4 const& dUdt_in, + Array4 const& U_in, + Array4 const& scratch, + Array4 const& flag, + AMREX_D_DECL(Array4 const& apx, + Array4 const& apy, + Array4 const& apz), + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom, Real dt, + std::string redistribution_type, + amrex::Real target_volfrac) +{ + // redistribution_type = "NoRedist"; // no redistribution + // redistribution_type = "FluxRedist" // flux_redistribute + // redistribution_type = "StateRedist"; // (weighted) state redistribute + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = 0.; + }); + + if (redistribution_type == "FluxRedist") + { + int icomp = 0; + apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); + + } else if (redistribution_type == "StateRedist") { + + Box const& bxg1 = grow(bx,1); + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); + // How many nbhds is a cell in +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + Box domain_per_grown = lev_geom.Domain(); + AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, + if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, + if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); + + // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 + // in the cells just outside the domain because those values will be used + // in the slope computation in state redistribution. We assume here that + // the ext_dir values of U_in itself have already been set. + if (!domain_per_grown.contains(bxg1)) + amrex::ParallelFor(bxg1,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) + dUdt_in(i,j,k,n) = 0.; + }); + + amrex::ParallelFor(Box(scratch), ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n); + } + ); + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + // Only update the values which actually changed -- this makes + // the results insensitive to tiling -- otherwise cells that aren't + // changed but are in a tile on which StateRedistribute gets called + // will have precision-level changes due to adding/subtracting U_in + // and multiplying/dividing by dt. Here we test on whether (i,j,k) + // has at least one neighbor and/or whether (i,j,k) is in the + // neighborhood of another cell -- if either of those is true the + // value may have changed + + if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) + { + dUdt_out(i,j,k,n) = (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; + } + else + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + } + ); + + } else if (redistribution_type == "NoRedist") { + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + ); + + } else { + amrex::Error("Not a legit redist_type"); + } +} + +void +Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, + Array4 const& U_out, + Array4 const& U_in, + Array4 const& flag, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry& lev_geom, std::string redistribution_type, + amrex::Real target_volfrac) +{ + if (redistribution_type == "StateRedist") { + amrex::Error("Redistribution::ApplyToInitialData: Shouldn't be here with this redist type"); + } + + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + U_out(i,j,k,n) = 0.; + }); + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); +} + +void +Redistribution::Make1DProfile ( Box const& bx, int ncomp, + Array4 const& U_in, + Array4 const& flag, + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& bcent, + Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom) +{ + amrex::Vector profile; + amrex::Vector xloc; + profile.resize(64,0.0); + xloc.resize(64,0.0); + + amrex::Real* prof_ptr = profile.data(); + amrex::Real* xloc_ptr = xloc.data(); + + const Box domain = lev_geom.Domain(); + const int domain_ilo = domain.smallEnd(0); + const int domain_ihi = domain.bigEnd(0); + const int domain_jlo = domain.smallEnd(1); + const int domain_jhi = domain.bigEnd(1); +#if (AMREX_SPACEDIM == 3) + const int domain_klo = domain.smallEnd(2); + const int domain_khi = domain.bigEnd(2); +#endif + + AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, + const auto& is_periodic_y = lev_geom.isPeriodic(1);, + const auto& is_periodic_z = lev_geom.isPeriodic(2);); + + Box const& bxg1 = amrex::grow(bx,1); + Box const& bxg2 = amrex::grow(bx,2); + Box const& bxg3 = amrex::grow(bx,3); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,2); + if (is_periodic_y) domain_per_grown.grow(1,2); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,2); +#endif + + amrex::ParallelFor(bxg1, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) + { + int max_order = 2; + + for (int n = 0; n < ncomp; n++) + { + bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); + bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); + bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); + bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); +#if (AMREX_SPACEDIM == 3) + bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); + bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); +#endif + // Initialize so that the slope stencil goes from -1:1 in each diretion + int nx = 1; int ny = 1; int nz = 1; + + // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil + // or do we need to enlarge it? + AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, + Real y_max = -1.e30; Real y_min = 1.e30;, + Real z_max = -1.e30; Real z_min = 1.e30;); + + Real slope_stencil_min_width = 0.5; +#if (AMREX_SPACEDIM == 2) + int kk = 0; +#elif (AMREX_SPACEDIM == 3) + for(int kk(-1); kk<=1; kk++) +#endif + { + for(int jj(-1); jj<=1; jj++) + for(int ii(-1); ii<=1; ii++) + if (flag(i,j,k).isConnected(ii,jj,kk)) + { + int r = i+ii; int s = j+jj; int t = k+kk; + + x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); + x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); + y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); + y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); +#if (AMREX_SPACEDIM == 3) + z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); + z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); +#endif + } + } + // If we need to grow the stencil, we let it be -nx:nx in the x-direction, + // for example. Note that nx,ny,nz are either 1 or 2 + if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; + if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; +#if (AMREX_SPACEDIM == 3) + if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; +#endif + + amrex::GpuArray slopes_eb; + if (nx*ny*nz == 1) + // Compute slope using 3x3x3 stencil + slopes_eb = amrex_calc_slopes_extdir_eb( + i,j,k,n,U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + else + { + // Compute slope using grown stencil (no larger than 5x5x5) + slopes_eb = amrex_calc_slopes_extdir_eb_grown( + i,j,k,n,AMREX_D_DECL(nx,ny,nz), + U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + } + + // We do the limiting separately because this limiter limits the slope based on the values + // extrapolated to the cell centroid locations - unlike the limiter in amrex + // which bases the limiting on values extrapolated to the face centroids. + amrex::GpuArray lim_slope = + amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); + + AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, + lim_slope[1] *= slopes_eb[1];, + lim_slope[2] *= slopes_eb[2];); + + // Add to the cell itself + if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) + { + if (n == 0 and j < 80) + { + prof_ptr[i] = U_in(i,j,k,n) + + lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + + lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); + xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); + } + + } // if bx contains + } // n + } // vfrac + }); + + for (int i = 0; i < 64; i++) + { + amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; + } + +} +/** @} */ diff --git a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack new file mode 100644 index 000000000..959c90632 --- /dev/null +++ b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack @@ -0,0 +1,466 @@ +/** + * \file hydro_redistribution.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include +#include + +#include +#if (AMREX_SPACEDIM == 2) +#include +#elif (AMREX_SPACEDIM == 3) +#include +#endif + +using namespace amrex; + +void Redistribution::Apply ( Box const& bx, int ncomp, + Array4 const& dUdt_out, + Array4 const& dUdt_in, + Array4 const& U_in, + Array4 const& scratch, + Array4 const& flag, + AMREX_D_DECL(Array4 const& apx, + Array4 const& apy, + Array4 const& apz), + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& bcc, + Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom, Real dt, + std::string redistribution_type, + amrex::Real target_volfrac) +{ + // redistribution_type = "NoRedist"; // no redistribution + // redistribution_type = "FluxRedist" // flux_redistribute + // redistribution_type = "StateRedist"; // state redistribute + // redistribution_type = "NewStateRedist"; // new form of state redistribute with alpha-weightings and + // alternative slope calculations + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = 0.; + }); + + if (redistribution_type == "FluxRedist") + { + int icomp = 0; + apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) *= dt; + dUdt_out(i,j,k,n) += U_in(i,j,k,n); + } + ); + + // Make sure to call this while dUdt_out is still the full state, not the increment + Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, + lev_geom); +amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) -= U_in(i,j,k,n); + dUdt_out(i,j,k,n) /= dt; + } + ); + + } else if (redistribution_type == "StateRedist" or redistribution_type == "NewStateRedist") { + + Box const& bxg1 = grow(bx,1); + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); + // How many nbhds is a cell in +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + Box domain_per_grown = lev_geom.Domain(); + AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, + if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, + if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); + + // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 + // in the cells just outside the domain because those values will be used + // in the slope computation in state redistribution. We assume here that + // the ext_dir values of U_in itself have already been set. + if (!domain_per_grown.contains(bxg1)) + amrex::ParallelFor(bxg1,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) + dUdt_in(i,j,k,n) = 0.; + }); + + amrex::ParallelFor(Box(scratch), ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n); + } + ); + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + if (redistribution_type == "StateRedist") + { + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, nbhd_vol, cent_hat, lev_geom); + + StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, nbhd_vol_const, cent_hat_const, lev_geom); + } else { + + MakeNewStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + NewStateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); + } + + // Make sure to call this while dUdt_out is still the full state, not the increment + Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, + lev_geom); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + // Only update the values which actually changed -- this makes + // the results insensitive to tiling -- otherwise cells that aren't + // changed but are in a tile on which StateRedistribute gets called + // will have precision-level changes due to adding/subtracting U_in + // and multiplying/dividing by dt. Here we test on whether (i,j,k) + // has at least one neighbor and/or whether (i,j,k) is in the + // neighborhood of another cell -- if either of those is true the + // value may have changed + + if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) + { + dUdt_out(i,j,k,n) = (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; + } + else + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + } + ); + + } else if (redistribution_type == "NoRedist") { + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + ); + + } else { + amrex::Error("Not a legit redist_type"); + } + +} + +void +Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, + Array4 const& U_out, + Array4 const& U_in, + Array4 const& flag, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry& lev_geom, std::string redistribution_type, + amrex::Real target_volfrac) +{ + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + U_out(i,j,k,n) = 0.; + }); + + if (redistribution_type == "StateRedist" || redistribution_type == "NewStateRedist") { + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + if (redistribution_type == "StateRedist") + { + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, nbhd_vol, cent_hat, lev_geom); + + StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, nbhd_vol_const, cent_hat_const, lev_geom); + } else { + + MakeNewStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + NewStateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); + } + + + } else { + amrex::Error("Redistribution::ApplyToInitialData: Shouldn't be here with this redist type"); + } +} + +void +Redistribution::Make1DProfile ( Box const& bx, int ncomp, + Array4 const& U_in, + Array4 const& flag, + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& bcent, + Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom) +{ + amrex::Vector profile; + amrex::Vector xloc; + profile.resize(64,0.0); + xloc.resize(64,0.0); + + amrex::Real* prof_ptr = profile.data(); + amrex::Real* xloc_ptr = xloc.data(); + + const Box domain = lev_geom.Domain(); + const int domain_ilo = domain.smallEnd(0); + const int domain_ihi = domain.bigEnd(0); + const int domain_jlo = domain.smallEnd(1); + const int domain_jhi = domain.bigEnd(1); +#if (AMREX_SPACEDIM == 3) + const int domain_klo = domain.smallEnd(2); + const int domain_khi = domain.bigEnd(2); +#endif + + AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, + const auto& is_periodic_y = lev_geom.isPeriodic(1);, + const auto& is_periodic_z = lev_geom.isPeriodic(2);); + + Box const& bxg1 = amrex::grow(bx,1); + Box const& bxg2 = amrex::grow(bx,2); + Box const& bxg3 = amrex::grow(bx,3); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,2); + if (is_periodic_y) domain_per_grown.grow(1,2); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,2); +#endif + + amrex::ParallelFor(bxg1, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) + { + int max_order = 2; + + for (int n = 0; n < ncomp; n++) + { + bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); + bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); + bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); + bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); +#if (AMREX_SPACEDIM == 3) + bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); + bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); +#endif + // Initialize so that the slope stencil goes from -1:1 in each diretion + int nx = 1; int ny = 1; int nz = 1; + + // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil + // or do we need to enlarge it? + AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, + Real y_max = -1.e30; Real y_min = 1.e30;, + Real z_max = -1.e30; Real z_min = 1.e30;); + + Real slope_stencil_min_width = 0.5; +#if (AMREX_SPACEDIM == 2) + int kk = 0; +#elif (AMREX_SPACEDIM == 3) + for(int kk(-1); kk<=1; kk++) +#endif + { + for(int jj(-1); jj<=1; jj++) + for(int ii(-1); ii<=1; ii++) + if (flag(i,j,k).isConnected(ii,jj,kk)) + { + int r = i+ii; int s = j+jj; int t = k+kk; + + x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); + x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); + y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); + y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); +#if (AMREX_SPACEDIM == 3) + z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); + z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); +#endif + } + } + // If we need to grow the stencil, we let it be -nx:nx in the x-direction, + // for example. Note that nx,ny,nz are either 1 or 2 + if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; + if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; +#if (AMREX_SPACEDIM == 3) + if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; +#endif + + amrex::GpuArray slopes_eb; + if (nx*ny*nz == 1) + // Compute slope using 3x3x3 stencil + slopes_eb = amrex_calc_slopes_extdir_eb( + i,j,k,n,U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + else + { + // Compute slope using grown stencil (no larger than 5x5x5) + slopes_eb = amrex_calc_slopes_extdir_eb_grown( + i,j,k,n,AMREX_D_DECL(nx,ny,nz), + U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + } + + // We do the limiting separately because this limiter limits the slope based on the values + // extrapolated to the cell centroid locations - unlike the limiter in amrex + // which bases the limiting on values extrapolated to the face centroids. + amrex::GpuArray lim_slope = + amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); + + AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, + lim_slope[1] *= slopes_eb[1];, + lim_slope[2] *= slopes_eb[2];); + + // Add to the cell itself + if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) + { + if (n == 0 and j < 80) + { + prof_ptr[i] = U_in(i,j,k,n) + + lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + + lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); + xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); + } + + } // if bx contains + } // n + } // vfrac + }); + + for (int i = 0; i < 64; i++) + { + amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; + } + +} +/** @} */ diff --git a/Diagnostics/Redistribution/Make.package b/Diagnostics/Redistribution/Make.package new file mode 100644 index 000000000..301f9a857 --- /dev/null +++ b/Diagnostics/Redistribution/Make.package @@ -0,0 +1,7 @@ +CEXE_sources += hydro_create_itracker_$(DIM)d.cpp +CEXE_sources += hydro_redistribution.cpp +CEXE_sources += hydro_state_redistribute.cpp +CEXE_sources += hydro_state_utils.cpp + +CEXE_headers += hydro_redistribution.H +CEXE_headers += hydro_slope_limiter_K.H diff --git a/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp b/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp new file mode 100644 index 000000000..8a0c19f42 --- /dev/null +++ b/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp @@ -0,0 +1,223 @@ +/** + * \file hydro_create_itracker_2d.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include + +using namespace amrex; + +#if (AMREX_SPACEDIM == 2) + +void +Redistribution::MakeITracker ( Box const& bx, + Array4 const& apx, + Array4 const& apy, + Array4 const& vfrac, + Array4 const& itracker, + Geometry const& lev_geom, + Real target_volfrac) +{ +#if 0 + int debug_verbose = 0; +#endif + + const Real small_norm_diff = 1.e-8; + + const Box domain = lev_geom.Domain(); + + // Note that itracker has 4 components and all are initialized to zero + // We will add to the first component every time this cell is included in a merged neighborhood, + // either by merging or being merged + // We identify the cells in the remaining three components with the following ordering + // + // ^ 6 7 8 + // | 4 5 + // j 1 2 3 + // i ---> + + Array imap{0,-1,0,1,-1,1,-1,0,1}; + Array jmap{0,-1,-1,-1,0,0,1,1,1}; + + const auto& is_periodic_x = lev_geom.isPeriodic(0); + const auto& is_periodic_y = lev_geom.isPeriodic(1); + +// if (debug_verbose > 0) +// amrex::Print() << " IN MAKE_ITRACKER DOING BOX " << bx << std::endl; + + amrex::ParallelFor(Box(itracker), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + itracker(i,j,k,0) = 0; + }); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,4); + if (is_periodic_y) domain_per_grown.grow(1,4); + + Box const& bxg4 = amrex::grow(bx,4); + Box bx_per_g4= domain_per_grown & bxg4; + + amrex::ParallelFor(bx_per_g4, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (i == 0 and apx(i,j,k) != 1.0 and apx(i,j,k) != 0.0) amrex::Print() << "APX " << j << " " << + apx(i,j,k) << " " << apx(i+1,j,k) << " " << apy(i,j,k) << " " << apy(i,j+1,k) << " " << vfrac(i,j,k) << std::endl; + if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < target_volfrac) + { + Real apnorm, apnorm_inv; + const Real dapx = apx(i+1,j ,k ) - apx(i,j,k); + const Real dapy = apy(i ,j+1,k ) - apy(i,j,k); + apnorm = std::sqrt(dapx*dapx+dapy*dapy); + apnorm_inv = 1.0/apnorm; + Real nx = dapx * apnorm_inv; + Real ny = dapy * apnorm_inv; + + bool nx_eq_ny = ( (std::abs(nx-ny) < small_norm_diff) || + (std::abs(nx+ny) < small_norm_diff) ) ? true : false; + + // As a first pass, choose just based on the normal + if (std::abs(nx) > std::abs(ny)) + { + if (nx > 0) + itracker(i,j,k,1) = 5; + else + itracker(i,j,k,1) = 4; + + } else { + if (ny > 0) + itracker(i,j,k,1) = 7; + else + itracker(i,j,k,1) = 2; + } + + bool xdir_mns_ok = (is_periodic_x || (i > domain.smallEnd(0))); + bool xdir_pls_ok = (is_periodic_x || (i < domain.bigEnd(0) )); + bool ydir_mns_ok = (is_periodic_y || (j > domain.smallEnd(1))); + bool ydir_pls_ok = (is_periodic_y || (j < domain.bigEnd(1) )); + + // Override above logic if trying to reach outside a domain boundary (and non-periodic) + if ( (!xdir_mns_ok && (itracker(i,j,k,1) == 4)) || + (!xdir_pls_ok && (itracker(i,j,k,1) == 5)) ) + { + itracker(i,j,k,1) = (ny > 0) ? 7 : 2; + } + if ( (!ydir_mns_ok && (itracker(i,j,k,1) == 2)) || + (!ydir_pls_ok && (itracker(i,j,k,1) == 7)) ) + { + itracker(i,j,k,1) = (nx > 0) ? 5 : 4; + } + + // (i,j) merges with at least one cell now + itracker(i,j,k,0) += 1; + + // (i+ioff,j+joff) is in the nbhd of (i,j) + int ioff = imap[itracker(i,j,k,1)]; + int joff = jmap[itracker(i,j,k,1)]; + + // Sanity check + if (vfrac(i+ioff,j+joff,k) == 0.) + amrex::Abort(" Trying to merge with covered cell"); + + Real sum_vol = vfrac(i,j,k) + vfrac(i+ioff,j+joff,k); + +#if 0 + if (debug_verbose > 0) + amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << + " trying to merge with " << IntVect(i+ioff,j+joff) << + " with volfrac " << vfrac(i+ioff,j+joff,k) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + + // If the merged cell isn't large enough, we try to merge in the other direction + if (sum_vol < target_volfrac || nx_eq_ny) + { + // Original offset was in y-direction, so we will add to the x-direction + // Note that if we can't because it would go outside the domain, we don't + if (ioff == 0) { + if (nx >= 0 && xdir_pls_ok) + { + itracker(i,j,k,2) = 5; + itracker(i,j,k,0) += 1; + } + else if (nx <= 0 && xdir_mns_ok) + { + itracker(i,j,k,2) = 4; + itracker(i,j,k,0) += 1; + } + + // Original offset was in x-direction, so we will add to the y-direction + // Note that if we can't because it would go outside the domain, we don't + } else { + if (ny >= 0 && ydir_pls_ok) + { + itracker(i,j,k,2) = 7; + itracker(i,j,k,0) += 1; + } + else if (ny <= 0 && ydir_mns_ok) + { + itracker(i,j,k,2) = 2; + itracker(i,j,k,0) += 1; + } + } + + if (itracker(i,j,k,0) > 1) + { + // (i+ioff2,j+joff2) is in the nbhd of (i,j) + int ioff2 = imap[itracker(i,j,k,2)]; + int joff2 = jmap[itracker(i,j,k,2)]; + + sum_vol += vfrac(i+ioff2,j+joff2,k); +#if 0 + if (debug_verbose > 0) + amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << + " trying to ALSO merge with " << IntVect(i+ioff2,j+joff2) << + " with volfrac " << vfrac(i+ioff2,j+joff2,k) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + } + } + + // Now we merge in the corner direction if we have already claimed two + if (itracker(i,j,k,0) == 2) + { + // We already have two offsets, and we know they are in different directions + ioff = imap[itracker(i,j,k,1)] + imap[itracker(i,j,k,2)]; + joff = jmap[itracker(i,j,k,1)] + jmap[itracker(i,j,k,2)]; + + if (ioff > 0 && joff > 0) + itracker(i,j,k,3) = 8; + else if (ioff < 0 && joff > 0) + itracker(i,j,k,3) = 6; + else if (ioff > 0 && joff < 0) + itracker(i,j,k,3) = 3; + else + itracker(i,j,k,3) = 1; + + // (i,j) merges with at least three cells now + itracker(i,j,k,0) += 1; + + sum_vol += vfrac(i+ioff,j+joff,k); +#if 0 + if (debug_verbose > 0) + amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << + " trying to ALSO merge with " << IntVect(i+ioff,j+joff) << + " with volfrac " << vfrac(i+ioff,j+joff,k) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + } + if (sum_vol < target_volfrac) + { +#if 0 + amrex::Print() << "Couldnt merge with enough cells to raise volume at " << + IntVect(i,j) << " so stuck with sum_vol " << sum_vol << std::endl; +#endif + amrex::Abort("Couldnt merge with enough cells to raise volume greater than target_volfrac"); + } + } + }); +} +#endif +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp b/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp new file mode 100644 index 000000000..d713e7c82 --- /dev/null +++ b/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp @@ -0,0 +1,500 @@ +/** + * \file hydro_create_itracker_3d.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include + +using namespace amrex; + +#if (AMREX_SPACEDIM == 3) +void +Redistribution::MakeITracker ( Box const& bx, + Array4 const& apx, + Array4 const& apy, + Array4 const& apz, + Array4 const& vfrac, + Array4 const& itracker, + Geometry const& lev_geom, + Real target_volfrac) +{ +#if 0 + bool debug_print = false; +#endif + + const Real small_norm_diff = 1.e-8; + + const Box domain = lev_geom.Domain(); + + // Note that itracker has 8 components and all are initialized to zero + // We will add to the first component every time this cell is included in a merged neighborhood, + // either by merging or being merged + // We identify the cells in the remaining three components with the following ordering + // + // at k-1 | at k | at k+1 + // + // ^ 15 16 17 | 6 7 8 | 24 25 26 + // | 12 13 14 | 4 5 | 21 22 23 + // j 9 10 11 | 1 2 3 | 18 19 20 + // i ---> + // + // Note the first component of each of these arrays should never be used + Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; + Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; + Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; + + const auto& is_periodic_x = lev_geom.isPeriodic(0); + const auto& is_periodic_y = lev_geom.isPeriodic(1); + const auto& is_periodic_z = lev_geom.isPeriodic(2); + +#if 0 + if (debug_print) + amrex::Print() << " IN MERGE_REDISTRIBUTE DOING BOX " << bx << std::endl; +#endif + + amrex::ParallelFor(Box(itracker), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + itracker(i,j,k,0) = 0; + }); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,4); + if (is_periodic_y) domain_per_grown.grow(1,4); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,4); +#endif + + Box const& bxg4 = amrex::grow(bx,4); + Box bx_per_g4= domain_per_grown & bxg4; + + amrex::ParallelFor(bx_per_g4, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < target_volfrac) + { + Real apnorm, apnorm_inv; + const Real dapx = apx(i+1,j ,k ) - apx(i,j,k); + const Real dapy = apy(i ,j+1,k ) - apy(i,j,k); + const Real dapz = apz(i ,j ,k+1) - apz(i,j,k); + apnorm = std::sqrt(dapx*dapx+dapy*dapy+dapz*dapz); + apnorm_inv = 1.0/apnorm; + Real nx = dapx * apnorm_inv; + Real ny = dapy * apnorm_inv; + Real nz = dapz * apnorm_inv; + + bool nx_eq_ny = ( (std::abs(nx-ny) < small_norm_diff) || + (std::abs(nx+ny) < small_norm_diff) ) ? true : false; + bool nx_eq_nz = ( (std::abs(nx-nz) < small_norm_diff) || + (std::abs(nx+nz) < small_norm_diff) ) ? true : false; + bool ny_eq_nz = ( (std::abs(ny-nz) < small_norm_diff) || + (std::abs(ny+nz) < small_norm_diff) ) ? true : false; + + bool xdir_mns_ok = (is_periodic_x || (i > domain.smallEnd(0))); + bool xdir_pls_ok = (is_periodic_x || (i < domain.bigEnd(0) )); + bool ydir_mns_ok = (is_periodic_y || (j > domain.smallEnd(1))); + bool ydir_pls_ok = (is_periodic_y || (j < domain.bigEnd(1) )); + bool zdir_mns_ok = (is_periodic_z || (k > domain.smallEnd(2))); + bool zdir_pls_ok = (is_periodic_z || (k < domain.bigEnd(2) )); + + // x-component of normal is greatest + if ( (std::abs(nx) > std::abs(ny)) && + (std::abs(nx) > std::abs(nz)) ) + { + if (nx > 0) + itracker(i,j,k,1) = 5; + else + itracker(i,j,k,1) = 4; + + // y-component of normal is greatest + } else if ( (std::abs(ny) >= std::abs(nx)) && + (std::abs(ny) > std::abs(nz)) ) + { + if (ny > 0) + itracker(i,j,k,1) = 7; + else + + itracker(i,j,k,1) = 2; + // z-component of normal is greatest + } else { + if (nz > 0) + itracker(i,j,k,1) = 22; + else + itracker(i,j,k,1) = 13; + } + + // Override above logic if trying to reach outside a domain boundary (and non-periodic) + if ( (!xdir_mns_ok && (itracker(i,j,k,1) == 4)) || + (!xdir_pls_ok && (itracker(i,j,k,1) == 5)) ) + { + if ( (std::abs(ny) > std::abs(nz)) ) + itracker(i,j,k,1) = (ny > 0) ? 7 : 2; + else + itracker(i,j,k,1) = (nz > 0) ? 22 : 13; + } + + if ( (!ydir_mns_ok && (itracker(i,j,k,1) == 2)) || + (!ydir_pls_ok && (itracker(i,j,k,1) == 7)) ) + { + if ( (std::abs(nx) > std::abs(nz)) ) + itracker(i,j,k,1) = (nx > 0) ? 5 : 4; + else + itracker(i,j,k,1) = (nz > 0) ? 22 : 13; + } + + if ( (!zdir_mns_ok && (itracker(i,j,k,1) == 13)) || + (!zdir_pls_ok && (itracker(i,j,k,1) == 22)) ) + { + if ( (std::abs(nx) > std::abs(ny)) ) + itracker(i,j,k,1) = (nx > 0) ? 5 : 4; + else + itracker(i,j,k,1) = (ny > 0) ? 7 : 2; + } + + // (i,j,k) merges with at least one cell now + itracker(i,j,k,0) += 1; + + // (i+ioff,j+joff,k+koff) is now the first cell in the nbhd of (i,j,k) + int ioff = imap[itracker(i,j,k,1)]; + int joff = jmap[itracker(i,j,k,1)]; + int koff = kmap[itracker(i,j,k,1)]; + + // Sanity check + if (vfrac(i+ioff,j+joff,k+koff) == 0.) + { + // amrex::Print() << "Cell " << IntVect(i,j,k) << " is trying to merge with cell " << IntVect(i+ioff,j+joff,k+koff) << std::endl; + amrex::Abort(" Trying to merge with covered cell"); + } + + Real sum_vol = vfrac(i,j,k) + vfrac(i+ioff,j+joff,k+koff); + +#if 0 + if (debug_print) + amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << + " trying to merge with " << IntVect(i+ioff,j+joff,k+koff) << + " with volfrac " << vfrac(i+ioff,j+joff,k+koff) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + + bool just_broke_symmetry = ( ( (joff == 0 && koff == 0) && (nx_eq_ny || nx_eq_nz) ) || + ( (ioff == 0 && koff == 0) && (nx_eq_ny || ny_eq_nz) ) || + ( (ioff == 0 && joff == 0) && (nx_eq_nz || ny_eq_nz) ) ); + + // If the merged cell isn't large enough, or if we broke symmetry by the current merge, + // we merge in one of the other directions. Note that the direction of the next merge + // is first set by a symmetry break, but if that isn't happening, we choose the next largest normal + + if ( (sum_vol < target_volfrac) || just_broke_symmetry ) + { + // Original offset was in x-direction + if (joff == 0 && koff == 0) + { + if (nx_eq_ny) { + itracker(i,j,k,2) = (ny > 0) ? 7 : 2; + } else if (nx_eq_nz) { + itracker(i,j,k,2) = (nz > 0) ? 22 : 13; + } else if ( (std::abs(ny) > std::abs(nz)) ) { + itracker(i,j,k,2) = (ny > 0) ? 7 : 2; + } else { + itracker(i,j,k,2) = (nz > 0) ? 22 : 13; + } + + // Original offset was in y-direction + } else if (ioff == 0 && koff == 0) + { + if (nx_eq_ny) { + itracker(i,j,k,2) = (nx > 0) ? 5 : 4; + } else if (ny_eq_nz) { + itracker(i,j,k,2) = (nz > 0) ? 22 : 13; + } else if ( (std::abs(nx) > std::abs(nz)) ) { + itracker(i,j,k,2) = (nx > 0) ? 5 : 4; + } else { + itracker(i,j,k,2) = (nz > 0) ? 22 : 13; + } + + // Original offset was in z-direction + } else if (ioff == 0 && joff == 0) + { + if (nx_eq_nz) { + itracker(i,j,k,2) = (nx > 0) ? 5 : 4; + } else if (ny_eq_nz) { + itracker(i,j,k,2) = (ny > 0) ? 7 : 2; + } else if ( (std::abs(nx) > std::abs(ny)) ) { + itracker(i,j,k,2) = (nx > 0) ? 5 : 4; + } else { + itracker(i,j,k,2) = (ny > 0) ? 7 : 2; + } + } + + // (i,j,k) merges with at least two cells now + itracker(i,j,k,0) += 1; + + // (i+ioff2,j+joff2,k+koff2) is in the nbhd of (i,j,k) + int ioff2 = imap[itracker(i,j,k,2)]; + int joff2 = jmap[itracker(i,j,k,2)]; + int koff2 = kmap[itracker(i,j,k,2)]; + + sum_vol += vfrac(i+ioff2,j+joff2,k+koff2); +#if 0 + if (debug_print) + amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << + " trying to ALSO merge with " << IntVect(i+ioff2,j+joff2,k+koff2) << + " with volfrac " << vfrac(i+ioff2,j+joff2,k+koff2) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + } + + // If the merged cell has merged in two directions, we now merge in the corner direction within the current plane + if (itracker(i,j,k,0) >= 2) + { + // We already have two offsets, and we know they are in different directions + ioff = imap[itracker(i,j,k,1)] + imap[itracker(i,j,k,2)]; + joff = jmap[itracker(i,j,k,1)] + jmap[itracker(i,j,k,2)]; + koff = kmap[itracker(i,j,k,1)] + kmap[itracker(i,j,k,2)]; + + // Both nbors are in the koff=0 plane + if (koff == 0) + { + if (ioff > 0 && joff > 0) + itracker(i,j,k,3) = 8; + else if (ioff < 0 && joff > 0) + itracker(i,j,k,3) = 6; + else if (ioff > 0 && joff < 0) + itracker(i,j,k,3) = 3; + else + itracker(i,j,k,3) = 1; + + // Both nbors are in the joff=0 plane + } else if (joff == 0) { + if (ioff > 0 && koff > 0) + itracker(i,j,k,3) = 23; + else if (ioff < 0 && koff > 0) + itracker(i,j,k,3) = 21; + else if (ioff > 0 && koff < 0) + itracker(i,j,k,3) = 14; + else + itracker(i,j,k,3) = 12; + + // Both nbors are in the ioff=0 plane + } else { + if (joff > 0 && koff > 0) + itracker(i,j,k,3) = 25; + else if (joff < 0 && koff > 0) + itracker(i,j,k,3) = 19; + else if (joff > 0 && koff < 0) + itracker(i,j,k,3) = 16; + else + itracker(i,j,k,3) = 10; + } + + // (i,j,k) merges with at least three cells now + itracker(i,j,k,0) += 1; + + sum_vol += vfrac(i+ioff,j+joff,k+koff); + +#if 0 + int ioff3 = imap[itracker(i,j,k,3)]; + int joff3 = jmap[itracker(i,j,k,3)]; + int koff3 = kmap[itracker(i,j,k,3)]; + if (debug_print) + amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << + " trying to ALSO merge with " << IntVect(i+ioff3,j+joff3,k+koff3) << + " with volfrac " << vfrac(i+ioff3,j+joff3,k+koff3) << std::endl; +#endif + + // All nbors are currently in one of three planes + just_broke_symmetry = ( ( (koff == 0) && (nx_eq_nz || ny_eq_nz) ) || + ( (joff == 0) && (nx_eq_ny || ny_eq_nz) ) || + ( (ioff == 0) && (nx_eq_ny || nx_eq_nz) ) ); + + // If with a nbhd of four cells we have still not reached vfrac > target_volfrac, we add another four + // cells to the nbhd to make a 2x2x2 block. We use the direction of the remaining + // normal to know whether to go lo or hi in the new direction. + if (sum_vol < target_volfrac || just_broke_symmetry) + { +#if 0 + if (debug_print) + if (just_broke_symmetry) + amrex::Print() << "Expanding neighborhood of " << IntVect(i,j,k) << + " from 4 to 8 since we just broke symmetry with the last merge " << std::endl; + else + amrex::Print() << "Expanding neighborhood of " << IntVect(i,j,k) << + " from 4 to 8 since sum_vol with 4 was only " << sum_vol << " " << std::endl; +#endif + // All nbors are currently in the koff=0 plane + if (koff == 0) + { + if (nz > 0) + { + itracker(i,j,k,4) = 22; + + if (ioff > 0) + itracker(i,j,k,5) = 23; + else + itracker(i,j,k,5) = 21; + if (joff > 0) + itracker(i,j,k,6) = 25; + else + itracker(i,j,k,6) = 19; + + if (ioff > 0 && joff > 0) { + itracker(i,j,k,7) = 26; + } else if (ioff < 0 && joff > 0) { + itracker(i,j,k,7) = 24; + } else if (ioff > 0 && joff < 0) { + itracker(i,j,k,7) = 20; + } else { + itracker(i,j,k,7) = 18; + } + } else { // nz <= 0 + + itracker(i,j,k,4) = 13; + + if (ioff > 0) + itracker(i,j,k,5) = 14; + else + itracker(i,j,k,5) = 12; + if (joff > 0) + itracker(i,j,k,6) = 16; + else + itracker(i,j,k,6) = 10; + + if (ioff > 0 && joff > 0) { + itracker(i,j,k,7) = 17; + } else if (ioff < 0 && joff > 0) { + itracker(i,j,k,7) = 15; + } else if (ioff > 0 && joff < 0) { + itracker(i,j,k,7) = 11; + } else { + itracker(i,j,k,7) = 9; + } + } + } else if (joff == 0) { + if (ny > 0) + { + itracker(i,j,k,4) = 7; + + if (ioff > 0) + itracker(i,j,k,5) = 8; + else + itracker(i,j,k,5) = 6; + if (koff > 0) + itracker(i,j,k,6) = 25; + else + itracker(i,j,k,6) = 16; + + if (ioff > 0 && koff > 0) { + itracker(i,j,k,7) = 26; + } else if (ioff < 0 && koff > 0) { + itracker(i,j,k,7) = 24; + } else if (ioff > 0 && koff < 0) { + itracker(i,j,k,7) = 17; + } else { + itracker(i,j,k,7) = 15; + } + + } else { // ny <= 0 + + itracker(i,j,k,4) = 2; + + if (ioff > 0) + itracker(i,j,k,5) = 3; + else + itracker(i,j,k,5) = 1; + if (koff > 0) + itracker(i,j,k,6) = 19; + else + itracker(i,j,k,6) = 10; + + if (ioff > 0 && koff > 0) { + itracker(i,j,k,7) = 20; + } else if (ioff < 0 && koff > 0) { + itracker(i,j,k,7) = 18; + } else if (ioff > 0 && koff < 0) { + itracker(i,j,k,7) = 11; + } else { + itracker(i,j,k,7) = 9; + } + } + } else if (ioff == 0) { + + if (nx > 0) + { + itracker(i,j,k,4) = 5; + + if (joff > 0) + itracker(i,j,k,5) = 8; + else + itracker(i,j,k,5) = 3; + if (koff > 0) + itracker(i,j,k,6) = 23; + else + itracker(i,j,k,6) = 14; + + if (joff > 0 && koff > 0) { + itracker(i,j,k,7) = 26; + } else if (joff < 0 && koff > 0) { + itracker(i,j,k,7) = 20; + } else if (joff > 0 && koff < 0) { + itracker(i,j,k,7) = 17; + } else { + itracker(i,j,k,7) = 11; + } + } else { // nx <= 0 + + itracker(i,j,k,4) = 4; + + if (joff > 0) + itracker(i,j,k,5) = 6; + else + itracker(i,j,k,5) = 1; + if (koff > 0) + itracker(i,j,k,6) = 21; + else + itracker(i,j,k,6) = 12; + + if (joff > 0 && koff > 0) { + itracker(i,j,k,7) = 24; + } else if (joff < 0 && koff > 0) { + itracker(i,j,k,7) = 18; + } else if (joff > 0 && koff < 0) { + itracker(i,j,k,7) = 15; + } else { + itracker(i,j,k,7) = 9; + } + } + } + + for(int n(4); n<8; n++){ + int ioffn = imap[itracker(i,j,k,n)]; + int joffn = jmap[itracker(i,j,k,n)]; + int koffn = kmap[itracker(i,j,k,n)]; + sum_vol += vfrac(i+ioffn,j+joffn,k+koffn); +#if 0 + if (debug_print) + amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << + " trying to ALSO merge with " << IntVect(i+ioffn,j+joffn,k+koffn) << + " with volfrac " << vfrac(i+ioffn,j+joffn,k+koffn) << + " to get new sum_vol " << sum_vol << std::endl; +#endif + } + + // (i,j,k) has a 2x2x2 neighborhood now + itracker(i,j,k,0) += 4; + } + } + if (sum_vol < target_volfrac) + { +#if 0 + amrex::Print() << "Couldnt merge with enough cells to raise volume at " << + IntVect(i,j,k) << " so stuck with sum_vol " << sum_vol << std::endl; +#endif + amrex::Abort("Couldnt merge with enough cells to raise volume greater than target_volfrac"); + } + } + }); +} +#endif +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_redistribution.H b/Diagnostics/Redistribution/hydro_redistribution.H new file mode 100644 index 000000000..57c51ea9b --- /dev/null +++ b/Diagnostics/Redistribution/hydro_redistribution.H @@ -0,0 +1,122 @@ +/** + * \file hydro_redistribution.H + * \addtogroup Redistribution + * @{ + * + */ + +#ifndef IAMR_REDISTRIBUTION_H_ +#define IAMR_REDISTRIBUTION_H_ + +#include +#include + +/** + * Placeholder description of Redistribution namespace. + * + */ + +namespace Redistribution { + + void Apply ( amrex::Box const& bx, int ncomp, + amrex::Array4 const& dUdt_out, + amrex::Array4 const& dUdt_in, + amrex::Array4 const& U_in, + amrex::Array4 const& scratch, + amrex::Array4 const& flag, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& bcent, + amrex::Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + amrex::Geometry const& geom, + amrex::Real dt, std::string redistribution_type, + const int srd_max_order = 2, + amrex::Real target_volfrac = 0.5, + amrex::Array4 const& update_scale={}); + + void ApplyToInitialData ( amrex::Box const& bx, int ncomp, + amrex::Array4 const& U_out, + amrex::Array4 const& U_in, + amrex::Array4 const& flag, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + amrex::Geometry& geom, std::string redistribution_type, + const int srd_max_order = 2, + amrex::Real target_volfrac = 0.5); + + void FluxRedistribute ( amrex::Box const& bx, int ncomp, + amrex::Array4 const& dUdt_out, + amrex::Array4 const& dUdt_in, + amrex::Array4 const& scratch, + amrex::Array4 const& flag, + amrex::Array4 const& vfrac, + amrex::Geometry const& geom); + + void StateRedistribute ( amrex::Box const& bx, int ncomp, + amrex::Array4 const& dUdt_out, + amrex::Array4 const& dUdt_in, + amrex::Array4 const& flag, + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + amrex::Array4 const& itracker, + amrex::Array4 const& nrs, + amrex::Array4 const& alpha, + amrex::Array4 const& nbhd_vol, + amrex::Array4 const& cent_hat, + amrex::Geometry const& geom, + const int max_order = 2); + + void MakeITracker ( amrex::Box const& bx, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + amrex::Array4 const& itracker, + amrex::Geometry const& geom, + amrex::Real target_volfrac); + + void MakeStateRedistUtils ( amrex::Box const& bx, + amrex::Array4 const& flag, + amrex::Array4 const& vfrac, + amrex::Array4 const& ccent, + amrex::Array4< int const> const& itracker, + amrex::Array4 const& nrs, + amrex::Array4 const& nbhd_vol, + amrex::Array4 const& alpha, + amrex::Array4 const& cent_hat, + amrex::Geometry const& geom, + amrex::Real target_volfrac); + + void Make1DProfile ( amrex::Box const& bx, int ncomp, + amrex::Array4 const& U_in, + amrex::Array4 const& flag, + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& bcent, + amrex::Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + amrex::Geometry const& lev_geom); + +} // namespace redistribution + +#endif +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_redistribution.cpp b/Diagnostics/Redistribution/hydro_redistribution.cpp new file mode 100644 index 000000000..b5e07d1ea --- /dev/null +++ b/Diagnostics/Redistribution/hydro_redistribution.cpp @@ -0,0 +1,446 @@ +/** + * \file hydro_redistribution.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include +#include + +#include +#if (AMREX_SPACEDIM == 2) +#include +#elif (AMREX_SPACEDIM == 3) +#include +#endif + +using namespace amrex; + +void Redistribution::Apply ( Box const& bx, int ncomp, + Array4 const& dUdt_out, + Array4 const& dUdt_in, + Array4 const& U_in, + Array4 const& scratch, + Array4 const& flag, + AMREX_D_DECL(Array4 const& apx, + Array4 const& apy, + Array4 const& apz), + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& bcc, + Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom, Real dt, + std::string redistribution_type, + const int srd_max_order, + amrex::Real target_volfrac, + Array4 const& srd_update_scale) +{ + // redistribution_type = "NoRedist"; // no redistribution + // redistribution_type = "FluxRedist" // flux_redistribute + // redistribution_type = "StateRedist"; // (weighted) state redistribute + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = 0.; + }); + + if (redistribution_type == "FluxRedist") + { + int icomp = 0; + apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) *= dt; + dUdt_out(i,j,k,n) += U_in(i,j,k,n); + } + ); + + // Make sure to call this while dUdt_out is still the full state, not the increment + Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, + lev_geom); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) -= U_in(i,j,k,n); + dUdt_out(i,j,k,n) /= dt; + } + ); + + } else if (redistribution_type == "StateRedist") { + + Box const& bxg1 = grow(bx,1); + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); + // How many nbhds is a cell in +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + Box domain_per_grown = lev_geom.Domain(); + AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, + if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, + if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); + + // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 + // in the cells just outside the domain because those values will be used + // in the slope computation in state redistribution. We assume here that + // the ext_dir values of U_in itself have already been set. + if (!domain_per_grown.contains(bxg1)) + amrex::ParallelFor(bxg1,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) + dUdt_in(i,j,k,n) = 0.; + }); + + amrex::ParallelFor(Box(scratch), ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + const Real scale = (srd_update_scale) ? srd_update_scale(i,j,k) : Real(1.0); + scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n) / scale; + } + ); + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, + cent_hat_const, lev_geom, srd_max_order); + + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + // Only update the values which actually changed -- this makes + // the results insensitive to tiling -- otherwise cells that aren't + // changed but are in a tile on which StateRedistribute gets called + // will have precision-level changes due to adding/subtracting U_in + // and multiplying/dividing by dt. Here we test on whether (i,j,k) + // has at least one neighbor and/or whether (i,j,k) is in the + // neighborhood of another cell -- if either of those is true the + // value may have changed + + if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) + { + const Real scale = (srd_update_scale) ? srd_update_scale(i,j,k) : Real(1.0); + + dUdt_out(i,j,k,n) = scale * (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; + + } + else + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + } + ); + + } else if (redistribution_type == "NoRedist") { + amrex::ParallelFor(bx, ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); + } + ); + + } else { + amrex::Error("Not a legit redist_type"); + } +} + +void +Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, + Array4 const& U_out, + Array4 const& U_in, + Array4 const& flag, + AMREX_D_DECL(amrex::Array4 const& apx, + amrex::Array4 const& apy, + amrex::Array4 const& apz), + amrex::Array4 const& vfrac, + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), + amrex::Array4 const& ccc, + amrex::BCRec const* d_bcrec_ptr, + Geometry& lev_geom, std::string redistribution_type, + const int srd_max_order, + amrex::Real target_volfrac) +{ + if (redistribution_type != "StateRedist") { + std::string msg = "Redistribution::ApplyToInitialData: Shouldn't be here with redist type "+redistribution_type; + amrex::Error(msg); + } + + Box const& bxg2 = grow(bx,2); + Box const& bxg3 = grow(bx,3); + Box const& bxg4 = grow(bx,4); + +#if (AMREX_SPACEDIM == 2) + // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,4); +#else + // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we + // use the first component of this for the number of neighbors + IArrayBox itracker(bxg4,8); +#endif + FArrayBox nrs_fab(bxg3,1); + FArrayBox alpha_fab(bxg3,2); + + // Total volume of all cells in my nbhd + FArrayBox nbhd_vol_fab(bxg2,1); + + // Centroid of my nbhd + FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); + + Elixir eli_itr = itracker.elixir(); + Array4 itr = itracker.array(); + Array4 itr_const = itracker.const_array(); + + Elixir eli_nrs = nrs_fab.elixir(); + Array4 nrs = nrs_fab.array(); + Array4 nrs_const = nrs_fab.const_array(); + + Elixir eli_alpha = alpha_fab.elixir(); + Array4 alpha = alpha_fab.array(); + Array4 alpha_const = alpha_fab.const_array(); + + Elixir eli_nbf = nbhd_vol_fab.elixir(); + Array4 nbhd_vol = nbhd_vol_fab.array(); + Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); + + Elixir eli_chf = cent_hat_fab.elixir(); + Array4 cent_hat = cent_hat_fab.array(); + Array4 cent_hat_const = cent_hat_fab.const_array(); + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + U_out(i,j,k,n) = 0.; + }); + + MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); + + MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, + lev_geom, target_volfrac); + + StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, + AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, + itr_const, nrs_const, alpha_const, nbhd_vol_const, + cent_hat_const, lev_geom, srd_max_order); +} + +void +Redistribution::Make1DProfile ( Box const& bx, int ncomp, + Array4 const& U_in, + Array4 const& flag, + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& bcent, + Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + Geometry const& lev_geom) +{ + amrex::Vector profile; + amrex::Vector xloc; + profile.resize(64,0.0); + xloc.resize(64,0.0); + + amrex::Real* prof_ptr = profile.data(); + amrex::Real* xloc_ptr = xloc.data(); + + const Box domain = lev_geom.Domain(); + const int domain_ilo = domain.smallEnd(0); + const int domain_ihi = domain.bigEnd(0); + const int domain_jlo = domain.smallEnd(1); + const int domain_jhi = domain.bigEnd(1); +#if (AMREX_SPACEDIM == 3) + const int domain_klo = domain.smallEnd(2); + const int domain_khi = domain.bigEnd(2); +#endif + + AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, + const auto& is_periodic_y = lev_geom.isPeriodic(1);, + const auto& is_periodic_z = lev_geom.isPeriodic(2);); + + Box const& bxg1 = amrex::grow(bx,1); + Box const& bxg2 = amrex::grow(bx,2); + Box const& bxg3 = amrex::grow(bx,3); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,2); + if (is_periodic_y) domain_per_grown.grow(1,2); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,2); +#endif + + amrex::ParallelFor(bxg1, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) + { + int max_order = 2; + + for (int n = 0; n < ncomp; n++) + { + bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); + bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); + bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); + bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); +#if (AMREX_SPACEDIM == 3) + bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); + bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); +#endif + // Initialize so that the slope stencil goes from -1:1 in each diretion + int nx = 1; int ny = 1; int nz = 1; + + // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil + // or do we need to enlarge it? + AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, + Real y_max = -1.e30; Real y_min = 1.e30;, + Real z_max = -1.e30; Real z_min = 1.e30;); + + Real slope_stencil_min_width = 0.5; +#if (AMREX_SPACEDIM == 2) + int kk = 0; +#elif (AMREX_SPACEDIM == 3) + for(int kk(-1); kk<=1; kk++) +#endif + { + for(int jj(-1); jj<=1; jj++) + for(int ii(-1); ii<=1; ii++) + if (flag(i,j,k).isConnected(ii,jj,kk)) + { + int r = i+ii; int s = j+jj; int t = k+kk; + + x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); + x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); + y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); + y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); +#if (AMREX_SPACEDIM == 3) + z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); + z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); +#endif + } + } + // If we need to grow the stencil, we let it be -nx:nx in the x-direction, + // for example. Note that nx,ny,nz are either 1 or 2 + if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; + if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; +#if (AMREX_SPACEDIM == 3) + if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; +#endif + + amrex::GpuArray slopes_eb; + if (nx*ny*nz == 1) + // Compute slope using 3x3x3 stencil + slopes_eb = amrex_calc_slopes_extdir_eb( + i,j,k,n,U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + else + { + // Compute slope using grown stencil (no larger than 5x5x5) + slopes_eb = amrex_calc_slopes_extdir_eb_grown( + i,j,k,n,AMREX_D_DECL(nx,ny,nz), + U_in,ccent,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + } + + // We do the limiting separately because this limiter limits the slope based on the values + // extrapolated to the cell centroid locations - unlike the limiter in amrex + // which bases the limiting on values extrapolated to the face centroids. + amrex::GpuArray lim_slope = + amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); + + AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, + lim_slope[1] *= slopes_eb[1];, + lim_slope[2] *= slopes_eb[2];); + + // Add to the cell itself + if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) + { + if (n == 0 and j > 40) + { + prof_ptr[i] = U_in(i,j,k,n) + + lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + + lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); + xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); + } + + } // if bx contains + } // n + } // vfrac + }); + + for (int i = 0; i < 64; i++) + { + amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; + } + +} +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_slope_limiter_K.H b/Diagnostics/Redistribution/hydro_slope_limiter_K.H new file mode 100644 index 000000000..aa9af8a89 --- /dev/null +++ b/Diagnostics/Redistribution/hydro_slope_limiter_K.H @@ -0,0 +1,86 @@ +/** + * \file hydro_slope_limiter_K.H + * \addtogroup Redistribution + * @{ + * + */ + +using namespace amrex; + +namespace { + constexpr Real epsilon = 1.e-12; +} + +AMREX_GPU_DEVICE AMREX_FORCE_INLINE +amrex::Real +amrex_calc_alpha_stencil(Real q_hat, Real q_max, Real q_min, Real state) noexcept +{ + const Real small = epsilon*amrex::max(amrex::Math::abs(q_max),amrex::Math::abs(q_min)); + Real alpha; + + if ((q_hat-state) > small) { + alpha = amrex::min(1.0_rt,(q_max-state)/(q_hat-state)); + } else if ((q_hat-state) < -small) { + alpha = amrex::min(1.0_rt,(q_min-state)/(q_hat-state)); + } else { + alpha = 1.0_rt; + } + return alpha; +} + +AMREX_GPU_DEVICE AMREX_FORCE_INLINE +amrex::GpuArray +amrex_calc_centroid_limiter(int i, int j, int k, int n, + amrex::Array4 const& state, + amrex::Array4 const& flag, + const amrex::GpuArray& slopes, + amrex::Array4 const& ccent) noexcept +{ + AMREX_D_TERM(amrex::Real xalpha = 1.0;, + amrex::Real yalpha = 1.0;, + amrex::Real zalpha = 1.0;); + + // Compute the limiters needed to keep the predicted q_hat between the max and min +#if (AMREX_SPACEDIM == 2) + int kk = 0; +#elif (AMREX_SPACEDIM == 3) + for(int kk(-1); kk<=1; kk++) +#endif + { + for(int jj(-1); jj<=1; jj++){ + for(int ii(-1); ii<=1; ii++){ + Real alpha = amrex::max(xalpha,yalpha); +#if (AMREX_SPACEDIM == 3) + alpha = amrex::max(alpha,zalpha); +#endif + if (flag(i,j,k).isConnected(ii,jj,kk) && alpha > 0.0) + { + AMREX_D_TERM(Real delta_x = ccent(i+ii,j+jj,k+kk,0) - ccent(i,j,k,0) + static_cast(ii);, + Real delta_y = ccent(i+ii,j+jj,k+kk,1) - ccent(i,j,k,1) + static_cast(jj);, + Real delta_z = ccent(i+ii,j+jj,k+kk,2) - ccent(i,j,k,2) + static_cast(kk);); + + Real q_hat = state(i,j,k,n) + AMREX_D_TERM( delta_x * slopes[0], + + delta_y * slopes[1], + + delta_z * slopes[2]); + + Real q_max = amrex::max(state(i+ii,j+jj,k+kk,n),state(i,j,k,n)); + Real q_min = amrex::min(state(i+ii,j+jj,k+kk,n),state(i,j,k,n)); + + if ( q_hat-q_max > amrex::Math::abs(epsilon*q_max) || q_hat-q_min < -1.0*amrex::Math::abs(epsilon*q_min) ) + { + Real new_lim = amrex_calc_alpha_stencil(q_hat, q_max, q_min, state(i,j,k,n)); + + if (amrex::Math::abs(delta_x) > epsilon) xalpha = amrex::min(xalpha,new_lim); + if (amrex::Math::abs(delta_y) > epsilon) yalpha = amrex::min(yalpha,new_lim); +#if (AMREX_SPACEDIM == 3) + if (amrex::Math::abs(delta_z) > epsilon) zalpha = amrex::min(zalpha,new_lim); +#endif + } + } + } + } + } + + return {AMREX_D_DECL(xalpha,yalpha,zalpha)}; +} +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_state_redistribute.cpp b/Diagnostics/Redistribution/hydro_state_redistribute.cpp new file mode 100644 index 000000000..be9866d84 --- /dev/null +++ b/Diagnostics/Redistribution/hydro_state_redistribute.cpp @@ -0,0 +1,324 @@ +/** + * \file hydro_state_redistribute.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include +#include +#if (AMREX_SPACEDIM == 2) +#include +#elif (AMREX_SPACEDIM == 3) +#include +#endif + +using namespace amrex; + + +void +Redistribution::StateRedistribute ( Box const& bx, int ncomp, + Array4 const& U_out, + Array4 const& U_in, + Array4 const& flag, + Array4 const& vfrac, + AMREX_D_DECL(Array4 const& fcx, + Array4 const& fcy, + Array4 const& fcz), + Array4 const& ccent, + amrex::BCRec const* d_bcrec_ptr, + Array4< int const> const& itracker, + Array4 const& nrs, + Array4 const& alpha, + Array4 const& nbhd_vol, + Array4 const& cent_hat, + Geometry const& lev_geom, + const int max_order) +{ + // Note that itracker has {4 in 2D, 8 in 3D} components and all are initialized to zero + // We will add to the first component every time this cell is included in a merged neighborhood, + // either by merging or being merged + // + // In 2D, we identify the cells in the remaining three components with the following ordering + // + // ^ 6 7 8 + // | 4 5 + // j 1 2 3 + // i ---> + // + // In 3D, We identify the cells in the remaining three components with the following ordering + // + // at k-1 | at k | at k+1 + // + // ^ 15 16 17 | 6 7 8 | 24 25 26 + // | 12 13 14 | 4 5 | 21 22 23 + // j 9 10 11 | 1 2 3 | 18 19 20 + // i ---> + // + // Note the first component of each of these arrays should never be used + // +#if (AMREX_SPACEDIM == 2) + amrex::GpuArray imap{0,-1, 0, 1,-1, 1,-1, 0, 1}; + amrex::GpuArray jmap{0,-1,-1,-1, 0, 0, 1, 1, 1}; + amrex::GpuArray kmap{0, 0, 0, 0, 0, 0, 0, 0, 0}; +#else + amrex::GpuArray imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; + amrex::GpuArray jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; + amrex::GpuArray kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +#endif + + const Box domain = lev_geom.Domain(); + const int domain_ilo = domain.smallEnd(0); + const int domain_ihi = domain.bigEnd(0); + const int domain_jlo = domain.smallEnd(1); + const int domain_jhi = domain.bigEnd(1); +#if (AMREX_SPACEDIM == 3) + const int domain_klo = domain.smallEnd(2); + const int domain_khi = domain.bigEnd(2); +#endif + + AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, + const auto& is_periodic_y = lev_geom.isPeriodic(1);, + const auto& is_periodic_z = lev_geom.isPeriodic(2);); + + // amrex::Print() << " IN STATE_REDISTRIBUTE DOING BOX " << bx << " with ncomp " << ncomp << std::endl; + // amrex::Print() << " Box(U_in) " << Box(U_in) << std::endl; + // amrex::Print() << " Box(U_out) " << Box(U_out) << std::endl; + + Box const& bxg1 = amrex::grow(bx,1); + Box const& bxg2 = amrex::grow(bx,2); + Box const& bxg3 = amrex::grow(bx,3); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,2); + if (is_periodic_y) domain_per_grown.grow(1,2); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,2); +#endif + + // Solution at the centroid of my nbhd + FArrayBox soln_hat_fab (bxg3,ncomp); + Array4 soln_hat = soln_hat_fab.array(); + Elixir eli_soln_hat = soln_hat_fab.elixir(); + + // Define Qhat (from Berger and Guliani) + // Here we initialize soln_hat to equal U_in on all cells in bxg3 so that + // in the event we need to use soln_hat 3 cells out from the bx limits + // in a modified slope computation, we have a value of soln_hat to use. + // But we only modify soln_hat inside bxg2 + amrex::ParallelFor(bxg3, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + for (int n = 0; n < ncomp; n++) + soln_hat(i,j,k,n) = U_in(i,j,k,n); + + if (vfrac(i,j,k) > 0.0 && bxg2.contains(IntVect(AMREX_D_DECL(i,j,k))) + && domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) { + + // Start with U_in(i,j,k) itself + for (int n = 0; n < ncomp; n++) + soln_hat(i,j,k,n) = U_in(i,j,k,n) * alpha(i,j,k,0) * vfrac(i,j,k); + + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + + if (domain_per_grown.contains(IntVect(AMREX_D_DECL(r,s,t)))) + { + for (int n = 0; n < ncomp; n++) + soln_hat(i,j,k,n) += U_in(r,s,t,n) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t); + } + } + for (int n = 0; n < ncomp; n++) + soln_hat(i,j,k,n) /= nbhd_vol(i,j,k); + } + }); + + amrex::ParallelFor(bxg1, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0) + { + int num_nbors = itracker(i,j,k,0); + + if (itracker(i,j,k,0) == 0) + { + if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) + { + for (int n = 0; n < ncomp; n++) + amrex::Gpu::Atomic::Add(&U_out(i,j,k,n),alpha(i,j,k,0)*nrs(i,j,k)*soln_hat(i,j,k,n)); + } + + } else { + + for (int n = 0; n < ncomp; n++) + { + bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); + bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); + bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); + bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); +#if (AMREX_SPACEDIM == 3) + bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); + bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || + d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); +#endif + // Initialize so that the slope stencil goes from -1:1 in each diretion + int nx = 1; int ny = 1; int nz = 1; + + // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil + // or do we need to enlarge it? + AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, + Real y_max = -1.e30; Real y_min = 1.e30;, + Real z_max = -1.e30; Real z_min = 1.e30;); + + Real slope_stencil_min_width = 0.5; +#if (AMREX_SPACEDIM == 2) + int kk = 0; +#elif (AMREX_SPACEDIM == 3) + for(int kk(-1); kk<=1; kk++) +#endif + { + for(int jj(-1); jj<=1; jj++) + for(int ii(-1); ii<=1; ii++) + if (flag(i,j,k).isConnected(ii,jj,kk)) + { + int r = i+ii; int s = j+jj; int t = k+kk; + + x_max = amrex::max(x_max, cent_hat(r,s,t,0)+static_cast(ii)); + x_min = amrex::min(x_min, cent_hat(r,s,t,0)+static_cast(ii)); + y_max = amrex::max(y_max, cent_hat(r,s,t,1)+static_cast(jj)); + y_min = amrex::min(y_min, cent_hat(r,s,t,1)+static_cast(jj)); +#if (AMREX_SPACEDIM == 3) + z_max = amrex::max(z_max, cent_hat(r,s,t,2)+static_cast(kk)); + z_min = amrex::min(z_min, cent_hat(r,s,t,2)+static_cast(kk)); +#endif + } + } + // If we need to grow the stencil, we let it be -nx:nx in the x-direction, + // for example. Note that nx,ny,nz are either 1 or 2 + if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; + if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; +#if (AMREX_SPACEDIM == 3) + if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; +#endif + + amrex::GpuArray slopes_eb; + if (nx*ny*nz == 1) + // Compute slope using 3x3x3 stencil + slopes_eb = amrex_calc_slopes_extdir_eb( + i,j,k,n,soln_hat,cent_hat,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + else + { + // Compute slope using grown stencil (no larger than 5x5x5) + slopes_eb = amrex_calc_slopes_extdir_eb_grown( + i,j,k,n,AMREX_D_DECL(nx,ny,nz), + soln_hat,cent_hat,vfrac, + AMREX_D_DECL(fcx,fcy,fcz),flag, + AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), + AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), + AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), + AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), + max_order); + } + + // We do the limiting separately because this limiter limits the slope based on the values + // extrapolated to the cell centroid (cent_hat) locations - unlike the limiter in amrex + // which bases the limiting on values extrapolated to the face centroids. + amrex::GpuArray lim_slope = + amrex_calc_centroid_limiter(i,j,k,n,soln_hat,flag,slopes_eb,cent_hat); + + AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, + lim_slope[1] *= slopes_eb[1];, + lim_slope[2] *= slopes_eb[2];); + + // Add to the cell itself + if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) + { + Real update = soln_hat(i,j,k,n); + AMREX_D_TERM(update += lim_slope[0] * (ccent(i,j,k,0)-cent_hat(i,j,k,0));, + update += lim_slope[1] * (ccent(i,j,k,1)-cent_hat(i,j,k,1));, + update += lim_slope[2] * (ccent(i,j,k,2)-cent_hat(i,j,k,2));); + amrex::Gpu::Atomic::Add(&U_out(i,j,k,n),alpha(i,j,k,0)*nrs(i,j,k)*update); + } // if bx contains + + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= num_nbors; i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + + if (bx.contains(IntVect(AMREX_D_DECL(r,s,t)))) + { + Real update = soln_hat(i,j,k,n); + AMREX_D_TERM(update += lim_slope[0] * (ccent(r,s,t,0)-cent_hat(i,j,k,0) + static_cast(r-i));, + update += lim_slope[1] * (ccent(r,s,t,1)-cent_hat(i,j,k,1) + static_cast(s-j));, + update += lim_slope[2] * (ccent(r,s,t,2)-cent_hat(i,j,k,2) + static_cast(t-k));); + amrex::Gpu::Atomic::Add(&U_out(r,s,t,n),alpha(i,j,k,1)*update); + } // if bx contains + } // i_nbor + } // n + } // num_nbors + } // vfrac + }); + + amrex::ParallelFor(bx,ncomp, + [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!flag(i,j,k).isCovered()) + { + // This seems to help with a compiler issue ... + Real denom = 1. / (nrs(i,j,k) + 1.e-40); + U_out(i,j,k,n) *= denom; + } + else + { + U_out(i,j,k,n) = 1.e40; + } + }); + +#if 0 + // + // This tests whether the redistribution procedure was conservative -- + // only use if bx is the whole domain + // + { + for (int n = 0; n < ncomp; n++) + { + Real sum1(0); + Real sum2(0); +#if (AMREX_SPACEDIM == 2) + int k = 0; +#else + for (int k = bx.smallEnd(2); k <= domain.bigEnd(2); k++) +#endif + for (int j = bx.smallEnd(1); j <= domain.bigEnd(1); j++) + for (int i = bx.smallEnd(0); i <= domain.bigEnd(0); i++) + { + sum1 += vfrac(i,j,k)*U_in(i,j,k,n); + sum2 += vfrac(i,j,k)*U_out(i,j,k,n); + } + if (std::abs(sum1-sum2) > 1.e-8 * sum1 && std::abs(sum1-sum2) > 1.e-8) + { + printf("SUMS DO NOT MATCH IN STATE REDIST : %f %f ",sum1,sum2); + amrex::Abort(); + } + } + } +#endif +} +/** @} */ diff --git a/Diagnostics/Redistribution/hydro_state_utils.cpp b/Diagnostics/Redistribution/hydro_state_utils.cpp new file mode 100644 index 000000000..8afcc17fc --- /dev/null +++ b/Diagnostics/Redistribution/hydro_state_utils.cpp @@ -0,0 +1,208 @@ +/** + * \file hydro_state_utils.cpp + * \addtogroup Redistribution + * @{ + * + */ + +#include + +using namespace amrex; + +void +Redistribution::MakeStateRedistUtils ( Box const& bx, + Array4 const& flag, + Array4 const& vfrac, + Array4 const& ccent, + Array4 const& itracker, + Array4 const& nrs, + Array4 const& alpha, + Array4 const& nbhd_vol, + Array4 const& cent_hat, + Geometry const& lev_geom, + Real target_vol) +{ + // Note that itracker has {4 in 2D, 8 in 3D} components and all are initialized to zero + // We will add to the first component every time this cell is included in a merged neighborhood, + // either by merging or being merged + // + // In 2D, we identify the cells in the remaining three components with the following ordering + // + // ^ 6 7 8 + // | 4 5 + // j 1 2 3 + // i ---> + // + // In 3D, We identify the cells in the remaining three components with the following ordering + // + // at k-1 | at k | at k+1 + // + // ^ 15 16 17 | 6 7 8 | 24 25 26 + // | 12 13 14 | 4 5 | 21 22 23 + // j 9 10 11 | 1 2 3 | 18 19 20 + // i ---> + // + // Note the first component of each of these arrays should never be used + // +#if (AMREX_SPACEDIM == 2) + Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1}; + Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1}; + Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0}; +#else + Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; + Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; + Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; +#endif + + AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, + const auto& is_periodic_y = lev_geom.isPeriodic(1);, + const auto& is_periodic_z = lev_geom.isPeriodic(2);); + + Box const& bxg2 = amrex::grow(bx,2); + Box const& bxg3 = amrex::grow(bx,3); + Box const& bxg4 = amrex::grow(bx,4); + + const Box domain = lev_geom.Domain(); + + Box domain_per_grown = domain; + if (is_periodic_x) domain_per_grown.grow(0,2); + if (is_periodic_y) domain_per_grown.grow(1,2); +#if (AMREX_SPACEDIM == 3) + if (is_periodic_z) domain_per_grown.grow(2,2); +#endif + + amrex::ParallelFor(bxg3, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + // Everyone is in their own neighborhood at least + nrs(i,j,k) = 1.; + alpha(i,j,k,0) = 1.; + alpha(i,j,k,1) = 1.; + }); + + // nrs captures how many neighborhoods (r,s) is in + amrex::ParallelFor(bxg4, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + if ( domain_per_grown.contains(IntVect(AMREX_D_DECL(r,s,t))) && + bxg3.contains(IntVect(AMREX_D_DECL(r,s,t))) ) + { + amrex::Gpu::Atomic::Add(&nrs(r,s,t),1.0_rt); + } + } + }); + + amrex::ParallelFor(bxg2, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (!flag(i,j,k).isCovered()) + { + // Start with the vfrac of (i,j,k) + nbhd_vol(i,j,k) = vfrac(i,j,k) / nrs(i,j,k); + Real vol_of_nbors = 0.; + + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + amrex::Gpu::Atomic::Add(&nbhd_vol(i,j,k),vfrac(r,s,t) / nrs(r,s,t)); + vol_of_nbors += vfrac(r,s,t); + } + + if (itracker(i,j,k,0) > 0) + alpha(i,j,k,1) = (target_vol - vfrac(i,j,k)) / vol_of_nbors; + + } else { + nbhd_vol(i,j,k) = 0.; + alpha(i,j,k,0) = 0.; + alpha(i,j,k,1) = 0.; + } + }); + + // Define how much each cell keeps + amrex::ParallelFor(bxg2, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (!flag(i,j,k).isCovered()) + { + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + amrex::Gpu::Atomic::Add(&alpha(r,s,t,0),-(alpha(i,j,k,1)/nrs(r,s,t))); + } + } + }); + + // Redefine nbhd_vol + amrex::ParallelFor(bxg2, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (!flag(i,j,k).isCovered()) + { + nbhd_vol(i,j,k) = alpha(i,j,k,0) * vfrac(i,j,k); + + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int r = i+imap[itracker(i,j,k,i_nbor)]; + int s = j+jmap[itracker(i,j,k,i_nbor)]; + int t = k+kmap[itracker(i,j,k,i_nbor)]; + amrex::Gpu::Atomic::Add(&nbhd_vol(i,j,k),alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t)); + } + } + }); + + // Define xhat,yhat,zhat (from Berger and Guliani) + amrex::ParallelFor(bxg3, + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { + if (vfrac(i,j,k) > 0.0) + { + AMREX_D_TERM(cent_hat(i,j,k,0) = ccent(i,j,k,0);, + cent_hat(i,j,k,1) = ccent(i,j,k,1);, + cent_hat(i,j,k,2) = ccent(i,j,k,2);); + + if ( itracker(i,j,k,0) > 0 && + domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k))) && + bxg2.contains(IntVect(AMREX_D_DECL(i,j,k))) ) { + + AMREX_D_TERM(cent_hat(i,j,k,0) = ccent(i,j,k,0) * alpha(i,j,k,0) *vfrac(i,j,k);, + cent_hat(i,j,k,1) = ccent(i,j,k,1) * alpha(i,j,k,0) *vfrac(i,j,k);, + cent_hat(i,j,k,2) = ccent(i,j,k,2) * alpha(i,j,k,0) *vfrac(i,j,k);); + + // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself + for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) + { + int ii = imap[itracker(i,j,k,i_nbor)]; int r = i+ii; + int jj = jmap[itracker(i,j,k,i_nbor)]; int s = j+jj; + int kk = kmap[itracker(i,j,k,i_nbor)]; int t = k+kk; + + AMREX_D_TERM(cent_hat(i,j,k,0) += (ccent(r,s,t,0) + ii) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);, + cent_hat(i,j,k,1) += (ccent(r,s,t,1) + jj) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);, + cent_hat(i,j,k,2) += (ccent(r,s,t,2) + kk) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);); + } + + AMREX_D_TERM(cent_hat(i,j,k,0) /= nbhd_vol(i,j,k);, + cent_hat(i,j,k,1) /= nbhd_vol(i,j,k);, + cent_hat(i,j,k,2) /= nbhd_vol(i,j,k);); + } + } else { + + AMREX_D_TERM(cent_hat(i,j,k,0) = 1.e40;, + cent_hat(i,j,k,1) = 1.e40;, + cent_hat(i,j,k,2) = 1.e40;); + } + }); +} +/** @} */ diff --git a/Diagnostics/hydro_ebgodunov.cpp b/Diagnostics/hydro_ebgodunov.cpp new file mode 100644 index 000000000..7a66dc8b9 --- /dev/null +++ b/Diagnostics/hydro_ebgodunov.cpp @@ -0,0 +1,660 @@ +/** + * \file hydro_ebgodunov.cpp + * \addtogroup EBGodunov + * @{ + * + */ + +#include +#include +#include +#include +#include + +using namespace amrex; + + +void +EBGodunov::ComputeAofs ( MultiFab& aofs, const int aofs_comp, const int ncomp, + MultiFab const& state, const int state_comp, + AMREX_D_DECL( MultiFab const& umac, + MultiFab const& vmac, + MultiFab const& wmac), + AMREX_D_DECL( MultiFab& xedge, + MultiFab& yedge, + MultiFab& zedge), + const int edge_comp, + const bool known_edgestate, + AMREX_D_DECL( MultiFab& xfluxes, + MultiFab& yfluxes, + MultiFab& zfluxes), + int fluxes_comp, + MultiFab const& fq, + const int fq_comp, + MultiFab const& divu, + Vector const& h_bc, + BCRec const* d_bc, + Geometry const& geom, + Vector& iconserv, + const Real dt, + const bool is_velocity, + std::string redistribution_type) +{ + BL_PROFILE("EBGodunov::ComputeAofs()"); + + bool fluxes_are_area_weighted = true; + + // Make a device copy of the iconserv vector for use in kernels + Gpu::DeviceVector iconserv_d(iconserv.size()); + Gpu::copy(Gpu::hostToDevice, iconserv.begin(), iconserv.end(), iconserv_d.begin()); + int const* iconserv_ptr = iconserv_d.data(); + + AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); + + auto const& ebfact= dynamic_cast(state.Factory()); + auto const& flags = ebfact.getMultiEBCellFlagFab(); + auto const& fcent = ebfact.getFaceCent(); + auto const& ccent = ebfact.getCentroid(); + auto const& vfrac = ebfact.getVolFrac(); + auto const& areafrac = ebfact.getAreaFrac(); + + // Create temporary holder for advection term. Needed so we can call FillBoundary. + MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfact); + advc.setVal(0.); + + // if we need convective form, we must also compute + // div(u_mac) + MultiFab divu_mac(state.boxArray(),state.DistributionMap(),1,0, MFInfo(), ebfact); + for (Long i = 0; i < iconserv.size(); ++i) + { + if (!iconserv[i]) + { + Array u; + AMREX_D_TERM(u[0] = &umac;, + u[1] = &vmac;, + u[2] = &wmac;); + + if (!ebfact.isAllRegular()) + amrex::EB_computeDivergence(divu_mac,u,geom,true); + else + amrex::computeDivergence(divu_mac,u,geom); + + break; + } + } + + // Compute -div instead of computing div -- this is just for consistency + // with the way we HAVE to do it for EB (because redistribution operates on + // -div rather than div + Real mult = -1.0; + +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + + const Box& bx = mfi.tilebox(); + + auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; + // A regular box uses 3 ghost cells: + // We predict the state on the edge based box; that calls slopes on + // i & i-1; slopes then looks at (i-1)-2 for 4th order slopes + // => test on bx grow 3 + bool regular = (flagfab.getType(amrex::grow(bx,3)) == FabType::regular); + + // Get handlers to Array4 + // + AMREX_D_TERM( const auto& fx = xfluxes.array(mfi,fluxes_comp);, + const auto& fy = yfluxes.array(mfi,fluxes_comp);, + const auto& fz = zfluxes.array(mfi,fluxes_comp);); + + AMREX_D_TERM( const auto& xed = xedge.array(mfi,edge_comp);, + const auto& yed = yedge.array(mfi,edge_comp);, + const auto& zed = zedge.array(mfi,edge_comp);); + + AMREX_D_TERM( const auto& u = umac.const_array(mfi);, + const auto& v = vmac.const_array(mfi);, + const auto& w = wmac.const_array(mfi);); + + Array4 advc_arr = advc.array(mfi); + + if (flagfab.getType(bx) == FabType::covered) + { + AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, + const Box& ybx = mfi.nodaltilebox(1);, + const Box& zbx = mfi.nodaltilebox(2); ); + + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + amrex::ParallelFor( + bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = covered_val;}, + + xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, + + ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); + +#if (AMREX_SPACEDIM==3) + amrex::ParallelFor( + zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); +#endif + } + else + { + if (regular) // Plain Godunov + { + if (not known_edgestate) + { + Godunov::ComputeEdgeState( bx, ncomp, + state.array(mfi,state_comp), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( u, v, w ), + divu.array(mfi), + fq.array(mfi,fq_comp), + geom, dt, d_bc, + iconserv_ptr, + false, + false, + is_velocity ); + } + + HydroUtils::ComputeFluxes( bx, + AMREX_D_DECL( fx, fy, fz ), + AMREX_D_DECL( u, v, w ), + AMREX_D_DECL( xed, yed, zed ), + geom, ncomp, fluxes_are_area_weighted ); + + HydroUtils::ComputeDivergence( bx, advc_arr, + AMREX_D_DECL( fx, fy, fz ), + ncomp, geom, + mult, fluxes_are_area_weighted); + + // Compute the convective form if needed by accounting for extra term + auto const& divu_arr = divu_mac.array(mfi); + amrex::ParallelFor(bx, ncomp, [=] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!iconserv_ptr[n]) + { + Real q = xed(i,j,k,n) + xed(i+1,j,k,n) + + yed(i,j,k,n) + yed(i,j+1,k,n); +#if (AMREX_SPACEDIM == 2) + q *= 0.25; +#else + q += zed(i,j,k,n) + zed(i,j,k+1,n); + q /= 6.0; +#endif + advc_arr(i,j,k,n) += q*divu_arr(i,j,k); + } + }); + + } + else // EB Godunov + { + AMREX_D_TERM(Array4 const& fcx = fcent[0]->const_array(mfi);, + Array4 const& fcy = fcent[1]->const_array(mfi);, + Array4 const& fcz = fcent[2]->const_array(mfi);); + + AMREX_D_TERM(Array4 const& apx = areafrac[0]->const_array(mfi);, + Array4 const& apy = areafrac[1]->const_array(mfi);, + Array4 const& apz = areafrac[2]->const_array(mfi);); + + Array4 const& ccent_arr = ccent.const_array(mfi); + Array4 const& vfrac_arr = vfrac.const_array(mfi); + auto const& flags_arr = flags.const_array(mfi); + + //FIXME - compare to HydroUtils which hard codes 4 ghost cells for all + int ngrow = 4; + + if (redistribution_type=="StateRedist") + ++ngrow; + + FArrayBox tmpfab(amrex::grow(bx,ngrow), (4*AMREX_SPACEDIM + 2)*ncomp); + Elixir eli = tmpfab.elixir(); + + + if (not known_edgestate) + { + EBGodunov::ComputeEdgeState( bx, ncomp, + state.array(mfi,state_comp), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( u, v, w ), + divu.array(mfi), + fq.array(mfi,fq_comp), + geom, dt, h_bc, d_bc, + iconserv_ptr, + tmpfab.dataPtr(), + flags_arr, + AMREX_D_DECL( apx, apy, apz ), + vfrac_arr, + AMREX_D_DECL( fcx, fcy, fcz ), + ccent_arr, + is_velocity, + Array4{} ); + } + + HydroUtils::EB_ComputeFluxes( bx, + AMREX_D_DECL( fx, fy, fz ), + AMREX_D_DECL( u, v, w ), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( apx, apy, apz ), + geom, ncomp, flags_arr, fluxes_are_area_weighted ); + + // div at ncomp*3 to make space for the 3 redistribute temporaries + HydroUtils::EB_ComputeDivergence( bx, + advc_arr, + AMREX_D_DECL( fx, fy, fz ), + vfrac_arr, ncomp, geom, + mult, fluxes_are_area_weighted); + + // Compute the convective form if needed by accounting for extra term + auto const& divu_arr = divu_mac.array(mfi); + amrex::ParallelFor(bx, ncomp, [=] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!iconserv_ptr[n]) + { + if ( vfrac_arr(i,j,k) != 0 ) + { + Real q = xed(i,j,k,n)*apx(i,j,k) + xed(i+1,j,k,n)*apx(i+1,j,k) + + yed(i,j,k,n)*apy(i,j,k) + yed(i,j+1,k,n)*apy(i,j+1,k); +#if (AMREX_SPACEDIM == 2) + q /= (apx(i,j,k)+apx(i+1,j,k)+apy(i,j,k)+apy(i,j+1,k)); +#else + q += zed(i,j,k,n)*apz(i,j,k) + zed(i,j,k+1,n)*apz(i,j,k+1); + q /= (apx(i,j,k)+apx(i+1,j,k)+apy(i,j,k)+apy(i,j+1,k)+apz(i,j,k)+apz(i,j,k+1)); +#endif + advc_arr(i,j,k,n) += q*divu_arr(i,j,k); + } + } + }); + } + } + } + + advc.FillBoundary(geom.periodicity()); + +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + + auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; + auto const& flag = flagfab.const_array(); + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + auto const& advc_arr = advc.array(mfi); + + if (flagfab.getType(bx) != FabType::covered ) + { + // FIXME? not sure if 4 is really needed or if 3 could do + // But this is a safe choice + if (flagfab.getType(grow(bx,4)) != FabType::regular) + { + // + // Redistribute + // + AMREX_D_TERM( auto apx = ebfact.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfact.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfact.getAreaFrac()[2]->const_array(mfi); ); + + AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfact.getFaceCent()[2]->const_array(mfi);); + + Array4 bcc = ebfact.getBndryCent().const_array(mfi); + Array4 ccc = ebfact.getCentroid().const_array(mfi); + Array4 const& vfrac_arr = vfrac.const_array(mfi); + + // This is scratch space if calling StateRedistribute, + // but is used as the weights (here set to 1) if calling + // FluxRedistribute + Box gbx = bx; + + if (redistribution_type == "StateRedist") + gbx.grow(3); + else if (redistribution_type == "FluxRedist") + gbx.grow(2); + + FArrayBox tmpfab(gbx, ncomp); + Elixir eli = tmpfab.elixir(); + Array4 scratch = tmpfab.array(0); + if (redistribution_type == "FluxRedist") + { + amrex::ParallelFor(Box(scratch), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { scratch(i,j,k) = 1.;}); + } + + Redistribution::Apply( bx, ncomp, aofs_arr, advc.array(mfi), + state.const_array(mfi, state_comp), scratch, flag, + AMREX_D_DECL(apx,apy,apz), vfrac_arr, + AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bc, + geom, dt, redistribution_type ); + + // Change sign because we computed -div for all cases + amrex::ParallelFor(bx, ncomp, [aofs_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) *= - 1.0; }); + } + else + { + // Change sign because for EB we computed -div + amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = -advc_arr(i,j,k,n); }); + } + } + } +} + + +void +EBGodunov::ComputeSyncAofs ( MultiFab& aofs, const int aofs_comp, const int ncomp, + MultiFab const& state, const int state_comp, + AMREX_D_DECL( MultiFab const& umac, + MultiFab const& vmac, + MultiFab const& wmac), + AMREX_D_DECL( MultiFab const& ucorr, + MultiFab const& vcorr, + MultiFab const& wcorr), + AMREX_D_DECL( MultiFab& xedge, + MultiFab& yedge, + MultiFab& zedge), + const int edge_comp, + const bool known_edgestate, + AMREX_D_DECL( MultiFab& xfluxes, + MultiFab& yfluxes, + MultiFab& zfluxes), + int fluxes_comp, + MultiFab const& fq, + const int fq_comp, + MultiFab const& divu, + Vector const& h_bc, + BCRec const* d_bc, + Geometry const& geom, + Gpu::DeviceVector& iconserv, + const Real dt, + const bool is_velocity, + std::string redistribution_type ) +{ + BL_PROFILE("EBGodunov::ComputeSyncAofs()"); + + bool fluxes_are_area_weighted = true; + + AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); + + auto const& ebfact= dynamic_cast(state.Factory()); + auto const& flags = ebfact.getMultiEBCellFlagFab(); + auto const& fcent = ebfact.getFaceCent(); + auto const& ccent = ebfact.getCentroid(); + auto const& vfrac = ebfact.getVolFrac(); + auto const& areafrac = ebfact.getAreaFrac(); + + // Create temporary holder for advection term. Needed so we can call FillBoundary. + MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfact); + advc.setVal(0.); + + // Compute -div instead of computing div -- this is just for consistency + // with the way we HAVE to do it for EB (because redistribution operates on + // -div rather than div + Real mult = -1.0; + + +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs,TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + + const Box& bx = mfi.tilebox(); + + auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; + bool regular = (flagfab.getType(amrex::grow(bx,3)) == FabType::regular); + + // + // Get handlers to Array4 + // + AMREX_D_TERM( const auto& fx = xfluxes.array(mfi,fluxes_comp);, + const auto& fy = yfluxes.array(mfi,fluxes_comp);, + const auto& fz = zfluxes.array(mfi,fluxes_comp);); + + AMREX_D_TERM( const auto& xed = xedge.array(mfi,edge_comp);, + const auto& yed = yedge.array(mfi,edge_comp);, + const auto& zed = zedge.array(mfi,edge_comp);); + + AMREX_D_TERM( const auto& uc = ucorr.const_array(mfi);, + const auto& vc = vcorr.const_array(mfi);, + const auto& wc = wcorr.const_array(mfi);); + + Array4 advc_arr = advc.array(mfi); + + if (flagfab.getType(bx) == FabType::covered) + { + AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, + const Box& ybx = mfi.nodaltilebox(1);, + const Box& zbx = mfi.nodaltilebox(2); ); + + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + amrex::ParallelFor( + bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = covered_val;}, + + xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, + + ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); + +#if (AMREX_SPACEDIM==3) + amrex::ParallelFor( + zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); +#endif + } + else + { + if (regular) // Plain Godunov + { + if (not known_edgestate) + { + AMREX_D_TERM( const auto& u = umac.const_array(mfi);, + const auto& v = vmac.const_array(mfi);, + const auto& w = wmac.const_array(mfi);); + + Godunov::ComputeEdgeState( bx, ncomp, + state.array(mfi,state_comp), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( u, v, w ), + divu.array(mfi), + fq.array(mfi,fq_comp), + geom, dt, d_bc, + iconserv.data(), + false, + false, + is_velocity ); + } + + + + HydroUtils::ComputeFluxes( bx, + AMREX_D_DECL( fx, fy, fz ), + AMREX_D_DECL( uc, vc, wc ), + AMREX_D_DECL( xed, yed, zed ), + geom, ncomp, fluxes_are_area_weighted ); + + + HydroUtils::ComputeDivergence( bx, advc_arr, + AMREX_D_DECL( fx, fy, fz ), + ncomp, geom, + mult, fluxes_are_area_weighted); + } + else // EB Godunov + { + AMREX_D_TERM(Array4 const& fcx = fcent[0]->const_array(mfi);, + Array4 const& fcy = fcent[1]->const_array(mfi);, + Array4 const& fcz = fcent[2]->const_array(mfi);); + + AMREX_D_TERM(Array4 const& apx = areafrac[0]->const_array(mfi);, + Array4 const& apy = areafrac[1]->const_array(mfi);, + Array4 const& apz = areafrac[2]->const_array(mfi);); + + Array4 const& ccent_arr = ccent.const_array(mfi); + Array4 const& vfrac_arr = vfrac.const_array(mfi); + auto const& flags_arr = flags.const_array(mfi); + + int ngrow = 4; + FArrayBox tmpfab(amrex::grow(bx,ngrow), (4*AMREX_SPACEDIM + 2)*ncomp); + Elixir eli = tmpfab.elixir(); + + + if (not known_edgestate) + { + AMREX_D_TERM( const auto& u = umac.const_array(mfi);, + const auto& v = vmac.const_array(mfi);, + const auto& w = wmac.const_array(mfi);); + + EBGodunov::ComputeEdgeState( bx, ncomp, + state.array(mfi,state_comp), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( u, v, w ), + divu.array(mfi), + fq.array(mfi,fq_comp), + geom, dt, h_bc, d_bc, + iconserv.data(), + tmpfab.dataPtr(), + flags_arr, + AMREX_D_DECL( apx, apy, apz ), + vfrac_arr, + AMREX_D_DECL( fcx, fcy, fcz ), + ccent_arr, + is_velocity, + Array4{} ); + } + + HydroUtils::EB_ComputeFluxes( bx, + AMREX_D_DECL( fx, fy, fz ), + AMREX_D_DECL( uc, vc, wc ), + AMREX_D_DECL( xed, yed, zed ), + AMREX_D_DECL( apx, apy, apz ), + geom, ncomp, flags_arr, fluxes_are_area_weighted ); + + HydroUtils::EB_ComputeDivergence( bx, + advc_arr, + AMREX_D_DECL( fx, fy, fz ), + vfrac_arr, ncomp, geom, mult, fluxes_are_area_weighted ); + + } + } + } + + advc.FillBoundary(geom.periodicity()); + + MultiFab sstate_tmp; + MultiFab* sstate; + if (redistribution_type == "StateRedist") + { + // Create temporary holder for sync "state" passed in via aofs + // Do this so we're not overwriting the "state" as we go through the redistribution + // process. + sstate_tmp.define(state.boxArray(),state.DistributionMap(),ncomp,state.nGrow(), + MFInfo(),ebfact); + sstate = &sstate_tmp; + MultiFab::Copy(*sstate,aofs,aofs_comp,0,ncomp,state.nGrow()); + } + else + { + // Doesn't matter what we put here, sstate only gets used for StateRedist + sstate = &aofs; + } + +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + + auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; + auto const& flags_arr = flagfab.const_array(); + + if (flagfab.getType(bx) != FabType::covered ) + { + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + auto const& advc_arr = advc.array(mfi); + + // FIXME? not sure if 4 is really needed or if 3 could do + // But this is a safe choice + if (flagfab.getType(grow(bx,4)) != FabType::regular) + { + // + // Redistribute + // + AMREX_D_TERM( auto apx = ebfact.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfact.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfact.getAreaFrac()[2]->const_array(mfi); ); + + AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfact.getFaceCent()[2]->const_array(mfi);); + + Array4 bcent_arr = ebfact.getBndryCent().const_array(mfi); + Array4 ccent_arr = ebfact.getCentroid().const_array(mfi); + Array4 const& vfrac_arr = vfrac.const_array(mfi); + + // This is scratch space if calling StateRedistribute, + // but is used as the weights (here set to 1) if calling + // FluxRedistribute + Box gbx = bx; + + if (redistribution_type == "StateRedist") + gbx.grow(3); + else if (redistribution_type == "FluxRedist") + gbx.grow(2); + + FArrayBox tmpfab(gbx, ncomp*2); + Elixir eli = tmpfab.elixir(); + Array4 scratch = tmpfab.array(0); + if (redistribution_type == "FluxRedist") + { + amrex::ParallelFor(Box(scratch), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { scratch(i,j,k) = 1.;}); + } + Array4 divtmp_redist_arr = tmpfab.array(ncomp); + + // Redistribute + // + // For StateRedistribution, we use the Sync as the "state". + // This may lead to oversmoothing. + // + Redistribution::Apply( bx, ncomp, divtmp_redist_arr, advc_arr, + sstate->const_array(mfi, 0), scratch, flags_arr, + AMREX_D_DECL(apx,apy,apz), vfrac_arr, + AMREX_D_DECL(fcx,fcy,fcz), bcent_arr, ccent_arr, d_bc, + geom, dt, redistribution_type ); + + // Subtract contribution to sync aofs -- sign of divergence is aofs is opposite + // of sign to div computed by EB_ComputeDivergence, thus it must be subtracted. + amrex::ParallelFor(bx, ncomp, [aofs_arr, divtmp_redist_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) -= divtmp_redist_arr( i, j, k, n ); }); + } + else + { + // Subtract contribution to sync aofs -- sign of divergence is aofs is opposite + // of sign to div computed by EB_ComputeDivergence, thus it must be subtracted. + amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) -= advc_arr( i, j, k, n ); }); + } + } + } +} +/** @} */ diff --git a/Diagnostics/hydro_ebmol.cpp b/Diagnostics/hydro_ebmol.cpp new file mode 100644 index 000000000..afd52111e --- /dev/null +++ b/Diagnostics/hydro_ebmol.cpp @@ -0,0 +1,613 @@ +/** + * \file hydro_ebmol.cpp + * \addtogroup EBMOL + * @{ + * + */ + +#include +#include +#include +#include +// #include +#include + +using namespace amrex; + + +void +EBMOL::ComputeAofs ( MultiFab& aofs, int aofs_comp, int ncomp, + MultiFab const& state, int state_comp, + AMREX_D_DECL( MultiFab const& umac, + MultiFab const& vmac, + MultiFab const& wmac), + AMREX_D_DECL( MultiFab& xedge, + MultiFab& yedge, + MultiFab& zedge), + int edge_comp, + bool known_edgestate, + AMREX_D_DECL( MultiFab& xfluxes, + MultiFab& yfluxes, + MultiFab& zfluxes), + int fluxes_comp, + MultiFab const& divu, + Vector const& bcs, + BCRec const* d_bcrec_ptr, + Gpu::DeviceVector& iconserv, + Geometry const& geom, + const Real dt, + const bool is_velocity, + std::string redistribution_type ) +{ + BL_PROFILE("EBMOL::ComputeAofs()"); + + bool fluxes_are_area_weighted = true; + + int const* iconserv_ptr = iconserv.data(); + + AMREX_ALWAYS_ASSERT(aofs.nComp() >= aofs_comp + ncomp); + AMREX_ALWAYS_ASSERT(state.nComp() >= state_comp + ncomp); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xedge.nComp() >= edge_comp + ncomp);, + AMREX_ALWAYS_ASSERT(yedge.nComp() >= edge_comp + ncomp);, + AMREX_ALWAYS_ASSERT(zedge.nComp() >= edge_comp + ncomp);); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nComp() >= fluxes_comp + ncomp);, + AMREX_ALWAYS_ASSERT(yfluxes.nComp() >= fluxes_comp + ncomp);, + AMREX_ALWAYS_ASSERT(zfluxes.nComp() >= fluxes_comp + ncomp);); + AMREX_ALWAYS_ASSERT(aofs.nGrow() == 0); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nGrow() == xedge.nGrow());, + AMREX_ALWAYS_ASSERT(yfluxes.nGrow() == yedge.nGrow());, + AMREX_ALWAYS_ASSERT(zfluxes.nGrow() == zedge.nGrow());); + + // To compute edge states, need at least 2 ghost cells in state + if ( !known_edgestate ) + AMREX_ALWAYS_ASSERT(state.nGrow() >= 2); + + // If !known_edgestate, need 2 additional cells in state to compute + // the slopes needed to compute the edge state, since MOL uses slope + // order==2. + int halo = known_edgestate ? 0 : 2; + + AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); + auto const& ebfactory = dynamic_cast(state.Factory()); + + // Create temporary holder for advection term. Needed so we can call FillBoundary. + MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfactory); + advc.setVal(0.); + + Box const& domain = geom.Domain(); + MFItInfo mfi_info; + + if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + + AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, + const Box& ybx = mfi.nodaltilebox(1);, + const Box& zbx = mfi.nodaltilebox(2); ); + + AMREX_D_TERM( Array4 fx = xfluxes.array(mfi,fluxes_comp);, + Array4 fy = yfluxes.array(mfi,fluxes_comp);, + Array4 fz = zfluxes.array(mfi,fluxes_comp);); + + AMREX_D_TERM( Array4 xed = xedge.array(mfi,edge_comp);, + Array4 yed = yedge.array(mfi,edge_comp);, + Array4 zed = zedge.array(mfi,edge_comp);); + + // Initialize covered cells + auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; + auto const& flag = flagfab.const_array(); + + if (flagfab.getType(bx) == FabType::covered) + { + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + amrex::ParallelFor( + bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = covered_val;}, + + xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, + + ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); + +#if (AMREX_SPACEDIM==3) + amrex::ParallelFor( + zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); +#endif + } + else + { + + AMREX_D_TERM( Array4 u = umac.const_array(mfi);, + Array4 v = vmac.const_array(mfi);, + Array4 w = wmac.const_array(mfi);); + + Array4 advc_arr = advc.array(mfi); + + bool regular = flagfab.getType(amrex::grow(bx,halo)) == FabType::regular; + + if (!regular) + { + AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); + + AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); + + Array4 ccc = ebfactory.getCentroid().const_array(mfi); + auto vfrac = ebfactory.getVolFrac().const_array(mfi); + + // Compute edge state if needed + if (!known_edgestate) + { + Array4 const q = state.const_array(mfi,state_comp); + + EBMOL::ComputeEdgeState( bx, AMREX_D_DECL(xed,yed,zed), + q, ncomp, + AMREX_D_DECL(u,v,w), + domain, bcs, d_bcrec_ptr, + AMREX_D_DECL(fcx,fcy,fcz), + ccc, vfrac, flag, is_velocity ); + } + + // Compute fluxes + HydroUtils::EB_ComputeFluxes(bx, AMREX_D_DECL(fx,fy,fz), + AMREX_D_DECL(u,v,w), + AMREX_D_DECL(xed,yed,zed), + AMREX_D_DECL(apx,apy,apz), + geom, ncomp, flag, fluxes_are_area_weighted ); + + // + // Compute divergence + // + + // Compute -div because that's what redistribution needs + Real mult = -1.0; + HydroUtils::EB_ComputeDivergence(bx, advc_arr, + AMREX_D_DECL(fx,fy,fz), + vfrac, ncomp, geom, + mult, fluxes_are_area_weighted ); + // Account for extra term needed for convective differencing + // Don't forget we're mutliplying by -1.0 here... + auto const& q = state.array(mfi, state_comp); + auto const& divu_arr = divu.array(mfi); + amrex::ParallelFor(bx, ncomp, [=] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!iconserv_ptr[n]) + advc_arr( i, j, k, n ) += q(i,j,k,n)*divu_arr(i,j,k); + + }); + } + else + { + // Compute edge state if needed + if (!known_edgestate) + { + Array4 const q = state.const_array(mfi,state_comp); + MOL::ComputeEdgeState( bx, + AMREX_D_DECL( xed, yed, zed ), + q, ncomp, + AMREX_D_DECL( u, v, w ), + domain, bcs, d_bcrec_ptr, + is_velocity); + } + + // Compute fluxes + HydroUtils::ComputeFluxes( bx, + AMREX_D_DECL(fx,fy,fz), + AMREX_D_DECL(u,v,w), + AMREX_D_DECL(xed,yed,zed), + geom, ncomp, fluxes_are_area_weighted ); + + // Compute divergence + // We use minus sign, i.e. -div, for consistency with EB above + Real mult = -1.0; + HydroUtils::ComputeDivergence(bx, advc_arr, + AMREX_D_DECL(fx,fy,fz), + ncomp, geom, + mult, fluxes_are_area_weighted ); + + // Account for extra term needed for convective differencing + auto const& q = state.array(mfi, state_comp); + auto const& divu_arr = divu.array(mfi); + amrex::ParallelFor(bx, ncomp, [=] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { + if (!iconserv_ptr[n]) + advc_arr( i, j, k, n ) += q(i,j,k,n)*divu_arr(i,j,k); + }); + } + } + } + + advc.FillBoundary(geom.periodicity()); + + if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + + auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; + auto const& flag = flagfab.const_array(); + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + if (flagfab.getType(bx) != FabType::covered ) + { + // FIXME? not sure if 4 is really needed or if 3 could do + // But this is a safe choice + if (flagfab.getType(grow(bx,4)) != FabType::regular) + { + // + // Redistribute + // + AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); + + AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); + + Array4 bcc = ebfactory.getBndryCent().const_array(mfi); + Array4 ccc = ebfactory.getCentroid().const_array(mfi); + auto vfrac = ebfactory.getVolFrac().const_array(mfi); + + // This is scratch space if calling StateRedistribute, + // but is used as the weights (here set to 1) if calling + // FluxRedistribute + Box gbx = bx; + + if (redistribution_type == "StateRedist") + gbx.grow(3); + else if (redistribution_type == "FluxRedist") + gbx.grow(2); + + FArrayBox tmpfab(gbx, ncomp); + Elixir eli = tmpfab.elixir(); + Array4 scratch = tmpfab.array(0); + if (redistribution_type == "FluxRedist") + { + amrex::ParallelFor(Box(scratch), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { scratch(i,j,k) = 1.;}); + } + + Redistribution::Apply( bx, ncomp, aofs_arr, advc.array(mfi), + state.const_array(mfi, state_comp), scratch, flag, + AMREX_D_DECL(apx,apy,apz), vfrac, + AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bcrec_ptr, + geom, dt, redistribution_type ); + + // Change sign because we computed -div for all cases + amrex::ParallelFor(bx, ncomp, [aofs_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) *= - 1.0; }); + } + else + { + // Change sign because we computed -div for all cases + auto const& advc_arr = advc.array(mfi); + amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = - advc_arr(i,j,k,n); }); + } + } + } +} + +void +EBMOL::ComputeSyncAofs ( MultiFab& aofs, int aofs_comp, int ncomp, + MultiFab const& state, int state_comp, + AMREX_D_DECL( MultiFab const& umac, + MultiFab const& vmac, + MultiFab const& wmac), + AMREX_D_DECL( MultiFab const& ucorr, + MultiFab const& vcorr, + MultiFab const& wcorr), + AMREX_D_DECL( MultiFab& xedge, + MultiFab& yedge, + MultiFab& zedge), + int edge_comp, + bool known_edgestate, + AMREX_D_DECL( MultiFab& xfluxes, + MultiFab& yfluxes, + MultiFab& zfluxes), + int fluxes_comp, + Vector const& bcs, + BCRec const* d_bcrec_ptr, + Geometry const& geom, + const Real dt, + const bool is_velocity, + std::string redistribution_type ) +{ + BL_PROFILE("EBMOL::ComputeSyncAofs()"); + + bool fluxes_are_area_weighted = true; + + AMREX_ALWAYS_ASSERT(state.nComp() >= state_comp + ncomp); + AMREX_ALWAYS_ASSERT(aofs.nComp() >= aofs_comp + ncomp); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xedge.nComp() >= edge_comp + ncomp);, + AMREX_ALWAYS_ASSERT(yedge.nComp() >= edge_comp + ncomp);, + AMREX_ALWAYS_ASSERT(zedge.nComp() >= edge_comp + ncomp);); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nComp() >= fluxes_comp + ncomp);, + AMREX_ALWAYS_ASSERT(yfluxes.nComp() >= fluxes_comp + ncomp);, + AMREX_ALWAYS_ASSERT(zfluxes.nComp() >= fluxes_comp + ncomp);); + AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nGrow() == xedge.nGrow());, + AMREX_ALWAYS_ASSERT(yfluxes.nGrow() == yedge.nGrow());, + AMREX_ALWAYS_ASSERT(zfluxes.nGrow() == zedge.nGrow());); + + + // To compute edge states, need at least 2 ghost cells in state + if ( !known_edgestate ) + AMREX_ALWAYS_ASSERT(state.nGrow() >= 2); + + AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); + auto const& ebfactory = dynamic_cast(state.Factory()); + + // Need 2 grow cells in state to compute the slopes needed to compute the edge state. + int halo = known_edgestate ? 0 : 2; + + // Create temporary holder for advection term. Needed to fill ghost cells. + MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfactory); + advc.setVal(0.); + + Box const& domain = geom.Domain(); + MFItInfo mfi_info; + + if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, + const Box& ybx = mfi.nodaltilebox(1);, + const Box& zbx = mfi.nodaltilebox(2); ); + + AMREX_D_TERM( Array4 fx = xfluxes.array(mfi,fluxes_comp);, + Array4 fy = yfluxes.array(mfi,fluxes_comp);, + Array4 fz = zfluxes.array(mfi,fluxes_comp);); + + AMREX_D_TERM( Array4 xed = xedge.array(mfi,edge_comp);, + Array4 yed = yedge.array(mfi,edge_comp);, + Array4 zed = zedge.array(mfi,edge_comp);); + + // Initialize covered cells + auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; + auto const& flag = flagfab.const_array(); + + if (flagfab.getType(bx) == FabType::covered) + { + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + amrex::ParallelFor( + bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) = covered_val;}, + + xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, + + ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); + +#if (AMREX_SPACEDIM==3) + amrex::ParallelFor( + zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); +#endif + } + else + { + AMREX_D_TERM( Array4 uc = ucorr.const_array(mfi);, + Array4 vc = vcorr.const_array(mfi);, + Array4 wc = wcorr.const_array(mfi);); + + Array4 advc_arr = advc.array(mfi); + + bool regular = flagfab.getType(amrex::grow(bx,halo)) == FabType::regular; + + if (!regular) + { + AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); + + Array4 ccc = ebfactory.getCentroid().const_array(mfi); + + auto vfrac = ebfactory.getVolFrac().const_array(mfi); + + AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); + + // Compute edge state if needed + if (!known_edgestate) + { + Array4 const q = state.const_array(mfi,state_comp); + + AMREX_D_TERM( Array4 u = umac.const_array(mfi);, + Array4 v = vmac.const_array(mfi);, + Array4 w = wmac.const_array(mfi);); + + EBMOL::ComputeEdgeState( bx, + AMREX_D_DECL(xed,yed,zed), + q, ncomp, + AMREX_D_DECL(u,v,w), + domain, bcs, d_bcrec_ptr, + AMREX_D_DECL(fcx,fcy,fcz), + ccc, vfrac, flag, + is_velocity ); + } + + // Compute fluxes + HydroUtils::EB_ComputeFluxes(bx, + AMREX_D_DECL(fx,fy,fz), + AMREX_D_DECL(uc,vc,wc), + AMREX_D_DECL(xed,yed,zed), + AMREX_D_DECL(apx,apy,apz), + geom, ncomp, flag, fluxes_are_area_weighted ); + + // Compute divergence + // Compute -div because that's what redistribution needs + Real mult = -1.0; + HydroUtils::EB_ComputeDivergence(bx, advc_arr, + AMREX_D_DECL(fx,fy,fz), vfrac, + ncomp, geom, mult, fluxes_are_area_weighted ); + } + else + { + // Compute edge state if needed + if (!known_edgestate) + { + Array4 const q = state.const_array(mfi,state_comp); + + AMREX_D_TERM( Array4 u = umac.const_array(mfi);, + Array4 v = vmac.const_array(mfi);, + Array4 w = wmac.const_array(mfi);); + + MOL::ComputeEdgeState( bx, + AMREX_D_DECL( xed, yed, zed ), + q, ncomp, + AMREX_D_DECL( u, v, w ), + domain, bcs, d_bcrec_ptr, + is_velocity); + + } + + // Compute fluxes + HydroUtils::ComputeFluxes(bx, + AMREX_D_DECL(fx,fy,fz), + AMREX_D_DECL(uc,vc,wc), + AMREX_D_DECL(xed,yed,zed), + geom, ncomp, fluxes_are_area_weighted ); + + // Compute divergence + // We use minus sign, i.e. -div, for consistency with EB above + Real mult = -1.0; + HydroUtils::ComputeDivergence(bx, advc_arr, + AMREX_D_DECL(fx,fy,fz), + ncomp, geom, + mult, fluxes_are_area_weighted ); + } + } + } + + advc.FillBoundary(geom.periodicity()); + + MultiFab sstate_tmp; + MultiFab* sstate; + if (redistribution_type == "StateRedist") + { + // Create temporary holder for sync "state" passed in via aofs + // Do this so we're not overwriting the "state" as we go through the redistribution + // process. + sstate_tmp.define(state.boxArray(),state.DistributionMap(),ncomp,state.nGrow(), + MFInfo(),ebfactory); + sstate = &sstate_tmp; + MultiFab::Copy(*sstate,aofs,aofs_comp,0,ncomp,state.nGrow()); + } + else + { + // Doesn't matter what we put here, sstate only gets used for StateRedist + sstate = &aofs; + } + + if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); +#ifdef _OPENMP +#pragma omp parallel if (Gpu::notInLaunchRegion()) +#endif + for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) + { + auto const& bx = mfi.tilebox(); + + auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; + auto const& flag = flagfab.const_array(); + + if (flagfab.getType(bx) != FabType::covered) + { + // FIXME? not sure if 4 is really needed or if 3 could do + // But this is a safe choice + if (flagfab.getType(grow(bx,4)) != FabType::regular) + { + // + // Redistribute + // + AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, + auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, + auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); + + AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, + Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, + Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); + + Array4 bcc = ebfactory.getBndryCent().const_array(mfi); + Array4 ccc = ebfactory.getCentroid().const_array(mfi); + auto vfrac = ebfactory.getVolFrac().const_array(mfi); + + // This is scratch space if calling StateRedistribute, + // but is used as the weights (here set to 1) if calling + // FluxRedistribute + Box gbx = bx; + + if (redistribution_type == "StateRedist") + gbx.grow(3); + else if (redistribution_type == "FluxRedist") + gbx.grow(2); + FArrayBox tmpfab(gbx, ncomp*2); + Elixir eli = tmpfab.elixir(); + Array4 scratch = tmpfab.array(0); + if (redistribution_type == "FluxRedist") + { + amrex::ParallelFor(Box(scratch), + [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept + { scratch(i,j,k) = 1.;}); + } + Array4 divtmp_redist_arr = tmpfab.array(ncomp); + + // Redistribute + // + // For StateRedistribution, we use the Sync as the "state". + // This may lead to oversmoothing. + // + Redistribution::Apply( bx, ncomp, divtmp_redist_arr, advc.array(mfi), + sstate->const_array(mfi, 0), scratch, flag, + AMREX_D_DECL(apx,apy,apz), vfrac, + AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bcrec_ptr, + geom, dt, redistribution_type ); + + // Subtract contribution to sync aofs -- sign of divergence in aofs is opposite + // of sign of div as computed by EB_ComputeDivergence, thus it must be subtracted. + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + + amrex::ParallelFor(bx, ncomp, [aofs_arr, divtmp_redist_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) -= divtmp_redist_arr( i, j, k, n ); }); + } + else + { + // Subtract contribution to sync aofs -- sign of divergence in aofs is opposite + // of sign of div as computed here, and thus it must be subtracted. + auto const& aofs_arr = aofs.array(mfi, aofs_comp); + Array4 advc_arr = advc.array(mfi); + + amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] + AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept + { aofs_arr( i, j, k, n ) -= advc_arr( i, j, k, n ); }); + } + } + } +} +/** @} */ diff --git a/Godunov/hydro_godunov_edge_state_2D.cpp b/Godunov/hydro_godunov_edge_state_2D.cpp index 389148a4a..864f8f1ee 100644 --- a/Godunov/hydro_godunov_edge_state_2D.cpp +++ b/Godunov/hydro_godunov_edge_state_2D.cpp @@ -155,8 +155,8 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (use_forces_in_trans && fq) { - lo += 0.5*l_dt*fq(i-1,j,k,n); - hi += 0.5*l_dt*fq(i ,j,k,n); + lo += Real(0.5)*l_dt*fq(i-1,j,k,n); + hi += Real(0.5)*l_dt*fq(i ,j,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -174,8 +174,8 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (use_forces_in_trans && fq) { - lo += 0.5*l_dt*fq(i,j-1,k,n); - hi += 0.5*l_dt*fq(i,j ,k,n); + lo += Real(0.5)*l_dt*fq(i,j-1,k,n); + hi += Real(0.5)*l_dt*fq(i,j ,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -207,8 +207,8 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(1, i, j, k, n, qnph, l_yzlo, l_yzhi, vmac(i,j,k), bc.hi(1), dhi.y, is_velocity); Real st = (vad >= 0.) ? l_yzlo : l_yzhi; - Real fu = (amrex::Math::abs(vad) < small_vel) ? 0.0 : 1.0; - yzlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_yzhi + l_yzlo); + Real fu = (amrex::Math::abs(vad) < small_vel) ? 0.0 : Real(1); + yzlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_yzhi + l_yzlo); }); // @@ -225,31 +225,31 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, // q + dx/2 q_x - dt/2 (u q_x + q u_x + (v q)_y) which is equivalent to // --> q + dx/2 q_x - dt/2 ( div (uvec q) ) Real quxl = (umac(i,j,k) - umac(i-1,j,k)) * q(i-1,j,k,n); - stl += ( - (0.5*dtdx) * quxl - - (0.5*dtdy) * (yzlo(i-1,j+1,k ,n)*vmac(i-1,j+1,k ) + stl += ( - (Real(0.5)*dtdx) * quxl + - (Real(0.5)*dtdy) * (yzlo(i-1,j+1,k ,n)*vmac(i-1,j+1,k ) -yzlo(i-1,j ,k ,n)*vmac(i-1,j ,k )) ); // Here we adjust for non-conservative by removing the q divu contribution to get // q + dx/2 q_x - dt/2 ( div (uvec q) - q divu ) which is equivalent to // --> q + dx/2 q_x - dt/2 ( uvec dot grad q) - stl += (!iconserv[n]) ? 0.5*l_dt* q(i-1,j,k,n)*divu(i-1,j,k) : 0.; + stl += (!iconserv[n]) ? Real(0.5)*l_dt* q(i-1,j,k,n)*divu(i-1,j,k) : Real(0); - stl += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i-1,j,k,n) : 0.; + stl += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i-1,j,k,n) : Real(0); // Here we add uq/r for RZ - stl += (is_rz) ? -0.25 * l_dt * q(i-1,j,k,n)*( umac(i,j,k) + umac(i-1,j,k) ) / ( dx*(amrex::Math::abs(Real(i)-0.5)) ) : 0.; + stl += (is_rz) ? -Real(0.25) * l_dt * q(i-1,j,k,n)*( umac(i,j,k) + umac(i-1,j,k) ) / ( dx*(amrex::Math::abs(Real(i)-Real(0.5))) ) : Real(0); // High side Real quxh = (umac(i+1,j,k) - umac(i,j,k)) * q(i,j,k,n); - sth += ( - (0.5*dtdx) * quxh - - (0.5*dtdy)*(yzlo(i,j+1,k,n)*vmac(i,j+1,k) + sth += ( - (Real(0.5)*dtdx) * quxh + - (Real(0.5)*dtdy)*(yzlo(i,j+1,k,n)*vmac(i,j+1,k) -yzlo(i,j ,k,n)*vmac(i,j ,k)) ); - sth += (!iconserv[n]) ? 0.5*l_dt* q(i ,j,k,n)*divu(i,j,k) : 0.; + sth += (!iconserv[n]) ? Real(0.5)*l_dt* q(i ,j,k,n)*divu(i,j,k) : Real(0); - sth += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i ,j,k,n) : 0.; + sth += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i ,j,k,n) : Real(0); - sth += (is_rz) ? -0.25 * l_dt * q(i,j,k,n)*( umac(i,j,k) + umac(i+1,j,k) ) / ( dx*(amrex::Math::abs(Real(i)+0.5)) ) : 0.; + sth += (is_rz) ? -Real(0.25) * l_dt * q(i,j,k,n)*( umac(i,j,k) + umac(i+1,j,k) ) / ( dx*(amrex::Math::abs(Real(i)+Real(0.5))) ) : Real(0); const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -270,7 +270,7 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, } Real temp = (umac(i,j,k) >= 0.) ? stl : sth; - temp = (amrex::Math::abs(umac(i,j,k)) < small_vel) ? 0.5*(stl + sth) : temp; + temp = (amrex::Math::abs(umac(i,j,k)) < small_vel) ? Real(0.5)*(stl + sth) : temp; xedge(i,j,k,n) = temp; }); @@ -294,8 +294,8 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, Real uad = umac(i,j,k); Real st = (uad >= 0.) ? l_xzlo : l_xzhi; - Real fu = (amrex::Math::abs(uad) < small_vel) ? 0.0 : 1.0; - xzlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_xzhi + l_xzlo); + Real fu = (amrex::Math::abs(uad) < small_vel) ? 0.0 : Real(1); + xzlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_xzhi + l_xzlo); }); // @@ -313,31 +313,31 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, // q + dy/2 q_y - dt/2 (v q_y + q v_y + (u q)_x) which is equivalent to // --> q + dy/2 q_y - dt/2 ( div (uvec q) ) Real qvyl = (vmac(i,j,k) - vmac(i,j-1,k)) * q(i,j-1,k,n); - stl += ( - (0.5*dtdy)*qvyl - - (0.5*dtdx)*(xzlo(i+1,j-1,k ,n)*umac(i+1,j-1,k ) + stl += ( - (Real(0.5)*dtdy)*qvyl + - (Real(0.5)*dtdx)*(xzlo(i+1,j-1,k ,n)*umac(i+1,j-1,k ) -xzlo(i ,j-1,k ,n)*umac(i ,j-1,k )) ); // Here we adjust for non-conservative by removing the q divu contribution to get // q + dy/2 q_y - dt/2 ( div (uvec q) - q divu ) which is equivalent to // --> q + dy/2 q_y - dt/2 ( uvec dot grad q) - stl += (!iconserv[n]) ? 0.5*l_dt* q(i,j-1,k,n)*divu(i,j-1,k) : 0.; + stl += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j-1,k,n)*divu(i,j-1,k) : Real(0); - stl += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j-1,k,n) : 0.; + stl += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j-1,k,n) : Real(0); // Here we add uq/r for RZ - stl += (is_rz) ? -0.25 * l_dt * q(i,j-1,k,n)*( umac(i,j-1,k) + umac(i+1,j-1,k) ) / ( dx*(amrex::Math::abs(Real(i)+0.5)) ) : 0.; + stl += (is_rz) ? -Real(0.25) * l_dt * q(i,j-1,k,n)*( umac(i,j-1,k) + umac(i+1,j-1,k) ) / ( dx*(amrex::Math::abs(Real(i)+Real(0.5))) ) : Real(0); // High side Real qvyh = (vmac(i,j+1,k) - vmac(i,j,k)) * q(i,j,k,n); - sth += ( - (0.5*dtdy)*qvyh - - (0.5*dtdx)*(xzlo(i+1,j,k ,n)*umac(i+1,j,k ) + sth += ( - (Real(0.5)*dtdy)*qvyh + - (Real(0.5)*dtdx)*(xzlo(i+1,j,k ,n)*umac(i+1,j,k ) -xzlo(i ,j,k ,n)*umac(i ,j,k )) ); - sth += (!iconserv[n]) ? 0.5*l_dt* q(i,j,k,n)*divu(i,j,k) : 0.; + sth += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j,k,n)*divu(i,j,k) : Real(0); - sth += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j,k,n) : 0.; + sth += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j,k,n) : Real(0); - sth += (is_rz) ? -0.25 * l_dt * q(i,j,k,n)*( umac(i,j ,k) + umac(i+1,j ,k) ) / ( dx*(amrex::Math::abs(Real(i)+0.5)) ) : 0.; + sth += (is_rz) ? -Real(0.25) * l_dt * q(i,j,k,n)*( umac(i,j ,k) + umac(i+1,j ,k) ) / ( dx*(amrex::Math::abs(Real(i)+Real(0.5))) ) : Real(0); const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -347,18 +347,18 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (j==dlo.y) && (bc.lo(1) == BCType::foextrap || bc.lo(1) == BCType::hoextrap) ) { - if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) sth = amrex::min(sth,0.0_rt); + if ( vmac(i,j,k) >= Real(0) && n==YVEL && is_velocity ) sth = amrex::min(sth,Real(0)); stl = sth; } if ( (j==dhi.y+1) && (bc.hi(1) == BCType::foextrap || bc.hi(1) == BCType::hoextrap) ) { - if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) stl = amrex::max(stl,0.0_rt); + if ( vmac(i,j,k) <= Real(0) && n==YVEL && is_velocity ) stl = amrex::max(stl,Real(0)); sth = stl; } } - Real temp = (vmac(i,j,k) >= 0.) ? stl : sth; - temp = (amrex::Math::abs(vmac(i,j,k)) < small_vel) ? 0.5*(stl + sth) : temp; + Real temp = (vmac(i,j,k) >= Real(0)) ? stl : sth; + temp = (amrex::Math::abs(vmac(i,j,k)) < small_vel) ? Real(0.5)*(stl + sth) : temp; yedge(i,j,k,n) = temp; }); diff --git a/Godunov/hydro_godunov_edge_state_3D.cpp b/Godunov/hydro_godunov_edge_state_3D.cpp index 2247c16e3..0a5b07854 100644 --- a/Godunov/hydro_godunov_edge_state_3D.cpp +++ b/Godunov/hydro_godunov_edge_state_3D.cpp @@ -170,15 +170,15 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, xebox, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real uad = umac(i,j,k); - Real fux = (amrex::Math::abs(uad) < small_vel)? 0. : 1.; - bool uval = uad >= 0.; + Real fux = (amrex::Math::abs(uad) < small_vel)? Real(0) : Real(1); + bool uval = uad >= Real(0); Real lo = Ipx(i-1,j,k,n); Real hi = Imx(i ,j,k,n); if (use_forces_in_trans && fq) { - lo += 0.5*l_dt*fq(i-1,j,k,n); - hi += 0.5*l_dt*fq(i ,j,k,n); + lo += Real(0.5)*l_dt*fq(i-1,j,k,n); + hi += Real(0.5)*l_dt*fq(i ,j,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -189,21 +189,21 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, xlo(i,j,k,n) = lo; xhi(i,j,k,n) = hi; Real st = (uval) ? lo : hi; - Imx(i,j,k,n) = fux*st + (1. - fux)*0.5*(hi + lo); + Imx(i,j,k,n) = fux*st + (Real(1) - fux)*Real(0.5)*(hi + lo); }, yebox, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real vad = vmac(i,j,k); - Real fuy = (amrex::Math::abs(vad) < small_vel)? 0. : 1.; - bool vval = vad >= 0.; + Real fuy = (amrex::Math::abs(vad) < small_vel)? Real(0) : Real(1); + bool vval = vad >= Real(0); Real lo = Ipy(i,j-1,k,n); Real hi = Imy(i,j ,k,n); if (use_forces_in_trans && fq) { - lo += 0.5*l_dt*fq(i,j-1,k,n); - hi += 0.5*l_dt*fq(i,j ,k,n); + lo += Real(0.5)*l_dt*fq(i,j-1,k,n); + hi += Real(0.5)*l_dt*fq(i,j ,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -214,20 +214,20 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, ylo(i,j,k,n) = lo; yhi(i,j,k,n) = hi; Real st = (vval) ? lo : hi; - Imy(i,j,k,n) = fuy*st + (1. - fuy)*0.5*(hi + lo); + Imy(i,j,k,n) = fuy*st + (Real(1) - fuy)*Real(0.5)*(hi + lo); }, zebox, ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept { Real wad = wmac(i,j,k); - Real fuz = (amrex::Math::abs(wad) < small_vel) ? 0. : 1.; - bool wval = wad >= 0.; + Real fuz = (amrex::Math::abs(wad) < small_vel) ? Real(0) : Real(1); + bool wval = wad >= Real(0); Real lo = Ipz(i,j,k-1,n); Real hi = Imz(i,j,k ,n); if (use_forces_in_trans && fq) { - lo += 0.5*l_dt*fq(i,j,k-1,n); - hi += 0.5*l_dt*fq(i,j,k ,n); + lo += Real(0.5)*l_dt*fq(i,j,k-1,n); + hi += Real(0.5)*l_dt*fq(i,j,k ,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -238,7 +238,7 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, zlo(i,j,k,n) = lo; zhi(i,j,k,n) = hi; Real st = (wval) ? lo : hi; - Imz(i,j,k,n) = fuz*st + (1. - fuz)*0.5*(hi + lo); + Imz(i,j,k,n) = fuz*st + (Real(1) - fuz)*Real(0.5)*(hi + lo); } ); @@ -265,9 +265,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(2, i, j, k, n, qnph, l_zylo, l_zyhi, wmac(i,j,k), bc.hi(2), dhi.z, is_velocity); Real wad = wmac(i,j,k); - Real st = (wad >= 0.) ? l_zylo : l_zyhi; - Real fu = (amrex::Math::abs(wad) < small_vel) ? 0.0 : 1.0; - zylo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_zyhi + l_zylo); + Real st = (wad >= Real(0)) ? l_zylo : l_zyhi; + Real fu = (amrex::Math::abs(wad) < small_vel) ? Real(0) : Real(1); + zylo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_zyhi + l_zylo); }, Box(yzlo), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept @@ -283,9 +283,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(1, i, j, k, n, qnph, l_yzlo, l_yzhi, vmac(i,j,k), bc.hi(1), dhi.y, is_velocity); Real vad = vmac(i,j,k); - Real st = (vad >= 0.) ? l_yzlo : l_yzhi; - Real fu = (amrex::Math::abs(vad) < small_vel) ? 0.0 : 1.0; - yzlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_yzhi + l_yzlo); + Real st = (vad >= Real(0)) ? l_yzlo : l_yzhi; + Real fu = (amrex::Math::abs(vad) < small_vel) ? Real(0) : Real(1); + yzlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_yzhi + l_yzlo); }); @@ -302,30 +302,30 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, // q + dx/2 q_x - dt/2 (u q_x + q u_x + (v q)_y + (w q)_z) which is equivalent to // --> q + dx/2 q_x - dt/2 ( div (uvec q) ) Real quxl = (umac(i,j,k) - umac(i-1,j,k)) * q(i-1,j,k,n); - stl += ( - (0.5*dtdx) * quxl - - (0.5*dtdy)*(yzlo(i-1,j+1,k ,n)*vmac(i-1,j+1,k ) + stl += ( - (Real(0.5)*dtdx) * quxl + - (Real(0.5)*dtdy)*(yzlo(i-1,j+1,k ,n)*vmac(i-1,j+1,k ) - yzlo(i-1,j ,k ,n)*vmac(i-1,j ,k )) - - (0.5*dtdz)*(zylo(i-1,j ,k+1,n)*wmac(i-1,j ,k+1) + - (Real(0.5)*dtdz)*(zylo(i-1,j ,k+1,n)*wmac(i-1,j ,k+1) - zylo(i-1,j ,k ,n)*wmac(i-1,j ,k )) ); // Here we adjust for non-conservative by removing the q divu contribution to get // q + dx/2 q_x - dt/2 ( div (uvec q) - q divu ) which is equivalent to // --> q + dx/2 q_x - dt/2 ( uvec dot grad q) - stl += (!iconserv[n]) ? 0.5*l_dt* q(i-1,j,k,n)*divu(i-1,j,k) : 0.; + stl += (!iconserv[n]) ? Real(0.5)*l_dt* q(i-1,j,k,n)*divu(i-1,j,k) : Real(0); - stl += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i-1,j,k,n) : 0.; + stl += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i-1,j,k,n) : Real(0); // High side Real quxh = (umac(i+1,j,k) - umac(i,j,k)) * q(i,j,k,n); - sth += ( - (0.5*dtdx) * quxh - - (0.5*dtdy)*(yzlo(i,j+1,k ,n)*vmac(i,j+1,k ) + sth += ( - (Real(0.5)*dtdx) * quxh + - (Real(0.5)*dtdy)*(yzlo(i,j+1,k ,n)*vmac(i,j+1,k ) - yzlo(i,j ,k ,n)*vmac(i,j ,k )) - - (0.5*dtdz)*(zylo(i,j ,k+1,n)*wmac(i,j ,k+1) + - (Real(0.5)*dtdz)*(zylo(i,j ,k+1,n)*wmac(i,j ,k+1) - zylo(i,j ,k ,n)*wmac(i,j ,k )) ); - sth += (!iconserv[n]) ? 0.5*l_dt* q(i ,j,k,n)*divu(i,j,k) : 0.; + sth += (!iconserv[n]) ? Real(0.5)*l_dt* q(i ,j,k,n)*divu(i,j,k) : Real(0); - sth += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i ,j,k,n) : 0.; + sth += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i ,j,k,n) : Real(0); const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -335,18 +335,18 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (i==dlo.x) && (bc.lo(0) == BCType::foextrap || bc.lo(0) == BCType::hoextrap) ) { - if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) sth = amrex::min(sth,0.0_rt); + if ( umac(i,j,k) >= Real(0) && n==XVEL && is_velocity ) sth = amrex::min(sth,Real(0)); stl = sth; } if ( (i==dhi.x+1) && (bc.hi(0) == BCType::foextrap || bc.hi(0) == BCType::hoextrap) ) { - if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) stl = amrex::max(stl,0.0_rt); + if ( umac(i,j,k) <= Real(0) && n==XVEL && is_velocity ) stl = amrex::max(stl,Real(0)); sth = stl; } } - Real temp = (umac(i,j,k) >= 0.) ? stl : sth; - temp = (amrex::Math::abs(umac(i,j,k)) < small_vel) ? 0.5*(stl + sth) : temp; + Real temp = (umac(i,j,k) >= Real(0)) ? stl : sth; + temp = (amrex::Math::abs(umac(i,j,k)) < small_vel) ? Real(0.5)*(stl + sth) : temp; xedge(i,j,k,n) = temp; }); @@ -371,9 +371,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(0, i, j, k, n, qnph, l_xzlo, l_xzhi, umac(i,j,k), bc.hi(0), dhi.x, is_velocity); Real uad = umac(i,j,k); - Real st = (uad >= 0.) ? l_xzlo : l_xzhi; - Real fu = (amrex::Math::abs(uad) < small_vel) ? 0.0 : 1.0; - xzlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_xzhi + l_xzlo); + Real st = (uad >= Real(0)) ? l_xzlo : l_xzhi; + Real fu = (amrex::Math::abs(uad) < small_vel) ? Real(0) : Real(1); + xzlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_xzhi + l_xzlo); }, Box(zxlo), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept @@ -389,9 +389,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(2, i, j, k, n, qnph, l_zxlo, l_zxhi, wmac(i,j,k), bc.hi(2), dhi.z, is_velocity); Real wad = wmac(i,j,k); - Real st = (wad >= 0.) ? l_zxlo : l_zxhi; - Real fu = (amrex::Math::abs(wad) < small_vel) ? 0.0 : 1.0; - zxlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_zxhi + l_zxlo); + Real st = (wad >= Real(0)) ? l_zxlo : l_zxhi; + Real fu = (amrex::Math::abs(wad) < small_vel) ? Real(0) : Real(1); + zxlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_zxhi + l_zxlo); }); // @@ -406,30 +406,30 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, // q + dy/2 q_y - dt/2 (v q_y + q v_y + (u q)_x + (w q)_z) which is equivalent to // --> q + dy/2 q_y - dt/2 ( div (uvec q) ) Real qvyl = (vmac(i,j,k) - vmac(i,j-1,k)) * q(i,j-1,k,n); - stl += ( - (0.5*dtdy) * qvyl - - (0.5*dtdx)*(xzlo(i+1,j-1,k ,n)*umac(i+1,j-1,k ) + stl += ( - (Real(0.5)*dtdy) * qvyl + - (Real(0.5)*dtdx)*(xzlo(i+1,j-1,k ,n)*umac(i+1,j-1,k ) - xzlo(i ,j-1,k ,n)*umac(i ,j-1,k )) - - (0.5*dtdz)*(zxlo(i ,j-1,k+1,n)*wmac(i ,j-1,k+1) + - (Real(0.5)*dtdz)*(zxlo(i ,j-1,k+1,n)*wmac(i ,j-1,k+1) - zxlo(i ,j-1,k ,n)*wmac(i ,j-1,k )) ); // Here we adjust for non-conservative by removing the q divu contribution to get // q + dy/2 q_y - dt/2 ( div (uvec q) - q divu ) which is equivalent to // --> q + dy/2 q_y - dt/2 ( uvec dot grad q) - stl += (!iconserv[n]) ? 0.5*l_dt* q(i,j-1,k,n)*divu(i,j-1,k) : 0.; + stl += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j-1,k,n)*divu(i,j-1,k) : Real(0); - stl += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j-1,k,n) : 0.; + stl += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j-1,k,n) : Real(0); // High side Real qvyh = (vmac(i,j+1,k) - vmac(i,j,k)) * q(i,j,k,n); - sth += ( - (0.5*dtdy) * qvyh - - (0.5*dtdx)*(xzlo(i+1,j,k ,n)*umac(i+1,j,k ) + sth += ( - (Real(0.5)*dtdy) * qvyh + - (Real(0.5)*dtdx)*(xzlo(i+1,j,k ,n)*umac(i+1,j,k ) - xzlo(i ,j,k ,n)*umac(i ,j,k )) - - (0.5*dtdz)*(zxlo(i ,j,k+1,n)*wmac(i ,j,k+1) + - (Real(0.5)*dtdz)*(zxlo(i ,j,k+1,n)*wmac(i ,j,k+1) - zxlo(i ,j,k ,n)*wmac(i ,j,k )) ); - sth += (!iconserv[n]) ? 0.5*l_dt* q(i,j,k,n)*divu(i,j,k) : 0.; + sth += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j,k,n)*divu(i,j,k) : Real(0); - sth += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j,k,n) : 0.; + sth += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j,k,n) : Real(0); const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -439,18 +439,18 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (j==dlo.y) && (bc.lo(1) == BCType::foextrap || bc.lo(1) == BCType::hoextrap) ) { - if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) sth = amrex::min(sth,0.0_rt); + if ( vmac(i,j,k) >= Real(0) && n==YVEL && is_velocity ) sth = amrex::min(sth,Real(0)); stl = sth; } if ( (j==dhi.y+1) && (bc.hi(1) == BCType::foextrap || bc.hi(1) == BCType::hoextrap) ) { - if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) stl = amrex::max(stl,0.0_rt); + if ( vmac(i,j,k) <= Real(0) && n==YVEL && is_velocity ) stl = amrex::max(stl,Real(0)); sth = stl; } } - Real temp = (vmac(i,j,k) >= 0.) ? stl : sth; - temp = (amrex::Math::abs(vmac(i,j,k)) < small_vel) ? 0.5*(stl + sth) : temp; + Real temp = (vmac(i,j,k) >= Real(0)) ? stl : sth; + temp = (amrex::Math::abs(vmac(i,j,k)) < small_vel) ? Real(0.5)*(stl + sth) : temp; yedge(i,j,k,n) = temp; }); @@ -475,9 +475,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(0, i, j, k, n, qnph, l_xylo, l_xyhi, umac(i,j,k), bc.hi(0), dhi.x, is_velocity); Real uad = umac(i,j,k); - Real st = (uad >= 0.) ? l_xylo : l_xyhi; - Real fu = (amrex::Math::abs(uad) < small_vel) ? 0.0 : 1.0; - xylo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_xyhi + l_xylo); + Real st = (uad >= Real(0)) ? l_xylo : l_xyhi; + Real fu = (amrex::Math::abs(uad) < small_vel) ? Real(0) : Real(1); + xylo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_xyhi + l_xylo); }, Box(yxlo), ncomp, [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept @@ -493,9 +493,9 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, HydroBC::SetEdgeBCsHi(1, i, j, k, n, qnph, l_yxlo, l_yxhi, vmac(i,j,k), bc.hi(1), dhi.y, is_velocity); Real vad = vmac(i,j,k); - Real st = (vad >= 0.) ? l_yxlo : l_yxhi; - Real fu = (amrex::Math::abs(vad) < small_vel) ? 0.0 : 1.0; - yxlo(i,j,k,n) = fu*st + (1.0 - fu) * 0.5 * (l_yxhi + l_yxlo); + Real st = (vad >= Real(0)) ? l_yxlo : l_yxhi; + Real fu = (amrex::Math::abs(vad) < small_vel) ? Real(0) : Real(1); + yxlo(i,j,k,n) = fu*st + (Real(1) - fu) * Real(0.5) * (l_yxhi + l_yxlo); }); // @@ -510,30 +510,30 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, // q + dz/2 q_z - dt/2 (w q_z + q w_z + (u q)_x + (v q)_y) which is equivalent to // --> q + dz/2 q_z - dt/2 ( div (uvec q) ) Real qwzl = (wmac(i,j,k) - wmac(i,j,k-1)) * q(i,j,k-1,n); - stl += ( - (0.5*dtdz) * qwzl - -(0.5*dtdx)*(xylo(i+1,j ,k-1,n)*umac(i+1,j ,k-1) + stl += ( -(Real(0.5)*dtdz) * qwzl + -(Real(0.5)*dtdx)*(xylo(i+1,j ,k-1,n)*umac(i+1,j ,k-1) -xylo(i ,j ,k-1,n)*umac(i ,j ,k-1)) - -(0.5*dtdy)*(yxlo(i ,j+1,k-1,n)*vmac(i ,j+1,k-1) + -(Real(0.5)*dtdy)*(yxlo(i ,j+1,k-1,n)*vmac(i ,j+1,k-1) -yxlo(i ,j ,k-1,n)*vmac(i ,j ,k-1)) ); // Here we adjust for non-conservative by removing the q divu contribution to get // q + dz/2 q_z - dt/2 ( div (uvec q) - q divu ) which is equivalent to // --> q + dz/2 q_z - dt/2 ( uvec dot grad q) - stl += (!iconserv[n]) ? 0.5*l_dt* q(i,j,k-1,n)*divu(i,j,k-1) : 0.; + stl += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j,k-1,n)*divu(i,j,k-1) : Real(0); - stl += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j,k-1,n) : 0.; + stl += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j,k-1,n) : Real(0); // High side Real qwzh = (wmac(i,j,k+1) - wmac(i,j,k)) * q(i,j,k,n); - sth += ( - (0.5*dtdz) * qwzh - - (0.5*dtdx)*(xylo(i+1,j ,k,n)*umac(i+1,j ,k) + sth += ( - (Real(0.5)*dtdz) * qwzh + - (Real(0.5)*dtdx)*(xylo(i+1,j ,k,n)*umac(i+1,j ,k) -xylo(i ,j ,k,n)*umac(i ,j ,k)) - - (0.5*dtdy)*(yxlo(i ,j+1,k,n)*vmac(i ,j+1,k) + - (Real(0.5)*dtdy)*(yxlo(i ,j+1,k,n)*vmac(i ,j+1,k) -yxlo(i ,j ,k,n)*vmac(i ,j ,k)) ); - sth += (!iconserv[n]) ? 0.5*l_dt* q(i,j,k,n)*divu(i,j,k) : 0.; + sth += (!iconserv[n]) ? Real(0.5)*l_dt* q(i,j,k,n)*divu(i,j,k) : Real(0); - sth += (!use_forces_in_trans && fq) ? 0.5*l_dt*fq(i,j,k,n) : 0.; + sth += (!use_forces_in_trans && fq) ? Real(0.5)*l_dt*fq(i,j,k,n) : Real(0); const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); HydroBC::SetEdgeBCsLo(2, i, j, k, n, qnph, stl, sth, wmac(i,j,k), bc.lo(2), dlo.z, is_velocity); @@ -542,18 +542,18 @@ Godunov::ComputeEdgeState (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (k==dlo.z) && (bc.lo(2) == BCType::foextrap || bc.lo(2) == BCType::hoextrap) ) { - if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) sth = amrex::min(sth,0.0_rt); + if ( wmac(i,j,k) >= Real(0) && n==ZVEL && is_velocity ) sth = amrex::min(sth,Real(0)); stl = sth; } if ( (k==dhi.z+1) && (bc.hi(2) == BCType::foextrap || bc.hi(2) == BCType::hoextrap) ) { - if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) stl = amrex::max(stl,0.0_rt); + if ( wmac(i,j,k) <= Real(0) && n==ZVEL && is_velocity ) stl = amrex::max(stl,Real(0)); sth = stl; } } - Real temp = (wmac(i,j,k) >= 0.) ? stl : sth; - temp = (amrex::Math::abs(wmac(i,j,k)) < small_vel) ? 0.5*(stl + sth) : temp; + Real temp = (wmac(i,j,k) >= Real(0)) ? stl : sth; + temp = (amrex::Math::abs(wmac(i,j,k)) < small_vel) ? Real(0.5)*(stl + sth) : temp; zedge(i,j,k,n) = temp; }); diff --git a/Godunov/hydro_godunov_extrap_vel_to_faces_2D.cpp b/Godunov/hydro_godunov_extrap_vel_to_faces_2D.cpp index 211593ad9..f99f0bdc4 100644 --- a/Godunov/hydro_godunov_extrap_vel_to_faces_2D.cpp +++ b/Godunov/hydro_godunov_extrap_vel_to_faces_2D.cpp @@ -150,17 +150,17 @@ Godunov::ComputeAdvectiveVel ( Box const& xbx, if (l_use_forces_in_trans) { - lo += 0.5*l_dt*f(i-1,j,k,n); - hi += 0.5*l_dt*f(i ,j,k,n); + lo += Real(0.5)*l_dt*f(i-1,j,k,n); + hi += Real(0.5)*l_dt*f(i ,j,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); HydroBC::SetExtrapVelBCsLo(0, i, j, k, n, vel, lo, hi, bc.lo(0), dlo.x); HydroBC::SetExtrapVelBCsHi(0, i, j, k, n, vel, lo, hi, bc.hi(0), dhi.x); - Real st = ( (lo+hi) >= 0.) ? lo : hi; - bool ltm = ( (lo <= 0. && hi >= 0.) || (amrex::Math::abs(lo+hi) < small_vel) ); - u_ad(i,j,k) = ltm ? 0. : st; + Real st = ( (lo+hi) >= Real(0)) ? lo : hi; + bool ltm = ( (lo <= Real(0) && hi >= Real(0)) || (amrex::Math::abs(lo+hi) < small_vel) ); + u_ad(i,j,k) = ltm ? Real(0) : st; }, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { @@ -172,17 +172,17 @@ Godunov::ComputeAdvectiveVel ( Box const& xbx, if (l_use_forces_in_trans) { - lo += 0.5*l_dt*f(i,j-1,k,n); - hi += 0.5*l_dt*f(i,j ,k,n); + lo += Real(0.5)*l_dt*f(i,j-1,k,n); + hi += Real(0.5)*l_dt*f(i,j ,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); HydroBC::SetExtrapVelBCsLo(1, i, j, k, n, vel, lo, hi, bc.lo(1), dlo.y); HydroBC::SetExtrapVelBCsHi(1, i, j, k, n, vel, lo, hi, bc.hi(1), dhi.y); - Real st = ( (lo+hi) >= 0.) ? lo : hi; - bool ltm = ( (lo <= 0. && hi >= 0.) || (amrex::Math::abs(lo+hi) < small_vel) ); - v_ad(i,j,k) = ltm ? 0. : st; + Real st = ( (lo+hi) >= Real(0)) ? lo : hi; + bool ltm = ( (lo <= Real(0) && hi >= Real(0)) || (amrex::Math::abs(lo+hi) < small_vel) ); + v_ad(i,j,k) = ltm ? Real(0) : st; } ); } @@ -240,8 +240,8 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, if (l_use_forces_in_trans) { - lo += 0.5*l_dt*f(i-1,j,k,n); - hi += 0.5*l_dt*f(i ,j,k,n); + lo += Real(0.5)*l_dt*f(i-1,j,k,n); + hi += Real(0.5)*l_dt*f(i ,j,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -258,8 +258,8 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, if (l_use_forces_in_trans) { - lo += 0.5*l_dt*f(i,j-1,k,n); - hi += 0.5*l_dt*f(i,j ,k,n); + lo += Real(0.5)*l_dt*f(i,j-1,k,n); + hi += Real(0.5)*l_dt*f(i,j ,k,n); } const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); @@ -293,22 +293,22 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, Real vad = v_ad(i,j,k); Real st = (vad >= 0.) ? l_yzlo : l_yzhi; Real fu = (amrex::Math::abs(vad) < small_vel) ? 0.0 : 1.0; - yzlo(i,j,k) = fu*st + (1.0 - fu) * 0.5 * (l_yzhi + l_yzlo); + yzlo(i,j,k) = fu*st + (Real(1) - fu) * Real(0.5) * (l_yzhi + l_yzlo); }); amrex::ParallelFor(xbx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept { constexpr int n = 0; const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); - Real stl = xlo(i,j,k,n) - (0.25*l_dt/dy)*(v_ad(i-1,j+1,k )+v_ad(i-1,j,k))* - (yzlo(i-1,j+1,k )-yzlo(i-1,j,k)); - Real sth = xhi(i,j,k,n) - (0.25*l_dt/dy)*(v_ad(i ,j+1,k )+v_ad(i ,j,k))* - (yzlo(i ,j+1,k )-yzlo(i ,j,k)); + Real stl = xlo(i,j,k,n) - (Real(0.25)*l_dt/dy)*(v_ad(i-1,j+1,k )+v_ad(i-1,j,k))* + (yzlo(i-1,j+1,k )-yzlo(i-1,j,k)); + Real sth = xhi(i,j,k,n) - (Real(0.25)*l_dt/dy)*(v_ad(i ,j+1,k )+v_ad(i ,j,k))* + (yzlo(i ,j+1,k )-yzlo(i ,j,k)); if (!l_use_forces_in_trans) { - stl += 0.5 * l_dt * f(i-1,j,k,n); - sth += 0.5 * l_dt * f(i ,j,k,n); + stl += Real(0.5) * l_dt * f(i-1,j,k,n); + sth += Real(0.5) * l_dt * f(i ,j,k,n); } HydroBC::SetExtrapVelBCsLo(0, i, j, k, n, q, stl, sth, bc.lo(0), dlo.x); @@ -317,19 +317,19 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (i==dlo.x) && (bc.lo(0) == BCType::foextrap || bc.lo(0) == BCType::hoextrap) ) { - sth = amrex::min(sth,0.0_rt); + sth = amrex::min(sth,Real(0)); stl = sth; } if ( (i==dhi.x+1) && (bc.hi(0) == BCType::foextrap || bc.hi(0) == BCType::hoextrap) ) { - stl = amrex::max(stl,0.0_rt); + stl = amrex::max(stl,Real(0)); sth = stl; } } - Real st = ( (stl+sth) >= 0.) ? stl : sth; - bool ltm = ( (stl <= 0. && sth >= 0.) || (amrex::Math::abs(stl+sth) < small_vel) ); - qx(i,j,k) = ltm ? 0. : st; + Real st = ( (stl+sth) >= Real(0)) ? stl : sth; + bool ltm = ( (stl <= Real(0) && sth >= Real(0)) || (amrex::Math::abs(stl+sth) < small_vel) ); + qx(i,j,k) = ltm ? Real(0) : st; }); // @@ -352,8 +352,8 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, Real uad = u_ad(i,j,k); Real st = (uad >= 0.) ? l_xzlo : l_xzhi; - Real fu = (amrex::Math::abs(uad) < small_vel) ? 0.0 : 1.0; - xzlo(i,j,k) = fu*st + (1.0 - fu) * 0.5 * (l_xzhi + l_xzlo); + Real fu = (amrex::Math::abs(uad) < small_vel) ? Real(0) : Real(1); + xzlo(i,j,k) = fu*st + (Real(1) - fu) * Real(0.5) * (l_xzhi + l_xzlo); }); amrex::ParallelFor(ybx, [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept @@ -361,15 +361,15 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, constexpr int n = 1; const auto bc = HydroBC::getBC(i, j, k, n, domain, pbc, bc_arr); - Real stl = ylo(i,j,k,n) - (0.25*l_dt/dx)*(u_ad(i+1,j-1,k )+u_ad(i,j-1,k))* - (xzlo(i+1,j-1,k )-xzlo(i,j-1,k)); - Real sth = yhi(i,j,k,n) - (0.25*l_dt/dx)*(u_ad(i+1,j ,k )+u_ad(i,j ,k))* - (xzlo(i+1,j ,k )-xzlo(i,j ,k)); + Real stl = ylo(i,j,k,n) - (Real(0.25)*l_dt/dx)*(u_ad(i+1,j-1,k )+u_ad(i,j-1,k))* + (xzlo(i+1,j-1,k )-xzlo(i,j-1,k)); + Real sth = yhi(i,j,k,n) - (Real(0.25)*l_dt/dx)*(u_ad(i+1,j ,k )+u_ad(i,j ,k))* + (xzlo(i+1,j ,k )-xzlo(i,j ,k)); if (!l_use_forces_in_trans) { - stl += 0.5 * l_dt * f(i,j-1,k,n); - sth += 0.5 * l_dt * f(i,j ,k,n); + stl += Real(0.5) * l_dt * f(i,j-1,k,n); + sth += Real(0.5) * l_dt * f(i,j ,k,n); } HydroBC::SetExtrapVelBCsLo(1, i, j, k, n, q, stl, sth, bc.lo(1), dlo.y); @@ -378,19 +378,19 @@ Godunov::ExtrapVelToFacesOnBox (Box const& bx, int ncomp, if (!allow_inflow_on_outflow) { if ( (j==dlo.y) && (bc.lo(1) == BCType::foextrap || bc.lo(1) == BCType::hoextrap) ) { - sth = amrex::min(sth,0.0_rt); + sth = amrex::min(sth,Real(0)); stl = sth; } if ( (j==dhi.y+1) && (bc.hi(1) == BCType::foextrap || bc.hi(1) == BCType::hoextrap) ) { - stl = amrex::max(stl,0.0_rt); + stl = amrex::max(stl,Real(0)); sth = stl; } } - Real st = ( (stl+sth) >= 0.) ? stl : sth; - bool ltm = ( (stl <= 0. && sth >= 0.) || (amrex::Math::abs(stl+sth) < small_vel) ); - qy(i,j,k) = ltm ? 0. : st; + Real st = ( (stl+sth) >= Real(0)) ? stl : sth; + bool ltm = ( (stl <= Real(0) && sth >= Real(0)) || (amrex::Math::abs(stl+sth) < small_vel) ); + qy(i,j,k) = ltm ? Real(0) : st; }); } /** @} */ diff --git a/Godunov/hydro_godunov_plm.cpp b/Godunov/hydro_godunov_plm.cpp index b33c67a02..cd8da1c29 100644 --- a/Godunov/hydro_godunov_plm.cpp +++ b/Godunov/hydro_godunov_plm.cpp @@ -68,9 +68,9 @@ PLM::PredictVelOnXFace ( Box const& xebox, int ncomp, int order = 4; - Real upls = q(i ,j,k,n) + 0.5 * (-1.0 - vcc(i ,j,k,0) * dtdx) * + Real upls = q(i ,j,k,n) + Real(0.5) * (-Real(1) - vcc(i ,j,k,0) * dtdx) * amrex_calc_xslope_extdir(i ,j,k,n,order,q,extdir_or_ho_ilo,extdir_or_ho_ihi,domain_ilo,domain_ihi); - Real umns = q(i-1,j,k,n) + 0.5 * ( 1.0 - vcc(i-1,j,k,0) * dtdx) * + Real umns = q(i-1,j,k,n) + Real(0.5) * ( Real(1) - vcc(i-1,j,k,0) * dtdx) * amrex_calc_xslope_extdir(i-1,j,k,n,order,q,extdir_or_ho_ilo,extdir_or_ho_ihi,domain_ilo,domain_ihi); Ipx(i-1,j,k,n) = umns; @@ -84,9 +84,9 @@ PLM::PredictVelOnXFace ( Box const& xebox, int ncomp, { int order = 4; - Real upls = q(i ,j,k,n) + 0.5 * (-1.0 - vcc(i ,j,k,0) * dtdx) * + Real upls = q(i ,j,k,n) + Real(0.5) * (-Real(1) - vcc(i ,j,k,0) * dtdx) * amrex_calc_xslope(i ,j,k,n,order,q); - Real umns = q(i-1,j,k,n) + 0.5 * ( 1.0 - vcc(i-1,j,k,0) * dtdx) * + Real umns = q(i-1,j,k,n) + Real(0.5) * ( Real(1) - vcc(i-1,j,k,0) * dtdx) * amrex_calc_xslope(i-1,j,k,n,order,q); Ipx(i-1,j,k,n) = umns; @@ -132,9 +132,9 @@ PLM::PredictVelOnYFace (Box const& yebox, int ncomp, int order = 4; - Real vpls = q(i,j ,k,n) + 0.5 * (-1.0 - vcc(i,j ,k,1) * dtdy) * + Real vpls = q(i,j ,k,n) + Real(0.5) * (-Real(1) - vcc(i,j ,k,1) * dtdy) * amrex_calc_yslope_extdir(i,j ,k,n,order,q,extdir_or_ho_jlo,extdir_or_ho_jhi,domain_jlo,domain_jhi); - Real vmns = q(i,j-1,k,n) + 0.5 * ( 1.0 - vcc(i,j-1,k,1) * dtdy) * + Real vmns = q(i,j-1,k,n) + Real(0.5) * ( Real(1) - vcc(i,j-1,k,1) * dtdy) * amrex_calc_yslope_extdir(i,j-1,k,n,order,q,extdir_or_ho_jlo,extdir_or_ho_jhi,domain_jlo,domain_jhi); Ipy(i,j-1,k,n) = vmns; @@ -148,9 +148,9 @@ PLM::PredictVelOnYFace (Box const& yebox, int ncomp, { int order = 4; - Real vpls = q(i,j ,k,n) + 0.5 * (-1.0 - vcc(i,j ,k,1) * dtdy) * + Real vpls = q(i,j ,k,n) + Real(0.5) * (-Real(1) - vcc(i,j ,k,1) * dtdy) * amrex_calc_yslope(i,j ,k,n,order,q); - Real vmns = q(i,j-1,k,n) + 0.5 * ( 1.0 - vcc(i,j-1,k,1) * dtdy) * + Real vmns = q(i,j-1,k,n) + Real(0.5) * ( Real(1) - vcc(i,j-1,k,1) * dtdy) * amrex_calc_yslope(i,j-1,k,n,order,q); Ipy(i,j-1,k,n) = vmns; @@ -197,9 +197,9 @@ PLM::PredictVelOnZFace ( Box const& zebox, int ncomp, int order = 4; - Real wpls = q(i,j,k ,n) + 0.5 * (-1.0 - vcc(i,j,k ,2) * dtdz) * + Real wpls = q(i,j,k ,n) + Real(0.5) * (-Real(1) - vcc(i,j,k ,2) * dtdz) * amrex_calc_zslope_extdir(i,j,k,n,order,q,extdir_or_ho_klo,extdir_or_ho_khi,domain_klo,domain_khi); - Real wmns = q(i,j,k-1,n) + 0.5 * ( 1.0 - vcc(i,j,k-1,2) * dtdz) * + Real wmns = q(i,j,k-1,n) + Real(0.5) * ( Real(1) - vcc(i,j,k-1,2) * dtdz) * amrex_calc_zslope_extdir(i,j,k-1,n,order,q,extdir_or_ho_klo,extdir_or_ho_khi,domain_klo,domain_khi); @@ -214,9 +214,9 @@ PLM::PredictVelOnZFace ( Box const& zebox, int ncomp, { int order = 4; - Real wpls = q(i,j,k ,n) + 0.5 * (-1.0 - vcc(i,j,k ,2) * dtdz) * + Real wpls = q(i,j,k ,n) + Real(0.5) * (-Real(1) - vcc(i,j,k ,2) * dtdz) * amrex_calc_zslope(i,j,k ,n,order,q); - Real wmns = q(i,j,k-1,n) + 0.5 * ( 1.0 - vcc(i,j,k-1,2) * dtdz) * + Real wmns = q(i,j,k-1,n) + Real(0.5) * ( Real(1) - vcc(i,j,k-1,2) * dtdz) * amrex_calc_zslope(i,j,k-1,n,order,q); Ipz(i,j,k-1,n) = wmns; diff --git a/Godunov/hydro_godunov_ppm.H b/Godunov/hydro_godunov_ppm.H index f955334c0..8f8eafe1c 100644 --- a/Godunov/hydro_godunov_ppm.H +++ b/Godunov/hydro_godunov_ppm.H @@ -101,7 +101,7 @@ struct nolimiter { amrex::Real d1 = amrex::Real(0.5) * (sp1 - sm1); amrex::Real d2 = amrex::Real(0.5) * (s0 - sm2); - amrex::Real sedge = amrex::Real(0.5)*(s0 + sm1) - amrex::Real(1./6.)*(d1 - d2); + amrex::Real sedge = amrex::Real(0.5)*(s0 + sm1) - (amrex::Real(1)/amrex::Real(6))*(d1 - d2); return sedge; } @@ -116,7 +116,7 @@ struct nolimiter { amrex::Real d1 = amrex::Real(0.5) * (sp2 - s0); amrex::Real d2 = amrex::Real(0.5) * (sp1 - sm1); - amrex::Real sedge = amrex::Real(0.5)*(sp1 + s0) - amrex::Real(1./6.)*(d1 - d2); + amrex::Real sedge = amrex::Real(0.5)*(sp1 + s0) - (amrex::Real(1)/amrex::Real(6))*(d1 - d2); return sedge; } @@ -159,7 +159,7 @@ struct vanleer { amrex::Real d1 = vanLeer(s0,sp1,sm1); amrex::Real d2 = vanLeer(sm1,s0,sm2); - amrex::Real sedge = amrex::Real(0.5)*(s0 + sm1) - amrex::Real(1./6.)*(d1 - d2); + amrex::Real sedge = amrex::Real(0.5)*(s0 + sm1) - (amrex::Real(1)/amrex::Real(6))*(d1 - d2); return amrex::min(amrex::max(sedge, amrex::min(s0, sm1)),amrex::max(s0,sm1)); } @@ -176,7 +176,7 @@ struct vanleer { amrex::Real d1 = vanLeer(sp1,sp2,s0); amrex::Real d2 = vanLeer(s0,sp1,sm1); - amrex::Real sedge = amrex::Real(0.5)*(sp1 + s0) - amrex::Real(1./6.)*(d1 - d2); + amrex::Real sedge = amrex::Real(0.5)*(sp1 + s0) - (amrex::Real(1)/amrex::Real(6))*(d1 - d2); return amrex::min(amrex::max(sedge, amrex::min(s0, sp1)),amrex::max(s0,sp1)); @@ -195,9 +195,9 @@ struct vanleer { sm_ = s0; sp_ = s0; } else if (amrex::Math::abs(sedge2-s0) >= amrex::Real(2.0)*amrex::Math::abs(sedge1-s0)) { - sp_ = amrex::Real(3.0)*s0 - amrex::Real(2.0)*sedge1; + sp_ = amrex::Real(3)*s0 - amrex::Real(2)*sedge1; } else if (amrex::Math::abs(sedge1-s0) >= amrex::Real(2.0)*amrex::Math::abs(sedge2-s0)) { - sm_ = amrex::Real(3.0)*s0 - amrex::Real(2.0)*sedge2; + sm_ = amrex::Real(3)*s0 - amrex::Real(2)*sedge2; } return amrex::makeTuple(sm_,sp_); @@ -209,10 +209,10 @@ struct vanleer { // amrex::Real sm_ = sedge1; // amrex::Real sp_ = sedge2; // if (amrex::Math::abs(sedge2-s0) >= amrex::Real(2.0)*amrex::Math::abs(sedge1-s0)) { -// sp_ = amrex::Real(3.0)*s0 - amrex::Real(2.0)*sedge1; +// sp_ = amrex::Real(3)*s0 - amrex::Real(2)*sedge1; // } // if (amrex::Math::abs(sedge1-s0) >= amrex::Real(2.0)*amrex::Math::abs(sedge2-s0)) { -// sm_ = amrex::Real(3.0)*s0 - amrex::Real(2.0)*sedge2; +// sm_ = amrex::Real(3)*s0 - amrex::Real(2)*sedge2; // } // return amrex::makeTuple(sm_,sp_); @@ -234,27 +234,27 @@ struct wenoz { constexpr auto eps = amrex::Real(1.0e-6); const amrex::Real beta1 = - amrex::Real(13.0) / amrex::Real(12.0) * (sm2 - amrex::Real(2.0) * sm1 + s0) * (sm2 - amrex::Real(2.0) * sm1 + s0) + - amrex::Real(0.25) * (sm2 - amrex::Real(4.0) * sm1 + amrex::Real(3.0) * s0) * (sm2 - amrex::Real(4.0) * sm1 + amrex::Real(3.0) * s0); + amrex::Real(13) / amrex::Real(12) * (sm2 - amrex::Real(2) * sm1 + s0) * (sm2 - amrex::Real(2) * sm1 + s0) + + amrex::Real(0.25) * (sm2 - amrex::Real(4) * sm1 + amrex::Real(3) * s0) * (sm2 - amrex::Real(4) * sm1 + amrex::Real(3) * s0); const amrex::Real beta2 = - amrex::Real(13.0) / amrex::Real(12.0) * (sm1 - amrex::Real(2.0) * s0 + sp1) * (sm1 - amrex::Real(2.0) * s0 + sp1) + + amrex::Real(13) / amrex::Real(12) * (sm1 - amrex::Real(2) * s0 + sp1) * (sm1 - amrex::Real(2) * s0 + sp1) + amrex::Real(0.25) * (sm1 - sp1) * (sm1 - sp1); const amrex::Real beta3 = - amrex::Real(13.0) / amrex::Real(12.0) * (s0 - amrex::Real(2.0) * sp1 + sp2) * (s0 - amrex::Real(2.0) * sp1 + sp2) + - amrex::Real(0.25) * (amrex::Real(3.0) * s0 - amrex::Real(4.0) * sp1 + sp2) * (amrex::Real(3.0) * s0 - amrex::Real(4.0) * sp1 + sp2); + amrex::Real(13) / amrex::Real(12) * (s0 - amrex::Real(2) * sp1 + sp2) * (s0 - amrex::Real(2) * sp1 + sp2) + + amrex::Real(0.25) * (amrex::Real(3) * s0 - amrex::Real(4) * sp1 + sp2) * (amrex::Real(3) * s0 - amrex::Real(4) * sp1 + sp2); const amrex::Real t5 = amrex::Math::abs(beta3 - beta1); - const amrex::Real omega1 = amrex::Real(0.1) * (amrex::Real(1.0) + t5 / (eps + beta1)); - const amrex::Real omega2 = amrex::Real(0.6) * (amrex::Real(1.0) + t5 / (eps + beta2)); - const amrex::Real omega3 = amrex::Real(0.3) * (amrex::Real(1.0) + t5 / (eps + beta3)); + const amrex::Real omega1 = amrex::Real(0.1) * (amrex::Real(1) + t5 / (eps + beta1)); + const amrex::Real omega2 = amrex::Real(0.6) * (amrex::Real(1) + t5 / (eps + beta2)); + const amrex::Real omega3 = amrex::Real(0.3) * (amrex::Real(1) + t5 / (eps + beta3)); const amrex::Real omega = omega1 + omega2 + omega3; - const amrex::Real v_1 = amrex::Real(2.0) * sm2 - amrex::Real(7.0) * sm1 + amrex::Real(11.0) * s0; - const amrex::Real v_2 = -sm1 + amrex::Real(5.0) * s0 + amrex::Real(2.0) * sp1; - const amrex::Real v_3 = amrex::Real(2.0) * s0 + amrex::Real(5.0) * sp1 - sp2; + const amrex::Real v_1 = amrex::Real(2) * sm2 - amrex::Real(7) * sm1 + amrex::Real(11) * s0; + const amrex::Real v_2 = -sm1 + amrex::Real(5) * s0 + amrex::Real(2) * sp1; + const amrex::Real v_3 = amrex::Real(2) * s0 + amrex::Real(5) * sp1 - sp2; - return (omega1 * v_1 + omega2 * v_2 + omega3 * v_3) / (amrex::Real(6.0) * omega); + return (omega1 * v_1 + omega2 * v_2 + omega3 * v_3) / (amrex::Real(6) * omega); } [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -293,19 +293,19 @@ struct weno_js { constexpr auto eps = amrex::Real(1.0e-6); const amrex::Real beta1 = - amrex::Real(13.0) / amrex::Real(12.0) * (sm2 - amrex::Real(2.0) * sm1 + s0) * - (sm2 - amrex::Real(2.0) * sm1 + s0) + - amrex::Real(0.25) * (sm2 - amrex::Real(4.0) * sm1 + amrex::Real(3.0) * s0) * - (sm2 - amrex::Real(4.0) * sm1 + amrex::Real(3.0) * s0); + amrex::Real(13) / amrex::Real(12) * (sm2 - amrex::Real(2) * sm1 + s0) * + (sm2 - amrex::Real(2) * sm1 + s0) + + amrex::Real(0.25) * (sm2 - amrex::Real(4) * sm1 + amrex::Real(3) * s0) * + (sm2 - amrex::Real(4) * sm1 + amrex::Real(3) * s0); const amrex::Real beta2 = - amrex::Real(13.0) / amrex::Real(12.0) * (sm1 - amrex::Real(2.0) * s0 + sp1) * - (sm1 - amrex::Real(2.0) * s0 + sp1) + + amrex::Real(13) / amrex::Real(12) * (sm1 - amrex::Real(2) * s0 + sp1) * + (sm1 - amrex::Real(2) * s0 + sp1) + amrex::Real(0.25) * (sm1 - sp1) * (sm1 - sp1); const amrex::Real beta3 = - amrex::Real(13.0) / amrex::Real(12.0) * (s0 - amrex::Real(2.0) * sp1 + sp2) * - (s0 - amrex::Real(2.0) * sp1 + sp2) + - amrex::Real(0.25) * (amrex::Real(3.0) * s0 - amrex::Real(4.0) * sp1 + sp2) * - (amrex::Real(3.0) * s0 - amrex::Real(4.0) * sp1 + sp2); + amrex::Real(13) / amrex::Real(12) * (s0 - amrex::Real(2) * sp1 + sp2) * + (s0 - amrex::Real(2) * sp1 + sp2) + + amrex::Real(0.25) * (amrex::Real(3) * s0 - amrex::Real(4) * sp1 + sp2) * + (amrex::Real(3) * s0 - amrex::Real(4) * sp1 + sp2); const amrex::Real omega1 = amrex::Real(0.1) / (eps + beta1); const amrex::Real omega2 = amrex::Real(0.6) / (eps + beta2); @@ -313,11 +313,11 @@ struct weno_js { const amrex::Real omega = omega1 + omega2 + omega3; - const amrex::Real v_1 = amrex::Real(2.0) * sm2 - amrex::Real(7.0) * sm1 + amrex::Real(11.0) * s0; - const amrex::Real v_2 = -sm1 + amrex::Real(5.0) * s0 + amrex::Real(2.0) * sp1; - const amrex::Real v_3 = amrex::Real(2.0) * s0 + amrex::Real(5.0) * sp1 - sp2; + const amrex::Real v_1 = amrex::Real(2) * sm2 - amrex::Real(7) * sm1 + amrex::Real(11) * s0; + const amrex::Real v_2 = -sm1 + amrex::Real(5) * s0 + amrex::Real(2) * sp1; + const amrex::Real v_3 = amrex::Real(2) * s0 + amrex::Real(5) * sp1 - sp2; - return (omega1 * v_1 + omega2 * v_2 + omega3 * v_3) / (amrex::Real(6.0) * omega); + return (omega1 * v_1 + omega2 * v_2 + omega3 * v_3) / (amrex::Real(6) * omega); } [[nodiscard]] AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE @@ -426,7 +426,7 @@ void SetXBCs ( const int i, const int j, const int k, const int n, using namespace amrex; if ( (bclo == BCType::ext_dir) || (bclo == BCType::hoextrap) || - (bclo == BCType::direction_dependent && velp >= 0.0) ) + (bclo == BCType::direction_dependent && velp >= Real(0)) ) { if (i == domlo) { @@ -453,21 +453,21 @@ void SetXBCs ( const int i, const int j, const int k, const int n, sm = sedge1; if constexpr (Limiter::do_limiting) { - if ( (sp - s(domlo+1,j,k,n))*(s(domlo+1,j,k,n) - sm) <= amrex::Real(0.0)) + if ( (sp - s(domlo+1,j,k,n))*(s(domlo+1,j,k,n) - sm) <= amrex::Real(0)) { sp = s(domlo+1,j,k,n); sm = s(domlo+1,j,k,n); - } else if(amrex::Math::abs(sp - s(domlo+1,j,k,n)) >= amrex::Real(2.0)*amrex::Math::abs(sm - s(domlo+1,j,k,n))) { - sp = amrex::Real(3.0)*s(domlo+1,j,k,n) - amrex::Real(2.0)*sm; - } else if(amrex::Math::abs(sm - s(domlo+1,j,k,n)) >= amrex::Real(2.0)*amrex::Math::abs(sp - s(domlo+1,j,k,n))) { - sm = amrex::Real(3.0)*s(domlo+1,j,k,n) - amrex::Real(2.0)*sp; + } else if(amrex::Math::abs(sp - s(domlo+1,j,k,n)) >= amrex::Real(2)*amrex::Math::abs(sm - s(domlo+1,j,k,n))) { + sp = amrex::Real(3)*s(domlo+1,j,k,n) - amrex::Real(2)*sm; + } else if(amrex::Math::abs(sm - s(domlo+1,j,k,n)) >= amrex::Real(2)*amrex::Math::abs(sp - s(domlo+1,j,k,n))) { + sm = amrex::Real(3)*s(domlo+1,j,k,n) - amrex::Real(2)*sp; } } } } if ( (bchi == BCType::ext_dir) || (bchi == BCType::hoextrap) || - (bchi == BCType::direction_dependent && velm <= 0.0) ) + (bchi == BCType::direction_dependent && velm <= Real(0)) ) { if (i == domhi) { @@ -494,14 +494,14 @@ void SetXBCs ( const int i, const int j, const int k, const int n, sm = sedge1; if constexpr (Limiter::do_limiting) { - if( (sp - s(domhi-1,j,k,n))*(s(domhi-1,j,k,n) - sm) <= amrex::Real(0.0)) + if( (sp - s(domhi-1,j,k,n))*(s(domhi-1,j,k,n) - sm) <= amrex::Real(0)) { sp = s(domhi-1,j,k,n); sm = s(domhi-1,j,k,n); } else if(amrex::Math::abs(sp - s(domhi-1,j,k,n)) >= 2.*amrex::Math::abs(sm - s(domhi-1,j,k,n))) { - sp = amrex::Real(3.0)*s(domhi-1,j,k,n) - amrex::Real(2.0)*sm; + sp = amrex::Real(3)*s(domhi-1,j,k,n) - amrex::Real(2)*sm; } else if(amrex::Math::abs(sm - s(domhi-1,j,k,n)) >= 2.*amrex::Math::abs(sp - s(domhi-1,j,k,n))) { - sm = amrex::Real(3.0)*s(domhi-1,j,k,n) - amrex::Real(2.0)*sp; + sm = amrex::Real(3)*s(domhi-1,j,k,n) - amrex::Real(2)*sp; } } } @@ -521,7 +521,7 @@ void SetYBCs ( const int i, const int j, const int k, const int n, using namespace amrex; if ( (bclo == BCType::ext_dir) || (bclo == BCType::hoextrap) || - (bclo == BCType::direction_dependent && velm >= 0.0) ) + (bclo == BCType::direction_dependent && velm >= Real(0)) ) { if (j == domlo) { @@ -548,21 +548,21 @@ void SetYBCs ( const int i, const int j, const int k, const int n, sm = sedge1; if constexpr (Limiter::do_limiting) { - if ( (sp - s(i,domlo+1,k,n))*(s(i,domlo+1,k,n) - sm) <= amrex::Real(0.0)) + if ( (sp - s(i,domlo+1,k,n))*(s(i,domlo+1,k,n) - sm) <= amrex::Real(0)) { sp = s(i,domlo+1,k,n); sm = s(i,domlo+1,k,n); - } else if(amrex::Math::abs(sp - s(i,domlo+1,k,n)) >= amrex::Real(2.0)*amrex::Math::abs(sm - s(i,domlo+1,k,n))) { - sp = amrex::Real(3.0)*s(i,domlo+1,k,n) - amrex::Real(2.0)*sm; - } else if(amrex::Math::abs(sm - s(i,domlo+1,k,n)) >= amrex::Real(2.0)*amrex::Math::abs(sp - s(i,domlo+1,k,n))) { - sm = amrex::Real(3.0)*s(i,domlo+1,k,n) - amrex::Real(2.0)*sp; + } else if(amrex::Math::abs(sp - s(i,domlo+1,k,n)) >= amrex::Real(2)*amrex::Math::abs(sm - s(i,domlo+1,k,n))) { + sp = amrex::Real(3)*s(i,domlo+1,k,n) - amrex::Real(2)*sm; + } else if(amrex::Math::abs(sm - s(i,domlo+1,k,n)) >= amrex::Real(2)*amrex::Math::abs(sp - s(i,domlo+1,k,n))) { + sm = amrex::Real(3)*s(i,domlo+1,k,n) - amrex::Real(2)*sp; } } } } if ( (bchi == BCType::ext_dir) || (bchi == BCType::hoextrap) || - (bchi == BCType::direction_dependent && velp <= 0.0) ) + (bchi == BCType::direction_dependent && velp <= Real(0)) ) { if (j == domhi) { @@ -589,13 +589,13 @@ void SetYBCs ( const int i, const int j, const int k, const int n, sm = sedge1; if constexpr (Limiter::do_limiting) { - if( (sp - s(i,domhi-1,k,n))*(s(i,domhi-1,k,n) - sm) <= amrex::Real(0.0)){ + if( (sp - s(i,domhi-1,k,n))*(s(i,domhi-1,k,n) - sm) <= amrex::Real(0)){ sp = s(i,domhi-1,k,n); sm = s(i,domhi-1,k,n); } else if(amrex::Math::abs(sp - s(i,domhi-1,k,n)) >= 2.*amrex::Math::abs(sm - s(i,domhi-1,k,n))) { - sp = amrex::Real(3.0)*s(i,domhi-1,k,n) - amrex::Real(2.0)*sm; + sp = amrex::Real(3)*s(i,domhi-1,k,n) - amrex::Real(2)*sm; } else if(amrex::Math::abs(sm - s(i,domhi-1,k,n)) >= 2.*amrex::Math::abs(sp - s(i,domhi-1,k,n))) { - sm = amrex::Real(3.0)*s(i,domhi-1,k,n) - amrex::Real(2.0)*sp; + sm = amrex::Real(3)*s(i,domhi-1,k,n) - amrex::Real(2)*sp; } } } @@ -616,7 +616,7 @@ void SetZBCs ( const int i, const int j, const int k, const int n, using namespace amrex; if ( (bclo == BCType::ext_dir) || (bclo == BCType::hoextrap) || - (bclo == BCType::direction_dependent && velm >= 0.0) ) + (bclo == BCType::direction_dependent && velm >= Real(0)) ) { if (k == domlo) { @@ -648,16 +648,16 @@ void SetZBCs ( const int i, const int j, const int k, const int n, sp = s(i,j,domlo+1,n); sm = s(i,j,domlo+1,n); } else if(amrex::Math::abs(sp - s(i,j,domlo+1,n)) >= 2.*amrex::Math::abs(sm - s(i,j,domlo+1,n))) { - sp = amrex::Real(3.0)*s(i,j,domlo+1,n) - amrex::Real(2.0)*sm; + sp = amrex::Real(3)*s(i,j,domlo+1,n) - amrex::Real(2)*sm; } else if(amrex::Math::abs(sm - s(i,j,domlo+1,n)) >= 2.*amrex::Math::abs(sp - s(i,j,domlo+1,n))) { - sm = amrex::Real(3.0)*s(i,j,domlo+1,n) - amrex::Real(2.0)*sp; + sm = amrex::Real(3)*s(i,j,domlo+1,n) - amrex::Real(2)*sp; } } } } if ( (bchi == BCType::ext_dir) || (bchi == BCType::hoextrap) || - (bchi == BCType::direction_dependent && velp <= 0.0) ) + (bchi == BCType::direction_dependent && velp <= Real(0)) ) { if (k == domhi) { @@ -689,9 +689,9 @@ void SetZBCs ( const int i, const int j, const int k, const int n, sp = s(i,j,domhi-1,n); sm = s(i,j,domhi-1,n); } else if(amrex::Math::abs(sp - s(i,j,domhi-1,n)) >= 2.*amrex::Math::abs(sm - s(i,j,domhi-1,n))) { - sp = amrex::Real(3.0)*s(i,j,domhi-1,n) - amrex::Real(2.0)*sm; + sp = amrex::Real(3)*s(i,j,domhi-1,n) - amrex::Real(2)*sm; } else if(amrex::Math::abs(sm - s(i,j,domhi-1,n)) >= 2.*amrex::Math::abs(sp - s(i,j,domhi-1,n))) { - sm = amrex::Real(3.0)*s(i,j,domhi-1,n) - amrex::Real(2.0)*sp; + sm = amrex::Real(3)*s(i,j,domhi-1,n) - amrex::Real(2)*sp; } } @@ -715,8 +715,8 @@ void PredictVelOnXFace ( const int i, const int j, const int k, const int n, const Limiter& /*limiter*/) { constexpr auto half{amrex::Real(0.5)}; - constexpr auto one{amrex::Real(1.0)}; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto one{amrex::Real(1)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i-2,j,k,n); const amrex::Real sm1 = S(i-1,j,k,n); @@ -732,7 +732,7 @@ void PredictVelOnXFace ( const int i, const int j, const int k, const int n, SetXBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, v_ad, v_ad, bc.lo(0), bc.hi(0), domlo, domhi); - const amrex::Real s6 = amrex::Real(6.0)*s0 - amrex::Real(3.0)*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0 - amrex::Real(3)*(sm + sp); const amrex::Real sigma = amrex::Math::abs(v_ad)*dtdx; @@ -763,8 +763,8 @@ void PredictVelOnYFace ( const int i, const int j, const int k, const int n, const Limiter& /*limiter*/) { constexpr auto half{amrex::Real(0.5)}; - constexpr auto one{amrex::Real(1.0)}; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto one{amrex::Real(1)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i,j-2,k,n); const amrex::Real sm1 = S(i,j-1,k,n); @@ -780,7 +780,7 @@ void PredictVelOnYFace ( const int i, const int j, const int k, const int n, SetYBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, v_ad, v_ad, bc.lo(1), bc.hi(1), domlo, domhi); - const amrex::Real s6 = amrex::Real(6.0)*s0 - amrex::Real(3.0)*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0 - amrex::Real(3)*(sm + sp); const amrex::Real sigma = amrex::Math::abs(v_ad)*dtdy; @@ -812,8 +812,8 @@ void PredictVelOnZFace ( const int i, const int j, const int k, const int n, const Limiter& /*limiter*/) { constexpr auto half{amrex::Real(0.5)}; - constexpr auto one{amrex::Real(1.0)}; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto one{amrex::Real(1)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i,j,k-2,n); const amrex::Real sm1 = S(i,j,k-1,n); @@ -829,7 +829,7 @@ void PredictVelOnZFace ( const int i, const int j, const int k, const int n, SetZBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, v_ad, v_ad, bc.lo(2), bc.hi(2), domlo, domhi); - const amrex::Real s6 = amrex::Real(6.0)*s0 - amrex::Real(3.0)*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0 - amrex::Real(3)*(sm + sp); const amrex::Real sigma = amrex::Math::abs(v_ad)*dtdz; @@ -871,12 +871,12 @@ void PredictStateOnXFace ( const int i, const int j, const int k, const int n, const amrex::Real sp1 = S(i+1,j,k,n); constexpr auto half{amrex::Real(0.5)}; - constexpr auto one{amrex::Real(1.0)}; + constexpr auto one{amrex::Real(1)}; const amrex::Real sigmap = amrex::Math::abs(vel_edge(i+1,j,k))*dt/dx; const amrex::Real sigmam = amrex::Math::abs(vel_edge(i ,j,k))*dt/dx; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i-2,j,k,n); const amrex::Real sp2 = S(i+2,j,k,n); @@ -889,7 +889,7 @@ void PredictStateOnXFace ( const int i, const int j, const int k, const int n, SetXBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, vel_edge(i,j,k), vel_edge(i,j,k), bc.lo(0), bc.hi(0), domlo, domhi); - const amrex::Real s6 = 6.0*s0 - 3.0*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0 - amrex::Real(3)*(sm + sp); if (vel_edge(i+1,j,k) > small_vel) { Ip = sp - (half*sigmap)*((sp - sm) - (one -two3rds*sigmap)*s6); @@ -984,7 +984,7 @@ void PredictStateOnYFace ( const int i, const int j, const int k, const int n, const amrex::Real sigmap = amrex::Math::abs(vel_edge(i,j+1,k))*dt/dx; const amrex::Real sigmam = amrex::Math::abs(vel_edge(i,j ,k))*dt/dx; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i,j-2,k,n); const amrex::Real sp2 = S(i,j+2,k,n); @@ -997,7 +997,7 @@ void PredictStateOnYFace ( const int i, const int j, const int k, const int n, SetYBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, vel_edge(i,j,k), vel_edge(i,j,k), bc.lo(1), bc.hi(1), domlo, domhi); - const amrex::Real s6 = 6.0*s0- 3.0*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0- amrex::Real(3)*(sm + sp); if (vel_edge(i,j+1,k) > small_vel) { Ip = sp - (half*sigmap)*((sp - sm) - (one -two3rds*sigmap)*s6); @@ -1093,7 +1093,7 @@ void PredictStateOnZFace ( const int i, const int j, const int k, const int n, const amrex::Real sigmap = amrex::Math::abs(vel_edge(i,j,k+1))*dt/dx; const amrex::Real sigmam = amrex::Math::abs(vel_edge(i,j,k ))*dt/dx; - constexpr auto two3rds{amrex::Real(2.0/3.0)}; + constexpr auto two3rds{amrex::Real(2.0)/amrex::Real(3.0)}; const amrex::Real sm2 = S(i,j,k-2,n); const amrex::Real sp2 = S(i,j,k+2,n); @@ -1106,7 +1106,7 @@ void PredictStateOnZFace ( const int i, const int j, const int k, const int n, SetZBCs(i, j, k, n, sm, sp, sedge1, sedge2, S, vel_edge(i,j,k), vel_edge(i,j,k), bc.lo(2), bc.hi(2), domlo, domhi); - const amrex::Real s6 = 6.0*s0- 3.0*(sm + sp); + const amrex::Real s6 = amrex::Real(6)*s0- amrex::Real(3)*(sm + sp); if(vel_edge(i,j,k+1) > small_vel) { Ip = sp - (half*sigmap)*((sp-sm) - (amrex::Real(1.0) -two3rds*sigmap)*s6); diff --git a/MOL/hydro_mol_edge_state_K.H b/MOL/hydro_mol_edge_state_K.H index c96442cef..8cee25a03 100644 --- a/MOL/hydro_mol_edge_state_K.H +++ b/MOL/hydro_mol_edge_state_K.H @@ -40,9 +40,9 @@ amrex::Real hydro_mol_xedge_state_extdir ( int i, int j, int k, int n, } else { - amrex::Real qpls = q(i ,j,k,n) - 0.5 * + amrex::Real qpls = q(i ,j,k,n) - amrex::Real(0.5) * amrex_calc_xslope_extdir( i , j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); - amrex::Real qmns = q(i-1,j,k,n) + 0.5 * + amrex::Real qmns = q(i-1,j,k,n) + amrex::Real(0.5) * amrex_calc_xslope_extdir( i-1, j, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity); @@ -50,12 +50,12 @@ amrex::Real hydro_mol_xedge_state_extdir ( int i, int j, int k, int n, if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) ) { - if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) ) { - if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -69,7 +69,7 @@ amrex::Real hydro_mol_xedge_state_extdir ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } } @@ -87,20 +87,20 @@ amrex::Real hydro_mol_xedge_state ( int i, int j, int k, int n, int order = 2; amrex::Real qs; - amrex::Real qpls = q(i ,j,k,n) - 0.5 * amrex_calc_xslope( i , j, k, n, order, q ); - amrex::Real qmns = q(i-1,j,k,n) + 0.5 * amrex_calc_xslope( i-1, j, k, n, order, q ); + amrex::Real qpls = q(i ,j,k,n) - amrex::Real(0.5) * amrex_calc_xslope( i , j, k, n, order, q ); + amrex::Real qmns = q(i-1,j,k,n) + amrex::Real(0.5) * amrex_calc_xslope( i-1, j, k, n, order, q ); HydroBC::SetEdgeBCsLo(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].lo(0),domlo,is_velocity); HydroBC::SetEdgeBCsHi(0,i,j,k,n,q,qmns,qpls,umac(i,j,k),d_bcrec[n].hi(0),domhi,is_velocity); if ( (i==domlo) && (d_bcrec[n].lo(0) == amrex::BCType::foextrap || d_bcrec[n].lo(0) == amrex::BCType::hoextrap) ) { - if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( umac(i,j,k) >= 0. && n==XVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (i==domhi+1) && (d_bcrec[n].hi(0) == amrex::BCType::foextrap || d_bcrec[n].hi(0) == amrex::BCType::hoextrap) ) { - if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( umac(i,j,k) <= 0. && n==XVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -114,7 +114,7 @@ amrex::Real hydro_mol_xedge_state ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } return qs; @@ -149,9 +149,9 @@ amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n, } else { - amrex::Real qpls = q(i,j ,k,n) - 0.5 * + amrex::Real qpls = q(i,j ,k,n) - amrex::Real(0.5) * amrex_calc_yslope_extdir( i, j , k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); - amrex::Real qmns = q(i,j-1,k,n) + 0.5 * + amrex::Real qmns = q(i,j-1,k,n) + amrex::Real(0.5) * amrex_calc_yslope_extdir( i, j-1, k, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k),d_bcrec[n].lo(1),domlo,is_velocity); @@ -159,12 +159,12 @@ amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n, if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) ) { - if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) ) { - if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -178,7 +178,7 @@ amrex::Real hydro_mol_yedge_state_extdir ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } } @@ -198,20 +198,20 @@ amrex::Real hydro_mol_yedge_state ( int i, int j, int k, int n, int order = 2; amrex::Real qs; - amrex::Real qpls = q(i,j ,k,n) - 0.5 * amrex_calc_yslope( i, j , k, n, order, q ); - amrex::Real qmns = q(i,j-1,k,n) + 0.5 * amrex_calc_yslope( i, j-1, k, n, order, q ); + amrex::Real qpls = q(i,j ,k,n) - amrex::Real(0.5) * amrex_calc_yslope( i, j , k, n, order, q ); + amrex::Real qmns = q(i,j-1,k,n) + amrex::Real(0.5) * amrex_calc_yslope( i, j-1, k, n, order, q ); HydroBC::SetEdgeBCsLo(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].lo(1),domlo,is_velocity); HydroBC::SetEdgeBCsHi(1,i,j,k,n,q,qmns,qpls,vmac(i,j,k), d_bcrec[n].hi(1),domhi,is_velocity); if ( (j==domlo) && (d_bcrec[n].lo(1) == amrex::BCType::foextrap || d_bcrec[n].lo(1) == amrex::BCType::hoextrap) ) { - if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( vmac(i,j,k) >= 0. && n==YVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (j==domhi+1) && (d_bcrec[n].hi(1) == amrex::BCType::foextrap || d_bcrec[n].hi(1) == amrex::BCType::hoextrap) ) { - if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( vmac(i,j,k) <= 0. && n==YVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -225,7 +225,7 @@ amrex::Real hydro_mol_yedge_state ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } return qs; @@ -262,9 +262,9 @@ amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n, } else { - amrex::Real qpls = q(i,j,k ,n) - 0.5 * + amrex::Real qpls = q(i,j,k ,n) - amrex::Real(0.5) * amrex_calc_zslope_extdir( i, j, k , n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); - amrex::Real qmns = q(i,j,k-1,n) + 0.5 * + amrex::Real qmns = q(i,j,k-1,n) + amrex::Real(0.5) * amrex_calc_zslope_extdir( i, j, k-1, n, order, q, extdir_or_ho_lo, extdir_or_ho_hi, domlo, domhi ); HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity); @@ -272,12 +272,12 @@ amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n, if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) ) { - if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) ) { - if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -291,7 +291,7 @@ amrex::Real hydro_mol_zedge_state_extdir ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } } @@ -311,20 +311,20 @@ amrex::Real hydro_mol_zedge_state ( int i, int j, int k, int n, int order = 2; amrex::Real qs; - amrex::Real qpls = q(i,j,k ,n) - 0.5 * amrex_calc_zslope( i, j, k , n, order, q ); - amrex::Real qmns = q(i,j,k-1,n) + 0.5 * amrex_calc_zslope( i, j, k-1, n, order, q ); + amrex::Real qpls = q(i,j,k ,n) - amrex::Real(0.5) * amrex_calc_zslope( i, j, k , n, order, q ); + amrex::Real qmns = q(i,j,k-1,n) + amrex::Real(0.5) * amrex_calc_zslope( i, j, k-1, n, order, q ); HydroBC::SetEdgeBCsLo(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].lo(2),domlo,is_velocity); HydroBC::SetEdgeBCsHi(2,i,j,k,n,q,qmns,qpls,wmac(i,j,k),d_bcrec[n].hi(2),domhi,is_velocity); if ( (k==domlo) && (d_bcrec[n].lo(2) == amrex::BCType::foextrap || d_bcrec[n].lo(2) == amrex::BCType::hoextrap) ) { - if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,0.0_rt); + if ( wmac(i,j,k) >= 0. && n==ZVEL && is_velocity ) qpls = amrex::min(qpls,amrex::Real(0)); qmns = qpls; } if ( (k==domhi+1) && (d_bcrec[n].hi(2) == amrex::BCType::foextrap || d_bcrec[n].hi(2) == amrex::BCType::hoextrap) ) { - if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,0.0_rt); + if ( wmac(i,j,k) <= 0. && n==ZVEL && is_velocity ) qmns = amrex::max(qmns,amrex::Real(0)); qpls = qmns; } @@ -338,7 +338,7 @@ amrex::Real hydro_mol_zedge_state ( int i, int j, int k, int n, } else { - qs = 0.5*(qmns+qpls); + qs = amrex::Real(0.5)*(qmns+qpls); } return qs; From 277aa3d0e4213ba7a41c66f19370c3d4bc52bdf0 Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Sun, 17 May 2026 15:52:48 -0700 Subject: [PATCH 02/18] remove tab --- Diagnostics/Redistribution/hydro_redistribution.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Diagnostics/Redistribution/hydro_redistribution.cpp b/Diagnostics/Redistribution/hydro_redistribution.cpp index b5e07d1ea..e184fe69e 100644 --- a/Diagnostics/Redistribution/hydro_redistribution.cpp +++ b/Diagnostics/Redistribution/hydro_redistribution.cpp @@ -214,7 +214,7 @@ Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, amrex::Real target_volfrac) { if (redistribution_type != "StateRedist") { - std::string msg = "Redistribution::ApplyToInitialData: Shouldn't be here with redist type "+redistribution_type; + std::string msg = "Redistribution::ApplyToInitialData: Shouldn't be here with redist type "+redistribution_type; amrex::Error(msg); } From 14ba966c24342be0d4e7125f8af7c7f070069c9b Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Mon, 18 May 2026 06:41:12 -0700 Subject: [PATCH 03/18] Didn't mean to commit Diagnostics --- Diagnostics/Redistribution/CMakeLists.txt | 15 - .../FOR_PAPER/hydro_redistribution.cpp | 407 ----------- .../FOR_PAPER/hydro_redistribution.cpp.hack | 466 ------------- Diagnostics/Redistribution/Make.package | 7 - .../hydro_create_itracker_2d.cpp | 223 ------ .../hydro_create_itracker_3d.cpp | 500 ------------- .../Redistribution/hydro_redistribution.H | 122 ---- .../Redistribution/hydro_redistribution.cpp | 446 ------------ .../Redistribution/hydro_slope_limiter_K.H | 86 --- .../hydro_state_redistribute.cpp | 324 --------- .../Redistribution/hydro_state_utils.cpp | 208 ------ Diagnostics/hydro_ebgodunov.cpp | 660 ------------------ Diagnostics/hydro_ebmol.cpp | 613 ---------------- 13 files changed, 4077 deletions(-) delete mode 100644 Diagnostics/Redistribution/CMakeLists.txt delete mode 100644 Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp delete mode 100644 Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack delete mode 100644 Diagnostics/Redistribution/Make.package delete mode 100644 Diagnostics/Redistribution/hydro_create_itracker_2d.cpp delete mode 100644 Diagnostics/Redistribution/hydro_create_itracker_3d.cpp delete mode 100644 Diagnostics/Redistribution/hydro_redistribution.H delete mode 100644 Diagnostics/Redistribution/hydro_redistribution.cpp delete mode 100644 Diagnostics/Redistribution/hydro_slope_limiter_K.H delete mode 100644 Diagnostics/Redistribution/hydro_state_redistribute.cpp delete mode 100644 Diagnostics/Redistribution/hydro_state_utils.cpp delete mode 100644 Diagnostics/hydro_ebgodunov.cpp delete mode 100644 Diagnostics/hydro_ebmol.cpp diff --git a/Diagnostics/Redistribution/CMakeLists.txt b/Diagnostics/Redistribution/CMakeLists.txt deleted file mode 100644 index ab2c5109d..000000000 --- a/Diagnostics/Redistribution/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -target_include_directories( - amrex_hydro - PUBLIC - $ - ) - -target_sources( - amrex_hydro - PRIVATE - hydro_redistribution.H - hydro_redistribution.cpp - hydro_create_itracker_${HYDRO_SPACEDIM}d.cpp - hydro_state_redistribute.cpp - hydro_state_utils.cpp - ) diff --git a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp deleted file mode 100644 index 9e0c45fc9..000000000 --- a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp +++ /dev/null @@ -1,407 +0,0 @@ -/** - * \file hydro_redistribution.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include -#include - -using namespace amrex; - -void Redistribution::Apply ( Box const& bx, int ncomp, - Array4 const& dUdt_out, - Array4 const& dUdt_in, - Array4 const& U_in, - Array4 const& scratch, - Array4 const& flag, - AMREX_D_DECL(Array4 const& apx, - Array4 const& apy, - Array4 const& apz), - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom, Real dt, - std::string redistribution_type, - amrex::Real target_volfrac) -{ - // redistribution_type = "NoRedist"; // no redistribution - // redistribution_type = "FluxRedist" // flux_redistribute - // redistribution_type = "StateRedist"; // (weighted) state redistribute - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = 0.; - }); - - if (redistribution_type == "FluxRedist") - { - int icomp = 0; - apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); - - } else if (redistribution_type == "StateRedist") { - - Box const& bxg1 = grow(bx,1); - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); - // How many nbhds is a cell in -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - Box domain_per_grown = lev_geom.Domain(); - AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, - if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, - if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); - - // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 - // in the cells just outside the domain because those values will be used - // in the slope computation in state redistribution. We assume here that - // the ext_dir values of U_in itself have already been set. - if (!domain_per_grown.contains(bxg1)) - amrex::ParallelFor(bxg1,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) - dUdt_in(i,j,k,n) = 0.; - }); - - amrex::ParallelFor(Box(scratch), ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n); - } - ); - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - // Only update the values which actually changed -- this makes - // the results insensitive to tiling -- otherwise cells that aren't - // changed but are in a tile on which StateRedistribute gets called - // will have precision-level changes due to adding/subtracting U_in - // and multiplying/dividing by dt. Here we test on whether (i,j,k) - // has at least one neighbor and/or whether (i,j,k) is in the - // neighborhood of another cell -- if either of those is true the - // value may have changed - - if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) - { - dUdt_out(i,j,k,n) = (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; - } - else - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - } - ); - - } else if (redistribution_type == "NoRedist") { - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - ); - - } else { - amrex::Error("Not a legit redist_type"); - } -} - -void -Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, - Array4 const& U_out, - Array4 const& U_in, - Array4 const& flag, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry& lev_geom, std::string redistribution_type, - amrex::Real target_volfrac) -{ - if (redistribution_type == "StateRedist") { - amrex::Error("Redistribution::ApplyToInitialData: Shouldn't be here with this redist type"); - } - - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - U_out(i,j,k,n) = 0.; - }); - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); -} - -void -Redistribution::Make1DProfile ( Box const& bx, int ncomp, - Array4 const& U_in, - Array4 const& flag, - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& bcent, - Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom) -{ - amrex::Vector profile; - amrex::Vector xloc; - profile.resize(64,0.0); - xloc.resize(64,0.0); - - amrex::Real* prof_ptr = profile.data(); - amrex::Real* xloc_ptr = xloc.data(); - - const Box domain = lev_geom.Domain(); - const int domain_ilo = domain.smallEnd(0); - const int domain_ihi = domain.bigEnd(0); - const int domain_jlo = domain.smallEnd(1); - const int domain_jhi = domain.bigEnd(1); -#if (AMREX_SPACEDIM == 3) - const int domain_klo = domain.smallEnd(2); - const int domain_khi = domain.bigEnd(2); -#endif - - AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, - const auto& is_periodic_y = lev_geom.isPeriodic(1);, - const auto& is_periodic_z = lev_geom.isPeriodic(2);); - - Box const& bxg1 = amrex::grow(bx,1); - Box const& bxg2 = amrex::grow(bx,2); - Box const& bxg3 = amrex::grow(bx,3); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,2); - if (is_periodic_y) domain_per_grown.grow(1,2); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,2); -#endif - - amrex::ParallelFor(bxg1, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) - { - int max_order = 2; - - for (int n = 0; n < ncomp; n++) - { - bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); - bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); - bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); - bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); -#if (AMREX_SPACEDIM == 3) - bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); - bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); -#endif - // Initialize so that the slope stencil goes from -1:1 in each diretion - int nx = 1; int ny = 1; int nz = 1; - - // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil - // or do we need to enlarge it? - AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, - Real y_max = -1.e30; Real y_min = 1.e30;, - Real z_max = -1.e30; Real z_min = 1.e30;); - - Real slope_stencil_min_width = 0.5; -#if (AMREX_SPACEDIM == 2) - int kk = 0; -#elif (AMREX_SPACEDIM == 3) - for(int kk(-1); kk<=1; kk++) -#endif - { - for(int jj(-1); jj<=1; jj++) - for(int ii(-1); ii<=1; ii++) - if (flag(i,j,k).isConnected(ii,jj,kk)) - { - int r = i+ii; int s = j+jj; int t = k+kk; - - x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); - x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); - y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); - y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); -#if (AMREX_SPACEDIM == 3) - z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); - z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); -#endif - } - } - // If we need to grow the stencil, we let it be -nx:nx in the x-direction, - // for example. Note that nx,ny,nz are either 1 or 2 - if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; - if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; -#if (AMREX_SPACEDIM == 3) - if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; -#endif - - amrex::GpuArray slopes_eb; - if (nx*ny*nz == 1) - // Compute slope using 3x3x3 stencil - slopes_eb = amrex_calc_slopes_extdir_eb( - i,j,k,n,U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - else - { - // Compute slope using grown stencil (no larger than 5x5x5) - slopes_eb = amrex_calc_slopes_extdir_eb_grown( - i,j,k,n,AMREX_D_DECL(nx,ny,nz), - U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - } - - // We do the limiting separately because this limiter limits the slope based on the values - // extrapolated to the cell centroid locations - unlike the limiter in amrex - // which bases the limiting on values extrapolated to the face centroids. - amrex::GpuArray lim_slope = - amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); - - AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, - lim_slope[1] *= slopes_eb[1];, - lim_slope[2] *= slopes_eb[2];); - - // Add to the cell itself - if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) - { - if (n == 0 and j < 80) - { - prof_ptr[i] = U_in(i,j,k,n) + - lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + - lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); - xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); - } - - } // if bx contains - } // n - } // vfrac - }); - - for (int i = 0; i < 64; i++) - { - amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; - } - -} -/** @} */ diff --git a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack b/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack deleted file mode 100644 index 959c90632..000000000 --- a/Diagnostics/Redistribution/FOR_PAPER/hydro_redistribution.cpp.hack +++ /dev/null @@ -1,466 +0,0 @@ -/** - * \file hydro_redistribution.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include -#include - -#include -#if (AMREX_SPACEDIM == 2) -#include -#elif (AMREX_SPACEDIM == 3) -#include -#endif - -using namespace amrex; - -void Redistribution::Apply ( Box const& bx, int ncomp, - Array4 const& dUdt_out, - Array4 const& dUdt_in, - Array4 const& U_in, - Array4 const& scratch, - Array4 const& flag, - AMREX_D_DECL(Array4 const& apx, - Array4 const& apy, - Array4 const& apz), - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& bcc, - Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom, Real dt, - std::string redistribution_type, - amrex::Real target_volfrac) -{ - // redistribution_type = "NoRedist"; // no redistribution - // redistribution_type = "FluxRedist" // flux_redistribute - // redistribution_type = "StateRedist"; // state redistribute - // redistribution_type = "NewStateRedist"; // new form of state redistribute with alpha-weightings and - // alternative slope calculations - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = 0.; - }); - - if (redistribution_type == "FluxRedist") - { - int icomp = 0; - apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) *= dt; - dUdt_out(i,j,k,n) += U_in(i,j,k,n); - } - ); - - // Make sure to call this while dUdt_out is still the full state, not the increment - Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, - lev_geom); -amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) -= U_in(i,j,k,n); - dUdt_out(i,j,k,n) /= dt; - } - ); - - } else if (redistribution_type == "StateRedist" or redistribution_type == "NewStateRedist") { - - Box const& bxg1 = grow(bx,1); - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); - // How many nbhds is a cell in -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - Box domain_per_grown = lev_geom.Domain(); - AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, - if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, - if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); - - // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 - // in the cells just outside the domain because those values will be used - // in the slope computation in state redistribution. We assume here that - // the ext_dir values of U_in itself have already been set. - if (!domain_per_grown.contains(bxg1)) - amrex::ParallelFor(bxg1,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) - dUdt_in(i,j,k,n) = 0.; - }); - - amrex::ParallelFor(Box(scratch), ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n); - } - ); - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - if (redistribution_type == "StateRedist") - { - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, nbhd_vol, cent_hat, lev_geom); - - StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, nbhd_vol_const, cent_hat_const, lev_geom); - } else { - - MakeNewStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - NewStateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); - } - - // Make sure to call this while dUdt_out is still the full state, not the increment - Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, - lev_geom); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - // Only update the values which actually changed -- this makes - // the results insensitive to tiling -- otherwise cells that aren't - // changed but are in a tile on which StateRedistribute gets called - // will have precision-level changes due to adding/subtracting U_in - // and multiplying/dividing by dt. Here we test on whether (i,j,k) - // has at least one neighbor and/or whether (i,j,k) is in the - // neighborhood of another cell -- if either of those is true the - // value may have changed - - if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) - { - dUdt_out(i,j,k,n) = (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; - } - else - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - } - ); - - } else if (redistribution_type == "NoRedist") { - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - ); - - } else { - amrex::Error("Not a legit redist_type"); - } - -} - -void -Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, - Array4 const& U_out, - Array4 const& U_in, - Array4 const& flag, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry& lev_geom, std::string redistribution_type, - amrex::Real target_volfrac) -{ - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - U_out(i,j,k,n) = 0.; - }); - - if (redistribution_type == "StateRedist" || redistribution_type == "NewStateRedist") { - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - if (redistribution_type == "StateRedist") - { - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, nbhd_vol, cent_hat, lev_geom); - - StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, nbhd_vol_const, cent_hat_const, lev_geom); - } else { - - MakeNewStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - NewStateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, cent_hat_const, lev_geom); - } - - - } else { - amrex::Error("Redistribution::ApplyToInitialData: Shouldn't be here with this redist type"); - } -} - -void -Redistribution::Make1DProfile ( Box const& bx, int ncomp, - Array4 const& U_in, - Array4 const& flag, - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& bcent, - Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom) -{ - amrex::Vector profile; - amrex::Vector xloc; - profile.resize(64,0.0); - xloc.resize(64,0.0); - - amrex::Real* prof_ptr = profile.data(); - amrex::Real* xloc_ptr = xloc.data(); - - const Box domain = lev_geom.Domain(); - const int domain_ilo = domain.smallEnd(0); - const int domain_ihi = domain.bigEnd(0); - const int domain_jlo = domain.smallEnd(1); - const int domain_jhi = domain.bigEnd(1); -#if (AMREX_SPACEDIM == 3) - const int domain_klo = domain.smallEnd(2); - const int domain_khi = domain.bigEnd(2); -#endif - - AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, - const auto& is_periodic_y = lev_geom.isPeriodic(1);, - const auto& is_periodic_z = lev_geom.isPeriodic(2);); - - Box const& bxg1 = amrex::grow(bx,1); - Box const& bxg2 = amrex::grow(bx,2); - Box const& bxg3 = amrex::grow(bx,3); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,2); - if (is_periodic_y) domain_per_grown.grow(1,2); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,2); -#endif - - amrex::ParallelFor(bxg1, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) - { - int max_order = 2; - - for (int n = 0; n < ncomp; n++) - { - bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); - bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); - bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); - bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); -#if (AMREX_SPACEDIM == 3) - bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); - bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); -#endif - // Initialize so that the slope stencil goes from -1:1 in each diretion - int nx = 1; int ny = 1; int nz = 1; - - // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil - // or do we need to enlarge it? - AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, - Real y_max = -1.e30; Real y_min = 1.e30;, - Real z_max = -1.e30; Real z_min = 1.e30;); - - Real slope_stencil_min_width = 0.5; -#if (AMREX_SPACEDIM == 2) - int kk = 0; -#elif (AMREX_SPACEDIM == 3) - for(int kk(-1); kk<=1; kk++) -#endif - { - for(int jj(-1); jj<=1; jj++) - for(int ii(-1); ii<=1; ii++) - if (flag(i,j,k).isConnected(ii,jj,kk)) - { - int r = i+ii; int s = j+jj; int t = k+kk; - - x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); - x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); - y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); - y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); -#if (AMREX_SPACEDIM == 3) - z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); - z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); -#endif - } - } - // If we need to grow the stencil, we let it be -nx:nx in the x-direction, - // for example. Note that nx,ny,nz are either 1 or 2 - if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; - if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; -#if (AMREX_SPACEDIM == 3) - if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; -#endif - - amrex::GpuArray slopes_eb; - if (nx*ny*nz == 1) - // Compute slope using 3x3x3 stencil - slopes_eb = amrex_calc_slopes_extdir_eb( - i,j,k,n,U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - else - { - // Compute slope using grown stencil (no larger than 5x5x5) - slopes_eb = amrex_calc_slopes_extdir_eb_grown( - i,j,k,n,AMREX_D_DECL(nx,ny,nz), - U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - } - - // We do the limiting separately because this limiter limits the slope based on the values - // extrapolated to the cell centroid locations - unlike the limiter in amrex - // which bases the limiting on values extrapolated to the face centroids. - amrex::GpuArray lim_slope = - amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); - - AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, - lim_slope[1] *= slopes_eb[1];, - lim_slope[2] *= slopes_eb[2];); - - // Add to the cell itself - if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) - { - if (n == 0 and j < 80) - { - prof_ptr[i] = U_in(i,j,k,n) + - lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + - lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); - xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); - } - - } // if bx contains - } // n - } // vfrac - }); - - for (int i = 0; i < 64; i++) - { - amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; - } - -} -/** @} */ diff --git a/Diagnostics/Redistribution/Make.package b/Diagnostics/Redistribution/Make.package deleted file mode 100644 index 301f9a857..000000000 --- a/Diagnostics/Redistribution/Make.package +++ /dev/null @@ -1,7 +0,0 @@ -CEXE_sources += hydro_create_itracker_$(DIM)d.cpp -CEXE_sources += hydro_redistribution.cpp -CEXE_sources += hydro_state_redistribute.cpp -CEXE_sources += hydro_state_utils.cpp - -CEXE_headers += hydro_redistribution.H -CEXE_headers += hydro_slope_limiter_K.H diff --git a/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp b/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp deleted file mode 100644 index 8a0c19f42..000000000 --- a/Diagnostics/Redistribution/hydro_create_itracker_2d.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/** - * \file hydro_create_itracker_2d.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include - -using namespace amrex; - -#if (AMREX_SPACEDIM == 2) - -void -Redistribution::MakeITracker ( Box const& bx, - Array4 const& apx, - Array4 const& apy, - Array4 const& vfrac, - Array4 const& itracker, - Geometry const& lev_geom, - Real target_volfrac) -{ -#if 0 - int debug_verbose = 0; -#endif - - const Real small_norm_diff = 1.e-8; - - const Box domain = lev_geom.Domain(); - - // Note that itracker has 4 components and all are initialized to zero - // We will add to the first component every time this cell is included in a merged neighborhood, - // either by merging or being merged - // We identify the cells in the remaining three components with the following ordering - // - // ^ 6 7 8 - // | 4 5 - // j 1 2 3 - // i ---> - - Array imap{0,-1,0,1,-1,1,-1,0,1}; - Array jmap{0,-1,-1,-1,0,0,1,1,1}; - - const auto& is_periodic_x = lev_geom.isPeriodic(0); - const auto& is_periodic_y = lev_geom.isPeriodic(1); - -// if (debug_verbose > 0) -// amrex::Print() << " IN MAKE_ITRACKER DOING BOX " << bx << std::endl; - - amrex::ParallelFor(Box(itracker), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - itracker(i,j,k,0) = 0; - }); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,4); - if (is_periodic_y) domain_per_grown.grow(1,4); - - Box const& bxg4 = amrex::grow(bx,4); - Box bx_per_g4= domain_per_grown & bxg4; - - amrex::ParallelFor(bx_per_g4, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (i == 0 and apx(i,j,k) != 1.0 and apx(i,j,k) != 0.0) amrex::Print() << "APX " << j << " " << - apx(i,j,k) << " " << apx(i+1,j,k) << " " << apy(i,j,k) << " " << apy(i,j+1,k) << " " << vfrac(i,j,k) << std::endl; - if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < target_volfrac) - { - Real apnorm, apnorm_inv; - const Real dapx = apx(i+1,j ,k ) - apx(i,j,k); - const Real dapy = apy(i ,j+1,k ) - apy(i,j,k); - apnorm = std::sqrt(dapx*dapx+dapy*dapy); - apnorm_inv = 1.0/apnorm; - Real nx = dapx * apnorm_inv; - Real ny = dapy * apnorm_inv; - - bool nx_eq_ny = ( (std::abs(nx-ny) < small_norm_diff) || - (std::abs(nx+ny) < small_norm_diff) ) ? true : false; - - // As a first pass, choose just based on the normal - if (std::abs(nx) > std::abs(ny)) - { - if (nx > 0) - itracker(i,j,k,1) = 5; - else - itracker(i,j,k,1) = 4; - - } else { - if (ny > 0) - itracker(i,j,k,1) = 7; - else - itracker(i,j,k,1) = 2; - } - - bool xdir_mns_ok = (is_periodic_x || (i > domain.smallEnd(0))); - bool xdir_pls_ok = (is_periodic_x || (i < domain.bigEnd(0) )); - bool ydir_mns_ok = (is_periodic_y || (j > domain.smallEnd(1))); - bool ydir_pls_ok = (is_periodic_y || (j < domain.bigEnd(1) )); - - // Override above logic if trying to reach outside a domain boundary (and non-periodic) - if ( (!xdir_mns_ok && (itracker(i,j,k,1) == 4)) || - (!xdir_pls_ok && (itracker(i,j,k,1) == 5)) ) - { - itracker(i,j,k,1) = (ny > 0) ? 7 : 2; - } - if ( (!ydir_mns_ok && (itracker(i,j,k,1) == 2)) || - (!ydir_pls_ok && (itracker(i,j,k,1) == 7)) ) - { - itracker(i,j,k,1) = (nx > 0) ? 5 : 4; - } - - // (i,j) merges with at least one cell now - itracker(i,j,k,0) += 1; - - // (i+ioff,j+joff) is in the nbhd of (i,j) - int ioff = imap[itracker(i,j,k,1)]; - int joff = jmap[itracker(i,j,k,1)]; - - // Sanity check - if (vfrac(i+ioff,j+joff,k) == 0.) - amrex::Abort(" Trying to merge with covered cell"); - - Real sum_vol = vfrac(i,j,k) + vfrac(i+ioff,j+joff,k); - -#if 0 - if (debug_verbose > 0) - amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << - " trying to merge with " << IntVect(i+ioff,j+joff) << - " with volfrac " << vfrac(i+ioff,j+joff,k) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - - // If the merged cell isn't large enough, we try to merge in the other direction - if (sum_vol < target_volfrac || nx_eq_ny) - { - // Original offset was in y-direction, so we will add to the x-direction - // Note that if we can't because it would go outside the domain, we don't - if (ioff == 0) { - if (nx >= 0 && xdir_pls_ok) - { - itracker(i,j,k,2) = 5; - itracker(i,j,k,0) += 1; - } - else if (nx <= 0 && xdir_mns_ok) - { - itracker(i,j,k,2) = 4; - itracker(i,j,k,0) += 1; - } - - // Original offset was in x-direction, so we will add to the y-direction - // Note that if we can't because it would go outside the domain, we don't - } else { - if (ny >= 0 && ydir_pls_ok) - { - itracker(i,j,k,2) = 7; - itracker(i,j,k,0) += 1; - } - else if (ny <= 0 && ydir_mns_ok) - { - itracker(i,j,k,2) = 2; - itracker(i,j,k,0) += 1; - } - } - - if (itracker(i,j,k,0) > 1) - { - // (i+ioff2,j+joff2) is in the nbhd of (i,j) - int ioff2 = imap[itracker(i,j,k,2)]; - int joff2 = jmap[itracker(i,j,k,2)]; - - sum_vol += vfrac(i+ioff2,j+joff2,k); -#if 0 - if (debug_verbose > 0) - amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << - " trying to ALSO merge with " << IntVect(i+ioff2,j+joff2) << - " with volfrac " << vfrac(i+ioff2,j+joff2,k) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - } - } - - // Now we merge in the corner direction if we have already claimed two - if (itracker(i,j,k,0) == 2) - { - // We already have two offsets, and we know they are in different directions - ioff = imap[itracker(i,j,k,1)] + imap[itracker(i,j,k,2)]; - joff = jmap[itracker(i,j,k,1)] + jmap[itracker(i,j,k,2)]; - - if (ioff > 0 && joff > 0) - itracker(i,j,k,3) = 8; - else if (ioff < 0 && joff > 0) - itracker(i,j,k,3) = 6; - else if (ioff > 0 && joff < 0) - itracker(i,j,k,3) = 3; - else - itracker(i,j,k,3) = 1; - - // (i,j) merges with at least three cells now - itracker(i,j,k,0) += 1; - - sum_vol += vfrac(i+ioff,j+joff,k); -#if 0 - if (debug_verbose > 0) - amrex::Print() << "Cell " << IntVect(i,j) << " with volfrac " << vfrac(i,j,k) << - " trying to ALSO merge with " << IntVect(i+ioff,j+joff) << - " with volfrac " << vfrac(i+ioff,j+joff,k) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - } - if (sum_vol < target_volfrac) - { -#if 0 - amrex::Print() << "Couldnt merge with enough cells to raise volume at " << - IntVect(i,j) << " so stuck with sum_vol " << sum_vol << std::endl; -#endif - amrex::Abort("Couldnt merge with enough cells to raise volume greater than target_volfrac"); - } - } - }); -} -#endif -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp b/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp deleted file mode 100644 index d713e7c82..000000000 --- a/Diagnostics/Redistribution/hydro_create_itracker_3d.cpp +++ /dev/null @@ -1,500 +0,0 @@ -/** - * \file hydro_create_itracker_3d.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include - -using namespace amrex; - -#if (AMREX_SPACEDIM == 3) -void -Redistribution::MakeITracker ( Box const& bx, - Array4 const& apx, - Array4 const& apy, - Array4 const& apz, - Array4 const& vfrac, - Array4 const& itracker, - Geometry const& lev_geom, - Real target_volfrac) -{ -#if 0 - bool debug_print = false; -#endif - - const Real small_norm_diff = 1.e-8; - - const Box domain = lev_geom.Domain(); - - // Note that itracker has 8 components and all are initialized to zero - // We will add to the first component every time this cell is included in a merged neighborhood, - // either by merging or being merged - // We identify the cells in the remaining three components with the following ordering - // - // at k-1 | at k | at k+1 - // - // ^ 15 16 17 | 6 7 8 | 24 25 26 - // | 12 13 14 | 4 5 | 21 22 23 - // j 9 10 11 | 1 2 3 | 18 19 20 - // i ---> - // - // Note the first component of each of these arrays should never be used - Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; - Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; - Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - - const auto& is_periodic_x = lev_geom.isPeriodic(0); - const auto& is_periodic_y = lev_geom.isPeriodic(1); - const auto& is_periodic_z = lev_geom.isPeriodic(2); - -#if 0 - if (debug_print) - amrex::Print() << " IN MERGE_REDISTRIBUTE DOING BOX " << bx << std::endl; -#endif - - amrex::ParallelFor(Box(itracker), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - itracker(i,j,k,0) = 0; - }); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,4); - if (is_periodic_y) domain_per_grown.grow(1,4); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,4); -#endif - - Box const& bxg4 = amrex::grow(bx,4); - Box bx_per_g4= domain_per_grown & bxg4; - - amrex::ParallelFor(bx_per_g4, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < target_volfrac) - { - Real apnorm, apnorm_inv; - const Real dapx = apx(i+1,j ,k ) - apx(i,j,k); - const Real dapy = apy(i ,j+1,k ) - apy(i,j,k); - const Real dapz = apz(i ,j ,k+1) - apz(i,j,k); - apnorm = std::sqrt(dapx*dapx+dapy*dapy+dapz*dapz); - apnorm_inv = 1.0/apnorm; - Real nx = dapx * apnorm_inv; - Real ny = dapy * apnorm_inv; - Real nz = dapz * apnorm_inv; - - bool nx_eq_ny = ( (std::abs(nx-ny) < small_norm_diff) || - (std::abs(nx+ny) < small_norm_diff) ) ? true : false; - bool nx_eq_nz = ( (std::abs(nx-nz) < small_norm_diff) || - (std::abs(nx+nz) < small_norm_diff) ) ? true : false; - bool ny_eq_nz = ( (std::abs(ny-nz) < small_norm_diff) || - (std::abs(ny+nz) < small_norm_diff) ) ? true : false; - - bool xdir_mns_ok = (is_periodic_x || (i > domain.smallEnd(0))); - bool xdir_pls_ok = (is_periodic_x || (i < domain.bigEnd(0) )); - bool ydir_mns_ok = (is_periodic_y || (j > domain.smallEnd(1))); - bool ydir_pls_ok = (is_periodic_y || (j < domain.bigEnd(1) )); - bool zdir_mns_ok = (is_periodic_z || (k > domain.smallEnd(2))); - bool zdir_pls_ok = (is_periodic_z || (k < domain.bigEnd(2) )); - - // x-component of normal is greatest - if ( (std::abs(nx) > std::abs(ny)) && - (std::abs(nx) > std::abs(nz)) ) - { - if (nx > 0) - itracker(i,j,k,1) = 5; - else - itracker(i,j,k,1) = 4; - - // y-component of normal is greatest - } else if ( (std::abs(ny) >= std::abs(nx)) && - (std::abs(ny) > std::abs(nz)) ) - { - if (ny > 0) - itracker(i,j,k,1) = 7; - else - - itracker(i,j,k,1) = 2; - // z-component of normal is greatest - } else { - if (nz > 0) - itracker(i,j,k,1) = 22; - else - itracker(i,j,k,1) = 13; - } - - // Override above logic if trying to reach outside a domain boundary (and non-periodic) - if ( (!xdir_mns_ok && (itracker(i,j,k,1) == 4)) || - (!xdir_pls_ok && (itracker(i,j,k,1) == 5)) ) - { - if ( (std::abs(ny) > std::abs(nz)) ) - itracker(i,j,k,1) = (ny > 0) ? 7 : 2; - else - itracker(i,j,k,1) = (nz > 0) ? 22 : 13; - } - - if ( (!ydir_mns_ok && (itracker(i,j,k,1) == 2)) || - (!ydir_pls_ok && (itracker(i,j,k,1) == 7)) ) - { - if ( (std::abs(nx) > std::abs(nz)) ) - itracker(i,j,k,1) = (nx > 0) ? 5 : 4; - else - itracker(i,j,k,1) = (nz > 0) ? 22 : 13; - } - - if ( (!zdir_mns_ok && (itracker(i,j,k,1) == 13)) || - (!zdir_pls_ok && (itracker(i,j,k,1) == 22)) ) - { - if ( (std::abs(nx) > std::abs(ny)) ) - itracker(i,j,k,1) = (nx > 0) ? 5 : 4; - else - itracker(i,j,k,1) = (ny > 0) ? 7 : 2; - } - - // (i,j,k) merges with at least one cell now - itracker(i,j,k,0) += 1; - - // (i+ioff,j+joff,k+koff) is now the first cell in the nbhd of (i,j,k) - int ioff = imap[itracker(i,j,k,1)]; - int joff = jmap[itracker(i,j,k,1)]; - int koff = kmap[itracker(i,j,k,1)]; - - // Sanity check - if (vfrac(i+ioff,j+joff,k+koff) == 0.) - { - // amrex::Print() << "Cell " << IntVect(i,j,k) << " is trying to merge with cell " << IntVect(i+ioff,j+joff,k+koff) << std::endl; - amrex::Abort(" Trying to merge with covered cell"); - } - - Real sum_vol = vfrac(i,j,k) + vfrac(i+ioff,j+joff,k+koff); - -#if 0 - if (debug_print) - amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << - " trying to merge with " << IntVect(i+ioff,j+joff,k+koff) << - " with volfrac " << vfrac(i+ioff,j+joff,k+koff) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - - bool just_broke_symmetry = ( ( (joff == 0 && koff == 0) && (nx_eq_ny || nx_eq_nz) ) || - ( (ioff == 0 && koff == 0) && (nx_eq_ny || ny_eq_nz) ) || - ( (ioff == 0 && joff == 0) && (nx_eq_nz || ny_eq_nz) ) ); - - // If the merged cell isn't large enough, or if we broke symmetry by the current merge, - // we merge in one of the other directions. Note that the direction of the next merge - // is first set by a symmetry break, but if that isn't happening, we choose the next largest normal - - if ( (sum_vol < target_volfrac) || just_broke_symmetry ) - { - // Original offset was in x-direction - if (joff == 0 && koff == 0) - { - if (nx_eq_ny) { - itracker(i,j,k,2) = (ny > 0) ? 7 : 2; - } else if (nx_eq_nz) { - itracker(i,j,k,2) = (nz > 0) ? 22 : 13; - } else if ( (std::abs(ny) > std::abs(nz)) ) { - itracker(i,j,k,2) = (ny > 0) ? 7 : 2; - } else { - itracker(i,j,k,2) = (nz > 0) ? 22 : 13; - } - - // Original offset was in y-direction - } else if (ioff == 0 && koff == 0) - { - if (nx_eq_ny) { - itracker(i,j,k,2) = (nx > 0) ? 5 : 4; - } else if (ny_eq_nz) { - itracker(i,j,k,2) = (nz > 0) ? 22 : 13; - } else if ( (std::abs(nx) > std::abs(nz)) ) { - itracker(i,j,k,2) = (nx > 0) ? 5 : 4; - } else { - itracker(i,j,k,2) = (nz > 0) ? 22 : 13; - } - - // Original offset was in z-direction - } else if (ioff == 0 && joff == 0) - { - if (nx_eq_nz) { - itracker(i,j,k,2) = (nx > 0) ? 5 : 4; - } else if (ny_eq_nz) { - itracker(i,j,k,2) = (ny > 0) ? 7 : 2; - } else if ( (std::abs(nx) > std::abs(ny)) ) { - itracker(i,j,k,2) = (nx > 0) ? 5 : 4; - } else { - itracker(i,j,k,2) = (ny > 0) ? 7 : 2; - } - } - - // (i,j,k) merges with at least two cells now - itracker(i,j,k,0) += 1; - - // (i+ioff2,j+joff2,k+koff2) is in the nbhd of (i,j,k) - int ioff2 = imap[itracker(i,j,k,2)]; - int joff2 = jmap[itracker(i,j,k,2)]; - int koff2 = kmap[itracker(i,j,k,2)]; - - sum_vol += vfrac(i+ioff2,j+joff2,k+koff2); -#if 0 - if (debug_print) - amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << - " trying to ALSO merge with " << IntVect(i+ioff2,j+joff2,k+koff2) << - " with volfrac " << vfrac(i+ioff2,j+joff2,k+koff2) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - } - - // If the merged cell has merged in two directions, we now merge in the corner direction within the current plane - if (itracker(i,j,k,0) >= 2) - { - // We already have two offsets, and we know they are in different directions - ioff = imap[itracker(i,j,k,1)] + imap[itracker(i,j,k,2)]; - joff = jmap[itracker(i,j,k,1)] + jmap[itracker(i,j,k,2)]; - koff = kmap[itracker(i,j,k,1)] + kmap[itracker(i,j,k,2)]; - - // Both nbors are in the koff=0 plane - if (koff == 0) - { - if (ioff > 0 && joff > 0) - itracker(i,j,k,3) = 8; - else if (ioff < 0 && joff > 0) - itracker(i,j,k,3) = 6; - else if (ioff > 0 && joff < 0) - itracker(i,j,k,3) = 3; - else - itracker(i,j,k,3) = 1; - - // Both nbors are in the joff=0 plane - } else if (joff == 0) { - if (ioff > 0 && koff > 0) - itracker(i,j,k,3) = 23; - else if (ioff < 0 && koff > 0) - itracker(i,j,k,3) = 21; - else if (ioff > 0 && koff < 0) - itracker(i,j,k,3) = 14; - else - itracker(i,j,k,3) = 12; - - // Both nbors are in the ioff=0 plane - } else { - if (joff > 0 && koff > 0) - itracker(i,j,k,3) = 25; - else if (joff < 0 && koff > 0) - itracker(i,j,k,3) = 19; - else if (joff > 0 && koff < 0) - itracker(i,j,k,3) = 16; - else - itracker(i,j,k,3) = 10; - } - - // (i,j,k) merges with at least three cells now - itracker(i,j,k,0) += 1; - - sum_vol += vfrac(i+ioff,j+joff,k+koff); - -#if 0 - int ioff3 = imap[itracker(i,j,k,3)]; - int joff3 = jmap[itracker(i,j,k,3)]; - int koff3 = kmap[itracker(i,j,k,3)]; - if (debug_print) - amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << - " trying to ALSO merge with " << IntVect(i+ioff3,j+joff3,k+koff3) << - " with volfrac " << vfrac(i+ioff3,j+joff3,k+koff3) << std::endl; -#endif - - // All nbors are currently in one of three planes - just_broke_symmetry = ( ( (koff == 0) && (nx_eq_nz || ny_eq_nz) ) || - ( (joff == 0) && (nx_eq_ny || ny_eq_nz) ) || - ( (ioff == 0) && (nx_eq_ny || nx_eq_nz) ) ); - - // If with a nbhd of four cells we have still not reached vfrac > target_volfrac, we add another four - // cells to the nbhd to make a 2x2x2 block. We use the direction of the remaining - // normal to know whether to go lo or hi in the new direction. - if (sum_vol < target_volfrac || just_broke_symmetry) - { -#if 0 - if (debug_print) - if (just_broke_symmetry) - amrex::Print() << "Expanding neighborhood of " << IntVect(i,j,k) << - " from 4 to 8 since we just broke symmetry with the last merge " << std::endl; - else - amrex::Print() << "Expanding neighborhood of " << IntVect(i,j,k) << - " from 4 to 8 since sum_vol with 4 was only " << sum_vol << " " << std::endl; -#endif - // All nbors are currently in the koff=0 plane - if (koff == 0) - { - if (nz > 0) - { - itracker(i,j,k,4) = 22; - - if (ioff > 0) - itracker(i,j,k,5) = 23; - else - itracker(i,j,k,5) = 21; - if (joff > 0) - itracker(i,j,k,6) = 25; - else - itracker(i,j,k,6) = 19; - - if (ioff > 0 && joff > 0) { - itracker(i,j,k,7) = 26; - } else if (ioff < 0 && joff > 0) { - itracker(i,j,k,7) = 24; - } else if (ioff > 0 && joff < 0) { - itracker(i,j,k,7) = 20; - } else { - itracker(i,j,k,7) = 18; - } - } else { // nz <= 0 - - itracker(i,j,k,4) = 13; - - if (ioff > 0) - itracker(i,j,k,5) = 14; - else - itracker(i,j,k,5) = 12; - if (joff > 0) - itracker(i,j,k,6) = 16; - else - itracker(i,j,k,6) = 10; - - if (ioff > 0 && joff > 0) { - itracker(i,j,k,7) = 17; - } else if (ioff < 0 && joff > 0) { - itracker(i,j,k,7) = 15; - } else if (ioff > 0 && joff < 0) { - itracker(i,j,k,7) = 11; - } else { - itracker(i,j,k,7) = 9; - } - } - } else if (joff == 0) { - if (ny > 0) - { - itracker(i,j,k,4) = 7; - - if (ioff > 0) - itracker(i,j,k,5) = 8; - else - itracker(i,j,k,5) = 6; - if (koff > 0) - itracker(i,j,k,6) = 25; - else - itracker(i,j,k,6) = 16; - - if (ioff > 0 && koff > 0) { - itracker(i,j,k,7) = 26; - } else if (ioff < 0 && koff > 0) { - itracker(i,j,k,7) = 24; - } else if (ioff > 0 && koff < 0) { - itracker(i,j,k,7) = 17; - } else { - itracker(i,j,k,7) = 15; - } - - } else { // ny <= 0 - - itracker(i,j,k,4) = 2; - - if (ioff > 0) - itracker(i,j,k,5) = 3; - else - itracker(i,j,k,5) = 1; - if (koff > 0) - itracker(i,j,k,6) = 19; - else - itracker(i,j,k,6) = 10; - - if (ioff > 0 && koff > 0) { - itracker(i,j,k,7) = 20; - } else if (ioff < 0 && koff > 0) { - itracker(i,j,k,7) = 18; - } else if (ioff > 0 && koff < 0) { - itracker(i,j,k,7) = 11; - } else { - itracker(i,j,k,7) = 9; - } - } - } else if (ioff == 0) { - - if (nx > 0) - { - itracker(i,j,k,4) = 5; - - if (joff > 0) - itracker(i,j,k,5) = 8; - else - itracker(i,j,k,5) = 3; - if (koff > 0) - itracker(i,j,k,6) = 23; - else - itracker(i,j,k,6) = 14; - - if (joff > 0 && koff > 0) { - itracker(i,j,k,7) = 26; - } else if (joff < 0 && koff > 0) { - itracker(i,j,k,7) = 20; - } else if (joff > 0 && koff < 0) { - itracker(i,j,k,7) = 17; - } else { - itracker(i,j,k,7) = 11; - } - } else { // nx <= 0 - - itracker(i,j,k,4) = 4; - - if (joff > 0) - itracker(i,j,k,5) = 6; - else - itracker(i,j,k,5) = 1; - if (koff > 0) - itracker(i,j,k,6) = 21; - else - itracker(i,j,k,6) = 12; - - if (joff > 0 && koff > 0) { - itracker(i,j,k,7) = 24; - } else if (joff < 0 && koff > 0) { - itracker(i,j,k,7) = 18; - } else if (joff > 0 && koff < 0) { - itracker(i,j,k,7) = 15; - } else { - itracker(i,j,k,7) = 9; - } - } - } - - for(int n(4); n<8; n++){ - int ioffn = imap[itracker(i,j,k,n)]; - int joffn = jmap[itracker(i,j,k,n)]; - int koffn = kmap[itracker(i,j,k,n)]; - sum_vol += vfrac(i+ioffn,j+joffn,k+koffn); -#if 0 - if (debug_print) - amrex::Print() << "Cell " << IntVect(i,j,k) << " with volfrac " << vfrac(i,j,k) << - " trying to ALSO merge with " << IntVect(i+ioffn,j+joffn,k+koffn) << - " with volfrac " << vfrac(i+ioffn,j+joffn,k+koffn) << - " to get new sum_vol " << sum_vol << std::endl; -#endif - } - - // (i,j,k) has a 2x2x2 neighborhood now - itracker(i,j,k,0) += 4; - } - } - if (sum_vol < target_volfrac) - { -#if 0 - amrex::Print() << "Couldnt merge with enough cells to raise volume at " << - IntVect(i,j,k) << " so stuck with sum_vol " << sum_vol << std::endl; -#endif - amrex::Abort("Couldnt merge with enough cells to raise volume greater than target_volfrac"); - } - } - }); -} -#endif -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_redistribution.H b/Diagnostics/Redistribution/hydro_redistribution.H deleted file mode 100644 index 57c51ea9b..000000000 --- a/Diagnostics/Redistribution/hydro_redistribution.H +++ /dev/null @@ -1,122 +0,0 @@ -/** - * \file hydro_redistribution.H - * \addtogroup Redistribution - * @{ - * - */ - -#ifndef IAMR_REDISTRIBUTION_H_ -#define IAMR_REDISTRIBUTION_H_ - -#include -#include - -/** - * Placeholder description of Redistribution namespace. - * - */ - -namespace Redistribution { - - void Apply ( amrex::Box const& bx, int ncomp, - amrex::Array4 const& dUdt_out, - amrex::Array4 const& dUdt_in, - amrex::Array4 const& U_in, - amrex::Array4 const& scratch, - amrex::Array4 const& flag, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& bcent, - amrex::Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - amrex::Geometry const& geom, - amrex::Real dt, std::string redistribution_type, - const int srd_max_order = 2, - amrex::Real target_volfrac = 0.5, - amrex::Array4 const& update_scale={}); - - void ApplyToInitialData ( amrex::Box const& bx, int ncomp, - amrex::Array4 const& U_out, - amrex::Array4 const& U_in, - amrex::Array4 const& flag, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - amrex::Geometry& geom, std::string redistribution_type, - const int srd_max_order = 2, - amrex::Real target_volfrac = 0.5); - - void FluxRedistribute ( amrex::Box const& bx, int ncomp, - amrex::Array4 const& dUdt_out, - amrex::Array4 const& dUdt_in, - amrex::Array4 const& scratch, - amrex::Array4 const& flag, - amrex::Array4 const& vfrac, - amrex::Geometry const& geom); - - void StateRedistribute ( amrex::Box const& bx, int ncomp, - amrex::Array4 const& dUdt_out, - amrex::Array4 const& dUdt_in, - amrex::Array4 const& flag, - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - amrex::Array4 const& itracker, - amrex::Array4 const& nrs, - amrex::Array4 const& alpha, - amrex::Array4 const& nbhd_vol, - amrex::Array4 const& cent_hat, - amrex::Geometry const& geom, - const int max_order = 2); - - void MakeITracker ( amrex::Box const& bx, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - amrex::Array4 const& itracker, - amrex::Geometry const& geom, - amrex::Real target_volfrac); - - void MakeStateRedistUtils ( amrex::Box const& bx, - amrex::Array4 const& flag, - amrex::Array4 const& vfrac, - amrex::Array4 const& ccent, - amrex::Array4< int const> const& itracker, - amrex::Array4 const& nrs, - amrex::Array4 const& nbhd_vol, - amrex::Array4 const& alpha, - amrex::Array4 const& cent_hat, - amrex::Geometry const& geom, - amrex::Real target_volfrac); - - void Make1DProfile ( amrex::Box const& bx, int ncomp, - amrex::Array4 const& U_in, - amrex::Array4 const& flag, - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& bcent, - amrex::Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - amrex::Geometry const& lev_geom); - -} // namespace redistribution - -#endif -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_redistribution.cpp b/Diagnostics/Redistribution/hydro_redistribution.cpp deleted file mode 100644 index e184fe69e..000000000 --- a/Diagnostics/Redistribution/hydro_redistribution.cpp +++ /dev/null @@ -1,446 +0,0 @@ -/** - * \file hydro_redistribution.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include -#include - -#include -#if (AMREX_SPACEDIM == 2) -#include -#elif (AMREX_SPACEDIM == 3) -#include -#endif - -using namespace amrex; - -void Redistribution::Apply ( Box const& bx, int ncomp, - Array4 const& dUdt_out, - Array4 const& dUdt_in, - Array4 const& U_in, - Array4 const& scratch, - Array4 const& flag, - AMREX_D_DECL(Array4 const& apx, - Array4 const& apy, - Array4 const& apz), - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& bcc, - Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom, Real dt, - std::string redistribution_type, - const int srd_max_order, - amrex::Real target_volfrac, - Array4 const& srd_update_scale) -{ - // redistribution_type = "NoRedist"; // no redistribution - // redistribution_type = "FluxRedist" // flux_redistribute - // redistribution_type = "StateRedist"; // (weighted) state redistribute - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = 0.; - }); - - if (redistribution_type == "FluxRedist") - { - int icomp = 0; - apply_flux_redistribution (bx, dUdt_out, dUdt_in, scratch, icomp, ncomp, flag, vfrac, lev_geom); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) *= dt; - dUdt_out(i,j,k,n) += U_in(i,j,k,n); - } - ); - - // Make sure to call this while dUdt_out is still the full state, not the increment - Make1DProfile(bx, ncomp, dUdt_out, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), bcc, ccc, d_bcrec_ptr, - lev_geom); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) -= U_in(i,j,k,n); - dUdt_out(i,j,k,n) /= dt; - } - ); - - } else if (redistribution_type == "StateRedist") { - - Box const& bxg1 = grow(bx,1); - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); - // How many nbhds is a cell in -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - Box domain_per_grown = lev_geom.Domain(); - AMREX_D_TERM(if (lev_geom.isPeriodic(0)) domain_per_grown.grow(0,1);, - if (lev_geom.isPeriodic(1)) domain_per_grown.grow(1,1);, - if (lev_geom.isPeriodic(2)) domain_per_grown.grow(2,1);); - - // At any external Dirichlet domain boundaries we need to set dUdt_in to 0 - // in the cells just outside the domain because those values will be used - // in the slope computation in state redistribution. We assume here that - // the ext_dir values of U_in itself have already been set. - if (!domain_per_grown.contains(bxg1)) - amrex::ParallelFor(bxg1,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) - dUdt_in(i,j,k,n) = 0.; - }); - - amrex::ParallelFor(Box(scratch), ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - const Real scale = (srd_update_scale) ? srd_update_scale(i,j,k) : Real(1.0); - scratch(i,j,k,n) = U_in(i,j,k,n) + dt * dUdt_in(i,j,k,n) / scale; - } - ); - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - StateRedistribute(bx, ncomp, dUdt_out, scratch, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, - cent_hat_const, lev_geom, srd_max_order); - - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - // Only update the values which actually changed -- this makes - // the results insensitive to tiling -- otherwise cells that aren't - // changed but are in a tile on which StateRedistribute gets called - // will have precision-level changes due to adding/subtracting U_in - // and multiplying/dividing by dt. Here we test on whether (i,j,k) - // has at least one neighbor and/or whether (i,j,k) is in the - // neighborhood of another cell -- if either of those is true the - // value may have changed - - if (itr(i,j,k,0) > 0 || nrs(i,j,k) > 1.) - { - const Real scale = (srd_update_scale) ? srd_update_scale(i,j,k) : Real(1.0); - - dUdt_out(i,j,k,n) = scale * (dUdt_out(i,j,k,n) - U_in(i,j,k,n)) / dt; - - } - else - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - } - ); - - } else if (redistribution_type == "NoRedist") { - amrex::ParallelFor(bx, ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - dUdt_out(i,j,k,n) = dUdt_in(i,j,k,n); - } - ); - - } else { - amrex::Error("Not a legit redist_type"); - } -} - -void -Redistribution::ApplyToInitialData ( Box const& bx, int ncomp, - Array4 const& U_out, - Array4 const& U_in, - Array4 const& flag, - AMREX_D_DECL(amrex::Array4 const& apx, - amrex::Array4 const& apy, - amrex::Array4 const& apz), - amrex::Array4 const& vfrac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), - amrex::Array4 const& ccc, - amrex::BCRec const* d_bcrec_ptr, - Geometry& lev_geom, std::string redistribution_type, - const int srd_max_order, - amrex::Real target_volfrac) -{ - if (redistribution_type != "StateRedist") { - std::string msg = "Redistribution::ApplyToInitialData: Shouldn't be here with redist type "+redistribution_type; - amrex::Error(msg); - } - - Box const& bxg2 = grow(bx,2); - Box const& bxg3 = grow(bx,3); - Box const& bxg4 = grow(bx,4); - -#if (AMREX_SPACEDIM == 2) - // We assume that in 2D a cell will only need at most 3 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,4); -#else - // We assume that in 3D a cell will only need at most 7 neighbors to merge with, and we - // use the first component of this for the number of neighbors - IArrayBox itracker(bxg4,8); -#endif - FArrayBox nrs_fab(bxg3,1); - FArrayBox alpha_fab(bxg3,2); - - // Total volume of all cells in my nbhd - FArrayBox nbhd_vol_fab(bxg2,1); - - // Centroid of my nbhd - FArrayBox cent_hat_fab (bxg3,AMREX_SPACEDIM); - - Elixir eli_itr = itracker.elixir(); - Array4 itr = itracker.array(); - Array4 itr_const = itracker.const_array(); - - Elixir eli_nrs = nrs_fab.elixir(); - Array4 nrs = nrs_fab.array(); - Array4 nrs_const = nrs_fab.const_array(); - - Elixir eli_alpha = alpha_fab.elixir(); - Array4 alpha = alpha_fab.array(); - Array4 alpha_const = alpha_fab.const_array(); - - Elixir eli_nbf = nbhd_vol_fab.elixir(); - Array4 nbhd_vol = nbhd_vol_fab.array(); - Array4 nbhd_vol_const = nbhd_vol_fab.const_array(); - - Elixir eli_chf = cent_hat_fab.elixir(); - Array4 cent_hat = cent_hat_fab.array(); - Array4 cent_hat_const = cent_hat_fab.const_array(); - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - U_out(i,j,k,n) = 0.; - }); - - MakeITracker(bx, AMREX_D_DECL(apx, apy, apz), vfrac, itr, lev_geom, target_volfrac); - - MakeStateRedistUtils(bx, flag, vfrac, ccc, itr, nrs, alpha, nbhd_vol, cent_hat, - lev_geom, target_volfrac); - - StateRedistribute(bx, ncomp, U_out, U_in, flag, vfrac, - AMREX_D_DECL(fcx, fcy, fcz), ccc, d_bcrec_ptr, - itr_const, nrs_const, alpha_const, nbhd_vol_const, - cent_hat_const, lev_geom, srd_max_order); -} - -void -Redistribution::Make1DProfile ( Box const& bx, int ncomp, - Array4 const& U_in, - Array4 const& flag, - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& bcent, - Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - Geometry const& lev_geom) -{ - amrex::Vector profile; - amrex::Vector xloc; - profile.resize(64,0.0); - xloc.resize(64,0.0); - - amrex::Real* prof_ptr = profile.data(); - amrex::Real* xloc_ptr = xloc.data(); - - const Box domain = lev_geom.Domain(); - const int domain_ilo = domain.smallEnd(0); - const int domain_ihi = domain.bigEnd(0); - const int domain_jlo = domain.smallEnd(1); - const int domain_jhi = domain.bigEnd(1); -#if (AMREX_SPACEDIM == 3) - const int domain_klo = domain.smallEnd(2); - const int domain_khi = domain.bigEnd(2); -#endif - - AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, - const auto& is_periodic_y = lev_geom.isPeriodic(1);, - const auto& is_periodic_z = lev_geom.isPeriodic(2);); - - Box const& bxg1 = amrex::grow(bx,1); - Box const& bxg2 = amrex::grow(bx,2); - Box const& bxg3 = amrex::grow(bx,3); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,2); - if (is_periodic_y) domain_per_grown.grow(1,2); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,2); -#endif - - amrex::ParallelFor(bxg1, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0 && vfrac(i,j,k) < 1.0) - { - int max_order = 2; - - for (int n = 0; n < ncomp; n++) - { - bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); - bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); - bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); - bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); -#if (AMREX_SPACEDIM == 3) - bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); - bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); -#endif - // Initialize so that the slope stencil goes from -1:1 in each diretion - int nx = 1; int ny = 1; int nz = 1; - - // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil - // or do we need to enlarge it? - AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, - Real y_max = -1.e30; Real y_min = 1.e30;, - Real z_max = -1.e30; Real z_min = 1.e30;); - - Real slope_stencil_min_width = 0.5; -#if (AMREX_SPACEDIM == 2) - int kk = 0; -#elif (AMREX_SPACEDIM == 3) - for(int kk(-1); kk<=1; kk++) -#endif - { - for(int jj(-1); jj<=1; jj++) - for(int ii(-1); ii<=1; ii++) - if (flag(i,j,k).isConnected(ii,jj,kk)) - { - int r = i+ii; int s = j+jj; int t = k+kk; - - x_max = std::max(x_max, ccent(r,s,t,0)+static_cast(ii)); - x_min = std::min(x_min, ccent(r,s,t,0)+static_cast(ii)); - y_max = std::max(y_max, ccent(r,s,t,1)+static_cast(jj)); - y_min = std::min(y_min, ccent(r,s,t,1)+static_cast(jj)); -#if (AMREX_SPACEDIM == 3) - z_max = std::max(z_max, ccent(r,s,t,2)+static_cast(kk)); - z_min = std::min(z_min, ccent(r,s,t,2)+static_cast(kk)); -#endif - } - } - // If we need to grow the stencil, we let it be -nx:nx in the x-direction, - // for example. Note that nx,ny,nz are either 1 or 2 - if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; - if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; -#if (AMREX_SPACEDIM == 3) - if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; -#endif - - amrex::GpuArray slopes_eb; - if (nx*ny*nz == 1) - // Compute slope using 3x3x3 stencil - slopes_eb = amrex_calc_slopes_extdir_eb( - i,j,k,n,U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - else - { - // Compute slope using grown stencil (no larger than 5x5x5) - slopes_eb = amrex_calc_slopes_extdir_eb_grown( - i,j,k,n,AMREX_D_DECL(nx,ny,nz), - U_in,ccent,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - } - - // We do the limiting separately because this limiter limits the slope based on the values - // extrapolated to the cell centroid locations - unlike the limiter in amrex - // which bases the limiting on values extrapolated to the face centroids. - amrex::GpuArray lim_slope = - amrex_calc_centroid_limiter(i,j,k,n,U_in,flag,slopes_eb,ccent); - - AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, - lim_slope[1] *= slopes_eb[1];, - lim_slope[2] *= slopes_eb[2];); - - // Add to the cell itself - if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) - { - if (n == 0 and j > 40) - { - prof_ptr[i] = U_in(i,j,k,n) + - lim_slope[0] * (bcent(i,j,k,0)-ccent(i,j,k,0)) + - lim_slope[1] * (bcent(i,j,k,1)-ccent(i,j,k,1)); - xloc_ptr[i] = (i+0.5+bcent(i,j,k,0)); - } - - } // if bx contains - } // n - } // vfrac - }); - - for (int i = 0; i < 64; i++) - { - amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; - } - -} -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_slope_limiter_K.H b/Diagnostics/Redistribution/hydro_slope_limiter_K.H deleted file mode 100644 index aa9af8a89..000000000 --- a/Diagnostics/Redistribution/hydro_slope_limiter_K.H +++ /dev/null @@ -1,86 +0,0 @@ -/** - * \file hydro_slope_limiter_K.H - * \addtogroup Redistribution - * @{ - * - */ - -using namespace amrex; - -namespace { - constexpr Real epsilon = 1.e-12; -} - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::Real -amrex_calc_alpha_stencil(Real q_hat, Real q_max, Real q_min, Real state) noexcept -{ - const Real small = epsilon*amrex::max(amrex::Math::abs(q_max),amrex::Math::abs(q_min)); - Real alpha; - - if ((q_hat-state) > small) { - alpha = amrex::min(1.0_rt,(q_max-state)/(q_hat-state)); - } else if ((q_hat-state) < -small) { - alpha = amrex::min(1.0_rt,(q_min-state)/(q_hat-state)); - } else { - alpha = 1.0_rt; - } - return alpha; -} - -AMREX_GPU_DEVICE AMREX_FORCE_INLINE -amrex::GpuArray -amrex_calc_centroid_limiter(int i, int j, int k, int n, - amrex::Array4 const& state, - amrex::Array4 const& flag, - const amrex::GpuArray& slopes, - amrex::Array4 const& ccent) noexcept -{ - AMREX_D_TERM(amrex::Real xalpha = 1.0;, - amrex::Real yalpha = 1.0;, - amrex::Real zalpha = 1.0;); - - // Compute the limiters needed to keep the predicted q_hat between the max and min -#if (AMREX_SPACEDIM == 2) - int kk = 0; -#elif (AMREX_SPACEDIM == 3) - for(int kk(-1); kk<=1; kk++) -#endif - { - for(int jj(-1); jj<=1; jj++){ - for(int ii(-1); ii<=1; ii++){ - Real alpha = amrex::max(xalpha,yalpha); -#if (AMREX_SPACEDIM == 3) - alpha = amrex::max(alpha,zalpha); -#endif - if (flag(i,j,k).isConnected(ii,jj,kk) && alpha > 0.0) - { - AMREX_D_TERM(Real delta_x = ccent(i+ii,j+jj,k+kk,0) - ccent(i,j,k,0) + static_cast(ii);, - Real delta_y = ccent(i+ii,j+jj,k+kk,1) - ccent(i,j,k,1) + static_cast(jj);, - Real delta_z = ccent(i+ii,j+jj,k+kk,2) - ccent(i,j,k,2) + static_cast(kk);); - - Real q_hat = state(i,j,k,n) + AMREX_D_TERM( delta_x * slopes[0], - + delta_y * slopes[1], - + delta_z * slopes[2]); - - Real q_max = amrex::max(state(i+ii,j+jj,k+kk,n),state(i,j,k,n)); - Real q_min = amrex::min(state(i+ii,j+jj,k+kk,n),state(i,j,k,n)); - - if ( q_hat-q_max > amrex::Math::abs(epsilon*q_max) || q_hat-q_min < -1.0*amrex::Math::abs(epsilon*q_min) ) - { - Real new_lim = amrex_calc_alpha_stencil(q_hat, q_max, q_min, state(i,j,k,n)); - - if (amrex::Math::abs(delta_x) > epsilon) xalpha = amrex::min(xalpha,new_lim); - if (amrex::Math::abs(delta_y) > epsilon) yalpha = amrex::min(yalpha,new_lim); -#if (AMREX_SPACEDIM == 3) - if (amrex::Math::abs(delta_z) > epsilon) zalpha = amrex::min(zalpha,new_lim); -#endif - } - } - } - } - } - - return {AMREX_D_DECL(xalpha,yalpha,zalpha)}; -} -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_state_redistribute.cpp b/Diagnostics/Redistribution/hydro_state_redistribute.cpp deleted file mode 100644 index be9866d84..000000000 --- a/Diagnostics/Redistribution/hydro_state_redistribute.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/** - * \file hydro_state_redistribute.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include -#include -#if (AMREX_SPACEDIM == 2) -#include -#elif (AMREX_SPACEDIM == 3) -#include -#endif - -using namespace amrex; - - -void -Redistribution::StateRedistribute ( Box const& bx, int ncomp, - Array4 const& U_out, - Array4 const& U_in, - Array4 const& flag, - Array4 const& vfrac, - AMREX_D_DECL(Array4 const& fcx, - Array4 const& fcy, - Array4 const& fcz), - Array4 const& ccent, - amrex::BCRec const* d_bcrec_ptr, - Array4< int const> const& itracker, - Array4 const& nrs, - Array4 const& alpha, - Array4 const& nbhd_vol, - Array4 const& cent_hat, - Geometry const& lev_geom, - const int max_order) -{ - // Note that itracker has {4 in 2D, 8 in 3D} components and all are initialized to zero - // We will add to the first component every time this cell is included in a merged neighborhood, - // either by merging or being merged - // - // In 2D, we identify the cells in the remaining three components with the following ordering - // - // ^ 6 7 8 - // | 4 5 - // j 1 2 3 - // i ---> - // - // In 3D, We identify the cells in the remaining three components with the following ordering - // - // at k-1 | at k | at k+1 - // - // ^ 15 16 17 | 6 7 8 | 24 25 26 - // | 12 13 14 | 4 5 | 21 22 23 - // j 9 10 11 | 1 2 3 | 18 19 20 - // i ---> - // - // Note the first component of each of these arrays should never be used - // -#if (AMREX_SPACEDIM == 2) - amrex::GpuArray imap{0,-1, 0, 1,-1, 1,-1, 0, 1}; - amrex::GpuArray jmap{0,-1,-1,-1, 0, 0, 1, 1, 1}; - amrex::GpuArray kmap{0, 0, 0, 0, 0, 0, 0, 0, 0}; -#else - amrex::GpuArray imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; - amrex::GpuArray jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; - amrex::GpuArray kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; -#endif - - const Box domain = lev_geom.Domain(); - const int domain_ilo = domain.smallEnd(0); - const int domain_ihi = domain.bigEnd(0); - const int domain_jlo = domain.smallEnd(1); - const int domain_jhi = domain.bigEnd(1); -#if (AMREX_SPACEDIM == 3) - const int domain_klo = domain.smallEnd(2); - const int domain_khi = domain.bigEnd(2); -#endif - - AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, - const auto& is_periodic_y = lev_geom.isPeriodic(1);, - const auto& is_periodic_z = lev_geom.isPeriodic(2);); - - // amrex::Print() << " IN STATE_REDISTRIBUTE DOING BOX " << bx << " with ncomp " << ncomp << std::endl; - // amrex::Print() << " Box(U_in) " << Box(U_in) << std::endl; - // amrex::Print() << " Box(U_out) " << Box(U_out) << std::endl; - - Box const& bxg1 = amrex::grow(bx,1); - Box const& bxg2 = amrex::grow(bx,2); - Box const& bxg3 = amrex::grow(bx,3); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,2); - if (is_periodic_y) domain_per_grown.grow(1,2); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,2); -#endif - - // Solution at the centroid of my nbhd - FArrayBox soln_hat_fab (bxg3,ncomp); - Array4 soln_hat = soln_hat_fab.array(); - Elixir eli_soln_hat = soln_hat_fab.elixir(); - - // Define Qhat (from Berger and Guliani) - // Here we initialize soln_hat to equal U_in on all cells in bxg3 so that - // in the event we need to use soln_hat 3 cells out from the bx limits - // in a modified slope computation, we have a value of soln_hat to use. - // But we only modify soln_hat inside bxg2 - amrex::ParallelFor(bxg3, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - for (int n = 0; n < ncomp; n++) - soln_hat(i,j,k,n) = U_in(i,j,k,n); - - if (vfrac(i,j,k) > 0.0 && bxg2.contains(IntVect(AMREX_D_DECL(i,j,k))) - && domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k)))) { - - // Start with U_in(i,j,k) itself - for (int n = 0; n < ncomp; n++) - soln_hat(i,j,k,n) = U_in(i,j,k,n) * alpha(i,j,k,0) * vfrac(i,j,k); - - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - - if (domain_per_grown.contains(IntVect(AMREX_D_DECL(r,s,t)))) - { - for (int n = 0; n < ncomp; n++) - soln_hat(i,j,k,n) += U_in(r,s,t,n) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t); - } - } - for (int n = 0; n < ncomp; n++) - soln_hat(i,j,k,n) /= nbhd_vol(i,j,k); - } - }); - - amrex::ParallelFor(bxg1, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0) - { - int num_nbors = itracker(i,j,k,0); - - if (itracker(i,j,k,0) == 0) - { - if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) - { - for (int n = 0; n < ncomp; n++) - amrex::Gpu::Atomic::Add(&U_out(i,j,k,n),alpha(i,j,k,0)*nrs(i,j,k)*soln_hat(i,j,k,n)); - } - - } else { - - for (int n = 0; n < ncomp; n++) - { - bool extdir_ilo = (d_bcrec_ptr[n].lo(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(0) == amrex::BCType::hoextrap); - bool extdir_ihi = (d_bcrec_ptr[n].hi(0) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(0) == amrex::BCType::hoextrap); - bool extdir_jlo = (d_bcrec_ptr[n].lo(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(1) == amrex::BCType::hoextrap); - bool extdir_jhi = (d_bcrec_ptr[n].hi(1) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(1) == amrex::BCType::hoextrap); -#if (AMREX_SPACEDIM == 3) - bool extdir_klo = (d_bcrec_ptr[n].lo(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].lo(2) == amrex::BCType::hoextrap); - bool extdir_khi = (d_bcrec_ptr[n].hi(2) == amrex::BCType::ext_dir || - d_bcrec_ptr[n].hi(2) == amrex::BCType::hoextrap); -#endif - // Initialize so that the slope stencil goes from -1:1 in each diretion - int nx = 1; int ny = 1; int nz = 1; - - // Do we have enough extent in each coordinate direction to use the 3x3x3 stencil - // or do we need to enlarge it? - AMREX_D_TERM(Real x_max = -1.e30; Real x_min = 1.e30;, - Real y_max = -1.e30; Real y_min = 1.e30;, - Real z_max = -1.e30; Real z_min = 1.e30;); - - Real slope_stencil_min_width = 0.5; -#if (AMREX_SPACEDIM == 2) - int kk = 0; -#elif (AMREX_SPACEDIM == 3) - for(int kk(-1); kk<=1; kk++) -#endif - { - for(int jj(-1); jj<=1; jj++) - for(int ii(-1); ii<=1; ii++) - if (flag(i,j,k).isConnected(ii,jj,kk)) - { - int r = i+ii; int s = j+jj; int t = k+kk; - - x_max = amrex::max(x_max, cent_hat(r,s,t,0)+static_cast(ii)); - x_min = amrex::min(x_min, cent_hat(r,s,t,0)+static_cast(ii)); - y_max = amrex::max(y_max, cent_hat(r,s,t,1)+static_cast(jj)); - y_min = amrex::min(y_min, cent_hat(r,s,t,1)+static_cast(jj)); -#if (AMREX_SPACEDIM == 3) - z_max = amrex::max(z_max, cent_hat(r,s,t,2)+static_cast(kk)); - z_min = amrex::min(z_min, cent_hat(r,s,t,2)+static_cast(kk)); -#endif - } - } - // If we need to grow the stencil, we let it be -nx:nx in the x-direction, - // for example. Note that nx,ny,nz are either 1 or 2 - if ( (x_max-x_min) < slope_stencil_min_width ) nx = 2; - if ( (y_max-y_min) < slope_stencil_min_width ) ny = 2; -#if (AMREX_SPACEDIM == 3) - if ( (z_max-z_min) < slope_stencil_min_width ) nz = 2; -#endif - - amrex::GpuArray slopes_eb; - if (nx*ny*nz == 1) - // Compute slope using 3x3x3 stencil - slopes_eb = amrex_calc_slopes_extdir_eb( - i,j,k,n,soln_hat,cent_hat,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - else - { - // Compute slope using grown stencil (no larger than 5x5x5) - slopes_eb = amrex_calc_slopes_extdir_eb_grown( - i,j,k,n,AMREX_D_DECL(nx,ny,nz), - soln_hat,cent_hat,vfrac, - AMREX_D_DECL(fcx,fcy,fcz),flag, - AMREX_D_DECL(extdir_ilo, extdir_jlo, extdir_klo), - AMREX_D_DECL(extdir_ihi, extdir_jhi, extdir_khi), - AMREX_D_DECL(domain_ilo, domain_jlo, domain_klo), - AMREX_D_DECL(domain_ihi, domain_jhi, domain_khi), - max_order); - } - - // We do the limiting separately because this limiter limits the slope based on the values - // extrapolated to the cell centroid (cent_hat) locations - unlike the limiter in amrex - // which bases the limiting on values extrapolated to the face centroids. - amrex::GpuArray lim_slope = - amrex_calc_centroid_limiter(i,j,k,n,soln_hat,flag,slopes_eb,cent_hat); - - AMREX_D_TERM(lim_slope[0] *= slopes_eb[0];, - lim_slope[1] *= slopes_eb[1];, - lim_slope[2] *= slopes_eb[2];); - - // Add to the cell itself - if (bx.contains(IntVect(AMREX_D_DECL(i,j,k)))) - { - Real update = soln_hat(i,j,k,n); - AMREX_D_TERM(update += lim_slope[0] * (ccent(i,j,k,0)-cent_hat(i,j,k,0));, - update += lim_slope[1] * (ccent(i,j,k,1)-cent_hat(i,j,k,1));, - update += lim_slope[2] * (ccent(i,j,k,2)-cent_hat(i,j,k,2));); - amrex::Gpu::Atomic::Add(&U_out(i,j,k,n),alpha(i,j,k,0)*nrs(i,j,k)*update); - } // if bx contains - - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= num_nbors; i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - - if (bx.contains(IntVect(AMREX_D_DECL(r,s,t)))) - { - Real update = soln_hat(i,j,k,n); - AMREX_D_TERM(update += lim_slope[0] * (ccent(r,s,t,0)-cent_hat(i,j,k,0) + static_cast(r-i));, - update += lim_slope[1] * (ccent(r,s,t,1)-cent_hat(i,j,k,1) + static_cast(s-j));, - update += lim_slope[2] * (ccent(r,s,t,2)-cent_hat(i,j,k,2) + static_cast(t-k));); - amrex::Gpu::Atomic::Add(&U_out(r,s,t,n),alpha(i,j,k,1)*update); - } // if bx contains - } // i_nbor - } // n - } // num_nbors - } // vfrac - }); - - amrex::ParallelFor(bx,ncomp, - [=] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!flag(i,j,k).isCovered()) - { - // This seems to help with a compiler issue ... - Real denom = 1. / (nrs(i,j,k) + 1.e-40); - U_out(i,j,k,n) *= denom; - } - else - { - U_out(i,j,k,n) = 1.e40; - } - }); - -#if 0 - // - // This tests whether the redistribution procedure was conservative -- - // only use if bx is the whole domain - // - { - for (int n = 0; n < ncomp; n++) - { - Real sum1(0); - Real sum2(0); -#if (AMREX_SPACEDIM == 2) - int k = 0; -#else - for (int k = bx.smallEnd(2); k <= domain.bigEnd(2); k++) -#endif - for (int j = bx.smallEnd(1); j <= domain.bigEnd(1); j++) - for (int i = bx.smallEnd(0); i <= domain.bigEnd(0); i++) - { - sum1 += vfrac(i,j,k)*U_in(i,j,k,n); - sum2 += vfrac(i,j,k)*U_out(i,j,k,n); - } - if (std::abs(sum1-sum2) > 1.e-8 * sum1 && std::abs(sum1-sum2) > 1.e-8) - { - printf("SUMS DO NOT MATCH IN STATE REDIST : %f %f ",sum1,sum2); - amrex::Abort(); - } - } - } -#endif -} -/** @} */ diff --git a/Diagnostics/Redistribution/hydro_state_utils.cpp b/Diagnostics/Redistribution/hydro_state_utils.cpp deleted file mode 100644 index 8afcc17fc..000000000 --- a/Diagnostics/Redistribution/hydro_state_utils.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/** - * \file hydro_state_utils.cpp - * \addtogroup Redistribution - * @{ - * - */ - -#include - -using namespace amrex; - -void -Redistribution::MakeStateRedistUtils ( Box const& bx, - Array4 const& flag, - Array4 const& vfrac, - Array4 const& ccent, - Array4 const& itracker, - Array4 const& nrs, - Array4 const& alpha, - Array4 const& nbhd_vol, - Array4 const& cent_hat, - Geometry const& lev_geom, - Real target_vol) -{ - // Note that itracker has {4 in 2D, 8 in 3D} components and all are initialized to zero - // We will add to the first component every time this cell is included in a merged neighborhood, - // either by merging or being merged - // - // In 2D, we identify the cells in the remaining three components with the following ordering - // - // ^ 6 7 8 - // | 4 5 - // j 1 2 3 - // i ---> - // - // In 3D, We identify the cells in the remaining three components with the following ordering - // - // at k-1 | at k | at k+1 - // - // ^ 15 16 17 | 6 7 8 | 24 25 26 - // | 12 13 14 | 4 5 | 21 22 23 - // j 9 10 11 | 1 2 3 | 18 19 20 - // i ---> - // - // Note the first component of each of these arrays should never be used - // -#if (AMREX_SPACEDIM == 2) - Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1}; - Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1}; - Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0}; -#else - Array imap{0,-1, 0, 1,-1, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1,-1, 0, 1}; - Array jmap{0,-1,-1,-1, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1,-1,-1,-1, 0, 0, 0, 1, 1, 1}; - Array kmap{0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; -#endif - - AMREX_D_TERM(const auto& is_periodic_x = lev_geom.isPeriodic(0);, - const auto& is_periodic_y = lev_geom.isPeriodic(1);, - const auto& is_periodic_z = lev_geom.isPeriodic(2);); - - Box const& bxg2 = amrex::grow(bx,2); - Box const& bxg3 = amrex::grow(bx,3); - Box const& bxg4 = amrex::grow(bx,4); - - const Box domain = lev_geom.Domain(); - - Box domain_per_grown = domain; - if (is_periodic_x) domain_per_grown.grow(0,2); - if (is_periodic_y) domain_per_grown.grow(1,2); -#if (AMREX_SPACEDIM == 3) - if (is_periodic_z) domain_per_grown.grow(2,2); -#endif - - amrex::ParallelFor(bxg3, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - // Everyone is in their own neighborhood at least - nrs(i,j,k) = 1.; - alpha(i,j,k,0) = 1.; - alpha(i,j,k,1) = 1.; - }); - - // nrs captures how many neighborhoods (r,s) is in - amrex::ParallelFor(bxg4, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - if ( domain_per_grown.contains(IntVect(AMREX_D_DECL(r,s,t))) && - bxg3.contains(IntVect(AMREX_D_DECL(r,s,t))) ) - { - amrex::Gpu::Atomic::Add(&nrs(r,s,t),1.0_rt); - } - } - }); - - amrex::ParallelFor(bxg2, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (!flag(i,j,k).isCovered()) - { - // Start with the vfrac of (i,j,k) - nbhd_vol(i,j,k) = vfrac(i,j,k) / nrs(i,j,k); - Real vol_of_nbors = 0.; - - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - amrex::Gpu::Atomic::Add(&nbhd_vol(i,j,k),vfrac(r,s,t) / nrs(r,s,t)); - vol_of_nbors += vfrac(r,s,t); - } - - if (itracker(i,j,k,0) > 0) - alpha(i,j,k,1) = (target_vol - vfrac(i,j,k)) / vol_of_nbors; - - } else { - nbhd_vol(i,j,k) = 0.; - alpha(i,j,k,0) = 0.; - alpha(i,j,k,1) = 0.; - } - }); - - // Define how much each cell keeps - amrex::ParallelFor(bxg2, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (!flag(i,j,k).isCovered()) - { - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - amrex::Gpu::Atomic::Add(&alpha(r,s,t,0),-(alpha(i,j,k,1)/nrs(r,s,t))); - } - } - }); - - // Redefine nbhd_vol - amrex::ParallelFor(bxg2, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (!flag(i,j,k).isCovered()) - { - nbhd_vol(i,j,k) = alpha(i,j,k,0) * vfrac(i,j,k); - - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int r = i+imap[itracker(i,j,k,i_nbor)]; - int s = j+jmap[itracker(i,j,k,i_nbor)]; - int t = k+kmap[itracker(i,j,k,i_nbor)]; - amrex::Gpu::Atomic::Add(&nbhd_vol(i,j,k),alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t)); - } - } - }); - - // Define xhat,yhat,zhat (from Berger and Guliani) - amrex::ParallelFor(bxg3, - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { - if (vfrac(i,j,k) > 0.0) - { - AMREX_D_TERM(cent_hat(i,j,k,0) = ccent(i,j,k,0);, - cent_hat(i,j,k,1) = ccent(i,j,k,1);, - cent_hat(i,j,k,2) = ccent(i,j,k,2);); - - if ( itracker(i,j,k,0) > 0 && - domain_per_grown.contains(IntVect(AMREX_D_DECL(i,j,k))) && - bxg2.contains(IntVect(AMREX_D_DECL(i,j,k))) ) { - - AMREX_D_TERM(cent_hat(i,j,k,0) = ccent(i,j,k,0) * alpha(i,j,k,0) *vfrac(i,j,k);, - cent_hat(i,j,k,1) = ccent(i,j,k,1) * alpha(i,j,k,0) *vfrac(i,j,k);, - cent_hat(i,j,k,2) = ccent(i,j,k,2) * alpha(i,j,k,0) *vfrac(i,j,k);); - - // This loops over the neighbors of (i,j,k), and doesn't include (i,j,k) itself - for (int i_nbor = 1; i_nbor <= itracker(i,j,k,0); i_nbor++) - { - int ii = imap[itracker(i,j,k,i_nbor)]; int r = i+ii; - int jj = jmap[itracker(i,j,k,i_nbor)]; int s = j+jj; - int kk = kmap[itracker(i,j,k,i_nbor)]; int t = k+kk; - - AMREX_D_TERM(cent_hat(i,j,k,0) += (ccent(r,s,t,0) + ii) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);, - cent_hat(i,j,k,1) += (ccent(r,s,t,1) + jj) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);, - cent_hat(i,j,k,2) += (ccent(r,s,t,2) + kk) * alpha(i,j,k,1) * vfrac(r,s,t) / nrs(r,s,t);); - } - - AMREX_D_TERM(cent_hat(i,j,k,0) /= nbhd_vol(i,j,k);, - cent_hat(i,j,k,1) /= nbhd_vol(i,j,k);, - cent_hat(i,j,k,2) /= nbhd_vol(i,j,k);); - } - } else { - - AMREX_D_TERM(cent_hat(i,j,k,0) = 1.e40;, - cent_hat(i,j,k,1) = 1.e40;, - cent_hat(i,j,k,2) = 1.e40;); - } - }); -} -/** @} */ diff --git a/Diagnostics/hydro_ebgodunov.cpp b/Diagnostics/hydro_ebgodunov.cpp deleted file mode 100644 index 7a66dc8b9..000000000 --- a/Diagnostics/hydro_ebgodunov.cpp +++ /dev/null @@ -1,660 +0,0 @@ -/** - * \file hydro_ebgodunov.cpp - * \addtogroup EBGodunov - * @{ - * - */ - -#include -#include -#include -#include -#include - -using namespace amrex; - - -void -EBGodunov::ComputeAofs ( MultiFab& aofs, const int aofs_comp, const int ncomp, - MultiFab const& state, const int state_comp, - AMREX_D_DECL( MultiFab const& umac, - MultiFab const& vmac, - MultiFab const& wmac), - AMREX_D_DECL( MultiFab& xedge, - MultiFab& yedge, - MultiFab& zedge), - const int edge_comp, - const bool known_edgestate, - AMREX_D_DECL( MultiFab& xfluxes, - MultiFab& yfluxes, - MultiFab& zfluxes), - int fluxes_comp, - MultiFab const& fq, - const int fq_comp, - MultiFab const& divu, - Vector const& h_bc, - BCRec const* d_bc, - Geometry const& geom, - Vector& iconserv, - const Real dt, - const bool is_velocity, - std::string redistribution_type) -{ - BL_PROFILE("EBGodunov::ComputeAofs()"); - - bool fluxes_are_area_weighted = true; - - // Make a device copy of the iconserv vector for use in kernels - Gpu::DeviceVector iconserv_d(iconserv.size()); - Gpu::copy(Gpu::hostToDevice, iconserv.begin(), iconserv.end(), iconserv_d.begin()); - int const* iconserv_ptr = iconserv_d.data(); - - AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); - - auto const& ebfact= dynamic_cast(state.Factory()); - auto const& flags = ebfact.getMultiEBCellFlagFab(); - auto const& fcent = ebfact.getFaceCent(); - auto const& ccent = ebfact.getCentroid(); - auto const& vfrac = ebfact.getVolFrac(); - auto const& areafrac = ebfact.getAreaFrac(); - - // Create temporary holder for advection term. Needed so we can call FillBoundary. - MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfact); - advc.setVal(0.); - - // if we need convective form, we must also compute - // div(u_mac) - MultiFab divu_mac(state.boxArray(),state.DistributionMap(),1,0, MFInfo(), ebfact); - for (Long i = 0; i < iconserv.size(); ++i) - { - if (!iconserv[i]) - { - Array u; - AMREX_D_TERM(u[0] = &umac;, - u[1] = &vmac;, - u[2] = &wmac;); - - if (!ebfact.isAllRegular()) - amrex::EB_computeDivergence(divu_mac,u,geom,true); - else - amrex::computeDivergence(divu_mac,u,geom); - - break; - } - } - - // Compute -div instead of computing div -- this is just for consistency - // with the way we HAVE to do it for EB (because redistribution operates on - // -div rather than div - Real mult = -1.0; - -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - - const Box& bx = mfi.tilebox(); - - auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; - // A regular box uses 3 ghost cells: - // We predict the state on the edge based box; that calls slopes on - // i & i-1; slopes then looks at (i-1)-2 for 4th order slopes - // => test on bx grow 3 - bool regular = (flagfab.getType(amrex::grow(bx,3)) == FabType::regular); - - // Get handlers to Array4 - // - AMREX_D_TERM( const auto& fx = xfluxes.array(mfi,fluxes_comp);, - const auto& fy = yfluxes.array(mfi,fluxes_comp);, - const auto& fz = zfluxes.array(mfi,fluxes_comp);); - - AMREX_D_TERM( const auto& xed = xedge.array(mfi,edge_comp);, - const auto& yed = yedge.array(mfi,edge_comp);, - const auto& zed = zedge.array(mfi,edge_comp);); - - AMREX_D_TERM( const auto& u = umac.const_array(mfi);, - const auto& v = vmac.const_array(mfi);, - const auto& w = wmac.const_array(mfi);); - - Array4 advc_arr = advc.array(mfi); - - if (flagfab.getType(bx) == FabType::covered) - { - AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, - const Box& ybx = mfi.nodaltilebox(1);, - const Box& zbx = mfi.nodaltilebox(2); ); - - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - amrex::ParallelFor( - bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = covered_val;}, - - xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, - - ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); - -#if (AMREX_SPACEDIM==3) - amrex::ParallelFor( - zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); -#endif - } - else - { - if (regular) // Plain Godunov - { - if (not known_edgestate) - { - Godunov::ComputeEdgeState( bx, ncomp, - state.array(mfi,state_comp), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( u, v, w ), - divu.array(mfi), - fq.array(mfi,fq_comp), - geom, dt, d_bc, - iconserv_ptr, - false, - false, - is_velocity ); - } - - HydroUtils::ComputeFluxes( bx, - AMREX_D_DECL( fx, fy, fz ), - AMREX_D_DECL( u, v, w ), - AMREX_D_DECL( xed, yed, zed ), - geom, ncomp, fluxes_are_area_weighted ); - - HydroUtils::ComputeDivergence( bx, advc_arr, - AMREX_D_DECL( fx, fy, fz ), - ncomp, geom, - mult, fluxes_are_area_weighted); - - // Compute the convective form if needed by accounting for extra term - auto const& divu_arr = divu_mac.array(mfi); - amrex::ParallelFor(bx, ncomp, [=] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!iconserv_ptr[n]) - { - Real q = xed(i,j,k,n) + xed(i+1,j,k,n) - + yed(i,j,k,n) + yed(i,j+1,k,n); -#if (AMREX_SPACEDIM == 2) - q *= 0.25; -#else - q += zed(i,j,k,n) + zed(i,j,k+1,n); - q /= 6.0; -#endif - advc_arr(i,j,k,n) += q*divu_arr(i,j,k); - } - }); - - } - else // EB Godunov - { - AMREX_D_TERM(Array4 const& fcx = fcent[0]->const_array(mfi);, - Array4 const& fcy = fcent[1]->const_array(mfi);, - Array4 const& fcz = fcent[2]->const_array(mfi);); - - AMREX_D_TERM(Array4 const& apx = areafrac[0]->const_array(mfi);, - Array4 const& apy = areafrac[1]->const_array(mfi);, - Array4 const& apz = areafrac[2]->const_array(mfi);); - - Array4 const& ccent_arr = ccent.const_array(mfi); - Array4 const& vfrac_arr = vfrac.const_array(mfi); - auto const& flags_arr = flags.const_array(mfi); - - //FIXME - compare to HydroUtils which hard codes 4 ghost cells for all - int ngrow = 4; - - if (redistribution_type=="StateRedist") - ++ngrow; - - FArrayBox tmpfab(amrex::grow(bx,ngrow), (4*AMREX_SPACEDIM + 2)*ncomp); - Elixir eli = tmpfab.elixir(); - - - if (not known_edgestate) - { - EBGodunov::ComputeEdgeState( bx, ncomp, - state.array(mfi,state_comp), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( u, v, w ), - divu.array(mfi), - fq.array(mfi,fq_comp), - geom, dt, h_bc, d_bc, - iconserv_ptr, - tmpfab.dataPtr(), - flags_arr, - AMREX_D_DECL( apx, apy, apz ), - vfrac_arr, - AMREX_D_DECL( fcx, fcy, fcz ), - ccent_arr, - is_velocity, - Array4{} ); - } - - HydroUtils::EB_ComputeFluxes( bx, - AMREX_D_DECL( fx, fy, fz ), - AMREX_D_DECL( u, v, w ), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( apx, apy, apz ), - geom, ncomp, flags_arr, fluxes_are_area_weighted ); - - // div at ncomp*3 to make space for the 3 redistribute temporaries - HydroUtils::EB_ComputeDivergence( bx, - advc_arr, - AMREX_D_DECL( fx, fy, fz ), - vfrac_arr, ncomp, geom, - mult, fluxes_are_area_weighted); - - // Compute the convective form if needed by accounting for extra term - auto const& divu_arr = divu_mac.array(mfi); - amrex::ParallelFor(bx, ncomp, [=] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!iconserv_ptr[n]) - { - if ( vfrac_arr(i,j,k) != 0 ) - { - Real q = xed(i,j,k,n)*apx(i,j,k) + xed(i+1,j,k,n)*apx(i+1,j,k) - + yed(i,j,k,n)*apy(i,j,k) + yed(i,j+1,k,n)*apy(i,j+1,k); -#if (AMREX_SPACEDIM == 2) - q /= (apx(i,j,k)+apx(i+1,j,k)+apy(i,j,k)+apy(i,j+1,k)); -#else - q += zed(i,j,k,n)*apz(i,j,k) + zed(i,j,k+1,n)*apz(i,j,k+1); - q /= (apx(i,j,k)+apx(i+1,j,k)+apy(i,j,k)+apy(i,j+1,k)+apz(i,j,k)+apz(i,j,k+1)); -#endif - advc_arr(i,j,k,n) += q*divu_arr(i,j,k); - } - } - }); - } - } - } - - advc.FillBoundary(geom.periodicity()); - -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - - auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; - auto const& flag = flagfab.const_array(); - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - auto const& advc_arr = advc.array(mfi); - - if (flagfab.getType(bx) != FabType::covered ) - { - // FIXME? not sure if 4 is really needed or if 3 could do - // But this is a safe choice - if (flagfab.getType(grow(bx,4)) != FabType::regular) - { - // - // Redistribute - // - AMREX_D_TERM( auto apx = ebfact.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfact.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfact.getAreaFrac()[2]->const_array(mfi); ); - - AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfact.getFaceCent()[2]->const_array(mfi);); - - Array4 bcc = ebfact.getBndryCent().const_array(mfi); - Array4 ccc = ebfact.getCentroid().const_array(mfi); - Array4 const& vfrac_arr = vfrac.const_array(mfi); - - // This is scratch space if calling StateRedistribute, - // but is used as the weights (here set to 1) if calling - // FluxRedistribute - Box gbx = bx; - - if (redistribution_type == "StateRedist") - gbx.grow(3); - else if (redistribution_type == "FluxRedist") - gbx.grow(2); - - FArrayBox tmpfab(gbx, ncomp); - Elixir eli = tmpfab.elixir(); - Array4 scratch = tmpfab.array(0); - if (redistribution_type == "FluxRedist") - { - amrex::ParallelFor(Box(scratch), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { scratch(i,j,k) = 1.;}); - } - - Redistribution::Apply( bx, ncomp, aofs_arr, advc.array(mfi), - state.const_array(mfi, state_comp), scratch, flag, - AMREX_D_DECL(apx,apy,apz), vfrac_arr, - AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bc, - geom, dt, redistribution_type ); - - // Change sign because we computed -div for all cases - amrex::ParallelFor(bx, ncomp, [aofs_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) *= - 1.0; }); - } - else - { - // Change sign because for EB we computed -div - amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = -advc_arr(i,j,k,n); }); - } - } - } -} - - -void -EBGodunov::ComputeSyncAofs ( MultiFab& aofs, const int aofs_comp, const int ncomp, - MultiFab const& state, const int state_comp, - AMREX_D_DECL( MultiFab const& umac, - MultiFab const& vmac, - MultiFab const& wmac), - AMREX_D_DECL( MultiFab const& ucorr, - MultiFab const& vcorr, - MultiFab const& wcorr), - AMREX_D_DECL( MultiFab& xedge, - MultiFab& yedge, - MultiFab& zedge), - const int edge_comp, - const bool known_edgestate, - AMREX_D_DECL( MultiFab& xfluxes, - MultiFab& yfluxes, - MultiFab& zfluxes), - int fluxes_comp, - MultiFab const& fq, - const int fq_comp, - MultiFab const& divu, - Vector const& h_bc, - BCRec const* d_bc, - Geometry const& geom, - Gpu::DeviceVector& iconserv, - const Real dt, - const bool is_velocity, - std::string redistribution_type ) -{ - BL_PROFILE("EBGodunov::ComputeSyncAofs()"); - - bool fluxes_are_area_weighted = true; - - AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); - - auto const& ebfact= dynamic_cast(state.Factory()); - auto const& flags = ebfact.getMultiEBCellFlagFab(); - auto const& fcent = ebfact.getFaceCent(); - auto const& ccent = ebfact.getCentroid(); - auto const& vfrac = ebfact.getVolFrac(); - auto const& areafrac = ebfact.getAreaFrac(); - - // Create temporary holder for advection term. Needed so we can call FillBoundary. - MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfact); - advc.setVal(0.); - - // Compute -div instead of computing div -- this is just for consistency - // with the way we HAVE to do it for EB (because redistribution operates on - // -div rather than div - Real mult = -1.0; - - -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs,TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - - const Box& bx = mfi.tilebox(); - - auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; - bool regular = (flagfab.getType(amrex::grow(bx,3)) == FabType::regular); - - // - // Get handlers to Array4 - // - AMREX_D_TERM( const auto& fx = xfluxes.array(mfi,fluxes_comp);, - const auto& fy = yfluxes.array(mfi,fluxes_comp);, - const auto& fz = zfluxes.array(mfi,fluxes_comp);); - - AMREX_D_TERM( const auto& xed = xedge.array(mfi,edge_comp);, - const auto& yed = yedge.array(mfi,edge_comp);, - const auto& zed = zedge.array(mfi,edge_comp);); - - AMREX_D_TERM( const auto& uc = ucorr.const_array(mfi);, - const auto& vc = vcorr.const_array(mfi);, - const auto& wc = wcorr.const_array(mfi);); - - Array4 advc_arr = advc.array(mfi); - - if (flagfab.getType(bx) == FabType::covered) - { - AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, - const Box& ybx = mfi.nodaltilebox(1);, - const Box& zbx = mfi.nodaltilebox(2); ); - - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - amrex::ParallelFor( - bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = covered_val;}, - - xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, - - ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); - -#if (AMREX_SPACEDIM==3) - amrex::ParallelFor( - zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); -#endif - } - else - { - if (regular) // Plain Godunov - { - if (not known_edgestate) - { - AMREX_D_TERM( const auto& u = umac.const_array(mfi);, - const auto& v = vmac.const_array(mfi);, - const auto& w = wmac.const_array(mfi);); - - Godunov::ComputeEdgeState( bx, ncomp, - state.array(mfi,state_comp), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( u, v, w ), - divu.array(mfi), - fq.array(mfi,fq_comp), - geom, dt, d_bc, - iconserv.data(), - false, - false, - is_velocity ); - } - - - - HydroUtils::ComputeFluxes( bx, - AMREX_D_DECL( fx, fy, fz ), - AMREX_D_DECL( uc, vc, wc ), - AMREX_D_DECL( xed, yed, zed ), - geom, ncomp, fluxes_are_area_weighted ); - - - HydroUtils::ComputeDivergence( bx, advc_arr, - AMREX_D_DECL( fx, fy, fz ), - ncomp, geom, - mult, fluxes_are_area_weighted); - } - else // EB Godunov - { - AMREX_D_TERM(Array4 const& fcx = fcent[0]->const_array(mfi);, - Array4 const& fcy = fcent[1]->const_array(mfi);, - Array4 const& fcz = fcent[2]->const_array(mfi);); - - AMREX_D_TERM(Array4 const& apx = areafrac[0]->const_array(mfi);, - Array4 const& apy = areafrac[1]->const_array(mfi);, - Array4 const& apz = areafrac[2]->const_array(mfi);); - - Array4 const& ccent_arr = ccent.const_array(mfi); - Array4 const& vfrac_arr = vfrac.const_array(mfi); - auto const& flags_arr = flags.const_array(mfi); - - int ngrow = 4; - FArrayBox tmpfab(amrex::grow(bx,ngrow), (4*AMREX_SPACEDIM + 2)*ncomp); - Elixir eli = tmpfab.elixir(); - - - if (not known_edgestate) - { - AMREX_D_TERM( const auto& u = umac.const_array(mfi);, - const auto& v = vmac.const_array(mfi);, - const auto& w = wmac.const_array(mfi);); - - EBGodunov::ComputeEdgeState( bx, ncomp, - state.array(mfi,state_comp), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( u, v, w ), - divu.array(mfi), - fq.array(mfi,fq_comp), - geom, dt, h_bc, d_bc, - iconserv.data(), - tmpfab.dataPtr(), - flags_arr, - AMREX_D_DECL( apx, apy, apz ), - vfrac_arr, - AMREX_D_DECL( fcx, fcy, fcz ), - ccent_arr, - is_velocity, - Array4{} ); - } - - HydroUtils::EB_ComputeFluxes( bx, - AMREX_D_DECL( fx, fy, fz ), - AMREX_D_DECL( uc, vc, wc ), - AMREX_D_DECL( xed, yed, zed ), - AMREX_D_DECL( apx, apy, apz ), - geom, ncomp, flags_arr, fluxes_are_area_weighted ); - - HydroUtils::EB_ComputeDivergence( bx, - advc_arr, - AMREX_D_DECL( fx, fy, fz ), - vfrac_arr, ncomp, geom, mult, fluxes_are_area_weighted ); - - } - } - } - - advc.FillBoundary(geom.periodicity()); - - MultiFab sstate_tmp; - MultiFab* sstate; - if (redistribution_type == "StateRedist") - { - // Create temporary holder for sync "state" passed in via aofs - // Do this so we're not overwriting the "state" as we go through the redistribution - // process. - sstate_tmp.define(state.boxArray(),state.DistributionMap(),ncomp,state.nGrow(), - MFInfo(),ebfact); - sstate = &sstate_tmp; - MultiFab::Copy(*sstate,aofs,aofs_comp,0,ncomp,state.nGrow()); - } - else - { - // Doesn't matter what we put here, sstate only gets used for StateRedist - sstate = &aofs; - } - -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs, TilingIfNotGPU()); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - - auto const& flagfab = ebfact.getMultiEBCellFlagFab()[mfi]; - auto const& flags_arr = flagfab.const_array(); - - if (flagfab.getType(bx) != FabType::covered ) - { - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - auto const& advc_arr = advc.array(mfi); - - // FIXME? not sure if 4 is really needed or if 3 could do - // But this is a safe choice - if (flagfab.getType(grow(bx,4)) != FabType::regular) - { - // - // Redistribute - // - AMREX_D_TERM( auto apx = ebfact.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfact.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfact.getAreaFrac()[2]->const_array(mfi); ); - - AMREX_D_TERM( Array4 fcx = ebfact.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfact.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfact.getFaceCent()[2]->const_array(mfi);); - - Array4 bcent_arr = ebfact.getBndryCent().const_array(mfi); - Array4 ccent_arr = ebfact.getCentroid().const_array(mfi); - Array4 const& vfrac_arr = vfrac.const_array(mfi); - - // This is scratch space if calling StateRedistribute, - // but is used as the weights (here set to 1) if calling - // FluxRedistribute - Box gbx = bx; - - if (redistribution_type == "StateRedist") - gbx.grow(3); - else if (redistribution_type == "FluxRedist") - gbx.grow(2); - - FArrayBox tmpfab(gbx, ncomp*2); - Elixir eli = tmpfab.elixir(); - Array4 scratch = tmpfab.array(0); - if (redistribution_type == "FluxRedist") - { - amrex::ParallelFor(Box(scratch), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { scratch(i,j,k) = 1.;}); - } - Array4 divtmp_redist_arr = tmpfab.array(ncomp); - - // Redistribute - // - // For StateRedistribution, we use the Sync as the "state". - // This may lead to oversmoothing. - // - Redistribution::Apply( bx, ncomp, divtmp_redist_arr, advc_arr, - sstate->const_array(mfi, 0), scratch, flags_arr, - AMREX_D_DECL(apx,apy,apz), vfrac_arr, - AMREX_D_DECL(fcx,fcy,fcz), bcent_arr, ccent_arr, d_bc, - geom, dt, redistribution_type ); - - // Subtract contribution to sync aofs -- sign of divergence is aofs is opposite - // of sign to div computed by EB_ComputeDivergence, thus it must be subtracted. - amrex::ParallelFor(bx, ncomp, [aofs_arr, divtmp_redist_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) -= divtmp_redist_arr( i, j, k, n ); }); - } - else - { - // Subtract contribution to sync aofs -- sign of divergence is aofs is opposite - // of sign to div computed by EB_ComputeDivergence, thus it must be subtracted. - amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) -= advc_arr( i, j, k, n ); }); - } - } - } -} -/** @} */ diff --git a/Diagnostics/hydro_ebmol.cpp b/Diagnostics/hydro_ebmol.cpp deleted file mode 100644 index afd52111e..000000000 --- a/Diagnostics/hydro_ebmol.cpp +++ /dev/null @@ -1,613 +0,0 @@ -/** - * \file hydro_ebmol.cpp - * \addtogroup EBMOL - * @{ - * - */ - -#include -#include -#include -#include -// #include -#include - -using namespace amrex; - - -void -EBMOL::ComputeAofs ( MultiFab& aofs, int aofs_comp, int ncomp, - MultiFab const& state, int state_comp, - AMREX_D_DECL( MultiFab const& umac, - MultiFab const& vmac, - MultiFab const& wmac), - AMREX_D_DECL( MultiFab& xedge, - MultiFab& yedge, - MultiFab& zedge), - int edge_comp, - bool known_edgestate, - AMREX_D_DECL( MultiFab& xfluxes, - MultiFab& yfluxes, - MultiFab& zfluxes), - int fluxes_comp, - MultiFab const& divu, - Vector const& bcs, - BCRec const* d_bcrec_ptr, - Gpu::DeviceVector& iconserv, - Geometry const& geom, - const Real dt, - const bool is_velocity, - std::string redistribution_type ) -{ - BL_PROFILE("EBMOL::ComputeAofs()"); - - bool fluxes_are_area_weighted = true; - - int const* iconserv_ptr = iconserv.data(); - - AMREX_ALWAYS_ASSERT(aofs.nComp() >= aofs_comp + ncomp); - AMREX_ALWAYS_ASSERT(state.nComp() >= state_comp + ncomp); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xedge.nComp() >= edge_comp + ncomp);, - AMREX_ALWAYS_ASSERT(yedge.nComp() >= edge_comp + ncomp);, - AMREX_ALWAYS_ASSERT(zedge.nComp() >= edge_comp + ncomp);); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nComp() >= fluxes_comp + ncomp);, - AMREX_ALWAYS_ASSERT(yfluxes.nComp() >= fluxes_comp + ncomp);, - AMREX_ALWAYS_ASSERT(zfluxes.nComp() >= fluxes_comp + ncomp);); - AMREX_ALWAYS_ASSERT(aofs.nGrow() == 0); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nGrow() == xedge.nGrow());, - AMREX_ALWAYS_ASSERT(yfluxes.nGrow() == yedge.nGrow());, - AMREX_ALWAYS_ASSERT(zfluxes.nGrow() == zedge.nGrow());); - - // To compute edge states, need at least 2 ghost cells in state - if ( !known_edgestate ) - AMREX_ALWAYS_ASSERT(state.nGrow() >= 2); - - // If !known_edgestate, need 2 additional cells in state to compute - // the slopes needed to compute the edge state, since MOL uses slope - // order==2. - int halo = known_edgestate ? 0 : 2; - - AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); - auto const& ebfactory = dynamic_cast(state.Factory()); - - // Create temporary holder for advection term. Needed so we can call FillBoundary. - MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfactory); - advc.setVal(0.); - - Box const& domain = geom.Domain(); - MFItInfo mfi_info; - - if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - - AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, - const Box& ybx = mfi.nodaltilebox(1);, - const Box& zbx = mfi.nodaltilebox(2); ); - - AMREX_D_TERM( Array4 fx = xfluxes.array(mfi,fluxes_comp);, - Array4 fy = yfluxes.array(mfi,fluxes_comp);, - Array4 fz = zfluxes.array(mfi,fluxes_comp);); - - AMREX_D_TERM( Array4 xed = xedge.array(mfi,edge_comp);, - Array4 yed = yedge.array(mfi,edge_comp);, - Array4 zed = zedge.array(mfi,edge_comp);); - - // Initialize covered cells - auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; - auto const& flag = flagfab.const_array(); - - if (flagfab.getType(bx) == FabType::covered) - { - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - amrex::ParallelFor( - bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = covered_val;}, - - xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, - - ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); - -#if (AMREX_SPACEDIM==3) - amrex::ParallelFor( - zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); -#endif - } - else - { - - AMREX_D_TERM( Array4 u = umac.const_array(mfi);, - Array4 v = vmac.const_array(mfi);, - Array4 w = wmac.const_array(mfi);); - - Array4 advc_arr = advc.array(mfi); - - bool regular = flagfab.getType(amrex::grow(bx,halo)) == FabType::regular; - - if (!regular) - { - AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); - - AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); - - Array4 ccc = ebfactory.getCentroid().const_array(mfi); - auto vfrac = ebfactory.getVolFrac().const_array(mfi); - - // Compute edge state if needed - if (!known_edgestate) - { - Array4 const q = state.const_array(mfi,state_comp); - - EBMOL::ComputeEdgeState( bx, AMREX_D_DECL(xed,yed,zed), - q, ncomp, - AMREX_D_DECL(u,v,w), - domain, bcs, d_bcrec_ptr, - AMREX_D_DECL(fcx,fcy,fcz), - ccc, vfrac, flag, is_velocity ); - } - - // Compute fluxes - HydroUtils::EB_ComputeFluxes(bx, AMREX_D_DECL(fx,fy,fz), - AMREX_D_DECL(u,v,w), - AMREX_D_DECL(xed,yed,zed), - AMREX_D_DECL(apx,apy,apz), - geom, ncomp, flag, fluxes_are_area_weighted ); - - // - // Compute divergence - // - - // Compute -div because that's what redistribution needs - Real mult = -1.0; - HydroUtils::EB_ComputeDivergence(bx, advc_arr, - AMREX_D_DECL(fx,fy,fz), - vfrac, ncomp, geom, - mult, fluxes_are_area_weighted ); - // Account for extra term needed for convective differencing - // Don't forget we're mutliplying by -1.0 here... - auto const& q = state.array(mfi, state_comp); - auto const& divu_arr = divu.array(mfi); - amrex::ParallelFor(bx, ncomp, [=] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!iconserv_ptr[n]) - advc_arr( i, j, k, n ) += q(i,j,k,n)*divu_arr(i,j,k); - - }); - } - else - { - // Compute edge state if needed - if (!known_edgestate) - { - Array4 const q = state.const_array(mfi,state_comp); - MOL::ComputeEdgeState( bx, - AMREX_D_DECL( xed, yed, zed ), - q, ncomp, - AMREX_D_DECL( u, v, w ), - domain, bcs, d_bcrec_ptr, - is_velocity); - } - - // Compute fluxes - HydroUtils::ComputeFluxes( bx, - AMREX_D_DECL(fx,fy,fz), - AMREX_D_DECL(u,v,w), - AMREX_D_DECL(xed,yed,zed), - geom, ncomp, fluxes_are_area_weighted ); - - // Compute divergence - // We use minus sign, i.e. -div, for consistency with EB above - Real mult = -1.0; - HydroUtils::ComputeDivergence(bx, advc_arr, - AMREX_D_DECL(fx,fy,fz), - ncomp, geom, - mult, fluxes_are_area_weighted ); - - // Account for extra term needed for convective differencing - auto const& q = state.array(mfi, state_comp); - auto const& divu_arr = divu.array(mfi); - amrex::ParallelFor(bx, ncomp, [=] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { - if (!iconserv_ptr[n]) - advc_arr( i, j, k, n ) += q(i,j,k,n)*divu_arr(i,j,k); - }); - } - } - } - - advc.FillBoundary(geom.periodicity()); - - if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - - auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; - auto const& flag = flagfab.const_array(); - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - if (flagfab.getType(bx) != FabType::covered ) - { - // FIXME? not sure if 4 is really needed or if 3 could do - // But this is a safe choice - if (flagfab.getType(grow(bx,4)) != FabType::regular) - { - // - // Redistribute - // - AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); - - AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); - - Array4 bcc = ebfactory.getBndryCent().const_array(mfi); - Array4 ccc = ebfactory.getCentroid().const_array(mfi); - auto vfrac = ebfactory.getVolFrac().const_array(mfi); - - // This is scratch space if calling StateRedistribute, - // but is used as the weights (here set to 1) if calling - // FluxRedistribute - Box gbx = bx; - - if (redistribution_type == "StateRedist") - gbx.grow(3); - else if (redistribution_type == "FluxRedist") - gbx.grow(2); - - FArrayBox tmpfab(gbx, ncomp); - Elixir eli = tmpfab.elixir(); - Array4 scratch = tmpfab.array(0); - if (redistribution_type == "FluxRedist") - { - amrex::ParallelFor(Box(scratch), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { scratch(i,j,k) = 1.;}); - } - - Redistribution::Apply( bx, ncomp, aofs_arr, advc.array(mfi), - state.const_array(mfi, state_comp), scratch, flag, - AMREX_D_DECL(apx,apy,apz), vfrac, - AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bcrec_ptr, - geom, dt, redistribution_type ); - - // Change sign because we computed -div for all cases - amrex::ParallelFor(bx, ncomp, [aofs_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) *= - 1.0; }); - } - else - { - // Change sign because we computed -div for all cases - auto const& advc_arr = advc.array(mfi); - amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = - advc_arr(i,j,k,n); }); - } - } - } -} - -void -EBMOL::ComputeSyncAofs ( MultiFab& aofs, int aofs_comp, int ncomp, - MultiFab const& state, int state_comp, - AMREX_D_DECL( MultiFab const& umac, - MultiFab const& vmac, - MultiFab const& wmac), - AMREX_D_DECL( MultiFab const& ucorr, - MultiFab const& vcorr, - MultiFab const& wcorr), - AMREX_D_DECL( MultiFab& xedge, - MultiFab& yedge, - MultiFab& zedge), - int edge_comp, - bool known_edgestate, - AMREX_D_DECL( MultiFab& xfluxes, - MultiFab& yfluxes, - MultiFab& zfluxes), - int fluxes_comp, - Vector const& bcs, - BCRec const* d_bcrec_ptr, - Geometry const& geom, - const Real dt, - const bool is_velocity, - std::string redistribution_type ) -{ - BL_PROFILE("EBMOL::ComputeSyncAofs()"); - - bool fluxes_are_area_weighted = true; - - AMREX_ALWAYS_ASSERT(state.nComp() >= state_comp + ncomp); - AMREX_ALWAYS_ASSERT(aofs.nComp() >= aofs_comp + ncomp); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xedge.nComp() >= edge_comp + ncomp);, - AMREX_ALWAYS_ASSERT(yedge.nComp() >= edge_comp + ncomp);, - AMREX_ALWAYS_ASSERT(zedge.nComp() >= edge_comp + ncomp);); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nComp() >= fluxes_comp + ncomp);, - AMREX_ALWAYS_ASSERT(yfluxes.nComp() >= fluxes_comp + ncomp);, - AMREX_ALWAYS_ASSERT(zfluxes.nComp() >= fluxes_comp + ncomp);); - AMREX_D_TERM( AMREX_ALWAYS_ASSERT(xfluxes.nGrow() == xedge.nGrow());, - AMREX_ALWAYS_ASSERT(yfluxes.nGrow() == yedge.nGrow());, - AMREX_ALWAYS_ASSERT(zfluxes.nGrow() == zedge.nGrow());); - - - // To compute edge states, need at least 2 ghost cells in state - if ( !known_edgestate ) - AMREX_ALWAYS_ASSERT(state.nGrow() >= 2); - - AMREX_ALWAYS_ASSERT(state.hasEBFabFactory()); - auto const& ebfactory = dynamic_cast(state.Factory()); - - // Need 2 grow cells in state to compute the slopes needed to compute the edge state. - int halo = known_edgestate ? 0 : 2; - - // Create temporary holder for advection term. Needed to fill ghost cells. - MultiFab advc(state.boxArray(),state.DistributionMap(),ncomp,3,MFInfo(),ebfactory); - advc.setVal(0.); - - Box const& domain = geom.Domain(); - MFItInfo mfi_info; - - if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - AMREX_D_TERM( const Box& xbx = mfi.nodaltilebox(0);, - const Box& ybx = mfi.nodaltilebox(1);, - const Box& zbx = mfi.nodaltilebox(2); ); - - AMREX_D_TERM( Array4 fx = xfluxes.array(mfi,fluxes_comp);, - Array4 fy = yfluxes.array(mfi,fluxes_comp);, - Array4 fz = zfluxes.array(mfi,fluxes_comp);); - - AMREX_D_TERM( Array4 xed = xedge.array(mfi,edge_comp);, - Array4 yed = yedge.array(mfi,edge_comp);, - Array4 zed = zedge.array(mfi,edge_comp);); - - // Initialize covered cells - auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; - auto const& flag = flagfab.const_array(); - - if (flagfab.getType(bx) == FabType::covered) - { - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - amrex::ParallelFor( - bx, ncomp, [aofs_arr] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) = covered_val;}, - - xbx, ncomp, [fx,xed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fx( i, j, k, n ) = 0.0; xed( i, j, k, n ) = covered_val;}, - - ybx, ncomp, [fy,yed] AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fy( i, j, k, n ) = 0.0; yed( i, j, k, n ) = covered_val;}); - -#if (AMREX_SPACEDIM==3) - amrex::ParallelFor( - zbx, ncomp, [fz,zed]AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { fz( i, j, k, n ) = 0.0; zed( i, j, k, n ) = covered_val;}); -#endif - } - else - { - AMREX_D_TERM( Array4 uc = ucorr.const_array(mfi);, - Array4 vc = vcorr.const_array(mfi);, - Array4 wc = wcorr.const_array(mfi);); - - Array4 advc_arr = advc.array(mfi); - - bool regular = flagfab.getType(amrex::grow(bx,halo)) == FabType::regular; - - if (!regular) - { - AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); - - Array4 ccc = ebfactory.getCentroid().const_array(mfi); - - auto vfrac = ebfactory.getVolFrac().const_array(mfi); - - AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); - - // Compute edge state if needed - if (!known_edgestate) - { - Array4 const q = state.const_array(mfi,state_comp); - - AMREX_D_TERM( Array4 u = umac.const_array(mfi);, - Array4 v = vmac.const_array(mfi);, - Array4 w = wmac.const_array(mfi);); - - EBMOL::ComputeEdgeState( bx, - AMREX_D_DECL(xed,yed,zed), - q, ncomp, - AMREX_D_DECL(u,v,w), - domain, bcs, d_bcrec_ptr, - AMREX_D_DECL(fcx,fcy,fcz), - ccc, vfrac, flag, - is_velocity ); - } - - // Compute fluxes - HydroUtils::EB_ComputeFluxes(bx, - AMREX_D_DECL(fx,fy,fz), - AMREX_D_DECL(uc,vc,wc), - AMREX_D_DECL(xed,yed,zed), - AMREX_D_DECL(apx,apy,apz), - geom, ncomp, flag, fluxes_are_area_weighted ); - - // Compute divergence - // Compute -div because that's what redistribution needs - Real mult = -1.0; - HydroUtils::EB_ComputeDivergence(bx, advc_arr, - AMREX_D_DECL(fx,fy,fz), vfrac, - ncomp, geom, mult, fluxes_are_area_weighted ); - } - else - { - // Compute edge state if needed - if (!known_edgestate) - { - Array4 const q = state.const_array(mfi,state_comp); - - AMREX_D_TERM( Array4 u = umac.const_array(mfi);, - Array4 v = vmac.const_array(mfi);, - Array4 w = wmac.const_array(mfi);); - - MOL::ComputeEdgeState( bx, - AMREX_D_DECL( xed, yed, zed ), - q, ncomp, - AMREX_D_DECL( u, v, w ), - domain, bcs, d_bcrec_ptr, - is_velocity); - - } - - // Compute fluxes - HydroUtils::ComputeFluxes(bx, - AMREX_D_DECL(fx,fy,fz), - AMREX_D_DECL(uc,vc,wc), - AMREX_D_DECL(xed,yed,zed), - geom, ncomp, fluxes_are_area_weighted ); - - // Compute divergence - // We use minus sign, i.e. -div, for consistency with EB above - Real mult = -1.0; - HydroUtils::ComputeDivergence(bx, advc_arr, - AMREX_D_DECL(fx,fy,fz), - ncomp, geom, - mult, fluxes_are_area_weighted ); - } - } - } - - advc.FillBoundary(geom.periodicity()); - - MultiFab sstate_tmp; - MultiFab* sstate; - if (redistribution_type == "StateRedist") - { - // Create temporary holder for sync "state" passed in via aofs - // Do this so we're not overwriting the "state" as we go through the redistribution - // process. - sstate_tmp.define(state.boxArray(),state.DistributionMap(),ncomp,state.nGrow(), - MFInfo(),ebfactory); - sstate = &sstate_tmp; - MultiFab::Copy(*sstate,aofs,aofs_comp,0,ncomp,state.nGrow()); - } - else - { - // Doesn't matter what we put here, sstate only gets used for StateRedist - sstate = &aofs; - } - - if (Gpu::notInLaunchRegion()) mfi_info.EnableTiling().SetDynamic(true); -#ifdef _OPENMP -#pragma omp parallel if (Gpu::notInLaunchRegion()) -#endif - for (MFIter mfi(aofs,mfi_info); mfi.isValid(); ++mfi) - { - auto const& bx = mfi.tilebox(); - - auto const& flagfab = ebfactory.getMultiEBCellFlagFab()[mfi]; - auto const& flag = flagfab.const_array(); - - if (flagfab.getType(bx) != FabType::covered) - { - // FIXME? not sure if 4 is really needed or if 3 could do - // But this is a safe choice - if (flagfab.getType(grow(bx,4)) != FabType::regular) - { - // - // Redistribute - // - AMREX_D_TERM( auto apx = ebfactory.getAreaFrac()[0]->const_array(mfi);, - auto apy = ebfactory.getAreaFrac()[1]->const_array(mfi);, - auto apz = ebfactory.getAreaFrac()[2]->const_array(mfi); ); - - AMREX_D_TERM( Array4 fcx = ebfactory.getFaceCent()[0]->const_array(mfi);, - Array4 fcy = ebfactory.getFaceCent()[1]->const_array(mfi);, - Array4 fcz = ebfactory.getFaceCent()[2]->const_array(mfi);); - - Array4 bcc = ebfactory.getBndryCent().const_array(mfi); - Array4 ccc = ebfactory.getCentroid().const_array(mfi); - auto vfrac = ebfactory.getVolFrac().const_array(mfi); - - // This is scratch space if calling StateRedistribute, - // but is used as the weights (here set to 1) if calling - // FluxRedistribute - Box gbx = bx; - - if (redistribution_type == "StateRedist") - gbx.grow(3); - else if (redistribution_type == "FluxRedist") - gbx.grow(2); - FArrayBox tmpfab(gbx, ncomp*2); - Elixir eli = tmpfab.elixir(); - Array4 scratch = tmpfab.array(0); - if (redistribution_type == "FluxRedist") - { - amrex::ParallelFor(Box(scratch), - [=] AMREX_GPU_DEVICE (int i, int j, int k) noexcept - { scratch(i,j,k) = 1.;}); - } - Array4 divtmp_redist_arr = tmpfab.array(ncomp); - - // Redistribute - // - // For StateRedistribution, we use the Sync as the "state". - // This may lead to oversmoothing. - // - Redistribution::Apply( bx, ncomp, divtmp_redist_arr, advc.array(mfi), - sstate->const_array(mfi, 0), scratch, flag, - AMREX_D_DECL(apx,apy,apz), vfrac, - AMREX_D_DECL(fcx,fcy,fcz), bcc, ccc, d_bcrec_ptr, - geom, dt, redistribution_type ); - - // Subtract contribution to sync aofs -- sign of divergence in aofs is opposite - // of sign of div as computed by EB_ComputeDivergence, thus it must be subtracted. - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - - amrex::ParallelFor(bx, ncomp, [aofs_arr, divtmp_redist_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) -= divtmp_redist_arr( i, j, k, n ); }); - } - else - { - // Subtract contribution to sync aofs -- sign of divergence in aofs is opposite - // of sign of div as computed here, and thus it must be subtracted. - auto const& aofs_arr = aofs.array(mfi, aofs_comp); - Array4 advc_arr = advc.array(mfi); - - amrex::ParallelFor(bx, ncomp, [aofs_arr, advc_arr] - AMREX_GPU_DEVICE (int i, int j, int k, int n) noexcept - { aofs_arr( i, j, k, n ) -= advc_arr( i, j, k, n ); }); - } - } - } -} -/** @} */ From 8f6ce63333af729fe2acec0272ac6bc8df93a667 Mon Sep 17 00:00:00 2001 From: Ann Almgren Date: Mon, 18 May 2026 09:36:08 -0700 Subject: [PATCH 04/18] more precision changes --- BDS/hydro_bds_edge_state_3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BDS/hydro_bds_edge_state_3D.cpp b/BDS/hydro_bds_edge_state_3D.cpp index 6dc2efe2b..5baedcc1a 100644 --- a/BDS/hydro_bds_edge_state_3D.cpp +++ b/BDS/hydro_bds_edge_state_3D.cpp @@ -988,7 +988,7 @@ BDS::ComputeConc (Box const& bx, } for(int ll=1; ll<=3; ++ll ){ - del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/Real(4) + del(ll) = (p1(ll)+p2(ll)+p3(ll)+p4(ll))/Real(4); } val1 = eval(s(i+ioff,j+joff,k+koff,icomp),slope_tmp,del); From f4e0f774e784d75347d850b96467284c5a5c0f5b Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Mon, 18 May 2026 10:59:36 -0700 Subject: [PATCH 05/18] Update docs build --- .github/workflows/docs.yml | 39 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8c2b03f78..38fd84d7e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: persist-credentials: false @@ -19,9 +19,8 @@ jobs: .github/workflows/dependencies/documentation.sh echo "Installing python packages for docs..." - pip install breathe sphinx sphinx_rtd_theme sphinxcontrib.bibtex - pip install docutils - pip install sphinx-toolbox + python3 -m pip install --upgrade pip + python3 -m pip install sphinx==5.0.0 sphinx_rtd_theme - name: Build Doxygen Docs run: | @@ -38,25 +37,25 @@ jobs: - name: Deploy if: github.event_name == 'push' && github.repository == 'AMReX-Fluids/AMReX-Hydro' && github.ref == 'refs/heads/development' - uses: JamesIves/github-pages-deploy-action@3.7.1 + uses: JamesIves/github-pages-deploy-action@v4.8.0 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ACCESS_TOKEN: ${{ secrets.DEPLOY_DOCS_HYDRO }} - REPOSITORY_NAME: AMReX-Fluids/AMReX-Fluids.github.io - BRANCH: main # The branch the action should deploy to. - FOLDER: Docs/build/html # The folder the action should deploy. - TARGET_FOLDER: amrex-hydro/docs_html # The folder the action should deploy to. - CLEAN: false # Do not remove existing files from the deploy target. + github-token: ${{ secrets.GITHUB_TOKEN }} + access-token: ${{ secrets.DEPLOY_DOCS_HYDRO }} + repository-name: AMReX-Fluids/AMReX-Fluids.github.io + branch: main # The branch the action should deploy to. + folder: Docs/build/html # The folder the action should deploy. + target-folder: amrex-hydro/docs_html # The folder the action should deploy to. + clean: false # Do not remove existing files from the deploy target. - name: Deploy Doxygen if: github.event_name == 'push' && github.repository == 'AMReX-Fluids/AMReX-Hydro' && github.ref == 'refs/heads/development' - uses: JamesIves/github-pages-deploy-action@3.7.1 + uses: JamesIves/github-pages-deploy-action@v4.8.0 with: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ACCESS_TOKEN: ${{ secrets.DEPLOY_DOCS_HYDRO }} - REPOSITORY_NAME: AMReX-Fluids/AMReX-Fluids.github.io - BRANCH: main # The branch the action should deploy to. - FOLDER: Docs/Doxygen/html # The folder the action should deploy. - TARGET_FOLDER: amrex-hydro/Doxygen/html # The folder the action should deploy to. - CLEAN: false # Do not remove existing files from the deploy target. + github-token: ${{ secrets.GITHUB_TOKEN }} + access-token: ${{ secrets.DEPLOY_DOCS_HYDRO }} + repository-name: AMReX-Fluids/AMReX-Fluids.github.io + branch: main # The branch the action should deploy to. + folder: Docs/Doxygen/html # The folder the action should deploy. + target-folder: amrex-hydro/Doxygen/html # The folder the action should deploy to. + clean: false # Do not remove existing files from the deploy target. From edf1b220cc6858ee5acb01b351514eaa5482a891 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Mon, 18 May 2026 11:13:06 -0700 Subject: [PATCH 06/18] Remove breathe --- Docs/source/conf.py | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Docs/source/conf.py b/Docs/source/conf.py index af60791f6..0d9fc90c5 100644 --- a/Docs/source/conf.py +++ b/Docs/source/conf.py @@ -16,15 +16,6 @@ # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. -### Added to get Breathe working in Git workflow -import os -import sys -import breathe - -sys.path.insert(0, os.path.abspath('../../')) -sys.path.append(os.path.dirname(breathe.__file__)) -### end Breathe - # sys.path.insert(0, os.path.abspath('.')) import sphinx_rtd_theme @@ -49,8 +40,7 @@ def get_amrex_hydro_version(): 'sphinx.ext.viewcode', 'sphinx.ext.intersphinx', 'sphinx.ext.autosectionlabel', - 'sphinx_toolbox.collapse', - 'breathe'] + 'sphinx_toolbox.collapse'] # Allow for same subheading in multiple sections autosectionlabel_prefix_document = True @@ -212,11 +202,3 @@ def get_amrex_hydro_version(): author, 'AMReX-Hydro team', 'One line description of project.', 'Miscellaneous'), ] - - -# -- Breathe for Doxygen Conversion ------------------------------------------- -# see https://github.com/michaeljones/breathe - -breathe_projects = { "amrex-hydro": "../Doxygen/xml/"} - -breathe_default_project = "amrex-hydro" From 532af0239f9f1f18f142905c2d979b081a605b31 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Mon, 18 May 2026 11:21:44 -0700 Subject: [PATCH 07/18] Fix pip install --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 38fd84d7e..1848f35a1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -20,7 +20,7 @@ jobs: echo "Installing python packages for docs..." python3 -m pip install --upgrade pip - python3 -m pip install sphinx==5.0.0 sphinx_rtd_theme + python3 -m pip install sphinx==5.0.0 sphinx_rtd_theme sphinxcontrib.bibtex docutils sphinx-toolbox - name: Build Doxygen Docs run: | From 2a0558f335510a14655244649f709077b7e04590 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 09:41:32 -0700 Subject: [PATCH 08/18] Update CIs --- .github/workflows/cuda.yml | 8 ++++---- .github/workflows/gcc.yml | 8 ++++---- .github/workflows/hip.yml | 4 ++-- .github/workflows/sycl.yml | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/cuda.yml b/.github/workflows/cuda.yml index 6b5c0b2c2..320566c01 100644 --- a/.github/workflows/cuda.yml +++ b/.github/workflows/cuda.yml @@ -18,11 +18,11 @@ jobs: env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wlogical-op -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex @@ -92,11 +92,11 @@ jobs: env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wlogical-op -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 9a8b6d49f..625f945fa 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -18,11 +18,11 @@ jobs: env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wnon-virtual-dtor -Wlogical-op -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wmissing-include-dirs"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex @@ -88,11 +88,11 @@ jobs: env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wnon-virtual-dtor -Wlogical-op -Wmisleading-indentation -Wduplicated-cond -Wduplicated-branches -Wmissing-include-dirs"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex diff --git a/.github/workflows/hip.yml b/.github/workflows/hip.yml index 52c46323b..4a872ed57 100644 --- a/.github/workflows/hip.yml +++ b/.github/workflows/hip.yml @@ -22,11 +22,11 @@ jobs: env: {CXXFLAGS: "-Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-deprecated-declarations -Wno-gnu-zero-variadic-macro-arguments"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex diff --git a/.github/workflows/sycl.yml b/.github/workflows/sycl.yml index 57456e3a1..375c037f4 100644 --- a/.github/workflows/sycl.yml +++ b/.github/workflows/sycl.yml @@ -18,11 +18,11 @@ jobs: env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor -Wno-sign-compare -Wno-missing-braces -Wno-unused-variable -Wno-shadow"} steps: - name: Checkout AMReX-Hydro - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: path: AMReX-Hydro - name: Checkout AMReX - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: repository: AMReX-Codes/amrex path: amrex From fa6a6677cbf494f9146aea93f05794a1c044a92d Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 09:42:08 -0700 Subject: [PATCH 09/18] Add dependabot --- .github/dependabot.yml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..60a11755c --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,9 @@ +# Dependabot configuration +# ref: https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + target-branch: "development" From 1febfce038374dfed6fee8225e061d3b6f71e4dc Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 10:08:24 -0700 Subject: [PATCH 10/18] Update clang-tidy --- .clang-tidy | 11 +++++++++++ .github/workflows/gcc.yml | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 84742de4e..109e2f5ec 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -44,3 +44,14 @@ Checks: > # Files not ending with nolint.H will be filtered in. HeaderFilterRegex: '([^n].....|[^o]....|[^l]...|[^i]..|[^n].|[^t])\.H$' + +HeaderFileExtensions: ['', "H", 'h', 'hh', 'hpp', 'hxx'] + +# We will try to modernize this in the future +# -modernize-use-constraints +# -modernize-use-designated-initializers +# -modernize-use-std-numbers +# -modernize-use-ranges +# -modernize-use-integer-sign-comparison +# -modernize-use-starts-ends-with +# -readability-container-contains diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 625f945fa..e60ebd4b9 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -36,7 +36,7 @@ jobs: - name: Load Dependencies run: | AMReX-Hydro/.github/workflows/dependencies/dependencies.sh - amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 14 + amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 21 amrex/.github/workflows/dependencies/dependencies_ccache.sh - name: Build & Install run: | @@ -106,7 +106,7 @@ jobs: - name: Load Dependencies run: | AMReX-Hydro/.github/workflows/dependencies/dependencies.sh - amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 14 + amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 21 amrex/.github/workflows/dependencies/dependencies_ccache.sh - name: Build & Install run: | From 76d9c5bf571fa4aae84e811b4fbb55dfe750f671 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 10:13:04 -0700 Subject: [PATCH 11/18] Fix the script name --- .github/workflows/gcc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index e60ebd4b9..5f27a8cb0 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -36,7 +36,7 @@ jobs: - name: Load Dependencies run: | AMReX-Hydro/.github/workflows/dependencies/dependencies.sh - amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 21 + amrex/.github/workflows/dependencies/dependencies_clang-tidy-apt-llvm.sh 21 amrex/.github/workflows/dependencies/dependencies_ccache.sh - name: Build & Install run: | @@ -106,7 +106,7 @@ jobs: - name: Load Dependencies run: | AMReX-Hydro/.github/workflows/dependencies/dependencies.sh - amrex/.github/workflows/dependencies/dependencies_clang-tidy.sh 21 + amrex/.github/workflows/dependencies/dependencies_clang-tidy-apt-llvm.sh 21 amrex/.github/workflows/dependencies/dependencies_ccache.sh - name: Build & Install run: | From c858cd2bcf74f6b2229fb3bf9ae7c5393a9381d1 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 10:20:13 -0700 Subject: [PATCH 12/18] Fix name --- .github/workflows/gcc.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gcc.yml b/.github/workflows/gcc.yml index 5f27a8cb0..372f29730 100644 --- a/.github/workflows/gcc.yml +++ b/.github/workflows/gcc.yml @@ -76,7 +76,7 @@ jobs: ${{github.workspace}}/amrex/Tools/C_scripts/mmclt.py --input ${{github.workspace}}/ccache.log.txt --identifier Godunov make -j2 -f clang-tidy-ccache-misses.mak \ - CLANG_TIDY=clang-tidy-14 \ + CLANG_TIDY=clang-tidy-21 \ CLANG_TIDY_ARGS="--config-file=${{github.workspace}}/AMReX-Hydro/.clang-tidy --warnings-as-errors=*" ccache -s @@ -148,7 +148,7 @@ jobs: ${{github.workspace}}/amrex/Tools/C_scripts/mmclt.py --input ${{github.workspace}}/ccache.log.txt --identifier Godunov make -j2 -f clang-tidy-ccache-misses.mak \ - CLANG_TIDY=clang-tidy-14 \ + CLANG_TIDY=clang-tidy-21 \ CLANG_TIDY_ARGS="--config-file=${{github.workspace}}/AMReX-Hydro/.clang-tidy --warnings-as-errors=*" ccache -s From f5dc0793073ce7c7e66a24a947edc065cea57232 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 11:09:57 -0700 Subject: [PATCH 13/18] clang-tidy rules --- .clang-tidy | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 109e2f5ec..e8de2a9a5 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -2,34 +2,58 @@ Checks: > '-*, bugprone-*, -bugprone-branch-clone, + -bugprone-casting-through-void, -bugprone-easily-swappable-parameters, -bugprone-exception-escape, -bugprone-implicit-widening-of-multiplication-result, + -bugprone-multi-level-implicit-pointer-conversion, clang-analyzer-*, -clang-analyzer-optin.mpi.MPI-Checker, clang-diagnostic-*, + -clang-diagnostic-deprecated-declarations, cppcoreguidelines-*, -cppcoreguidelines-avoid-c-arrays, - -cppcoreguidelines-avoid-goto, + -cppcoreguidelines-avoid-do-while, -cppcoreguidelines-avoid-magic-numbers, -cppcoreguidelines-avoid-non-const-global-variables, -cppcoreguidelines-init-variables, -cppcoreguidelines-interfaces-global-init, + -cppcoreguidelines-macro-to-enum, -cppcoreguidelines-macro-usage, -cppcoreguidelines-no-malloc, -cppcoreguidelines-non-private-member-variables-in-classes, -cppcoreguidelines-owning-memory, -cppcoreguidelines-pro-*, + -cppcoreguidelines-use-enum-class, + google-build-explicit-make-pair, + google-build-namespaces, + google-global-names-in-headers, + misc-*, + -misc-const-correctness, + -misc-include-cleaner, + -misc-non-private-member-variables-in-classes, + -misc-no-recursion, + -misc-use-internal-linkage, modernize-*, -modernize-avoid-c-arrays, -modernize-macro-to-enum, -modernize-return-braced-init-list, + -modernize-use-constraints, + -modernize-use-designated-initializers, + -modernize-use-integer-sign-comparison, + -modernize-use-ranges, + -modernize-use-starts-ends-with, + -modernize-use-std-numbers, -modernize-use-trailing-return-type, - -modernize-use-using, performance-*, + -performance-enum-size, + portability-*, + -portability-avoid-pragma-once, + -portability-template-virtual-member-function, readability-*, - -readability-braces-around-statements, - -readability-container-data-pointer, + -readability-avoid-nested-conditional-operator, + -readability-avoid-unconditional-preprocessor-if, + -readability-container-contains, -readability-else-after-return, -readability-function-cognitive-complexity, -readability-function-size, @@ -37,8 +61,14 @@ Checks: > -readability-implicit-bool-conversion, -readability-isolate-declaration, -readability-magic-numbers, + -readability-math-missing-parentheses, -readability-named-parameter, + -readability-redundant-casting, + -readability-redundant-member-init, + -readability-static-accessed-through-instance, -readability-simplify-boolean-expr, + -readability-use-concise-preprocessor-directives, + -readability-use-std-min-max, mpi-* ' From 929826dd7914eb16ea0ed54d25dbe769a1152c67 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 12:37:43 -0700 Subject: [PATCH 14/18] Tweak clang-tidy rules --- .clang-tidy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index e8de2a9a5..8779b7d99 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -53,6 +53,7 @@ Checks: > readability-*, -readability-avoid-nested-conditional-operator, -readability-avoid-unconditional-preprocessor-if, + -readability-braces-around-statements, -readability-container-contains, -readability-else-after-return, -readability-function-cognitive-complexity, @@ -85,3 +86,4 @@ HeaderFileExtensions: ['', "H", 'h', 'hh', 'hpp', 'hxx'] # -modernize-use-integer-sign-comparison # -modernize-use-starts-ends-with # -readability-container-contains +# -readability-braces-around-statements From 4523f1192669f68fcf4502271b3224bc66c5ba1a Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 12:48:45 -0700 Subject: [PATCH 15/18] remove using namespace amrex::literals --- MOL/hydro_mol_edge_state_K.H | 2 -- 1 file changed, 2 deletions(-) diff --git a/MOL/hydro_mol_edge_state_K.H b/MOL/hydro_mol_edge_state_K.H index 8cee25a03..73f6bfa59 100644 --- a/MOL/hydro_mol_edge_state_K.H +++ b/MOL/hydro_mol_edge_state_K.H @@ -8,8 +8,6 @@ #include #include -using namespace amrex::literals; - namespace MOL { AMREX_GPU_DEVICE AMREX_FORCE_INLINE From 88c3e88d411a2c8a92be79ff57de2d28502627c8 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 13:14:43 -0700 Subject: [PATCH 16/18] endl -> \n --- Projections/hydro_NodalProjector.cpp | 12 +++++----- .../FOR_PAPER/hydro_redistribution.cpp | 2 +- Tests/MAC_Projection_EB/main.cpp | 22 +++++++++---------- Tests/Nodal_Projection_EB/main.cpp | 22 +++++++++---------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/Projections/hydro_NodalProjector.cpp b/Projections/hydro_NodalProjector.cpp index 49bfbcd86..d62417028 100644 --- a/Projections/hydro_NodalProjector.cpp +++ b/Projections/hydro_NodalProjector.cpp @@ -268,7 +268,7 @@ NodalProjector::project ( Real a_rtol, Real a_atol ) AMREX_ALWAYS_ASSERT(!m_need_bcs); if (m_verbose > 0) - amrex::Print() << "Nodal Projection:" << std::endl; + amrex::Print() << "Nodal Projection:" << '\n'; // // Average fine grid velocity values down to the coarse grid @@ -295,9 +295,9 @@ NodalProjector::project ( Real a_rtol, Real a_atol ) // Print diagnostics if (m_verbose > 0) { - amrex::Print() << " >> Before projection:" << std::endl; + amrex::Print() << " >> Before projection:" << '\n'; printInfo(); - amrex::Print() << std::endl; + amrex::Print() << '\n'; } // Solve @@ -343,9 +343,9 @@ NodalProjector::project ( Real a_rtol, Real a_atol ) if ( (m_verbose > 0) && (!m_has_rhs)) { computeRHS( GetVecOfPtrs(m_rhs), m_vel, m_S_cc, m_S_nd ); - amrex::Print() << " >> After projection:" << std::endl; + amrex::Print() << " >> After projection:" << '\n'; printInfo(); - amrex::Print() << std::endl; + amrex::Print() << '\n'; } } @@ -447,7 +447,7 @@ NodalProjector::printInfo () amrex::Print() << " * On lev " << lev << " max(abs(rhs)) = " << m_rhs[lev].norm0(0,0,false,true) - << std::endl; + << '\n'; } } diff --git a/Redistribution/FOR_PAPER/hydro_redistribution.cpp b/Redistribution/FOR_PAPER/hydro_redistribution.cpp index 1a3873eaf..81beda750 100644 --- a/Redistribution/FOR_PAPER/hydro_redistribution.cpp +++ b/Redistribution/FOR_PAPER/hydro_redistribution.cpp @@ -400,7 +400,7 @@ Redistribution::Make1DProfile ( Box const& bx, int ncomp, for (int i = 0; i < 64; i++) { - amrex::Print() << xloc[i] << " " << prof_ptr[i] << std::endl; + amrex::Print() << xloc[i] << " " << prof_ptr[i] << '\n'; } } diff --git a/Tests/MAC_Projection_EB/main.cpp b/Tests/MAC_Projection_EB/main.cpp index 4990cae06..c41054887 100644 --- a/Tests/MAC_Projection_EB/main.cpp +++ b/Tests/MAC_Projection_EB/main.cpp @@ -19,7 +19,7 @@ void write_plotfile(const Geometry& geom, const MultiFab& plotmf, int regtest) sstream << "plt00000"; std::string plotfile_name = sstream.str(); - amrex::Print() << "Writing " << plotfile_name << std::endl; + amrex::Print() << "Writing " << plotfile_name << '\n'; #if (AMREX_SPACEDIM == 2) EB_WriteSingleLevelPlotfile(plotfile_name, plotmf, @@ -235,12 +235,12 @@ int main (int argc, char* argv[]) macproj.getMLMG().setBottomVerbose(bottom_verbose); - amrex::Print() << " \n********************************************************************" << std::endl; - amrex::Print() << " Let's project the initial velocity to find " << std::endl; - amrex::Print() << " the flow field around the obstacles ... " << std::endl; - amrex::Print() << " The domain has " << n_cell_x << " cells in the x-direction " << std::endl; - amrex::Print() << " The maximum grid size is " << max_grid_size << std::endl; - amrex::Print() << "******************************************************************** \n" << std::endl; + amrex::Print() << " \n********************************************************************" << '\n'; + amrex::Print() << " Let's project the initial velocity to find " << '\n'; + amrex::Print() << " the flow field around the obstacles ... " << '\n'; + amrex::Print() << " The domain has " << n_cell_x << " cells in the x-direction " << '\n'; + amrex::Print() << " The maximum grid size is " << max_grid_size << '\n'; + amrex::Print() << "******************************************************************** \n" << '\n'; // Solve for phi and subtract from the velocity to make it divergence-free // Note that the normal velocities are at face centers (not centroids) @@ -254,9 +254,9 @@ int main (int argc, char* argv[]) // phi_inout.setVal(0.); // macproj.project_center_vels({&phi_inout},reltol,abstol,MLMG::Location::FaceCenter); - amrex::Print() << " \n********************************************************************" << std::endl; - amrex::Print() << " Done!" << std::endl; - amrex::Print() << "******************************************************************** \n" << std::endl; + amrex::Print() << " \n********************************************************************" << '\n'; + amrex::Print() << " Done!" << '\n'; + amrex::Print() << "******************************************************************** \n" << '\n'; for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) { vel[idim].FillBoundary(geom.periodicity()); @@ -272,7 +272,7 @@ int main (int argc, char* argv[]) } auto stop_time = amrex::second() - strt_time; - amrex::Print() << "Total run time " << stop_time << std::endl; + amrex::Print() << "Total run time " << stop_time << '\n'; amrex::Finalize(); } diff --git a/Tests/Nodal_Projection_EB/main.cpp b/Tests/Nodal_Projection_EB/main.cpp index 95673682d..b4f6403e7 100644 --- a/Tests/Nodal_Projection_EB/main.cpp +++ b/Tests/Nodal_Projection_EB/main.cpp @@ -16,7 +16,7 @@ void write_plotfile(const Geometry& geom, const MultiFab& plotmf) { std::string plotfile_name("plt00000"); - amrex::Print() << "Writing " << plotfile_name << std::endl; + amrex::Print() << "Writing " << plotfile_name << '\n'; #if (AMREX_SPACEDIM == 2) EB_WriteSingleLevelPlotfile(plotfile_name, plotmf, @@ -204,12 +204,12 @@ int main (int argc, char* argv[]) LinOpBCType::Periodic)}); - amrex::Print() << " \n********************************************************************" << std::endl; - amrex::Print() << " Let's project the initial velocity to find " << std::endl; - amrex::Print() << " the flow field around the obstacles ... " << std::endl; - amrex::Print() << " The domain has " << n_cell_x << " cells in the x-direction " << std::endl; - amrex::Print() << " The maximum grid size is " << max_grid_size << std::endl; - amrex::Print() << "******************************************************************** \n" << std::endl; + amrex::Print() << " \n********************************************************************" << '\n'; + amrex::Print() << " Let's project the initial velocity to find " << '\n'; + amrex::Print() << " the flow field around the obstacles ... " << '\n'; + amrex::Print() << " The domain has " << n_cell_x << " cells in the x-direction " << '\n'; + amrex::Print() << " The maximum grid size is " << max_grid_size << '\n'; + amrex::Print() << "******************************************************************** \n" << '\n'; // // Solve div( sigma * grad(phi) ) = RHS @@ -223,9 +223,9 @@ int main (int argc, char* argv[]) // phi.setVal(0.0); // Must initialize phi; we simply set to 0 for this example. // nodal_proj.project( {&phi}, reltol, abstol); - amrex::Print() << " \n********************************************************************" << std::endl; - amrex::Print() << " Projection complete " << std::endl; - amrex::Print() << "******************************************************************** \n" << std::endl; + amrex::Print() << " \n********************************************************************" << '\n'; + amrex::Print() << " Projection complete " << '\n'; + amrex::Print() << "******************************************************************** \n" << '\n'; // Store plotfile variables; velocity and processor id MultiFab plotfile_mf(grids, dmap, AMREX_SPACEDIM+1, 0, MFInfo(), factory); @@ -241,7 +241,7 @@ int main (int argc, char* argv[]) } auto stop_time = amrex::second() - strt_time; - amrex::Print() << "Total run time " << stop_time << std::endl; + amrex::Print() << "Total run time " << stop_time << '\n'; amrex::Finalize(); } From 9a4a492f80910bdd4f83f61caf6e7e43dfb5b33c Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 13:34:15 -0700 Subject: [PATCH 17/18] remove using namespace amrex::literals --- EBMOL/hydro_ebmol_edge_state_K.H | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/EBMOL/hydro_ebmol_edge_state_K.H b/EBMOL/hydro_ebmol_edge_state_K.H index 97bc8de78..45d0f4041 100644 --- a/EBMOL/hydro_ebmol_edge_state_K.H +++ b/EBMOL/hydro_ebmol_edge_state_K.H @@ -5,8 +5,6 @@ * */ -using namespace amrex::literals; - #ifndef HYDRO_EBMOL_EDGE_STATE_K_H_ #define HYDRO_EBMOL_EDGE_STATE_K_H_ @@ -21,9 +19,9 @@ AMREX_GPU_DEVICE AMREX_FORCE_INLINE amrex::Real hydro_ebmol_xedge_state_extdir ( AMREX_D_DECL(int i, int j, int k), int n, amrex::Array4 const& q, amrex::Array4 const& umac, - AMREX_D_DECL(amrex::Array4 const& fcx, - amrex::Array4 const& fcy, - amrex::Array4 const& fcz), + AMREX_D_DECL(amrex::Array4 const& fcx, + amrex::Array4 const& fcy, + amrex::Array4 const& fcz), amrex::Array4 const& ccc, amrex::Array4 const& vfrac, amrex::Array4 const& flag, From 4c924cd5f92c635defa7c3f1ec0f75e6aba2fa86 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Tue, 19 May 2026 14:21:26 -0700 Subject: [PATCH 18/18] remove google-global-names-in-headers --- .clang-tidy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clang-tidy b/.clang-tidy index 8779b7d99..384e2db97 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -27,7 +27,6 @@ Checks: > -cppcoreguidelines-use-enum-class, google-build-explicit-make-pair, google-build-namespaces, - google-global-names-in-headers, misc-*, -misc-const-correctness, -misc-include-cleaner, @@ -87,3 +86,4 @@ HeaderFileExtensions: ['', "H", 'h', 'hh', 'hpp', 'hxx'] # -modernize-use-starts-ends-with # -readability-container-contains # -readability-braces-around-statements +# -google-global-names-in-headers