Skip to content

Commit

Permalink
Add struct for cell-line/point
Browse files Browse the repository at this point in the history
  • Loading branch information
acdaigneault committed Aug 9, 2024
1 parent 496b99c commit d6531ce
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 111 deletions.
24 changes: 16 additions & 8 deletions include/dem/contact_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,18 @@ struct particle_line_contact_info
};

/**
* @brief Handle information related to the calculation of the particle-line
* contact forces. TODO
* @brief Handle information related to the calculation of the particle-point
* contact forces.
*/
template <int dim>
struct particle_point_contact_info
{
Particles::ParticleIterator<dim> particle;
Point<3> point;
};

/**
* @brief Handle information related to the cell-line matching.
*/
template <int dim>
struct cell_line_info
Expand All @@ -125,16 +135,14 @@ struct cell_line_info
Point<3> point_two;
};


/**
* @brief Handle information related to the calculation of the particle-point
* contact forces.
* @brief Handle information related to the cell-point matching.
*/
template <int dim>
struct particle_point_contact_info
struct cell_point_info
{
Particles::ParticleIterator<dim> particle;
Point<3> point;
typename Triangulation<dim>::active_cell_iterator cell;
Point<3> point;
};

#endif
7 changes: 3 additions & 4 deletions include/dem/data_containers.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ namespace DEM
particle_point_contact_info<dim>>
particle_point_in_contact;

// <particle id, (particle iterator, point, point)>
// <particle id, line info>
typedef std::unordered_map<types::particle_index,
particle_line_contact_info<dim>>
particle_line_candidates;

// <particle id, (particle iterator, point)>
typedef std::unordered_map<
types::particle_index,
std::pair<Particles::ParticleIterator<dim>, Point<dim>>>
typedef std::unordered_map<types::particle_index,
particle_point_contact_info<dim>>
particle_point_candidates;

// <particle id, <global face id, particle iterator>>
Expand Down
8 changes: 2 additions & 6 deletions include/dem/find_boundary_cells_information.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ class BoundaryCellsInformation
return boundary_cells_information;
}

std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>> &
std::unordered_map<std::string, cell_point_info<dim>> &
get_boundary_cells_with_points()
{
return boundary_cells_with_points;
Expand Down Expand Up @@ -248,9 +246,7 @@ class BoundaryCellsInformation
local_cells_with_boundary_lines;

// Structure that contains the boundary cells which have a point
std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>>
std::unordered_map<std::string, cell_point_info<dim>>
boundary_cells_with_points;

// Structure that contains the boundary cells with floating walls
Expand Down
8 changes: 2 additions & 6 deletions include/dem/particle_point_line_broad_search.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ template <int dim>
void
find_particle_point_contact_pairs(
const Particles::ParticleHandler<dim> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>>
const std::unordered_map<std::string, cell_point_info<dim>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<dim>::particle_point_candidates
&particle_point_contact_candidates);
Expand All @@ -74,9 +72,7 @@ template <int dim>
void
find_particle_point_contact_pairs(
const Particles::ParticleHandler<dim> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>>
const std::unordered_map<std::string, cell_point_info<dim>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<dim>::particle_point_candidates
&particle_point_contact_candidates,
Expand Down
22 changes: 15 additions & 7 deletions source/dem/find_boundary_cells_information.cc
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ BoundaryCellsInformation<dim>::find_particle_point_and_line_contact_cells(
{
all_cells_with_boundary_lines[cell->id()
.to_string()]
.insert(
{face->line_index(l),
std::make_pair(face->line(l)->vertex(0),
face->line(l)->vertex(1))});
.emplace(
face->line_index(l),
std::make_pair(face->line(l)->vertex(0),
face->line(l)->vertex(1)));
}
}
}
Expand Down Expand Up @@ -441,9 +441,17 @@ BoundaryCellsInformation<dim>::find_particle_point_and_line_contact_cells(
{
if (boundary_vertices.count(face->vertex_index(v)) > 0)
{
boundary_cells_with_points.insert(
{cell->id().to_string(),
std::make_pair(cell, face->vertex(v))});
Point<3> vertex;

if constexpr (dim == 3)
vertex = face->vertex(v);

if constexpr (dim == 2)
vertex = point_nd_to_3d(face->vertex(v));

boundary_cells_with_points.emplace(
cell->id().to_string(),
cell_point_info<dim>{cell, vertex});
}
}
}
Expand Down
71 changes: 26 additions & 45 deletions source/dem/particle_point_line_broad_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ template <int dim>
void
find_particle_point_contact_pairs(
const Particles::ParticleHandler<dim> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>>
const std::unordered_map<std::string, cell_point_info<dim>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<dim>::particle_point_candidates
&particle_point_contact_candidates)
Expand All @@ -31,19 +29,13 @@ find_particle_point_contact_pairs(
map_iterator != boundary_cells_with_points.end();
++map_iterator)
{
auto cells_with_boundary_points_information = &map_iterator->second;

// Getting the cell and boundary vertex as local variables
auto cell_with_boundary_point =
cells_with_boundary_points_information->first;

Point<dim> vertex_location =
cells_with_boundary_points_information->second;
const cell_point_info<dim> &cells_with_boundary_points_information =
map_iterator->second;

// Finding particles located in the corresponding cell
typename Particles::ParticleHandler<dim>::particle_iterator_range
particles_in_cell =
particle_handler.particles_in_cell(cell_with_boundary_point);
particles_in_cell = particle_handler.particles_in_cell(
cells_with_boundary_points_information.cell);

for (typename Particles::ParticleHandler<dim>::particle_iterator_range::
iterator particles_in_cell_iterator = particles_in_cell.begin();
Expand All @@ -53,9 +45,11 @@ find_particle_point_contact_pairs(
// Making the pair and adding it to the
// particle_point_contact_candidates map. This map is the output of
// this function
particle_point_contact_candidates.insert(
{contact_candidate_counter,
std::make_pair(particles_in_cell_iterator, vertex_location)});
particle_point_contact_candidates.emplace(
contact_candidate_counter,
particle_point_contact_info<dim>{
particles_in_cell_iterator,
cells_with_boundary_points_information.point});
++contact_candidate_counter;
}
}
Expand All @@ -65,9 +59,7 @@ template <int dim>
void
find_particle_point_contact_pairs(
const Particles::ParticleHandler<dim> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<dim>::active_cell_iterator, Point<dim>>>
const std::unordered_map<std::string, cell_point_info<dim>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<dim>::particle_point_candidates
&particle_point_contact_candidates,
Expand All @@ -89,25 +81,20 @@ find_particle_point_contact_pairs(
map_iterator != boundary_cells_with_points.end();
++map_iterator)
{
auto cells_with_boundary_points_information = &map_iterator->second;

// Getting the cell and boundary vertex as local variables
auto cell_with_boundary_point =
cells_with_boundary_points_information->first;
const cell_point_info<dim> &cells_with_boundary_points_information =
map_iterator->second;

// If main cell has status other than mobile, skip to next cell
unsigned int main_cell_mobility_status =
sparse_contacts_object.check_cell_mobility(cell_with_boundary_point);
sparse_contacts_object.check_cell_mobility(
cells_with_boundary_points_information.cell);
if (main_cell_mobility_status != AdaptiveSparseContacts<dim>::mobile)
continue;

Point<dim> vertex_location =
cells_with_boundary_points_information->second;

// Finding particles located in the corresponding cell
typename Particles::ParticleHandler<dim>::particle_iterator_range
particles_in_cell =
particle_handler.particles_in_cell(cell_with_boundary_point);
particles_in_cell = particle_handler.particles_in_cell(
cells_with_boundary_points_information.cell);

for (typename Particles::ParticleHandler<dim>::particle_iterator_range::
iterator particles_in_cell_iterator = particles_in_cell.begin();
Expand All @@ -117,9 +104,11 @@ find_particle_point_contact_pairs(
// Making the pair and adding it to the
// particle_point_contact_candidates map. This map is the output of
// this function
particle_point_contact_candidates.insert(
{contact_candidate_counter,
std::make_pair(particles_in_cell_iterator, vertex_location)});
particle_point_contact_candidates.emplace(
contact_candidate_counter,
particle_point_contact_info<dim>{
particles_in_cell_iterator,
cells_with_boundary_points_information.point});
++contact_candidate_counter;
}
}
Expand Down Expand Up @@ -271,29 +260,23 @@ find_particle_line_contact_pairs<3>(
template void
find_particle_point_contact_pairs<2>(
const Particles::ParticleHandler<2> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<2>::active_cell_iterator, Point<2>>>
const std::unordered_map<std::string, cell_point_info<2>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<2>::particle_point_candidates
&particle_point_contact_candidates);

template void
find_particle_point_contact_pairs<3>(
const Particles::ParticleHandler<3> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<3>::active_cell_iterator, Point<3>>>
const std::unordered_map<std::string, cell_point_info<3>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<3>::particle_point_candidates
&particle_point_contact_candidates);

template void
find_particle_point_contact_pairs<2>(
const Particles::ParticleHandler<2> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<2>::active_cell_iterator, Point<2>>>
const std::unordered_map<std::string, cell_point_info<2>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<2>::particle_point_candidates
&particle_point_contact_candidates,
Expand All @@ -302,9 +285,7 @@ find_particle_point_contact_pairs<2>(
template void
find_particle_point_contact_pairs<3>(
const Particles::ParticleHandler<3> &particle_handler,
const std::unordered_map<
std::string,
std::pair<typename Triangulation<3>::active_cell_iterator, Point<3>>>
const std::unordered_map<std::string, cell_point_info<3>>
&boundary_cells_with_points,
typename DEM::dem_data_structures<3>::particle_point_candidates
&particle_point_contact_candidates,
Expand Down
64 changes: 29 additions & 35 deletions source/dem/particle_point_line_fine_search.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,35 @@ particle_point_fine_search(
{
// Get the value of the map (pair candidate) from the
// contact_pair_candidates_iterator
auto pair_candidates = &contact_pair_candidates_iterator->second;

// Get the particle, particle properties and boundary vertex location once
// to improve efficiency
auto particle = std::get<0>(*pair_candidates);
auto particle_properties = particle->get_properties();
Point<3> vertex_location_3d;

if constexpr (dim == 3)
vertex_location_3d = std::get<1>(*pair_candidates);

if constexpr (dim == 2)
vertex_location_3d = point_nd_to_3d(std::get<1>(*pair_candidates));
const particle_point_contact_info<dim> &pair_candidates =
contact_pair_candidates_iterator->second;

Point<3> particle_location_3d;
if constexpr (dim == 3)
particle_location_3d = particle->get_location();
// Get the particle, particle diameter and boundary vertex location once
Particles::ParticleIterator<dim> particle = pair_candidates.particle;
double particle_diameter =
particle->get_properties()[DEM::PropertiesIndex::dp];

if constexpr (dim == 2)
particle_location_3d = point_nd_to_3d(particle->get_location());
Point<3> vertex_location = pair_candidates.point;
Point<3> particle_location = [&] {
if constexpr (dim == 3)
return particle->get_location();
else
return point_nd_to_3d(particle->get_location());
}();

// Calculation of the square_distance between the particle and boundary
// vertex
const double square_distance =
((particle_properties[DEM::PropertiesIndex::dp]) / 2) -
vertex_location_3d.distance_square(particle_location_3d);
(particle_diameter / 2.0) -
vertex_location.distance_square(particle_location);

// If the distance is larger than neighberhood threshold, then the
// If the distance is larger than neighborhood threshold, then the
// particle-point pair are in contact
if (square_distance > neighborhood_threshold)
{
// Adding contact info to the sample
particle_point_pairs_in_contact.emplace(
particle->get_id(),
particle_point_contact_info<dim>{particle, vertex_location_3d});
particle_point_pairs_in_contact.emplace(particle->get_id(),
pair_candidates);
}
}
}
Expand Down Expand Up @@ -99,20 +93,20 @@ particle_line_fine_search(
const particle_line_contact_info<dim> &pair_candidates =
contact_pair_candidates_iterator->second;

// Get the particle, particle properties and the locations of beginning
// and ending vertices of the boundary line once to improve efficiency
// Get the particle, particle diameter and the locations of beginning
// and ending vertices of the boundary line
Particles::ParticleIterator<dim> particle = pair_candidates.particle;
ArrayView<double> particle_properties = particle->get_properties();
double particle_diameter =
particle->get_properties()[DEM::PropertiesIndex::dp];

Point<3> vertex_one_location = pair_candidates.point_one;
Point<3> vertex_two_location = pair_candidates.point_two;
Point<3> particle_location;

if constexpr (dim == 3)
particle_location = particle->get_location();

if constexpr (dim == 2)
particle_location = point_nd_to_3d(particle->get_location());
Point<3> particle_location = [&] {
if constexpr (dim == 3)
return particle->get_location();
else
return point_nd_to_3d(particle->get_location());
}();

// For finding the particle-line distance, the projection of the particle
// on the line should be obtained
Expand All @@ -122,7 +116,7 @@ particle_line_fine_search(

// Calculation of the distance between the particle and boundary line
const double square_distance =
((particle_properties[DEM::PropertiesIndex::dp]) / 2) -
(particle_diameter / 2.0) -
projection.distance_square(particle_location);

// If the distance is positive, then the particle-line pair are in
Expand Down

0 comments on commit d6531ce

Please sign in to comment.