diff --git a/include/dem/contact_info.h b/include/dem/contact_info.h index 19989106af..df7ea28072 100644 --- a/include/dem/contact_info.h +++ b/include/dem/contact_info.h @@ -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 +struct particle_point_contact_info +{ + Particles::ParticleIterator particle; + Point<3> point; +}; + +/** + * @brief Handle information related to the cell-line matching. */ template struct cell_line_info @@ -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 -struct particle_point_contact_info +struct cell_point_info { - Particles::ParticleIterator particle; - Point<3> point; + typename Triangulation::active_cell_iterator cell; + Point<3> point; }; #endif diff --git a/include/dem/data_containers.h b/include/dem/data_containers.h index 5e371ff554..c1a2f722be 100644 --- a/include/dem/data_containers.h +++ b/include/dem/data_containers.h @@ -129,15 +129,14 @@ namespace DEM particle_point_contact_info> particle_point_in_contact; - // + // typedef std::unordered_map> particle_line_candidates; // - typedef std::unordered_map< - types::particle_index, - std::pair, Point>> + typedef std::unordered_map> particle_point_candidates; // > diff --git a/include/dem/find_boundary_cells_information.h b/include/dem/find_boundary_cells_information.h index 7dd819b70d..3433865cc6 100644 --- a/include/dem/find_boundary_cells_information.h +++ b/include/dem/find_boundary_cells_information.h @@ -88,9 +88,7 @@ class BoundaryCellsInformation return boundary_cells_information; } - std::unordered_map< - std::string, - std::pair::active_cell_iterator, Point>> & + std::unordered_map> & get_boundary_cells_with_points() { return boundary_cells_with_points; @@ -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::active_cell_iterator, Point>> + std::unordered_map> boundary_cells_with_points; // Structure that contains the boundary cells with floating walls diff --git a/include/dem/particle_point_line_broad_search.h b/include/dem/particle_point_line_broad_search.h index 9463278da9..68b8d7206f 100644 --- a/include/dem/particle_point_line_broad_search.h +++ b/include/dem/particle_point_line_broad_search.h @@ -46,9 +46,7 @@ template void find_particle_point_contact_pairs( const Particles::ParticleHandler &particle_handler, - const std::unordered_map< - std::string, - std::pair::active_cell_iterator, Point>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures::particle_point_candidates &particle_point_contact_candidates); @@ -74,9 +72,7 @@ template void find_particle_point_contact_pairs( const Particles::ParticleHandler &particle_handler, - const std::unordered_map< - std::string, - std::pair::active_cell_iterator, Point>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures::particle_point_candidates &particle_point_contact_candidates, diff --git a/source/dem/find_boundary_cells_information.cc b/source/dem/find_boundary_cells_information.cc index 034c7d3065..4786f43c25 100644 --- a/source/dem/find_boundary_cells_information.cc +++ b/source/dem/find_boundary_cells_information.cc @@ -323,10 +323,10 @@ BoundaryCellsInformation::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))); } } } @@ -441,9 +441,17 @@ BoundaryCellsInformation::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{cell, vertex}); } } } diff --git a/source/dem/particle_point_line_broad_search.cc b/source/dem/particle_point_line_broad_search.cc index fe426c6d28..aa639d875c 100644 --- a/source/dem/particle_point_line_broad_search.cc +++ b/source/dem/particle_point_line_broad_search.cc @@ -8,9 +8,7 @@ template void find_particle_point_contact_pairs( const Particles::ParticleHandler &particle_handler, - const std::unordered_map< - std::string, - std::pair::active_cell_iterator, Point>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures::particle_point_candidates &particle_point_contact_candidates) @@ -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 vertex_location = - cells_with_boundary_points_information->second; + const cell_point_info &cells_with_boundary_points_information = + map_iterator->second; // Finding particles located in the corresponding cell typename Particles::ParticleHandler::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::particle_iterator_range:: iterator particles_in_cell_iterator = particles_in_cell.begin(); @@ -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{ + particles_in_cell_iterator, + cells_with_boundary_points_information.point}); ++contact_candidate_counter; } } @@ -65,9 +59,7 @@ template void find_particle_point_contact_pairs( const Particles::ParticleHandler &particle_handler, - const std::unordered_map< - std::string, - std::pair::active_cell_iterator, Point>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures::particle_point_candidates &particle_point_contact_candidates, @@ -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 &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::mobile) continue; - Point vertex_location = - cells_with_boundary_points_information->second; - // Finding particles located in the corresponding cell typename Particles::ParticleHandler::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::particle_iterator_range:: iterator particles_in_cell_iterator = particles_in_cell.begin(); @@ -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{ + particles_in_cell_iterator, + cells_with_boundary_points_information.point}); ++contact_candidate_counter; } } @@ -271,9 +260,7 @@ 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::active_cell_iterator, Point<2>>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures<2>::particle_point_candidates &particle_point_contact_candidates); @@ -281,9 +268,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::active_cell_iterator, Point<3>>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures<3>::particle_point_candidates &particle_point_contact_candidates); @@ -291,9 +276,7 @@ find_particle_point_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::active_cell_iterator, Point<2>>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures<2>::particle_point_candidates &particle_point_contact_candidates, @@ -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::active_cell_iterator, Point<3>>> + const std::unordered_map> &boundary_cells_with_points, typename DEM::dem_data_structures<3>::particle_point_candidates &particle_point_contact_candidates, diff --git a/source/dem/particle_point_line_fine_search.cc b/source/dem/particle_point_line_fine_search.cc index 3f39df9ddc..ed6a19b358 100644 --- a/source/dem/particle_point_line_fine_search.cc +++ b/source/dem/particle_point_line_fine_search.cc @@ -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 &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 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{particle, vertex_location_3d}); + particle_point_pairs_in_contact.emplace(particle->get_id(), + pair_candidates); } } } @@ -99,20 +93,20 @@ particle_line_fine_search( const particle_line_contact_info &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 particle = pair_candidates.particle; - ArrayView 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 @@ -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