From 04f8622f35f7e788f3b1690fcdc51ef0c45dcd72 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Tue, 9 Jul 2024 17:43:05 -0400 Subject: [PATCH] clang-tidy on MHD (#2880) this also fixes a issue with degeneracy in the eigenvectors --- .../LoopAdvection/problem_initialize.H | 4 +- .../problem_initialize_mhd_data.H | 2 + .../problem_initialize_state_data.H | 2 + Source/mhd/Castro_mhd.H | 2 +- Source/mhd/mhd_eigen.H | 73 +++++++++++-------- Source/mhd/mhd_plm.cpp | 13 ++-- Source/mhd/mhd_ppm.cpp | 13 ++-- 7 files changed, 60 insertions(+), 49 deletions(-) diff --git a/Exec/mhd_tests/LoopAdvection/problem_initialize.H b/Exec/mhd_tests/LoopAdvection/problem_initialize.H index 350fe3be27..fb229657cb 100644 --- a/Exec/mhd_tests/LoopAdvection/problem_initialize.H +++ b/Exec/mhd_tests/LoopAdvection/problem_initialize.H @@ -16,8 +16,8 @@ void problem_initialize () eos_state.rho = problem::rho_0; eos_state.p = problem::p_0; eos_state.T = 100000.0_rt; // initial guess - for (int n = 0; n < NumSpec; n++) { - eos_state.xn[n] = 0.0_rt; + for (auto & X : eos_state.xn) { + X = 0.0_rt; } eos_state.xn[0] = 1.0_rt; diff --git a/Exec/mhd_tests/LoopAdvection/problem_initialize_mhd_data.H b/Exec/mhd_tests/LoopAdvection/problem_initialize_mhd_data.H index 3241f0ab28..7c9716f44c 100644 --- a/Exec/mhd_tests/LoopAdvection/problem_initialize_mhd_data.H +++ b/Exec/mhd_tests/LoopAdvection/problem_initialize_mhd_data.H @@ -7,6 +7,8 @@ Real A_z (int i, int j, int k, const GeometryData& geomdata) { + amrex::ignore_unused(k); + // Compute A_z. This lives on edges, e.g., {A_z}_{i-1/2,j-1/2,k} // so it is centered only in the z-direction. diff --git a/Exec/mhd_tests/LoopAdvection/problem_initialize_state_data.H b/Exec/mhd_tests/LoopAdvection/problem_initialize_state_data.H index d3a6a25391..b7eab9ee6a 100644 --- a/Exec/mhd_tests/LoopAdvection/problem_initialize_state_data.H +++ b/Exec/mhd_tests/LoopAdvection/problem_initialize_state_data.H @@ -10,6 +10,8 @@ void problem_initialize_state_data (int i, int j, int k, const GeometryData& geomdata) { + amrex::ignore_unused(geomdata); + state(i,j,k,URHO) = problem::rho_0; state(i,j,k,UMX) = problem::rho_0 * problem::u_x; state(i,j,k,UMY) = problem::rho_0 * problem::u_y; diff --git a/Source/mhd/Castro_mhd.H b/Source/mhd/Castro_mhd.H index 12037acc75..3d72a01726 100644 --- a/Source/mhd/Castro_mhd.H +++ b/Source/mhd/Castro_mhd.H @@ -99,7 +99,7 @@ amrex::Array4 const& Ed2, const int d, const int d1, const int d2, const amrex::Real dt); - void + static void hlld(const amrex::Box& bx, amrex::Array4 const& qleft, amrex::Array4 const& qright, diff --git a/Source/mhd/mhd_eigen.H b/Source/mhd/mhd_eigen.H index 3fe6cfd919..7757a71e12 100644 --- a/Source/mhd/mhd_eigen.H +++ b/Source/mhd/mhd_eigen.H @@ -86,21 +86,24 @@ evecx(Array2D& leig, Real alf; Real als; - if (std::abs(cfx-csx) <= 1e-14){ + // if C_f = C_s, then we are degenerate, and set the alpha's accordingly. + // see Stone et a. 2008 comment just after Eql A17. + + if (std::abs(cfx - csx) <= 1e-14){ alf = 1.0_rt; als = 0.0_rt; - } - - if (as - csx < 0.0) { - alf = 0.0_rt; } else { - alf = std::sqrt((as - csx)/(cfx - csx)); - } + if (as - csx < 0.0) { + alf = 0.0_rt; + } else { + alf = std::sqrt((as - csx)/(cfx - csx)); + } - if (cfx - as < 0.0) { - als = 0.0_rt; - } else { - als = std::sqrt((cfx - as)/(cfx - csx)); + if (cfx - as < 0.0) { + als = 0.0_rt; + } else { + als = std::sqrt((cfx - as)/(cfx - csx)); + } } @@ -287,21 +290,24 @@ evecy(Array2D& leig, Real alf; Real als; - if (std::abs(cfy-csy) <= 1e-14){ + // if C_f = C_s, then we are degenerate, and set the alpha's accordingly. + // see Stone et a. 2008 comment just after Eql A17. + + if (std::abs(cfy - csy) <= 1e-14){ alf = 1.0_rt; als = 0.0_rt; - } - - if (as - csy < 0.0) { - alf = 0.0_rt; } else { - alf = std::sqrt((as - csy)/(cfy - csy)); - } + if (as - csy < 0.0) { + alf = 0.0_rt; + } else { + alf = std::sqrt((as - csy)/(cfy - csy)); + } - if (cfy - as < 0.0) { - als = 0.0_rt; - } else { - als = std::sqrt((cfy - as)/(cfy - csy)); + if (cfy - as < 0.0) { + als = 0.0_rt; + } else { + als = std::sqrt((cfy - as)/(cfy - csy)); + } } Real betx; @@ -485,21 +491,24 @@ evecz(Array2D& leig, Real alf; Real als; + // if C_f = C_s, then we are degenerate, and set the alpha's accordingly. + // see Stone et a. 2008 comment just after Eql A17. + if (std::abs(cfz-csz) <= 1e-14){ alf = 1.0_rt; als = 0.0_rt; - } - - if (as - csz < 0.0) { - alf = 0.0_rt; } else { - alf = std::sqrt((as - csz)/(cfz - csz)); - } + if (as - csz < 0.0) { + alf = 0.0_rt; + } else { + alf = std::sqrt((as - csz)/(cfz - csz)); + } - if (cfz - as < 0.0) { - als = 0.0_rt; - } else { - als = std::sqrt((cfz - as)/(cfz - csz)); + if (cfz - as < 0.0) { + als = 0.0_rt; + } else { + als = std::sqrt((cfz - as)/(cfz - csz)); + } } Real betx; diff --git a/Source/mhd/mhd_plm.cpp b/Source/mhd/mhd_plm.cpp index 2747812513..bf61c799f9 100644 --- a/Source/mhd/mhd_plm.cpp +++ b/Source/mhd/mhd_plm.cpp @@ -154,8 +154,8 @@ Castro::plm(const Box& bx, smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (Bx(i+1,j,k) - Bx(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (Bx(i+1,j,k) - Bx(i,j,k)) / dx[idir]; } } else if (idir == 1) { @@ -163,8 +163,8 @@ Castro::plm(const Box& bx, smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (By(i,j+1,k) - By(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (By(i,j+1,k) - By(i,j,k)) / dx[idir]; } } else { @@ -172,8 +172,8 @@ Castro::plm(const Box& bx, smhd[IEIGN_BTT] = q_zone(QV); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (Bz(i,j,k+1) - Bz(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (Bz(i,j,k+1) - Bz(i,j,k)) / dx[idir]; } } @@ -441,4 +441,3 @@ Castro::plm(const Box& bx, }); } - diff --git a/Source/mhd/mhd_ppm.cpp b/Source/mhd/mhd_ppm.cpp index f084a95a39..30cd9668d6 100644 --- a/Source/mhd/mhd_ppm.cpp +++ b/Source/mhd/mhd_ppm.cpp @@ -200,8 +200,8 @@ Castro::ppm_mhd(const Box& bx, smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (Bx(i+1,j,k) - Bx(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (Bx(i+1,j,k) - Bx(i,j,k)) / dx[idir]; } } else if (idir == 1) { @@ -209,8 +209,8 @@ Castro::ppm_mhd(const Box& bx, smhd[IEIGN_BTT] = q_zone(QW); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (By(i,j+1,k) - By(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (By(i,j+1,k) - By(i,j,k)) / dx[idir]; } } else { @@ -218,8 +218,8 @@ Castro::ppm_mhd(const Box& bx, smhd[IEIGN_BTT] = q_zone(QV); // cross-talk of normal magnetic field direction - for (int n = 0; n < NEIGN; n++) { - smhd[n] = smhd[n] * (Bz(i,j,k+1) - Bz(i,j,k)) / dx[idir]; + for (auto & source : smhd) { + source *= (Bz(i,j,k+1) - Bz(i,j,k)) / dx[idir]; } } @@ -505,4 +505,3 @@ Castro::ppm_mhd(const Box& bx, }); } -