Skip to content

Particle Use Enum Class - #2176

Merged
jeremylt merged 6 commits into
4C-multiphysics:mainfrom
jeremylt:jeremy/enum-class
Aug 12, 2026
Merged

Particle Use Enum Class#2176
jeremylt merged 6 commits into
4C-multiphysics:mainfrom
jeremylt:jeremy/enum-class

Conversation

@jeremylt

Copy link
Copy Markdown
Contributor

The Dual View PR is rather big and difficult to review. I have pulled out some of the changes that can be easily reviewed and merged without anything to do about device access.

This PR includes swapping the enums over to enum classes specifically

After this #2136 will only have the Dual View changes.

Related Issues and Pull Requests

Subset of #2136, downstream of #2171

Disclosure of AI assistance

Some local AI review prompting after I wrote the code

@jeremylt

Copy link
Copy Markdown
Contributor Author

Note: Currently draft, will rebase after #2171 merges so it only has the enum changes

@jeremylt
jeremylt marked this pull request as draft August 11, 2026 08:01
@jeremylt
jeremylt force-pushed the jeremy/enum-class branch 3 times, most recently from 6093c9e to 93de4ae Compare August 11, 2026 09:31
@jeremylt
jeremylt marked this pull request as ready for review August 11, 2026 09:31
@jeremylt
jeremylt requested a lite review from Copilot August 11, 2026 09:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR is a preparatory refactor that converts the particle engine’s core enums (particle type, status, and state) from unscoped enum to scoped enum class, updating call sites across particle interactions/algorithms so the upcoming DualView/GPU work can be isolated in a smaller follow-up PR.

Changes:

  • Convert ParticleState, ParticleType, and ParticleStatus to enum class and update all usage sites to use scoped names (Particle::State::…, Particle::Type::…, Particle::Status::…).
  • Replace implicit enum→int conversions with explicit static_cast<int>(…) where enums are used for indexing (container storage, per-type vectors, etc.).
  • Update particle container tests and various interaction/algorithm components to compile with the new scoped enums.

Reviewed changes

