Skip to content

Commit

Permalink
fix clang-tidy warnings (#468)
Browse files Browse the repository at this point in the history
### Description
This fixes many `clang-tidy` warnings thoughout the code. Most of them
had to do with unnecessary header includes or const issues. No outputs
should change at the bitwise level.

### Related issues
N/A

### Checklist
_Before this pull request can be reviewed, all of these tasks should be
completed. Denote completed tasks with an `x` inside the square brackets
`[ ]` in the Markdown source below:_
- [x] I have added a description (see above).
- [x] I have added a link to any related issues see (see above).
- [x] I have read the [Contributing
Guide](https://github.com/quokka-astro/quokka/blob/development/CONTRIBUTING.md).
- [x] I have added tests for any new physics that this PR adds to the
code.
- [x] I have tested this PR on my local computer and all tests pass.
- [x] I have manually triggered the GPU tests with the magic comment
`/azp run`.
- [x] I have requested a reviewer for this PR.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
BenWibking and pre-commit-ci[bot] authored Feb 9, 2024
1 parent a16b88f commit 2d863d6
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 245 deletions.
2 changes: 1 addition & 1 deletion extern/Microphysics
Submodule Microphysics updated 188 files
11 changes: 2 additions & 9 deletions src/AdvectionSimulation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,15 @@

#include <array>

#include "AMReX.H"
#include "AMReX_Arena.H"
#include "AMReX_Array.H"
#include "AMReX_Array4.H"
#include "AMReX_BLassert.H"
#include "AMReX_Box.H"
#include "AMReX_Config.H"
#include "AMReX_DistributionMapping.H"
#include "AMReX_FArrayBox.H"
#include "AMReX_FabArrayUtility.H"
#include "AMReX_IntVect.H"
#include "AMReX_MultiFab.H"
#include "AMReX_REAL.H"
#include "AMReX_SPACE.H"
#include "AMReX_TagBox.H"
#include "AMReX_Utility.H"
#include "AMReX_YAFluxRegister.H"
#include <AMReX_FluxRegister.H>

Expand Down Expand Up @@ -98,7 +91,7 @@ template <typename problem_t> class AdvectionSimulation : public AMRSimulation<p

template <FluxDir DIR>
void fluxFunction(amrex::MultiFab const &consState, amrex::MultiFab &primVar, amrex::MultiFab &x1Flux, amrex::MultiFab &x1LeftState,
amrex::MultiFab &x1RightState, const int ng_reconstruct, const int nvars);
amrex::MultiFab &x1RightState, int ng_reconstruct, int nvars);

double advectionVx_ = 1.0; // default
double advectionVy_ = 0.0; // default
Expand Down Expand Up @@ -131,7 +124,7 @@ template <typename problem_t> void AdvectionSimulation<problem_t>::applyPoissonG
// deliberately empty
}

template <typename problem_t> auto AdvectionSimulation<problem_t>::computeExtraPhysicsTimestep(int const level) -> amrex::Real
template <typename problem_t> auto AdvectionSimulation<problem_t>::computeExtraPhysicsTimestep(int const /*level*/) -> amrex::Real
{
// user can override this
return std::numeric_limits<amrex::Real>::max();
Expand Down
5 changes: 1 addition & 4 deletions src/Chemistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
///

#include <array>
#include <limits>

#include "AMReX.H"
#include "AMReX_BLassert.H"
#include "AMReX_Extension.H"
#include "AMReX_GpuQualifiers.H"

#include "hydro_system.hpp"
Expand All @@ -29,7 +26,7 @@
namespace quokka::chemistry
{

AMREX_GPU_DEVICE void chemburner(burn_t &chemstate, const Real dt);
AMREX_GPU_DEVICE void chemburner(burn_t &chemstate, Real dt);

template <typename problem_t> void computeChemistry(amrex::MultiFab &mf, const Real dt, const Real max_density_allowed, const Real min_density_allowed)
{
Expand Down
1 change: 0 additions & 1 deletion src/CloudyCooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
///

#include "CloudyCooling.hpp"
#include "ODEIntegrate.hpp"

namespace quokka::cooling
{
Expand Down
24 changes: 12 additions & 12 deletions src/CloudyCooling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
/// \brief Defines methods for interpolating cooling rates from Cloudy tables.
///

#include <limits>

#include "AMReX.H"
#include "AMReX_BLassert.H"
#include "AMReX_Extension.H"
#include "AMReX_GpuQualifiers.H"
#include "AMReX_iMultiFab.H"

#include "FastMath.hpp"
#include "GrackleDataReader.hpp"
#include "Interpolate2D.hpp"
#include "ODEIntegrate.hpp"
#include "fmt/core.h"
#include "fundamental_constants.H"
#include "hydro_system.hpp"
#include "radiation_system.hpp"
Expand Down Expand Up @@ -47,14 +46,14 @@ constexpr double E_cmb = radiation_constant_cgs_ * (T_cmb * T_cmb * T_cmb * T_cm

struct cloudyGpuConstTables {
// these are non-owning, so can make a copy of the whole struct
amrex::Table1D<const Real> const log_nH;
amrex::Table1D<const Real> const log_Tgas;

amrex::Table2D<const Real> const primCool;
amrex::Table2D<const Real> const primHeat;
amrex::Table2D<const Real> const metalCool;
amrex::Table2D<const Real> const metalHeat;
amrex::Table2D<const Real> const meanMolWeight;
amrex::Table1D<const Real> log_nH;
amrex::Table1D<const Real> log_Tgas;

amrex::Table2D<const Real> primCool;
amrex::Table2D<const Real> primHeat;
amrex::Table2D<const Real> metalCool;
amrex::Table2D<const Real> metalHeat;
amrex::Table2D<const Real> meanMolWeight;
};

class cloudy_tables
Expand Down Expand Up @@ -152,7 +151,8 @@ AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE auto ComputeTgasFromEgas(double rho, do

if (Egas <= Eint_min) {
return Tmin_table;
} else if (Egas >= Eint_max) {
}
if (Egas >= Eint_max) {
return Tmax_table;
}

Expand Down
18 changes: 7 additions & 11 deletions src/EOS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "physics_info.hpp"
#include <AMReX_Print.H>

#include "burn_type.H"
#include "eos.H"
#include "extern_parameters.H"

#ifdef PRIMORDIAL_CHEM
#include "actual_eos_data.H"
Expand All @@ -43,27 +41,25 @@ template <typename problem_t> class EOS
public:
static constexpr int nmscalars_ = Physics_Traits<problem_t>::numMassScalars;
[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeTgasFromEint(amrex::Real rho, amrex::Real Eint, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
ComputeTgasFromEint(amrex::Real rho, amrex::Real Eint, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintFromTgas(amrex::Real rho, amrex::Real Tgas, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
ComputeEintFromTgas(amrex::Real rho, amrex::Real Tgas, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintFromPres(amrex::Real rho, amrex::Real Pressure, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {})
-> amrex::Real;
ComputeEintFromPres(amrex::Real rho, amrex::Real Pressure, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeEintTempDerivative(amrex::Real rho, amrex::Real Tgas, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {})
-> amrex::Real;
ComputeEintTempDerivative(amrex::Real rho, amrex::Real Tgas, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeOtherDerivatives(amrex::Real rho, amrex::Real P, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {});
ComputeOtherDerivatives(amrex::Real rho, amrex::Real P, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {});

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputePressure(amrex::Real rho, amrex::Real Eint, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
ComputePressure(amrex::Real rho, amrex::Real Eint, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

[[nodiscard]] AMREX_FORCE_INLINE AMREX_GPU_HOST_DEVICE static auto
ComputeSoundSpeed(amrex::Real rho, amrex::Real Pressure, const std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;
ComputeSoundSpeed(amrex::Real rho, amrex::Real Pressure, std::optional<amrex::GpuArray<amrex::Real, nmscalars_>> massScalars = {}) -> amrex::Real;

private:
static constexpr amrex::Real gamma_ = EOS_Traits<problem_t>::gamma;
Expand Down
10 changes: 5 additions & 5 deletions src/FCQuantities/test_fc_quantities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ void checkMFs(amrex::Vector<amrex::Array<amrex::MultiFab, AMREX_SPACEDIM>> const
for (int level = 0; level < state1.size(); ++level) {
for (int idim = 0; idim < AMREX_SPACEDIM; ++idim) {
// initialise MF
const BoxArray &ba = state1[level][idim].boxArray();
const DistributionMapping &dm = state1[level][idim].DistributionMap();
const amrex::BoxArray &ba = state1[level][idim].boxArray();
const amrex::DistributionMapping &dm = state1[level][idim].DistributionMap();
int ncomp = state1[level][idim].nComp();
int ngrow = state1[level][idim].nGrow();
MultiFab mf_diff(ba, dm, ncomp, ngrow);
amrex::MultiFab mf_diff(ba, dm, ncomp, ngrow);
// compute difference between two MFs (at level)
MultiFab::Copy(mf_diff, state1[level][idim], 0, 0, ncomp, ngrow);
MultiFab::Subtract(mf_diff, state2[level][idim], 0, 0, ncomp, ngrow);
amrex::MultiFab::Copy(mf_diff, state1[level][idim], 0, 0, ncomp, ngrow);
amrex::MultiFab::Subtract(mf_diff, state2[level][idim], 0, 0, ncomp, ngrow);
// compute error (summed over each component)
for (int icomp = 0; icomp < Physics_Indices<FCQuantities>::nvarPerDim_fc; ++icomp) {
err += mf_diff.norm1(icomp);
Expand Down
14 changes: 8 additions & 6 deletions src/GrackleDataReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "AMReX_Print.H"
#include "AMReX_TableData.H"
#include "FastMath.hpp"
#include "fmt/core.h"

static const bool grackle_verbose = true;

Expand Down Expand Up @@ -109,15 +110,15 @@ void initialize_cloudy_data(cloudy_data &my_cloudy, char const *group_name, std:
parameter_name = "Temperature";
}

double *temp_data = new double[my_cloudy.grid_dimension[q]];
auto *temp_data = new double[my_cloudy.grid_dimension[q]]; // NOLINT(cppcoreguidelines-owning-memory)

attr_id = H5Aopen_name(dset_id, parameter_name.c_str());

status = H5Aread(attr_id, HDF5_R8, temp_data);

my_cloudy.grid_parameters[q] = amrex::Table1D<double>(temp_data, 0, static_cast<int>(my_cloudy.grid_dimension[q]));

for (int64_t w = 0; w < my_cloudy.grid_dimension[q]; w++) {
for (int w = 0; w < my_cloudy.grid_dimension[q]; w++) {
if (q < my_cloudy.grid_rank - 1) {
my_cloudy.grid_parameters[q](w) = temp_data[w];
} else {
Expand All @@ -128,7 +129,8 @@ void initialize_cloudy_data(cloudy_data &my_cloudy, char const *group_name, std:

if (grackle_verbose) {
amrex::Print() << fmt::format("\t{}: {} to {} ({} steps).\n", parameter_name, my_cloudy.grid_parameters[q](0),
my_cloudy.grid_parameters[q](my_cloudy.grid_dimension[q] - 1), my_cloudy.grid_dimension[q]);
my_cloudy.grid_parameters[q](static_cast<int>(my_cloudy.grid_dimension[q]) - 1),
my_cloudy.grid_dimension[q]);
}

status = H5Aclose(attr_id);
Expand All @@ -142,7 +144,7 @@ void initialize_cloudy_data(cloudy_data &my_cloudy, char const *group_name, std:

{
// Read Cooling data
double *temp_data = new double[my_cloudy.data_size];
auto *temp_data = new double[my_cloudy.data_size]; // NOLINT(cppcoreguidelines-owning-memory)

status = H5Dread(dset_id, HDF5_R8, H5S_ALL, H5S_ALL, H5P_DEFAULT, temp_data);

Expand All @@ -168,7 +170,7 @@ void initialize_cloudy_data(cloudy_data &my_cloudy, char const *group_name, std:

{
// Read Heating data
double *temp_data = new double[my_cloudy.data_size];
auto *temp_data = new double[my_cloudy.data_size]; // NOLINT(cppcoreguidelines-owning-memory)

parameter_name = fmt::format("/CoolingRates/{}/Heating", group_name);

Expand Down Expand Up @@ -199,7 +201,7 @@ void initialize_cloudy_data(cloudy_data &my_cloudy, char const *group_name, std:

if (std::string(group_name) == "Primordial") {
// Read mean molecular weight table
double *temp_data = new double[my_cloudy.data_size];
auto *temp_data = new double[my_cloudy.data_size]; // NOLINT(cppcoreguidelines-owning-memory)

amrex::GpuArray<int, 3> lo{0, 0, 0};
amrex::GpuArray<int, 3> hi{static_cast<int>(my_cloudy.grid_dimension[2]), static_cast<int>(my_cloudy.grid_dimension[1]),
Expand Down
11 changes: 2 additions & 9 deletions src/GrackleDataReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,19 @@
/// \brief Defines methods for reading the cooling rate tables used by Grackle.
///

#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <string>

#include "fmt/core.h"
#include <H5Dpublic.h>
#include <H5Ppublic.h>
#include <hdf5.h>

#include "AMReX.H"
#include "AMReX_Array.H"
#include "AMReX_BLassert.H"
#include "AMReX_TableData.H"

using Real = amrex::Real;

#define SMALL_LOG_VALUE -99.0
#define CLOUDY_MAX_DIMENSION 3 // we are using amrex::Table3D
constexpr double SMALL_LOG_VALUE = -99.0;
constexpr int CLOUDY_MAX_DIMENSION = 3; // we are using amrex::Table3D

/* HDF5 definitions */

Expand Down
2 changes: 0 additions & 2 deletions src/LLF.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <AMReX.H>
#include <AMReX_REAL.H>

#include "ArrayView.hpp"
#include "EOS.hpp"
#include "HydroState.hpp"
#include "valarray.hpp"

Expand Down
20 changes: 10 additions & 10 deletions src/NSCBC/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ template <> struct Physics_Traits<Channel> {
namespace
{
#endif
Real rho0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Real u0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Real s0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real Tgas0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real P_outflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real u_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real v_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real w_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED GpuArray<Real, Physics_Traits<Channel>::numPassiveScalars> s_inflow{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#if 0 // workaround AMDGPU compiler bug
Real rho0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Real u0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
Real s0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real Tgas0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real P_outflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real u_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real v_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real w_inflow = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::GpuArray<Real, Physics_Traits<Channel>::numPassiveScalars> s_inflow{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#if 0 // workaround AMDGPU compiler bug
}; // namespace
#endif

Expand Down
16 changes: 8 additions & 8 deletions src/NSCBC/vortex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ template <> struct Physics_Traits<Vortex> {
namespace
{
const bool outflow_boundary_along_x_axis = true;
Real G_vortex = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real T_ref = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real P_ref = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real u0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real v0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED Real w0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED GpuArray<Real, HydroSystem<Vortex>::nscalars_> s0{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
}; // namespace
amrex::Real G_vortex = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real T_ref = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real P_ref = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real u0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real v0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::Real w0 = NAN; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
AMREX_GPU_MANAGED amrex::GpuArray<Real, HydroSystem<Vortex>::nscalars_> s0{}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
}; // namespace

template <> void RadhydroSimulation<Vortex>::setInitialConditionsOnGrid(quokka::grid grid_elem)
{
Expand Down
1 change: 0 additions & 1 deletion src/NSCBC_inflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "AMReX_REAL.H"
#include "EOS.hpp"
#include "hydro_system.hpp"
#include "physics_numVars.hpp"
#include "valarray.hpp"

namespace NSCBC
Expand Down
2 changes: 0 additions & 2 deletions src/NSCBC_outflow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@

#include "AMReX_GpuQualifiers.H"
#include "AMReX_REAL.H"
#include "ArrayView.hpp"
#include "EOS.hpp"
#include "hydro_system.hpp"
#include "physics_numVars.hpp"
#include "valarray.hpp"

namespace NSCBC
Expand Down
Loading

0 comments on commit 2d863d6

Please sign in to comment.