<commit_before>#include "collision/ChCCollisionModel.h"

#include "math/ChParallelMath.h"
#include "collision/ChCNarrowphaseR.h"
#include "collision/ChCNarrowphaseRUtils.h"


using namespace chrono;
using namespace chrono::collision;


//// TODO: what is a good value here?
////       Should this even be a constant?  Maybe set it based on object size?
const real edge_radius = 0.1;


void ChCNarrowphaseR::Process(ChParallelDataManager* data_container)
{
	// Aliases for readibility
	custom_vector<real3>& norm_data = data_container->host_data.norm_rigid_rigid;
	custom_vector<real3>& cpta_data = data_container->host_data.cpta_rigid_rigid;
	custom_vector<real3>& cptb_data = data_container->host_data.cptb_rigid_rigid;
	custom_vector<real>&  dpth_data = data_container->host_data.dpth_rigid_rigid;
	custom_vector<real>&  erad_data = data_container->host_data.erad_rigid_rigid;
	custom_vector<int2>&  bids_data = data_container->host_data.bids_rigid_rigid;

	custom_vector<long long>& potentialCollisions = data_container->host_data.pair_rigid_rigid;

	// Create a vector to hold the maximum number of contacts produced by each potential
	// collision pair identified by the broadphase.
	uint num_potentialCollisions = potentialCollisions.size();
	custom_vector<uint> contact_index(num_potentialCollisions);

	host_count(data_container, num_potentialCollisions, contact_index);

	// Perform an exclusive scan on the contact_index array and calculate the total number
	// of possible contacts.
	int num_potentialContacts = contact_index.back();
	thrust::exclusive_scan(contact_index.begin(), contact_index.end(), contact_index.begin());
	num_potentialContacts += contact_index.back();

	// Allocate enough space for all possible contacts
	norm_data.resize(num_potentialContacts);
	cpta_data.resize(num_potentialContacts);
	cptb_data.resize(num_potentialContacts);
	dpth_data.resize(num_potentialContacts);
	erad_data.resize(num_potentialContacts);
	bids_data.resize(num_potentialContacts);

	// Create a vector of flags to indicate whether actual contact exists
	custom_vector<uint> contact_flag(num_potentialContacts);
	thrust::fill(contact_flag.begin(), contact_flag.end(), 1);

	// Perform actual narrow phase collision detection. For each potential collision between two
	// shapes, calculate and fill in contact information for contacts that actually occur and set
	// the corresponding flag to 0.
	host_process(data_container, num_potentialCollisions, contact_index, contact_flag);<commit_msg>Fix crash when no potential collisions are identified by the broad phase.<commit_after>#include "collision/ChCCollisionModel.h"

#include "math/ChParallelMath.h"
#include "collision/ChCNarrowphaseR.h"
#include "collision/ChCNarrowphaseRUtils.h"


using namespace chrono;
using namespace chrono::collision;


//// TODO: what is a good value here?
////       Should this even be a constant?  Maybe set it based on object size?
const real edge_radius = 0.1;


void ChCNarrowphaseR::Process(ChParallelDataManager* data_container)
{
	// Aliases for readibility
	custom_vector<real3>& norm_data = data_container->host_data.norm_rigid_rigid;
	custom_vector<real3>& cpta_data = data_container->host_data.cpta_rigid_rigid;
	custom_vector<real3>& cptb_data = data_container->host_data.cptb_rigid_rigid;
	custom_vector<real>&  dpth_data = data_container->host_data.dpth_rigid_rigid;
	custom_vector<real>&  erad_data = data_container->host_data.erad_rigid_rigid;
	custom_vector<int2>&  bids_data = data_container->host_data.bids_rigid_rigid;

	custom_vector<long long>& potentialCollisions = data_container->host_data.pair_rigid_rigid;
	uint num_potentialCollisions = potentialCollisions.size();

	// Return now if no potential collisions.
	if (num_potentialCollisions == 0) {
		norm_data.resize(0);
		cpta_data.resize(0);
		cptb_data.resize(0);
		dpth_data.resize(0);
		erad_data.resize(0);
		bids_data.resize(0);
		data_container->number_of_rigid_rigid = 0;
		return;
	}

	// Create a vector to hold the maximum number of contacts produced by each potential
	// collision pair identified by the broadphase.
	custom_vector<uint> contact_index(num_potentialCollisions);

	host_count(data_container, num_potentialCollisions, contact_index);

	// Perform an exclusive scan on the contact_index array and calculate the total number
	// of possible contacts.
	int num_potentialContacts = contact_index.back();
	thrust::exclusive_scan(contact_index.begin(), contact_index.end(), contact_index.begin());
	num_potentialContacts += contact_index.back();

	// Allocate enough space for all possible contacts
	norm_data.resize(num_potentialContacts);
	cpta_data.resize(num_potentialContacts);
	cptb_data.resize(num_potentialContacts);
	dpth_data.resize(num_potentialContacts);
	erad_data.resize(num_potentialContacts);
	bids_data.resize(num_potentialContacts);

	// Create a vector of flags to indicate whether actual contact exists
	custom_vector<uint> contact_flag(num_potentialContacts);
	thrust::fill(contact_flag.begin(), contact_flag.end(), 1);

	// Perform actual narrow phase collision detection. For each potential collision between two
	// shapes, calculate and fill in contact information for contacts that actually occur and set
	// the corresponding flag to 0.
	host_process(data_container, num_potentialCollisions, contact_index, contact_flag);
{'fraction_non_alphanumeric': 0.0894095595126523, 'fraction_numerical': 0.004498594189315839, 'mean_word_length': 6.349862258953168, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3626729', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1634, 'n_words': 392}