Copilot reviewed 87 out of 87 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/pasi/4C_pasi_partitioned_twowaycoup.cpp Update particle container/status/state enum usage to scoped enums.
src/particle/tests/4C_particle_container_test.cpp Update tests for enum class states and explicit indexing casts.
src/particle/src/wall/4C_particle_wall.hpp Update API signatures to use Particle::Type/Particle::State.
src/particle/src/wall/4C_particle_wall.cpp Update state/type/status handling to scoped enums.
src/particle/src/rigidbody/4C_particle_rigidbody.hpp Update API signatures to use scoped enums.
src/particle/src/rigidbody/4C_particle_rigidbody_initial_field.cpp Update maps/switches to scoped state/type enums.
src/particle/src/interaction/4C_particle_interaction_sph.hpp Update virtual interface signature to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph.cpp Update type/status/state usage to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_virtual_wall_particle.hpp Update member sets from TypeEnum to Type.
src/particle/src/interaction/4C_particle_interaction_sph_virtual_wall_particle.cpp Update tuple unpacking and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_temperature.hpp Update type sets and signatures to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_temperature.cpp Update per-type vector indexing and state enums to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension.hpp Update type members/sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_recoilpressure_evaporation.hpp Update phase type member to scoped enum.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_recoilpressure_evaporation.cpp Update container access/state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_interface_viscosity.hpp Update type members/sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_interface_viscosity.cpp Update per-type vector indexing and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_barrier_force.hpp Update type members/sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_surface_tension_barrier_force.cpp Update tuple types and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_rigid_particle_contact.hpp Update boundary type set to scoped enum.
src/particle/src/interaction/4C_particle_interaction_sph_rigid_particle_contact.cpp Update relevant-type queries and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_pressure.hpp Update fluid type set to scoped enum.
src/particle/src/interaction/4C_particle_interaction_sph_pressure.cpp Update container/status/state usage to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_phase_change.hpp Update phase/state members to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_phase_change.cpp Update type/state indexing and container access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_peridynamic.hpp Update signature types to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_open_boundary.hpp Update phase members to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_neighbor_pairs.hpp Update query signatures to accept std::set<Particle::Type>.
src/particle/src/interaction/4C_particle_interaction_sph_neighbor_pairs.cpp Update per-type indexing to explicit casts for enum class.
src/particle/src/interaction/4C_particle_interaction_sph_momentum.hpp Update type sets and signatures to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_heatsource.hpp Update type sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_heatsource.cpp Update per-type indexing and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_heatloss_evaporation.hpp Update phase member to scoped enum.
src/particle/src/interaction/4C_particle_interaction_sph_heatloss_evaporation.cpp Update per-type indexing and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_equationofstate_bundle.hpp Update API to accept scoped Particle::Type and cast for indexing.
src/particle/src/interaction/4C_particle_interaction_sph_equationofstate_bundle.cpp Update per-type storage/indexing to explicit casts.
src/particle/src/interaction/4C_particle_interaction_sph_density.hpp Update base/derived signatures and type sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_boundary_particle.hpp Update type sets to scoped enums.
src/particle/src/interaction/4C_particle_interaction_sph_boundary_particle.cpp Update per-type indexing and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_pd_neighbor_pairs.cpp Update tuple element types and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_material_handler.hpp Update API types and cast for indexing into vectors.
src/particle/src/interaction/4C_particle_interaction_material_handler.cpp Update maps and per-type indexing to explicit casts.
src/particle/src/interaction/4C_particle_interaction_dem.hpp Update interaction signature to scoped enums.
src/particle/src/interaction/4C_particle_interaction_dem.cpp Update state access and container status usage to scoped enums.
src/particle/src/interaction/4C_particle_interaction_dem_neighbor_pairs.cpp Update tuple element types and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_dem_contact.hpp Update signature to scoped enums.
src/particle/src/interaction/4C_particle_interaction_dem_contact.cpp Update state access and status checks to scoped enums.
src/particle/src/interaction/4C_particle_interaction_dem_adhesion.cpp Update tuple element types and state access to scoped enums.
src/particle/src/interaction/4C_particle_interaction_base.hpp Update base interface signature to scoped enums.
src/particle/src/interaction/4C_particle_interaction_base.cpp Update container access and state access to scoped enums.
src/particle/src/engine/4C_particle_engine_typedefs.hpp Rename typedefs to Type/Status/State aliases.
src/particle/src/engine/4C_particle_engine_runtime_vtp_writer.cpp Update state blacklist and per-type/status indexing to explicit casts.
src/particle/src/engine/4C_particle_engine_refresh_entry.cpp Rename unpack temp variable and keep enum cast explicit.
src/particle/src/engine/4C_particle_engine_particlereader.cpp Update state enum usage and explicit sizing/index casts.
src/particle/src/engine/4C_particle_engine_object.cpp Update default constructor to use scoped type enum.
src/particle/src/engine/4C_particle_engine_enums.hpp Convert particle enums to enum class and adjust enumerator names.
src/particle/src/engine/4C_particle_engine_enums.cpp Update switch statements and name helpers for scoped enums + explicit casts.
src/particle/src/engine/4C_particle_engine_container.hpp Update indexing sites to cast scoped enums to int.
src/particle/src/engine/4C_particle_engine_container.cpp Update internal container storage/indexing to use explicit enum casts.
src/particle/src/engine/4C_particle_engine_container_bundle.hpp Update container lookup and forwarding helpers to cast type/status indices.
src/particle/src/engine/4C_particle_engine_container_bundle.cpp Update container allocation/indexing to use explicit casts.
src/particle/src/algorithm/4C_particle_algorithm.hpp Update state/type map member types to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm.cpp Update type/state sets and container access to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_viscous_damping.cpp Update type checks and state updates to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_utils.hpp Update template signature to use std::map<Particle::Type,…>.
src/particle/src/algorithm/4C_particle_algorithm_utils.cpp Update template impl/instantiations for scoped Particle::Type.
src/particle/src/algorithm/4C_particle_algorithm_timint.hpp Update type set and signature to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_timint.cpp Update excluded/integrated type sets and container access to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.hpp Update type sets/maps and signature to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.cpp Update container access and state usage to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_result_test.cpp Update state selection logic to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_input_generator.hpp Update generated particle type parameter to scoped enum.
src/particle/src/algorithm/4C_particle_algorithm_input_generator.cpp Update particle state storage sizing/indexing to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_initial_field.hpp Update state→type map to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_initial_field.cpp Update initial-field state/type maps to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.hpp Update type sets/maps and signature to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp Update state/type usage and container access to scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_constraints.hpp Update constraint handler interfaces to use scoped enums.
src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp Update container access and state usage to scoped enums.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/particle/src/interaction/4C_particle_interaction_pd_neighbor_pairs.cpp Outdated
jeremylt and others added 6 commits August 11, 2026 15:45
@jeremylt
jeremylt requested a review from mayrmt August 12, 2026 05:56
@jeremylt
jeremylt merged commit 29107ef into 4C-multiphysics:main Aug 12, 2026
48 checks passed
@jeremylt
jeremylt deleted the jeremy/enum-class branch August 12, 2026 08:29
Comment on lines 785 to +786
Particle::ParticleContainer* container =
particlecontainerbundle->get_specific_container(typeEnum, Particle::Owned);
particlecontainerbundle->get_specific_container(type, Particle::Status::Owned);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two notes on this examplary line:
In almost all cases, the namespace Particle:: can be removed because the code already is in the Particle namespace. This is mainly due to historical reasons. ParticleContainer has been in the ParticleEngine namespace. At some point, all particle-related namespaces were consolidated into one Particle namespace.

Particle::Status::Owned can be Status::Owned. Though I'm unsure how useful the typedefs are for this case. If we always want to use the typedef Status, we could have directly named the enum class Status. I'm slightly in favor of the enum classes ParticleState, ParticleStatus, and ParticleType because, for me, 'Particle' means in this context the state, status, or type for a "physical" particle and not a prefix due to being in the particle code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In almost all cases, the namespace Particle:: can be removed because the code already is in the Particle namespace. This is mainly due to historical reasons. ParticleContainer has been in the ParticleEngine namespace. At some point, all particle-related namespaces were consolidated into one Particle namespace.

This explains why I saw a mix of conventions.

Particle::Status::Owned can be Status::Owned. Though I'm unsure how useful the typedefs are for this case. If we always want to use the typedef Status, we could have directly named the enum class Status. I'm slightly in favor of the enum classes ParticleState, ParticleStatus, and ParticleType because, for me, 'Particle' means in this context the state, status, or type for a "physical" particle and not a prefix due to being in the particle code.

I was trying to avoid the awkward Particle::ParticleState::Owned business in code that isn't using Particle. Could use ParticleState::Owned when using Particle and Particle::State::Owned when not.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was trying to avoid the awkward Particle::ParticleState::Owned business in code that isn't using Particle. Could use ParticleState::Owned when using Particle and Particle::State::Owned when not.

This is a good compromise. Though I wouldn't change it in one big PR, but just gradually improve the code when working on specific sections.

@c-p-schmidt c-p-schmidt mentioned this pull request Aug 14, 2026
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants