Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New particle interface using derived classes #827

Draft
wants to merge 119 commits into
base: development
Choose a base branch
from

Conversation

chongchonghe
Copy link
Contributor

@chongchonghe chongchonghe commented Dec 19, 2024

Description

The physics particle interface provides a flexible and extensible system for managing different types of particles in the simulation. It uses a combination of the Strategy pattern and Registry pattern to handle multiple particle types through a common interface.

Core Components

1. PhysicsParticleDescriptor (Base Class)
class PhysicsParticleDescriptor {
		protected:
  int massIndex_{-1};	// index for gravity mass, -1 if not used
  int lumIndex_{-1};	// index for radiation luminosity, -1 if not used
  int birthTimeIndex_{-1}; // index for birth time, -1 if not used
  bool interactsWithHydro_{false}; // whether particles interact with hydro

		public:
	virtual void redistribute(int lev) = 0;
  virtual void writePlotFile(...) = 0;
  virtual void depositRadiation(...) = 0;
  virtual void depositMass(...) = 0;
  // ...
};

This abstract base class defines the interface that all particle descriptors must implement. It provides virtual methods for common particle operations like:

  • Redistribution across processors
  • Writing to plot files and checkpoints
  • Depositing radiation and mass to the grid
2. Concrete Descriptor Classes

Currently, the system provides three specialized descriptor classes. More can be added by subclassing PhysicsParticleDescriptor.

  • RadParticleDescriptor: For radiation-emitting particles
  • CICParticleDescriptor: For Cloud-In-Cell (gravitating) particles
  • CICRadParticleDescriptor: For particles that both emit radiation and interact via CIC
3. PhysicsParticleRegister
template <typename problem_t>
class PhysicsParticleRegister {
    void registerParticleType(const std::string &name, 
                            std::unique_ptr<ParticleDescriptor> descriptor);
    void depositRadiation(...);
    void depositMass(...);
    // ...
};

A registry that manages all particle descriptors and provides high-level operations that apply to all registered particles.

Usage

1. Creating and Registering Particles

See example in src/simulation.hpp: InitParticles()

// Create particle descriptor
auto radParticleDesc = std::make_unique<RadParticleDescriptor<problem_t>>(
    -1,                // mass index
    RadParticleLumIdx, // luminosity index 
    RadParticleBirthTimeIdx, // birth time index
    false              // hydro interaction flag
);

// Create particle container
RadParticles = std::make_unique<RadParticleContainer<problem_t>>(this);

// Set container in descriptor
radParticleDesc->setParticleContainer(RadParticles.get());

// Register with particle register
particleRegister_->registerParticleType("Rad_particles", std::move(radParticleDesc));
2. Using the Interface

Once particles are registered, you can perform operations on all particles through the register:

// Deposit radiation from all particles that have luminosity
particleRegister_->depositRadiation(radEnergySource, lev, current_time);

// Redistribute particles after grid changes
particleRegister_->redistribute(lev);

// Write particle data to plot files
particleRegister_->writePlotFile(plotfilename);

Key Features

  1. Type Safety: Each descriptor handles type-safe casting of its particle container internally.

  2. Extensibility: New particle types can be added by:

    • Creating a new particle container class
    • Creating a new descriptor class that inherits from PhysicsParticleDescriptor
    • Implementing the required virtual methods
  3. Unified Interface: All particle operations can be performed through the register without knowing the specific particle types.

  4. Selective Operations: The system automatically handles operations only for particles that support them:

    // Only particles with luminosity will deposit radiation
    if (descriptor->getLumIndex() >= 0) {
        descriptor->depositRadiation(...);
    }

Adding a New Particle Type

  1. Create a new particle container and iterator:
using XXXParticleContainer = amrex::AmrParticleContainer<XXXParticleRealComps>;
using XXXParticleIterator = amrex::ParIter<XXXParticleRealComps>;
  1. Create a new descriptor class:
class XXXParticleDescriptor : public PhysicsParticleDescriptor {
    void redistribute(int lev) override {
        if (auto *container = dynamic_cast<XXXParticleContainer*>(
            this->neighborParticleContainer_)) {
            container->Redistribute(lev);
        }
    }
    // Implement other virtual methods
};
  1. Define a unique_ptr to the new particle container in AMRSimulation:
std::unique_ptr<XXXParticleContainer> XXXParticles;
  1. Register the new particle type in AMRSimulation::InitPhyParticles():
auto newParticleDesc = std::make_unique<XXXParticleDescriptor>(...);
...
particleRegister_->registerParticleType("XXX_particles", std::move(newParticleDesc));
// Initialize particles through derived class
createInitialXXXParticles();
  1. Register the new particle type in AMRSimulation::ReadCheckpointFile():
particleRegister_->registerParticleType("XXX_particles", std::move(newParticleDesc));

New test problems

This implementation is totally working, passing both RadParticle and GravRadParticle3D tests.

Related issues

None.

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:

  • I have added a description (see above).
  • I have added a link to any related issues (if applicable; see above).
  • I have read the Contributing Guide.
  • I have added tests for any new physics that this PR adds to the code.
  • (For quokka-astro org members) I have manually triggered the GPU tests with the magic comment /azp run.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 68. Check the log or trigger a new build to see more.

src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
src/particles/PhysicsParticles.hpp Show resolved Hide resolved
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 70. Check the log or trigger a new build to see more.


const double lum1 = 1.0;

template <> struct quokka::EOS_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "quokka::EOS_Traits" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "test_grav_rad_particle_3D.hpp"
+ #include "hydro/EOS.hpp"
+ #include "test_grav_rad_particle_3D.hpp"

static constexpr double gamma = 5. / 3.;
};

template <> struct Physics_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Physics_Traits" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "test_grav_rad_particle_3D.hpp"
+ #include "physics_info.hpp"
+ #include "test_grav_rad_particle_3D.hpp"

CICRadParticles->InitFromAsciiFile("GravRadParticles3D.txt", nreal_extra, nullptr);
}

template <> AMREX_GPU_HOST_DEVICE auto RadSystem<ParticleProblem>::ComputePlanckOpacity(const double /*rho*/, const double /*Tgas*/) -> amrex::Real
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_GPU_HOST_DEVICE" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_GpuQualifiers.H"
+ #include "AMReX_Vector.H"

return kappa0;
}

template <> void QuokkaSimulation<ParticleProblem>::setInitialConditionsOnGrid(quokka::grid const &grid_elem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "quokka::grid" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "test_grav_rad_particle_3D.hpp"
+ #include "grid.hpp"
+ #include "test_grav_rad_particle_3D.hpp"

template <> void QuokkaSimulation<ParticleProblem>::setInitialConditionsOnGrid(quokka::grid const &grid_elem)
{
const amrex::Box &indexRange = grid_elem.indexRange_;
const amrex::Array4<double> &state_cc = grid_elem.array_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Array4" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:7:

- #include "AMReX_BCRec.H"
+ #include "AMReX_Array4.H"
+ #include "AMReX_BCRec.H"

const auto Egas0 = initial_Egas;

// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::ParallelFor" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_GpuLaunchFunctsC.H"
+ #include "AMReX_Vector.H"

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 64. Check the log or trigger a new build to see more.

src/particles/PhysicsParticles.hpp Show resolved Hide resolved

// get particle positions
quokka::CICRadParticleContainer<ParticleProblem> analysisPC{};
amrex::Box const box(amrex::IntVect{AMREX_D_DECL(0, 0, 0)}, amrex::IntVect{AMREX_D_DECL(1, 1, 1)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_D_DECL" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_SPACE.H"
+ #include "AMReX_Vector.H"

quokka::CICRadParticleContainer<ParticleProblem> analysisPC{};
amrex::Box const box(amrex::IntVect{AMREX_D_DECL(0, 0, 0)}, amrex::IntVect{AMREX_D_DECL(1, 1, 1)});
amrex::Geometry const geom(box);
amrex::BoxArray const boxArray(box);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::BoxArray" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_BoxArray.H"
+ #include "AMReX_Vector.H"

amrex::Geometry const geom(box);
amrex::BoxArray const boxArray(box);
amrex::Vector<int> const ranks({0}); // workaround nvcc bug
amrex::DistributionMapping const dmap(ranks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::DistributionMapping" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_DistributionMapping.H"
+ #include "AMReX_Vector.H"

sim.particleRegister_.getParticleDescriptor("CICRad_particles")->getParticleContainer<quokka::CICRadParticleContainer<ParticleProblem>>();
analysisPC.copyParticles(*container);

if (amrex::ParallelDescriptor::IOProcessor()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::ParallelDescriptor::IOProcessor" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:10:

- #include "AMReX_Vector.H"
+ #include "AMReX_ParallelDescriptor.H"
+ #include "AMReX_Vector.H"

analysisPC.copyParticles(*container);

if (amrex::ParallelDescriptor::IOProcessor()) {
quokka::CICRadParticleIterator<ParticleProblem> const pIter(analysisPC, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "quokka::CICRadParticleIterator" is directly included [misc-include-cleaner]

		quokka::CICRadParticleIterator<ParticleProblem> const pIter(analysisPC, 0);
          ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 63. Check the log or trigger a new build to see more.

src/particles/PhysicsParticles.hpp Show resolved Hide resolved

#include "AMReX.H"
#include "AMReX_BCRec.H"
#include "AMReX_BC_TYPES.H"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header AMReX_BCRec.H is not used directly [misc-include-cleaner]

Suggested change
#include "AMReX_BC_TYPES.H"
#include "AMReX_BC_TYPES.H"

#include "AMReX_BC_TYPES.H"
#include "AMReX_Box.H"
#include "AMReX_GpuLaunchFunctsC.H"
#include "AMReX_REAL.H"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header AMReX_GpuLaunchFunctsC.H is not used directly [misc-include-cleaner]

Suggested change
#include "AMReX_REAL.H"
#include "AMReX_REAL.H"

#include "AMReX_Box.H"
#include "AMReX_GpuLaunchFunctsC.H"
#include "AMReX_REAL.H"
#include "AMReX_Vector.H"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header AMReX_REAL.H is not used directly [misc-include-cleaner]

Suggested change
#include "AMReX_Vector.H"
#include "AMReX_Vector.H"

#include "AMReX_GpuLaunchFunctsC.H"
#include "AMReX_REAL.H"
#include "AMReX_Vector.H"
#include "QuokkaSimulation.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header AMReX_Vector.H is not used directly [misc-include-cleaner]

Suggested change
#include "QuokkaSimulation.hpp"
#include "QuokkaSimulation.hpp"

#include "QuokkaSimulation.hpp"
#include "hydro/EOS.hpp"
#include "particles/PhysicsParticles.hpp"
#include "radiation/radiation_system.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header PhysicsParticles.hpp is not used directly [misc-include-cleaner]

Suggested change
#include "radiation/radiation_system.hpp"
#include "radiation/radiation_system.hpp"

static constexpr double gamma = 5. / 3.;
};

template <> struct Physics_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Physics_Traits" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:18:

- #include "radiation/radiation_system.hpp"
+ #include "physics_info.hpp"
+ #include "radiation/radiation_system.hpp"

CICRadParticles->InitFromAsciiFile("GravRadParticles3D.txt", nreal_extra, nullptr);
}

template <> AMREX_GPU_HOST_DEVICE auto RadSystem<ParticleProblem>::ComputePlanckOpacity(const double /*rho*/, const double /*Tgas*/) -> amrex::Real
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_GPU_HOST_DEVICE" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:13:

- #include "AMReX_REAL.H"
+ #include "AMReX_GpuQualifiers.H"
+ #include "AMReX_REAL.H"

};

// Boundary conditions
constexpr int nvars = RadSystem<ParticleProblem>::nvar_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'nvars' is not initialized [cppcoreguidelines-init-variables]

Suggested change
constexpr int nvars = RadSystem<ParticleProblem>::nvar_;
constexpr int nvars = 0 = RadSystem<ParticleProblem>::nvar_;

sim.evolve();

// compute total radiation energy
const double total_Erad_over_vol = sim.state_new_cc_[0].sum(RadSystem<ParticleProblem>::radEnergy_index);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'total_Erad_over_vol' is not initialized [cppcoreguidelines-init-variables]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:20:

+ 
+ #include <math.h>
Suggested change
const double total_Erad_over_vol = sim.state_new_cc_[0].sum(RadSystem<ParticleProblem>::radEnergy_index);
const double total_Erad_over_vol = NAN = sim.state_new_cc_[0].sum(RadSystem<ParticleProblem>::radEnergy_index);

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 58. Check the log or trigger a new build to see more.

src/particles/PhysicsParticles.hpp Show resolved Hide resolved
static constexpr double gamma = 5. / 3.;
};

template <> struct Physics_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Physics_Traits" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:17:

- #include "radiation/radiation_system.hpp"
+ #include "physics_info.hpp"
+ #include "radiation/radiation_system.hpp"

CICRadParticles->InitFromAsciiFile("GravRadParticles3D.txt", nreal_extra, nullptr);
}

template <> AMREX_GPU_HOST_DEVICE auto RadSystem<ParticleProblem>::ComputePlanckOpacity(const double /*rho*/, const double /*Tgas*/) -> amrex::Real
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_GPU_HOST_DEVICE" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_GpuQualifiers.H"
+ #include "AMReX_REAL.H"

return kappa0;
}

template <> void QuokkaSimulation<ParticleProblem>::setInitialConditionsOnGrid(quokka::grid const &grid_elem)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "quokka::grid" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:15:

- #include "hydro/EOS.hpp"
+ #include "grid.hpp"
+ #include "hydro/EOS.hpp"

template <> void QuokkaSimulation<ParticleProblem>::setInitialConditionsOnGrid(quokka::grid const &grid_elem)
{
const amrex::Box &indexRange = grid_elem.indexRange_;
const amrex::Array4<double> &state_cc = grid_elem.array_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Array4" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:9:

- #include "AMReX_BCRec.H"
+ #include "AMReX_Array4.H"
+ #include "AMReX_BCRec.H"

const auto Egas0 = initial_Egas;

// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::ParallelFor" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_GpuLaunchFunctsC.H"
+ #include "AMReX_REAL.H"


// get particle positions
quokka::CICRadParticleContainer<ParticleProblem> analysisPC{};
amrex::Box const box(amrex::IntVect{AMREX_D_DECL(0, 0, 0)}, amrex::IntVect{AMREX_D_DECL(1, 1, 1)});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_D_DECL" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:13:

- #include "AMReX_Vector.H"
+ #include "AMReX_SPACE.H"
+ #include "AMReX_Vector.H"

quokka::CICRadParticleContainer<ParticleProblem> analysisPC{};
amrex::Box const box(amrex::IntVect{AMREX_D_DECL(0, 0, 0)}, amrex::IntVect{AMREX_D_DECL(1, 1, 1)});
amrex::Geometry const geom(box);
amrex::BoxArray const boxArray(box);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::BoxArray" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_BoxArray.H"
+ #include "AMReX_REAL.H"

amrex::Geometry const geom(box);
amrex::BoxArray const boxArray(box);
amrex::Vector<int> const ranks({0}); // workaround nvcc bug
amrex::DistributionMapping const dmap(ranks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::DistributionMapping" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_DistributionMapping.H"
+ #include "AMReX_REAL.H"

sim.particleRegister_.getParticleDescriptor("CICRad_particles")->getParticleContainer<quokka::CICRadParticleContainer<ParticleProblem>>();
analysisPC.copyParticles(*container);

if (amrex::ParallelDescriptor::IOProcessor()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::ParallelDescriptor::IOProcessor" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_ParallelDescriptor.H"
+ #include "AMReX_REAL.H"

@chongchonghe
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@chongchonghe
Copy link
Contributor Author

chongchonghe commented Dec 31, 2024

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 49. Check the log or trigger a new build to see more.

src/particles/PhysicsParticles.hpp Show resolved Hide resolved
if (amrex::ParallelDescriptor::IOProcessor()) {
quokka::CICRadParticleIterator<ParticleProblem> const pIter(analysisPC, 0);
if (pIter.isValid()) {
const amrex::Long np = pIter.numParticles();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Long" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_INT.H"
+ #include "AMReX_REAL.H"

// copy particles from device to host
quokka::CICRadParticleContainer<ParticleProblem>::ParticleType *pData = particles().data();
amrex::Vector<quokka::CICRadParticleContainer<ParticleProblem>::ParticleType> pData_h(np);
amrex::Gpu::copy(amrex::Gpu::deviceToHost, pData, pData + np,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not use pointer arithmetic [cppcoreguidelines-pro-bounds-pointer-arithmetic]

			amrex::Gpu::copy(amrex::Gpu::deviceToHost, pData, pData + np,
                                                           ^

// copy particles from device to host
quokka::CICRadParticleContainer<ParticleProblem>::ParticleType *pData = particles().data();
amrex::Vector<quokka::CICRadParticleContainer<ParticleProblem>::ParticleType> pData_h(np);
amrex::Gpu::copy(amrex::Gpu::deviceToHost, pData, pData + np,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Gpu::copy" is directly included [misc-include-cleaner]

src/problems/GravRadParticle3D/test_grav_rad_particle_3D.cpp:12:

- #include "AMReX_REAL.H"
+ #include "AMReX_GpuContainers.H"
+ #include "AMReX_REAL.H"

// copy particles from device to host
quokka::CICRadParticleContainer<ParticleProblem>::ParticleType *pData = particles().data();
amrex::Vector<quokka::CICRadParticleContainer<ParticleProblem>::ParticleType> pData_h(np);
amrex::Gpu::copy(amrex::Gpu::deviceToHost, pData, pData + np,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Gpu::deviceToHost" is directly included [misc-include-cleaner]

			amrex::Gpu::copy(amrex::Gpu::deviceToHost, pData, pData + np,
                                ^

static constexpr int beta_order = 0;
static constexpr OpacityModel opacity_model = OpacityModel::piecewise_constant_opacity;
static constexpr double energy_unit = 1.0;
static constexpr amrex::GpuArray<double, nGroups_ + 1> radBoundaries{0.001, 1.0, 3.0, 100.0};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::GpuArray" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:6:

- #include "AMReX_Array4.H"
+ #include "AMReX_Array.H"
+ #include "AMReX_Array4.H"

// }

template <>
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE auto
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "AMREX_FORCE_INLINE" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:8:

- #include "AMReX_GpuQualifiers.H"
+ #include "AMReX_Extension.H"
+ #include "AMReX_GpuQualifiers.H"

const auto Egas0 = initial_Egas;

// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::ParallelFor" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:8:

- #include "AMReX_GpuQualifiers.H"
+ #include "AMReX_GpuLaunchFunctsC.H"
+ #include "AMReX_GpuQualifiers.H"

// loop over the grid and set the initial condition
amrex::ParallelFor(indexRange, [=] AMREX_GPU_DEVICE(int i, int j, int k) {
for (int g = 0; g < nGroups_; ++g) {
state_cc(i, j, k, RadSystem<ParticleProblem>::radEnergy_index + Physics_NumVars::numRadVars * g) = Erad0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Physics_NumVars" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:13:

- #include "radiation/radiation_system.hpp"
+ #include "physics_numVars.hpp"
+ #include "radiation/radiation_system.hpp"


// Boundary conditions
constexpr int nvars = RadSystem<ParticleProblem>::nvar_;
amrex::Vector<amrex::BCRec> BCs_cc(nvars);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::BCRec" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:7:

- #include "AMReX_Box.H"
+ #include "AMReX_BCRec.H"
+ #include "AMReX_Box.H"

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 29. Check the log or trigger a new build to see more.


// Boundary conditions
constexpr int nvars = RadSystem<ParticleProblem>::nvar_;
amrex::Vector<amrex::BCRec> BCs_cc(nvars);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Vector" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:9:

- #include "QuokkaSimulation.hpp"
+ #include "AMReX_Vector.H"
+ #include "QuokkaSimulation.hpp"

amrex::Vector<amrex::BCRec> BCs_cc(nvars);
for (int n = 0; n < nvars; ++n) {
for (int i = 0; i < AMREX_SPACEDIM; ++i) {
BCs_cc[n].setLo(i, amrex::BCType::int_dir); // periodic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::BCType::int_dir" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:7:

- #include "AMReX_Box.H"
+ #include "AMReX_BC_TYPES.H"
+ #include "AMReX_Box.H"

const double dx = sim.Geom(0).CellSize(0);

// compute error norm
std::vector<double> Erad_group0(nx);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:16:

- #ifdef HAVE_PYTHON
+ #include <vector>
+ #ifdef HAVE_PYTHON

double tot_lum_group1 = 0.0;
double tot_lum_group2 = 0.0;
for (int i = 0; i < nx; ++i) {
amrex::Real const x = position[i];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "amrex::Real" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:9:

- #include "QuokkaSimulation.hpp"
+ #include "AMReX_REAL.H"
+ #include "QuokkaSimulation.hpp"

const double lum_exact_group2 = lum3 * tmax;

const double err_norm =
std::abs(tot_lum_group0 - lum_exact_group0) + std::abs(tot_lum_group1 - lum_exact_group1) + std::abs(tot_lum_group2 - lum_exact_group2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::abs" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:15:

- #include <fmt/format.h>
+ #include <cstdlib>
+ #include <fmt/format.h>

matplotlibcpp::clf();
matplotlibcpp::ylim(-0.05, 1.4);

std::map<std::string, std::string> erad_args;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::map" is directly included [misc-include-cleaner]

src/problems/RadParticle/test_radparticle.cpp:16:

- #ifdef HAVE_PYTHON
+ #include <map>
+ #ifdef HAVE_PYTHON

///

#include "test_radparticle_2D.hpp"
#include "QuokkaSimulation.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header test_radparticle_2D.hpp is not used directly [misc-include-cleaner]

Suggested change
#include "QuokkaSimulation.hpp"
#include "QuokkaSimulation.hpp"


const double lum1 = 1.0;

template <> struct quokka::EOS_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "quokka::EOS_Traits" is directly included [misc-include-cleaner]

src/problems/RadParticle2D/test_radparticle_2D.cpp:6:

+ #include "hydro/EOS.hpp"

static constexpr double gamma = 5. / 3.;
};

template <> struct Physics_Traits<ParticleProblem> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "Physics_Traits" is directly included [misc-include-cleaner]

src/problems/RadParticle2D/test_radparticle_2D.cpp:6:

+ #include "physics_info.hpp"

// face-centred
static constexpr bool is_mhd_enabled = false;
static constexpr int nGroups = nGroups_; // number of radiation groups
static constexpr UnitSystem unit_system = UnitSystem::CONSTANTS;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "UnitSystem" is directly included [misc-include-cleaner]

	static constexpr UnitSystem unit_system = UnitSystem::CONSTANTS;
                  ^

// Redistribute particles after movement. This ensures particles are in the correct cells/processors for radiation deposition
// TODO(cch): I believe this is needed and missing this in the original code was a bug, but I don't understand why this was not caught earlier.
// Maybe the binary_orbit test was the only test for gravity and there was no multiple boxes in that test?
for (int lev = 0; lev <= finest_level; ++lev) {

Check notice

Code scanning / CodeQL

Declaration hides variable Note

Variable lev hides another variable of the same name (on
line 961
).
github-merge-queue bot pushed a commit that referenced this pull request Jan 13, 2025
### Description
add `misc-include-cleaner` to exclusion list of .clang-tidy. This will
get rid of warnings like `warning: no header providing
"AMREX_GPU_HOST_DEVICE" is directly included` in clang-tidy-review.

### Related issues
Should get rid of the `clang-tidy-review` failure in PR #827 . 

### 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 (if applicable; see
above).
- [x] I have read the [Contributing
Guide](https://github.com/quokka-astro/quokka/blob/development/CONTRIBUTING.md).
- [ ] I have added tests for any new physics that this PR adds to the
code.
- [ ] *(For quokka-astro org members)* I have manually triggered the GPU
tests with the magic comment `/azp run`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants