Skip to content

Commit

Permalink
Avoid M_PI because it's not in the C++ standard (AMReX-Codes#2807)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeiqunZhang authored Jun 2, 2022
1 parent 6e907ff commit 45e3042
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
6 changes: 4 additions & 2 deletions Src/Base/AMReX_Geometry.H
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ public:
Real rl = geomdata.ProbLo()[0] + static_cast<Real>(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
Expand All @@ -270,7 +271,8 @@ public:
Real r_l = geomdata.ProbLo()[0] + static_cast<Real>(point[0]) * dx[0];
Real r_r = geomdata.ProbLo()[0] + static_cast<Real>(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
Expand Down
4 changes: 3 additions & 1 deletion Tests/EB_CNS/Exec/Pulse/cns_prob.H
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ cns_initdata (int i, int j, int k, amrex::Array4<amrex::Real> 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();
Expand All @@ -31,7 +33,7 @@ cns_initdata (int i, int j, int k, amrex::Array4<amrex::Real> 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);
Expand Down
8 changes: 5 additions & 3 deletions Tests/LinearSolvers/LeastSquares/initEB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)},
Expand All @@ -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<Real> norm(3);
Real norm_mag = std::sqrt(std::sin(alpha)*std::sin(alpha) +
Expand Down
3 changes: 2 additions & 1 deletion Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions Tests/LinearSolvers/LeastSquares/initPoiseuilleDataFor3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions Tools/Plotfile/fvolumesum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Real,AMREX_SPACEDIM> dx = pf.cellSize(ilev);
Expand Down Expand Up @@ -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<Real>(i+1)*dx[0];
Real r_l = problo[0]+static_cast<Real>(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;
Expand Down Expand Up @@ -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<Real>(i+1)*dx[0];
Real r_l = problo[0]+static_cast<Real>(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;
Expand Down

0 comments on commit 45e3042

Please sign in to comment.