Skip to content

Commit

Permalink
clang-tidy on MHD (#2880)
Browse files Browse the repository at this point in the history
this also fixes a issue with degeneracy in the eigenvectors
  • Loading branch information
zingale committed Jul 9, 2024
1 parent c5d4887 commit 04f8622
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 49 deletions.
4 changes: 2 additions & 2 deletions Exec/mhd_tests/LoopAdvection/problem_initialize.H
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions Exec/mhd_tests/LoopAdvection/problem_initialize_mhd_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 2 additions & 0 deletions Exec/mhd_tests/LoopAdvection/problem_initialize_state_data.H
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Source/mhd/Castro_mhd.H
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
amrex::Array4<amrex::Real const> 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<amrex::Real const> const& qleft,
amrex::Array4<amrex::Real const> const& qright,
Expand Down
73 changes: 41 additions & 32 deletions Source/mhd/mhd_eigen.H
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,24 @@ evecx(Array2D<Real, 0, NEIGN-1, 0, NEIGN-1>& 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));
}
}


Expand Down Expand Up @@ -287,21 +290,24 @@ evecy(Array2D<Real, 0, NEIGN-1, 0, NEIGN-1>& 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;
Expand Down Expand Up @@ -485,21 +491,24 @@ evecz(Array2D<Real, 0, NEIGN-1, 0, NEIGN-1>& 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;
Expand Down
13 changes: 6 additions & 7 deletions Source/mhd/mhd_plm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,26 +154,26 @@ 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) {
smhd[IEIGN_BT] = q_zone(QU);
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 {
smhd[IEIGN_BT] = q_zone(QU);
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];
}
}

Expand Down Expand Up @@ -441,4 +441,3 @@ Castro::plm(const Box& bx,

});
}

13 changes: 6 additions & 7 deletions Source/mhd/mhd_ppm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,26 @@ 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) {
smhd[IEIGN_BT] = q_zone(QU);
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 {
smhd[IEIGN_BT] = q_zone(QU);
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];
}
}

Expand Down Expand Up @@ -505,4 +505,3 @@ Castro::ppm_mhd(const Box& bx,

});
}

0 comments on commit 04f8622

Please sign in to comment.