From 45e3042691ba9352d929cd1d22c5e7db3f182ce2 Mon Sep 17 00:00:00 2001 From: Weiqun Zhang Date: Thu, 2 Jun 2022 12:12:41 -0700 Subject: [PATCH] Avoid M_PI because it's not in the C++ standard (#2807) --- Src/Base/AMReX_Geometry.H | 6 ++++-- Tests/EB_CNS/Exec/Pulse/cns_prob.H | 4 +++- Tests/LinearSolvers/LeastSquares/initEB.cpp | 8 +++++--- .../LeastSquares/initPoiseuilleDataFor2D.cpp | 3 ++- .../LeastSquares/initPoiseuilleDataFor3D.cpp | 5 +++-- Tools/Plotfile/fvolumesum.cpp | 10 ++++++---- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/Src/Base/AMReX_Geometry.H b/Src/Base/AMReX_Geometry.H index 1a9910bc52..54a8b8630d 100644 --- a/Src/Base/AMReX_Geometry.H +++ b/Src/Base/AMReX_Geometry.H @@ -252,7 +252,8 @@ public: Real rl = geomdata.ProbLo()[0] + static_cast(point[0]) * dx[0]; Real rr = rl + dx[0]; - vol = (4.0_rt / 3.0_rt) * M_PI * dx[0] * (rl * rl + rl * rr + rr * rr); + constexpr Real pi = 3.1415926535897932; + vol = (4.0_rt / 3.0_rt) * pi * dx[0] * (rl * rl + rl * rr + rr * rr); } #elif AMREX_SPACEDIM == 2 @@ -270,7 +271,8 @@ public: Real r_l = geomdata.ProbLo()[0] + static_cast(point[0]) * dx[0]; Real r_r = geomdata.ProbLo()[0] + static_cast(point[0]+1) * dx[0]; - vol = M_PI * (r_l + r_r) * dx[0] * dx[1]; + constexpr Real pi = 3.1415926535897932; + vol = pi * (r_l + r_r) * dx[0] * dx[1]; } #else diff --git a/Tests/EB_CNS/Exec/Pulse/cns_prob.H b/Tests/EB_CNS/Exec/Pulse/cns_prob.H index 0f79820daa..10f2ec4067 100644 --- a/Tests/EB_CNS/Exec/Pulse/cns_prob.H +++ b/Tests/EB_CNS/Exec/Pulse/cns_prob.H @@ -15,6 +15,8 @@ cns_initdata (int i, int j, int k, amrex::Array4 const& state, { using amrex::Real; + constexpr Real pi = 3.1415926535897932; + const Real* prob_lo = geomdata.ProbLo(); const Real* prob_hi = geomdata.ProbHi(); const Real* dx = geomdata.CellSize(); @@ -31,7 +33,7 @@ cns_initdata (int i, int j, int k, amrex::Array4 const& state, if (r > prob_parm.rpulse) { state(i,j,k,URHO ) = prob_parm.rho0; } else { - state(i,j,k,URHO ) = prob_parm.rho0 + prob_parm.drho0 * exp(-16.*r*r) * std::pow(std::cos(M_PI*r),6.0); + state(i,j,k,URHO ) = prob_parm.rho0 + prob_parm.drho0 * exp(-16.*r*r) * std::pow(std::cos(pi*r),6.0); } state(i,j,k,UMX ) = Real(0.0); diff --git a/Tests/LinearSolvers/LeastSquares/initEB.cpp b/Tests/LinearSolvers/LeastSquares/initEB.cpp index d4fb19ac0e..a5fc561785 100644 --- a/Tests/LinearSolvers/LeastSquares/initEB.cpp +++ b/Tests/LinearSolvers/LeastSquares/initEB.cpp @@ -15,6 +15,8 @@ using namespace amrex; void MyTest::initializeEB () { + constexpr Real pi = 3.1415926535897932; + ParmParse pp("eb2"); std::string geom_type; pp.get("geom_type", geom_type); @@ -68,7 +70,7 @@ MyTest::initializeEB () pp.getarr("channel_pt_on_top_wall", pt_on_top_wall, 0, 3); pp.get("channel_rotation", rotation); pp.get("channel_height", height); - rotation = (rotation/180.) * M_PI; + rotation = (rotation/180.) * pi; EB2::PlaneIF left({AMREX_D_DECL(pt_on_top_wall[0],pt_on_top_wall[1],0.0)}, {AMREX_D_DECL(-std::sin(rotation),std::cos(rotation),0.0)}, @@ -92,8 +94,8 @@ MyTest::initializeEB () pp.getarr("channel_rotation", rotation, 0, 2); pp.get("channel_height", height); - Real alpha = (rotation[0]/180.) * M_PI; - Real gamma = (rotation[1]/180.) * M_PI; + Real alpha = (rotation[0]/180.) * pi; + Real gamma = (rotation[1]/180.) * pi; Vector norm(3); Real norm_mag = std::sqrt(std::sin(alpha)*std::sin(alpha) + diff --git a/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor2D.cpp b/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor2D.cpp index 79e900d96a..5bc8536384 100644 --- a/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor2D.cpp +++ b/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor2D.cpp @@ -40,7 +40,8 @@ void MyTest::initializePoiseuilleDataFor2D(int ilev) { amrex::ParallelFor(bx, [=] AMREX_GPU_DEVICE(int i, int j, int k) noexcept { Real H = poiseuille_height; - Real t = (poiseuille_rotation / 180.) * M_PI; + constexpr Real pi = 3.1415926535897932; + Real t = (poiseuille_rotation / 180.) * pi; Real a = std::tan(t); Real b = -1.0; diff --git a/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor3D.cpp b/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor3D.cpp index 2079acbe0f..98c8c4d051 100644 --- a/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor3D.cpp +++ b/Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor3D.cpp @@ -49,8 +49,9 @@ void MyTest::initializePoiseuilleDataFor3D(int ilev) { int k) noexcept { Real H = poiseuille_height; int nfdir = poiseuille_no_flow_dir; - Real alpha = (poiseuille_askew_rotation[0] / 180.) * M_PI; - Real gamma = (poiseuille_askew_rotation[1] / 180.) * M_PI; + constexpr Real pi = 3.1415926535897932; + Real alpha = (poiseuille_askew_rotation[0] / 180.) * pi; + Real gamma = (poiseuille_askew_rotation[1] / 180.) * pi; Real a = std::sin(gamma); Real b = -std::cos(alpha) * std::cos(gamma); diff --git a/Tools/Plotfile/fvolumesum.cpp b/Tools/Plotfile/fvolumesum.cpp index 1a55961b77..e12418254f 100644 --- a/Tools/Plotfile/fvolumesum.cpp +++ b/Tools/Plotfile/fvolumesum.cpp @@ -89,6 +89,8 @@ void main_main() int coord = pf.coordSys(); + constexpr Real pi = 3.1415926535897932; + for (int ilev = 0; ilev <= fine_level; ++ilev) { Array dx = pf.cellSize(ilev); @@ -129,12 +131,12 @@ void main_main() // axisymmetric V = pi (r_r**2 - r_l**2) * dz // = pi dr * dz * (r_r + r_l) // = 2 pi r dr dz - vol = 2 * M_PI * p[0] * dx[0] * dx[1]; + vol = 2 * pi * p[0] * dx[0] * dx[1]; } else if (coord == 2) { // 1-d spherical V = 4/3 pi (r_r**3 - r_l**3) Real r_r = problo[0]+static_cast(i+1)*dx[0]; Real r_l = problo[0]+static_cast(i)*dx[0]; - vol = (4.0_rt/3.0_rt) * M_PI * dx[0] * (r_r*r_r + r_l*r_r + r_l*r_l); + vol = (4.0_rt/3.0_rt) * pi * dx[0] * (r_r*r_r + r_l*r_r + r_l*r_l); } lsum += fab(i,j,k) * vol; @@ -172,12 +174,12 @@ void main_main() // axisymmetric V = pi (r_r**2 - r_l**2) * dz // = pi dr * dz * (r_r + r_l) // = 2 pi r dr dz - vol = 2 * M_PI * p[0] * dx[0] * dx[1]; + vol = 2 * pi * p[0] * dx[0] * dx[1]; } else if (coord == 2) { // 1-d spherical V = 4/3 pi (r_r**3 - r_l**3) Real r_r = problo[0]+static_cast(i+1)*dx[0]; Real r_l = problo[0]+static_cast(i)*dx[0]; - vol = (4.0_rt/3.0_rt) * M_PI * dx[0] * (r_r*r_r + r_l*r_r + r_l*r_l); + vol = (4.0_rt/3.0_rt) * pi * dx[0] * (r_r*r_r + r_l*r_r + r_l*r_l); } lsum += fab(i,j,k) * vol;