Skip to content

Commit

Permalink
refactor: Automatically update types in ForceComposite::update
Browse files Browse the repository at this point in the history
  • Loading branch information
b-butler committed Nov 28, 2022
1 parent 599b94e commit bc4ceb3
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
30 changes: 10 additions & 20 deletions hoomd/md/ForceComposite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,6 @@ void ForceComposite::validateRigidBodies()
{
// access body data
ArrayHandle<unsigned int> h_body_len(m_body_len, access_location::host, access_mode::read);
ArrayHandle<unsigned int> h_body_type(m_body_types,
access_location::host,
access_mode::read);

typedef std::map<unsigned int, unsigned int> map_t;
// This will count the length of all molecules (realized rigid bodies) in the system.
map_t body_particle_count;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -919,6 +907,7 @@ void ForceComposite::updateCompositeParticles(uint64_t timestep)
ArrayHandle<Scalar4> h_body_orientation(m_body_orientation,
access_location::host,
access_mode::read);
ArrayHandle<unsigned int> h_body_types(m_body_types, access_location::host, access_mode::read);
ArrayHandle<unsigned int> h_body_len(m_body_len, access_location::host, access_mode::read);

const BoxDim& box = m_pdata->getBox();
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 5 additions & 1 deletion hoomd/md/ForceCompositeGPU.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Scalar3> d_body_pos(m_body_pos, access_location::device, access_mode::read);
ArrayHandle<Scalar4> d_body_orientation(m_body_orientation,
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_body_types(m_body_types,
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_body_len(m_body_len, access_location::device, access_mode::read);

// lookup table
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion hoomd/md/ForceCompositeGPU.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions hoomd/md/ForceCompositeGPU.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bc4ceb3

Please sign in to comment.