Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/particle/src/algorithm/4C_particle_algorithm_constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions src/particle/src/algorithm/4C_particle_algorithm_dirichlet_bc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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<int>(funct_id_ptr[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ void Particle::InitialFieldHandler::set_initial_fields()
Global::Problem::instance()->function_by_id<Core::Utils::FunctionOfSpaceTime>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ void Particle::TemperatureBoundaryConditionHandler::evaluate_temperature_boundar
Global::Problem::instance()->function_by_id<Core::Utils::FunctionOfSpaceTime>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/particle/src/engine/4C_particle_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/particle/src/engine/4C_particle_engine_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(state)]); ++i)
Expand All @@ -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<int>(state)]); ++i)
Expand Down
114 changes: 101 additions & 13 deletions src/particle/src/engine/4C_particle_engine_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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
*
Expand All @@ -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
*
Expand All @@ -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
*
Expand Down Expand Up @@ -285,9 +381,7 @@ 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, 0);
double* state_ptr = get_ptr_to_state_writable(state);

for (int i = 0; i < (particlestored_ * statedim_[static_cast<int>(state)]); ++i)
state_ptr[i] *= fac;
Expand Down Expand Up @@ -319,10 +413,8 @@ namespace Particle
FOUR_C_ASSERT(statedim_[static_cast<int>(stateA)] == statedim_[static_cast<int>(stateB)],
"dimensions of states do not match!");

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<int>(stateA)]); ++i)
state_a_ptr[i] = facA * state_a_ptr[i] + facB * state_b_ptr[i];
Expand All @@ -343,9 +435,7 @@ namespace Particle
FOUR_C_ASSERT(statedim_[static_cast<int>(state)] == static_cast<int>(val.size()),
"dimensions of states do not match!");

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<int>(state)]; ++dim)
Expand All @@ -363,9 +453,7 @@ 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, 0);
double* state_ptr = get_ptr_to_state_writable(state);

for (int i = 0; i < (particlestored_ * statedim_[static_cast<int>(state)]); ++i)
state_ptr[i] = 0.0;
Expand Down
Loading
Loading