From bc4ceb396b81ace23df51d3bca0ef98bf864ddf4 Mon Sep 17 00:00:00 2001 From: Brandon Butler Date: Mon, 28 Nov 2022 13:58:16 -0500 Subject: [PATCH] refactor: Automatically update types in ForceComposite::update --- hoomd/md/ForceComposite.cc | 30 ++++++++++-------------------- hoomd/md/ForceCompositeGPU.cc | 6 +++++- hoomd/md/ForceCompositeGPU.cu | 8 +++++++- hoomd/md/ForceCompositeGPU.cuh | 1 + 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/hoomd/md/ForceComposite.cc b/hoomd/md/ForceComposite.cc index 92d65bcd2d..a7402fa7f9 100644 --- a/hoomd/md/ForceComposite.cc +++ b/hoomd/md/ForceComposite.cc @@ -365,10 +365,6 @@ void ForceComposite::validateRigidBodies() { // access body data ArrayHandle h_body_len(m_body_len, access_location::host, access_mode::read); - ArrayHandle h_body_type(m_body_types, - access_location::host, - access_mode::read); - typedef std::map map_t; // This will count the length of all molecules (realized rigid bodies) in the system. map_t body_particle_count; @@ -431,14 +427,6 @@ void ForceComposite::validateRigidBodies() "Error validating rigid bodies: Too many constituent particles for " "rigid body."); } - - if (h_body_type.data[m_body_idx(body_type, current_molecule_size)] != snap.type[i]) - { - throw std::runtime_error( - "Error validating rigid bodies: Constituent particle types must be " - "consistent with the rigid body definition. Rigid body definition " - "is in order of particle tag."); - } // increase molecule size by one as particle is validated it->second++; // Mark consistent particle in molecule as belonging to its central particle. @@ -607,7 +595,7 @@ void ForceComposite::createRigidBodies( ++current_body_index) { // Update constituent particle snapshot properties from default. - // Position and orientation are handled by updateCompositeParticles. + // Position, orientation, and types are handled by updateCompositeParticles. snap.type[constituent_particle_tag] = h_body_type.data[m_body_idx(body_type, current_body_index)]; snap.body[constituent_particle_tag] = particle_tag; @@ -873,9 +861,9 @@ void ForceComposite::computeForces(uint64_t timestep) } } -/* Set position and velocity of constituent particles in rigid bodies in the 1st or second half of - * integration on the CPU based on the body center of mass and particle relative position in each - * body frame. +/* Set position, velocity, and type of constituent particles in rigid bodies in the 1st or second + * half of integration on the CPU based on the body center of mass and particle relative position in + * each body frame. */ void ForceComposite::updateCompositeParticles(uint64_t timestep) @@ -919,6 +907,7 @@ void ForceComposite::updateCompositeParticles(uint64_t timestep) ArrayHandle h_body_orientation(m_body_orientation, access_location::host, access_mode::read); + ArrayHandle h_body_types(m_body_types, access_location::host, access_mode::read); ArrayHandle h_body_len(m_body_len, access_location::host, access_mode::read); const BoxDim& box = m_pdata->getBox(); @@ -1016,10 +1005,11 @@ void ForceComposite::updateCompositeParticles(uint64_t timestep) int3 negimgi = make_int3(-imgi.x, -imgi.y, -imgi.z); updated_pos = global_box.shift(updated_pos, negimgi); - h_postype.data[particle_index] = make_scalar4(updated_pos.x, - updated_pos.y, - updated_pos.z, - h_postype.data[particle_index].w); + h_postype.data[particle_index] + = make_scalar4(updated_pos.x, + updated_pos.y, + updated_pos.z, + __int_as_scalar(h_body_types.data[m_body_idx(type, idx_in_body)])); h_orientation.data[particle_index] = quat_to_scalar4(updated_orientation); h_image.data[particle_index] = img + imgi; } diff --git a/hoomd/md/ForceCompositeGPU.cc b/hoomd/md/ForceCompositeGPU.cc index 0b22d3c556..13d106de3d 100644 --- a/hoomd/md/ForceCompositeGPU.cc +++ b/hoomd/md/ForceCompositeGPU.cc @@ -324,11 +324,14 @@ void ForceCompositeGPU::updateCompositeParticles(uint64_t timestep) access_location::device, access_mode::readwrite); - // access body positions and orientations + // access body positions, orientations, and types ArrayHandle d_body_pos(m_body_pos, access_location::device, access_mode::read); ArrayHandle d_body_orientation(m_body_orientation, access_location::device, access_mode::read); + ArrayHandle d_body_types(m_body_types, + access_location::device, + access_mode::read); ArrayHandle d_body_len(m_body_len, access_location::device, access_mode::read); // lookup table @@ -352,6 +355,7 @@ void ForceCompositeGPU::updateCompositeParticles(uint64_t timestep) d_lookup_center.data, d_body_pos.data, d_body_orientation.data, + d_body_types.data, d_body_len.data, d_molecule_order.data, d_molecule_len.data, diff --git a/hoomd/md/ForceCompositeGPU.cu b/hoomd/md/ForceCompositeGPU.cu index d402e41673..09f1ef81a0 100644 --- a/hoomd/md/ForceCompositeGPU.cu +++ b/hoomd/md/ForceCompositeGPU.cu @@ -658,6 +658,7 @@ __global__ void gpu_update_composite_kernel(unsigned int N, Index2D body_indexer, const Scalar3* d_body_pos, const Scalar4* d_body_orientation, + const unsigned int* d_body_types, const unsigned int* d_body_len, const unsigned int* d_molecule_order, const unsigned int* d_molecule_len, @@ -737,7 +738,10 @@ __global__ void gpu_update_composite_kernel(unsigned int N, unsigned int type = __scalar_as_int(d_postype[idx].w); d_postype[idx] - = make_scalar4(updated_pos.x, updated_pos.y, updated_pos.z, __int_as_scalar(type)); + = make_scalar4(updated_pos.x, + updated_pos.y, + updated_pos.z, + __int_as_scalar(d_body_types[body_indexer(body_type, idx_in_body)])); d_orientation[idx] = quat_to_scalar4(updated_orientation); d_image[idx] = img + imgi; } @@ -750,6 +754,7 @@ void gpu_update_composite(unsigned int N, const unsigned int* d_lookup_center, const Scalar3* d_body_pos, const Scalar4* d_body_orientation, + const unsigned int* d_body_types, const unsigned int* d_body_len, const unsigned int* d_molecule_order, const unsigned int* d_molecule_len, @@ -800,6 +805,7 @@ void gpu_update_composite(unsigned int N, body_indexer, d_body_pos, d_body_orientation, + d_body_types, d_body_len, d_molecule_order, d_molecule_len, diff --git a/hoomd/md/ForceCompositeGPU.cuh b/hoomd/md/ForceCompositeGPU.cuh index f2692db40d..f27267d7e8 100644 --- a/hoomd/md/ForceCompositeGPU.cuh +++ b/hoomd/md/ForceCompositeGPU.cuh @@ -72,6 +72,7 @@ void gpu_update_composite(unsigned int N, const unsigned int* d_lookup_center, const Scalar3* d_body_pos, const Scalar4* d_body_orientation, + const unsigned int* d_body_types, const unsigned int* d_body_len, const unsigned int* d_molecule_order, const unsigned int* d_molecule_len,