From 9c01eb7b98b5309a60a4d4a92dfd4047c26218a5 Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Thu, 27 Aug 2026 15:36:28 +0200 Subject: [PATCH 1/5] Particle: minor test fix --- .../src/algorithm/4C_particle_algorithm_result_test.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/particle/src/algorithm/4C_particle_algorithm_result_test.cpp b/src/particle/src/algorithm/4C_particle_algorithm_result_test.cpp index 2cda298e8fe..27f9f44b8b1 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_result_test.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_result_test.cpp @@ -195,13 +195,10 @@ void Particle::ParticleResultTest::test_special( "state '{}' not found in container!", Particle::enum_to_state_name(particleState)); // get pointer to particle state - const double* state = container->get_ptr_to_state(particleState, 0); - - // get particle state dimension - int statedim = container->get_state_dim(particleState); + const double* state = container->get_ptr_to_state(particleState, index); // get actual result - actresult = state[statedim * index + dim]; + actresult = state[dim]; // compare values const int err = compare_values(actresult, "SPECIAL", result_container); From f38e43cddda1cf39f1e50a4d206d9d717436e3d9 Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Thu, 27 Aug 2026 07:29:00 +0200 Subject: [PATCH 2/5] Particle: accessor for all state data --- .../4C_particle_algorithm_constraints.cpp | 18 +-- .../4C_particle_algorithm_dirichlet_bc.cpp | 21 ++-- .../4C_particle_algorithm_initial_field.cpp | 4 +- .../4C_particle_algorithm_temperature_bc.cpp | 4 +- .../4C_particle_algorithm_timint.cpp | 2 +- .../src/engine/4C_particle_engine.cpp | 6 +- .../engine/4C_particle_engine_container.cpp | 4 +- .../engine/4C_particle_engine_container.hpp | 106 +++++++++++++++++- .../4C_particle_engine_runtime_vtp_writer.cpp | 3 +- .../4C_particle_interaction_dem.cpp | 37 +++--- .../4C_particle_interaction_sph_density.cpp | 6 +- ..._particle_interaction_sph_phase_change.cpp | 4 +- .../4C_particle_interaction_sph_pressure.cpp | 4 +- 13 files changed, 156 insertions(+), 63 deletions(-) diff --git a/src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp b/src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp index c382958b7a8..7a12ccc4a58 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp @@ -45,11 +45,11 @@ void Particle::ConstraintsProjectionBase::apply( if (n_particle_stored <= 0) continue; // get pointer to particle velocity and acceleration - double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity, 0); - double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration, 0); - double* modvel = container->try_get_ptr_to_state_writable(Particle::State::ModifiedVelocity, 0); + double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity); + double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration); + double* modvel = container->try_get_ptr_to_state_writable(Particle::State::ModifiedVelocity); double* modacc = - container->try_get_ptr_to_state_writable(Particle::State::ModifiedAcceleration, 0); + container->try_get_ptr_to_state_writable(Particle::State::ModifiedAcceleration); // get particle state dimension const int pos_state_dim = container->get_state_dim(Particle::State::Position); @@ -105,10 +105,10 @@ void Particle::ConstraintsProjectionBase::check_particles( if (n_particle_stored <= 0) continue; // get pointer to particle position - const double* pos = container->get_ptr_to_state(Particle::State::Position, 0); + const double* pos = container->get_ptr_to_state(Particle::State::Position); // get pointer to particle radius - const double* rad = container->get_ptr_to_state(Particle::State::Radius, 0); + const double* rad = container->get_ptr_to_state(Particle::State::Radius); // get particle state dimension const int pos_state_dim = container->get_state_dim(Particle::State::Position); @@ -145,8 +145,8 @@ int Particle::ConstraintsProjection2D::calc_primary_axis_local( if (n_particle_stored < 3) continue; // get pointer to particle position and radius - const double* pos = container->get_ptr_to_state(Particle::State::Position, 0); - const double* rad = container->get_ptr_to_state(Particle::State::Radius, 0); + const double* pos = container->get_ptr_to_state(Particle::State::Position); + const double* rad = container->get_ptr_to_state(Particle::State::Radius); // get particle state dimension const int pos_state_dim = container->get_state_dim(Particle::State::Position); @@ -271,7 +271,7 @@ int Particle::ConstraintsProjection1D::calc_primary_axis_local( if (n_particle_stored < 2) continue; // get pointer to particle position - const double* pos = container->get_ptr_to_state(Particle::State::Position, 0); + const double* pos = container->get_ptr_to_state(Particle::State::Position); // get particle state dimension const int pos_state_dim = container->get_state_dim(Particle::State::Position); diff --git a/src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp b/src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp index 23753a3b509..b5156d2e7d3 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp @@ -209,10 +209,10 @@ void Particle::DirichletBoundaryConditionHandler::evaluate_dirichlet_boundary_co "dimension of function defining dirichlet boundary condition not correct!"); // get pointer to particle states - const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition, 0); - double* pos = container->get_ptr_to_state_writable(Particle::State::Position, 0); - double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity, 0); - double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration, 0); + const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition); + double* pos = container->get_ptr_to_state_writable(Particle::State::Position); + double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity); + double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration); // iterate over owned particles of current type and apply dbc values to particle states for (int i = 0; i < particlestored; ++i) @@ -239,11 +239,11 @@ void Particle::DirichletBoundaryConditionHandler::evaluate_dirichlet_boundary_co // get pointer to particle states const double* dirichlet_function_id = - container->get_ptr_to_state(Particle::State::DirichletFunctionId, 0); - const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition, 0); - double* pos = container->get_ptr_to_state_writable(Particle::State::Position, 0); - double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity, 0); - double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration, 0); + container->get_ptr_to_state(Particle::State::DirichletFunctionId); + const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition); + double* pos = container->get_ptr_to_state_writable(Particle::State::Position); + double* vel = container->get_ptr_to_state_writable(Particle::State::Velocity); + double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration); // iterate over owned particles of current type for (int i = 0; i < particlestored; ++i) @@ -285,8 +285,7 @@ void Particle::DirichletBoundaryConditionHandler::build_funct_cache(MPI_Comm com const int n = container->particles_stored(); if (n <= 0) continue; - const double* funct_id_ptr = - container->get_ptr_to_state(Particle::State::DirichletFunctionId, 0); + const double* funct_id_ptr = container->get_ptr_to_state(Particle::State::DirichletFunctionId); for (int i = 0; i < n; ++i) { const int funct_id = static_cast(funct_id_ptr[i]); diff --git a/src/particle/src/algorithm/4C_particle_algorithm_initial_field.cpp b/src/particle/src/algorithm/4C_particle_algorithm_initial_field.cpp index cf6c2cfabc9..a4444a7f8a5 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_initial_field.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_initial_field.cpp @@ -92,8 +92,8 @@ void Particle::InitialFieldHandler::set_initial_fields() Global::Problem::instance()->function_by_id(functid); // get pointer to particle states - const double* pos = container->get_ptr_to_state(Particle::State::Position, 0); - double* state = container->get_ptr_to_state_writable(particleState, 0); + const double* pos = container->get_ptr_to_state(Particle::State::Position); + double* state = container->get_ptr_to_state_writable(particleState); // get particle state dimensions int posstatedim = container->get_state_dim(Particle::State::Position); diff --git a/src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.cpp b/src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.cpp index 6edb7176932..6ab99251e5e 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_temperature_bc.cpp @@ -105,8 +105,8 @@ void Particle::TemperatureBoundaryConditionHandler::evaluate_temperature_boundar Global::Problem::instance()->function_by_id(functid); // get pointer to particle states - const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition, 0); - double* temp = container->get_ptr_to_state_writable(Particle::State::Temperature, 0); + const double* refpos = container->get_ptr_to_state(Particle::State::ReferencePosition); + double* temp = container->get_ptr_to_state_writable(Particle::State::Temperature); // get particle state dimension int statedim = container->get_state_dim(Particle::State::Position); diff --git a/src/particle/src/algorithm/4C_particle_algorithm_timint.cpp b/src/particle/src/algorithm/4C_particle_algorithm_timint.cpp index aacfcb4fa64..7514d0cd3cb 100644 --- a/src/particle/src/algorithm/4C_particle_algorithm_timint.cpp +++ b/src/particle/src/algorithm/4C_particle_algorithm_timint.cpp @@ -206,7 +206,7 @@ void Particle::TimInt::add_initial_random_noise_to_position() if (particlestored <= 0) continue; // get pointer to particle state - double* pos = container->get_ptr_to_state_writable(Particle::State::Position, 0); + double* pos = container->get_ptr_to_state_writable(Particle::State::Position); // get particle state dimension int statedim = container->get_state_dim(Particle::State::Position); diff --git a/src/particle/src/engine/4C_particle_engine.cpp b/src/particle/src/engine/4C_particle_engine.cpp index d2398d860e0..b5a77e609fd 100644 --- a/src/particle/src/engine/4C_particle_engine.cpp +++ b/src/particle/src/engine/4C_particle_engine.cpp @@ -2012,8 +2012,8 @@ void Particle::ParticleEngine::store_positions_after_particle_transfer() if (particlestored == 0) continue; // get pointer to particle states - const double* pos = container->get_ptr_to_state(State::Position, 0); - double* lasttransferpos = container->get_ptr_to_state_writable(State::LastTransferPosition, 0); + const double* pos = container->get_ptr_to_state(State::Position); + double* lasttransferpos = container->get_ptr_to_state_writable(State::LastTransferPosition); // get particle state dimension int statedim = container->get_state_dim(State::Position); @@ -2046,7 +2046,7 @@ void Particle::ParticleEngine::relate_owned_particles_to_bins() if (particlestored <= 0) continue; // get pointer to position of particle after last transfer - const double* lasttransferpos = container->get_ptr_to_state(State::LastTransferPosition, 0); + const double* lasttransferpos = container->get_ptr_to_state(State::LastTransferPosition); // get particle state dimension int statedim = container->get_state_dim(State::Position); diff --git a/src/particle/src/engine/4C_particle_engine_container.cpp b/src/particle/src/engine/4C_particle_engine_container.cpp index 1d37b72a199..df2f2ca5e49 100644 --- a/src/particle/src/engine/4C_particle_engine_container.cpp +++ b/src/particle/src/engine/4C_particle_engine_container.cpp @@ -264,7 +264,7 @@ double Particle::ParticleContainer::get_min_value_of_state(Particle::State state if (particlestored_ <= 0) return 0.0; - const double* state_ptr = get_ptr_to_state(state, 0); + const double* state_ptr = get_ptr_to_state(state); double min = state_ptr[0]; for (int i = 1; i < (particlestored_ * statedim_[static_cast(state)]); ++i) @@ -280,7 +280,7 @@ double Particle::ParticleContainer::get_max_value_of_state(Particle::State state if (particlestored_ <= 0) return 0.0; - const double* state_ptr = get_ptr_to_state(state, 0); + const double* state_ptr = get_ptr_to_state(state); double max = state_ptr[0]; for (int i = 1; i < (particlestored_ * statedim_[static_cast(state)]); ++i) diff --git a/src/particle/src/engine/4C_particle_engine_container.hpp b/src/particle/src/engine/4C_particle_engine_container.hpp index f2d94211633..6ff6ba1105a 100644 --- a/src/particle/src/engine/4C_particle_engine_container.hpp +++ b/src/particle/src/engine/4C_particle_engine_container.hpp @@ -183,6 +183,32 @@ namespace Particle */ const double* get_ptr_to_state(Particle::State state, int index) const; + /*! + * \brief get read-only pointer to state of all particles + * + * This is the default method to be used to get a pointer with read-only access to the state of + * all particles. Returns a nullptr if the container is empty. + * + * \note Throws an error in the debug version in case the requested state is not stored in the + * particle container. + * + * \note The returned pointer may not be used to access memory without checking for a nullptr. + * + * + * \param[in] state particle state + * + * \return pointer with read-only access to particle state or nullptr + */ + inline const double* get_ptr_to_state(Particle::State state) const + { + FOUR_C_ASSERT(storedstates_.contains(state), "particle state '{}' not stored in container!", + enum_to_state_name(state)); + + if (particlestored_ == 0) return nullptr; + + return get_ptr_to_state(state, 0); + }; + /*! * \brief conditionally get read-only pointer to state of a particle at index * @@ -209,6 +235,28 @@ namespace Particle return nullptr; }; + /*! + * \brief conditionally get read-only pointer to state of all particles + * + * This method to get a pointer with read-only access to the state of all particles + * is used in cases when a state may not be stored in the particle container. + * Conditionally, a pointer is returned in case the state is stored in the particle container, + * otherwise, a nullptr is returned. Returns a nullptr if the container is empty. + * + * \note The returned pointer may not be used to access memory without checking for a nullptr. + * + * + * \param[in] state particle state + * + * \return pointer with read-only access to particle state or nullptr + */ + inline const double* try_get_ptr_to_state(Particle::State state) const + { + if (particlestored_ == 0) return nullptr; + + return try_get_ptr_to_state(state, 0); + }; + /*! * \brief get writable pointer to state of a particle at index * @@ -226,6 +274,32 @@ namespace Particle */ double* get_ptr_to_state_writable(Particle::State state, int index); + /*! + * \brief get writable pointer to state of all particles + * + * This is the default method to be used to get a pointer with writable access to the state of + * all particles. Returns a nullptr if the container is empty. + * + * \note Throws an error in the debug version in case the requested state is not stored in the + * particle container. + * + * \note The returned pointer may not be used to access memory without checking for a nullptr. + * + * + * \param[in] state particle state + * + * \return pointer with writable access to particle state or nullptr + */ + double* get_ptr_to_state_writable(Particle::State state) + { + FOUR_C_ASSERT(storedstates_.contains(state), "particle state '{}' not stored in container!", + enum_to_state_name(state)); + + if (particlestored_ == 0) return nullptr; + + return get_ptr_to_state_writable(state, 0); + }; + /*! * \brief conditionally get writable pointer to state of a particle at index * @@ -252,6 +326,28 @@ namespace Particle return nullptr; }; + /*! + * \brief conditionally get writable pointer to state of all particles + * + * This method to get a pointer with writable access to the state of all particles + * is used in cases when a state may not be stored in the particle container. + * Conditionally, a pointer is returned in case the state is stored in the particle container, + * otherwise, a nullptr is returned. Returns a nullptr if the container is empty. + * + * \note The returned pointer may not be used to access memory without checking for a nullptr. + * + * + * \param[in] state particle state + * + * \return pointer with writable access to particle state or nullptr + */ + inline double* try_get_ptr_to_state_writable(Particle::State state) + { + if (particlestored_ == 0) return nullptr; + + return try_get_ptr_to_state_writable(state, 0); + }; + /*! * \brief get pointer to global id of a particle at index * @@ -287,7 +383,7 @@ namespace Particle if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state, 0); + double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < (particlestored_ * statedim_[static_cast(state)]); ++i) state_ptr[i] *= fac; @@ -321,8 +417,8 @@ namespace Particle if (particlestored_ <= 0) return; - const double* state_b_ptr = get_ptr_to_state(stateB, 0); - double* state_a_ptr = get_ptr_to_state_writable(stateA, 0); + const double* state_b_ptr = get_ptr_to_state(stateB); + double* state_a_ptr = get_ptr_to_state_writable(stateA); for (int i = 0; i < (particlestored_ * statedim_[static_cast(stateA)]); ++i) state_a_ptr[i] = facA * state_a_ptr[i] + facB * state_b_ptr[i]; @@ -345,7 +441,7 @@ namespace Particle if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state, 0); + double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < particlestored_; ++i) for (int dim = 0; dim < statedim_[static_cast(state)]; ++dim) @@ -365,7 +461,7 @@ namespace Particle if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state, 0); + double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < (particlestored_ * statedim_[static_cast(state)]); ++i) state_ptr[i] = 0.0; diff --git a/src/particle/src/engine/4C_particle_engine_runtime_vtp_writer.cpp b/src/particle/src/engine/4C_particle_engine_runtime_vtp_writer.cpp index 1df023df1f6..dee1dcb3efa 100644 --- a/src/particle/src/engine/4C_particle_engine_runtime_vtp_writer.cpp +++ b/src/particle/src/engine/4C_particle_engine_runtime_vtp_writer.cpp @@ -121,8 +121,7 @@ void Particle::ParticleRuntimeVtpWriter::set_particle_positions_and_states() std::string statename = enum_to_state_name(state); // get pointer to particle state - const double* state_ptr = - (particlestored > 0) ? container->get_ptr_to_state(state, 0) : nullptr; + const double* state_ptr = container->get_ptr_to_state(state); if (state == State::Position) { diff --git a/src/particle/src/interaction/4C_particle_interaction_dem.cpp b/src/particle/src/interaction/4C_particle_interaction_dem.cpp index b5939419e10..f975c63ff43 100644 --- a/src/particle/src/interaction/4C_particle_interaction_dem.cpp +++ b/src/particle/src/interaction/4C_particle_interaction_dem.cpp @@ -334,7 +334,7 @@ void Particle::ParticleInteractionDEM::set_initial_radius() particlematerial_->get_ptr_to_particle_mat_parameter(type_i); // get pointer to particle state - double* radius = container->get_ptr_to_state_writable(Particle::State::Radius, 0); + double* radius = container->get_ptr_to_state_writable(Particle::State::Radius); // determine mu of random particle radius distribution const double mu = (radiusdistributiontype == Particle::NormalRadiusDistribution) @@ -392,8 +392,8 @@ void Particle::ParticleInteractionDEM::set_initial_mass() particlematerial_->get_ptr_to_particle_mat_parameter(type_i); // get pointer to particle states - const double* radius = container->get_ptr_to_state(Particle::State::Radius, 0); - double* mass = container->get_ptr_to_state_writable(Particle::State::Mass, 0); + const double* radius = container->get_ptr_to_state(Particle::State::Radius); + double* mass = container->get_ptr_to_state_writable(Particle::State::Mass); // compute mass via particle volume and initial density const double fac = material->initDensity_ * 4.0 / 3.0 * std::numbers::pi; @@ -420,9 +420,9 @@ void Particle::ParticleInteractionDEM::set_initial_inertia() if (not container->have_stored_state(Particle::State::Inertia)) continue; // get pointer to particle states - const double* radius = container->get_ptr_to_state(Particle::State::Radius, 0); - const double* mass = container->get_ptr_to_state(Particle::State::Mass, 0); - double* inertia = container->get_ptr_to_state_writable(Particle::State::Inertia, 0); + const double* radius = container->get_ptr_to_state(Particle::State::Radius); + const double* mass = container->get_ptr_to_state(Particle::State::Mass); + double* inertia = container->get_ptr_to_state_writable(Particle::State::Inertia); // compute mass via particle volume and initial density for (int i = 0; i < particlestored; ++i) @@ -469,13 +469,12 @@ void Particle::ParticleInteractionDEM::compute_acceleration() const const int statedim = container->get_state_dim(Particle::State::Acceleration); // get pointer to particle states - const double* radius = container->get_ptr_to_state(Particle::State::Radius, 0); - const double* mass = container->get_ptr_to_state(Particle::State::Mass, 0); - const double* force = container->get_ptr_to_state(Particle::State::Force, 0); - const double* moment = container->try_get_ptr_to_state(Particle::State::Moment, 0); - double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration, 0); - double* angacc = - container->try_get_ptr_to_state_writable(Particle::State::AngularAcceleration, 0); + const double* radius = container->get_ptr_to_state(Particle::State::Radius); + const double* mass = container->get_ptr_to_state(Particle::State::Mass); + const double* force = container->get_ptr_to_state(Particle::State::Force); + const double* moment = container->try_get_ptr_to_state(Particle::State::Moment); + double* acc = container->get_ptr_to_state_writable(Particle::State::Acceleration); + double* angacc = container->try_get_ptr_to_state_writable(Particle::State::AngularAcceleration); // compute acceleration for (int i = 0; i < particlestored; ++i) @@ -550,10 +549,10 @@ void Particle::ParticleInteractionDEM::evaluate_particle_kinetic_energy(double& const int statedim = container->get_state_dim(Particle::State::Position); // get pointer to particle states - const double* radius = container->get_ptr_to_state(Particle::State::Radius, 0); - const double* mass = container->get_ptr_to_state(Particle::State::Mass, 0); - const double* vel = container->get_ptr_to_state(Particle::State::Velocity, 0); - const double* angvel = container->try_get_ptr_to_state(Particle::State::AngularVelocity, 0); + const double* radius = container->get_ptr_to_state(Particle::State::Radius); + const double* mass = container->get_ptr_to_state(Particle::State::Mass); + const double* vel = container->get_ptr_to_state(Particle::State::Velocity); + const double* angvel = container->try_get_ptr_to_state(Particle::State::AngularVelocity); // add translational kinetic energy contribution for (int i = 0; i < particlestored; ++i) @@ -594,8 +593,8 @@ void Particle::ParticleInteractionDEM::evaluate_particle_gravitational_potential const int statedim = container->get_state_dim(Particle::State::Position); // get pointer to particle states - const double* pos = container->get_ptr_to_state(Particle::State::Position, 0); - const double* mass = container->get_ptr_to_state(Particle::State::Mass, 0); + const double* pos = container->get_ptr_to_state(Particle::State::Position); + const double* mass = container->get_ptr_to_state(Particle::State::Mass); // add gravitational potential energy contribution for (int i = 0; i < particlestored; ++i) diff --git a/src/particle/src/interaction/4C_particle_interaction_sph_density.cpp b/src/particle/src/interaction/4C_particle_interaction_sph_density.cpp index 140c46efdba..fe753ac2d5a 100644 --- a/src/particle/src/interaction/4C_particle_interaction_sph_density.cpp +++ b/src/particle/src/interaction/4C_particle_interaction_sph_density.cpp @@ -924,9 +924,9 @@ void Particle::SPHDensityPredictCorrect::correct_density() const if (particlestored <= 0) continue; // get pointer to particle state - const double* denssum = container_i->get_ptr_to_state(Particle::State::DensitySum, 0); - const double* colorfield = container_i->get_ptr_to_state(Particle::State::Colorfield, 0); - double* dens = container_i->get_ptr_to_state_writable(Particle::State::Density, 0); + const double* denssum = container_i->get_ptr_to_state(Particle::State::DensitySum); + const double* colorfield = container_i->get_ptr_to_state(Particle::State::Colorfield); + double* dens = container_i->get_ptr_to_state_writable(Particle::State::Density); // get material for current particle type const Mat::PAR::ParticleMaterialBase* material = diff --git a/src/particle/src/interaction/4C_particle_interaction_sph_phase_change.cpp b/src/particle/src/interaction/4C_particle_interaction_sph_phase_change.cpp index 8430e1a7769..a65be6a6d5c 100644 --- a/src/particle/src/interaction/4C_particle_interaction_sph_phase_change.cpp +++ b/src/particle/src/interaction/4C_particle_interaction_sph_phase_change.cpp @@ -154,7 +154,7 @@ void Particle::SPHPhaseChangeBase::evaluate_phase_change_from_below_to_above_pha if (particlestored <= 0) return; // get pointer to particle state - const double* state = container->get_ptr_to_state(transitionstate_, 0); + const double* state = container->get_ptr_to_state(transitionstate_); // get material for particle types const Mat::PAR::ParticleMaterialBase* material_source = @@ -239,7 +239,7 @@ void Particle::SPHPhaseChangeBase::evaluate_phase_change_from_above_to_below_pha if (particlestored <= 0) return; // get pointer to particle state - const double* state = container->get_ptr_to_state(transitionstate_, 0); + const double* state = container->get_ptr_to_state(transitionstate_); // get material for particle types const Mat::PAR::ParticleMaterialBase* material_source = diff --git a/src/particle/src/interaction/4C_particle_interaction_sph_pressure.cpp b/src/particle/src/interaction/4C_particle_interaction_sph_pressure.cpp index fe630bbdeef..9029dbefc86 100644 --- a/src/particle/src/interaction/4C_particle_interaction_sph_pressure.cpp +++ b/src/particle/src/interaction/4C_particle_interaction_sph_pressure.cpp @@ -73,8 +73,8 @@ void Particle::SPHPressure::compute_pressure() const if (particlestored <= 0) continue; // get pointer to particle state - const double* dens = container->get_ptr_to_state(Particle::State::Density, 0); - double* press = container->get_ptr_to_state_writable(Particle::State::Pressure, 0); + const double* dens = container->get_ptr_to_state(Particle::State::Density); + double* press = container->get_ptr_to_state_writable(Particle::State::Pressure); // get material for current particle type const Mat::PAR::ParticleMaterialBase* material = From 8c08395e8b4ac7d935c11c98689fb0af61e8433f Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Thu, 27 Aug 2026 11:59:10 +0200 Subject: [PATCH 3/5] Particle: add test for full state access --- .../tests/4C_particle_container_test.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/particle/tests/4C_particle_container_test.cpp b/src/particle/tests/4C_particle_container_test.cpp index 0935c3a5906..f74e112c562 100644 --- a/src/particle/tests/4C_particle_container_test.cpp +++ b/src/particle/tests/4C_particle_container_test.cpp @@ -19,6 +19,7 @@ namespace { protected: std::unique_ptr container_; + std::unique_ptr container_empty_; int statesvectorsize_; @@ -32,6 +33,10 @@ namespace container_ = std::make_unique(); container_->setup(size, stateEnumSet); + // and the empty container + container_empty_ = std::make_unique(); + container_empty_->setup(0, stateEnumSet); + const int maximum_stored_state_enum_set_value{static_cast(*(--stateEnumSet.end()))}; statesvectorsize_ = maximum_stored_state_enum_set_value + 1; @@ -301,12 +306,19 @@ namespace { double* newmass = container_->get_ptr_to_state_writable(Particle::State::Mass, index); newmass[0] = newmass[0] * 3.14; + + double* newvel = container_->get_ptr_to_state_writable(Particle::State::Velocity); + newvel[index * 3] = newvel[index * 3] * 3.14; } { const double* currmass = container_->get_ptr_to_state(Particle::State::Mass, index); EXPECT_NEAR(currmass[0], mass[0] * 3.14, 1e-14); + + const double* currvel = container_->get_ptr_to_state(Particle::State::Velocity, index); + EXPECT_NEAR(currvel[0], vel[0] * 3.14, 1e-14); } } + EXPECT_EQ(container_empty_->get_ptr_to_state(Particle::State::Velocity), nullptr); } TEST_F(ParticleContainerTest, TryGetPtrToState) @@ -360,21 +372,35 @@ namespace { double* newmass = container_->try_get_ptr_to_state_writable(Particle::State::Mass, index); newmass[0] = newmass[0] * 3.14; + + double* newvel = container_->try_get_ptr_to_state_writable(Particle::State::Velocity); + newvel[index * 3] = newvel[index * 3] * 3.14; } { const double* currmass = container_->try_get_ptr_to_state(Particle::State::Mass, index); EXPECT_NEAR(currmass[0], mass[0] * 3.14, 1e-14); + + const double* currvel = container_->try_get_ptr_to_state(Particle::State::Velocity, index); + EXPECT_NEAR(currvel[0], vel[0] * 3.14, 1e-14); } } + EXPECT_EQ(container_empty_->try_get_ptr_to_state(Particle::State::Velocity), nullptr); } TEST_F(ParticleContainerTest, TryGetPtrToStateNotStored) { - const double* acc = container_->try_get_ptr_to_state(Particle::State::Acceleration, 0); + const double* acc_0 = container_->try_get_ptr_to_state(Particle::State::Acceleration, 0); + EXPECT_EQ(acc_0, nullptr); + + const double* acc = container_->try_get_ptr_to_state(Particle::State::Acceleration); EXPECT_EQ(acc, nullptr); - double* angacc = + double* angacc_0 = container_->try_get_ptr_to_state_writable(Particle::State::AngularAcceleration, 0); + EXPECT_EQ(angacc_0, nullptr); + + double* angacc = + container_->try_get_ptr_to_state_writable(Particle::State::AngularAcceleration); EXPECT_EQ(angacc, nullptr); } From 609f83c9595a0d90e9b3687a1b3790916e90cd34 Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Thu, 27 Aug 2026 14:49:02 +0200 Subject: [PATCH 4/5] Particle: remove redundant returns --- src/particle/src/engine/4C_particle_engine_container.hpp | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/particle/src/engine/4C_particle_engine_container.hpp b/src/particle/src/engine/4C_particle_engine_container.hpp index 6ff6ba1105a..c80439b7dfd 100644 --- a/src/particle/src/engine/4C_particle_engine_container.hpp +++ b/src/particle/src/engine/4C_particle_engine_container.hpp @@ -381,8 +381,6 @@ namespace Particle FOUR_C_ASSERT(storedstates_.contains(state), "particle state '{}' not stored in container!", enum_to_state_name(state)); - if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < (particlestored_ * statedim_[static_cast(state)]); ++i) @@ -415,8 +413,6 @@ namespace Particle FOUR_C_ASSERT(statedim_[static_cast(stateA)] == statedim_[static_cast(stateB)], "dimensions of states do not match!"); - if (particlestored_ <= 0) return; - const double* state_b_ptr = get_ptr_to_state(stateB); double* state_a_ptr = get_ptr_to_state_writable(stateA); @@ -439,8 +435,6 @@ namespace Particle FOUR_C_ASSERT(statedim_[static_cast(state)] == static_cast(val.size()), "dimensions of states do not match!"); - if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < particlestored_; ++i) @@ -459,8 +453,6 @@ namespace Particle FOUR_C_ASSERT(storedstates_.contains(state), "particle state '{}' not stored in container!", enum_to_state_name(state)); - if (particlestored_ <= 0) return; - double* state_ptr = get_ptr_to_state_writable(state); for (int i = 0; i < (particlestored_ * statedim_[static_cast(state)]); ++i) From 33e0782dc6464d4ed4fccc2fd59d775bc1de679e Mon Sep 17 00:00:00 2001 From: Jeremy L Thompson Date: Tue, 1 Sep 2026 11:36:35 +0200 Subject: [PATCH 5/5] Particle: add few extra test asserts Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: Jeremy L Thompson --- src/particle/tests/4C_particle_container_test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/particle/tests/4C_particle_container_test.cpp b/src/particle/tests/4C_particle_container_test.cpp index f74e112c562..c076175d445 100644 --- a/src/particle/tests/4C_particle_container_test.cpp +++ b/src/particle/tests/4C_particle_container_test.cpp @@ -319,6 +319,7 @@ namespace } } EXPECT_EQ(container_empty_->get_ptr_to_state(Particle::State::Velocity), nullptr); + EXPECT_EQ(container_empty_->get_ptr_to_state_writable(Particle::State::Velocity), nullptr); } TEST_F(ParticleContainerTest, TryGetPtrToState) @@ -385,6 +386,7 @@ namespace } } EXPECT_EQ(container_empty_->try_get_ptr_to_state(Particle::State::Velocity), nullptr); + EXPECT_EQ(container_empty_->try_get_ptr_to_state_writable(Particle::State::Velocity), nullptr); } TEST_F(ParticleContainerTest, TryGetPtrToStateNotStored)