Skip to content

Commit

Permalink
Merge pull request #1965 from glotzerlab/fix-nec
Browse files Browse the repository at this point in the history
Fix NEC integrators
  • Loading branch information
joaander authored Dec 5, 2024
2 parents ab1ba91 + 661d39e commit 58b7ba5
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 38 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ Change Log
5.x
---

5.0.1 (not yet released)
^^^^^^^^^^^^^^^^^^^^^^^^

*Fixed*

* Prevent ``missing 1 required positional argument: 'kT'`` errors when using NEC integrators
(`#1965 <https://github.com/glotzerlab/hoomd-blue/pull/1965>`__)


5.0.0 (2024-12-02)
^^^^^^^^^^^^^^^^^^

Expand Down
74 changes: 40 additions & 34 deletions hoomd/hpmc/IntegratorHPMCMonoNEC.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,12 @@ template<class Shape> void IntegratorHPMCMonoNEC<Shape>::update(uint64_t timeste
this->m_exec_conf->msg->notice(10) << "HPMCMonoEC update: " << timestep << std::endl;
IntegratorHPMC::update(timestep);

// get needed vars
ArrayHandle<hpmc_counters_t> h_counters(this->m_count_total,
access_location::host,
access_mode::readwrite);
hpmc_counters_t& counters = h_counters.data[0];

ArrayHandle<hpmc_nec_counters_t> h_nec_counters(m_nec_count_total,
access_location::host,
access_mode::readwrite);
hpmc_nec_counters_t& nec_counters = h_nec_counters.data[0];
m_nec_count_step_start = h_nec_counters.data[0];
{
ArrayHandle<hpmc_nec_counters_t> h_nec_counters(m_nec_count_total,
access_location::host,
access_mode::readwrite);
m_nec_count_step_start = h_nec_counters.data[0];
}

const BoxDim& box = this->m_pdata->getBox();
unsigned int ndim = this->m_sysdef->getNDimensions();
Expand All @@ -294,29 +289,6 @@ template<class Shape> void IntegratorHPMCMonoNEC<Shape>::update(uint64_t timeste
count_pressurevirial = 0.0;
count_movelength = 0.0;

// access interaction matrix
ArrayHandle<unsigned int> h_overlaps(this->m_overlaps,
access_location::host,
access_mode::read);
ArrayHandle<int3> h_image(this->m_pdata->getImages(),
access_location::host,
access_mode::readwrite);

// access particle data
ArrayHandle<Scalar4> h_postype(this->m_pdata->getPositions(),
access_location::host,
access_mode::readwrite);
ArrayHandle<Scalar4> h_velocities(this->m_pdata->getVelocities(),
access_location::host,
access_mode::readwrite);
ArrayHandle<Scalar4> h_orientation(this->m_pdata->getOrientationArray(),
access_location::host,
access_mode::readwrite);

// access move sizes
ArrayHandle<Scalar> h_d(this->m_d, access_location::host, access_mode::read);
ArrayHandle<Scalar> h_a(this->m_a, access_location::host, access_mode::read);

uint16_t seed = this->m_sysdef->getSeed();

// loop over local particles nselect times
Expand All @@ -333,6 +305,40 @@ template<class Shape> void IntegratorHPMCMonoNEC<Shape>::update(uint64_t timeste
// update the image list
this->updateImageList();

// get needed vars
ArrayHandle<hpmc_counters_t> h_counters(this->m_count_total,
access_location::host,
access_mode::readwrite);
hpmc_counters_t& counters = h_counters.data[0];

ArrayHandle<hpmc_nec_counters_t> h_nec_counters(m_nec_count_total,
access_location::host,
access_mode::readwrite);
hpmc_nec_counters_t& nec_counters = h_nec_counters.data[0];

// access interaction matrix
ArrayHandle<unsigned int> h_overlaps(this->m_overlaps,
access_location::host,
access_mode::read);
ArrayHandle<int3> h_image(this->m_pdata->getImages(),
access_location::host,
access_mode::readwrite);

// access particle data
ArrayHandle<Scalar4> h_postype(this->m_pdata->getPositions(),
access_location::host,
access_mode::readwrite);
ArrayHandle<Scalar4> h_velocities(this->m_pdata->getVelocities(),
access_location::host,
access_mode::readwrite);
ArrayHandle<Scalar4> h_orientation(this->m_pdata->getOrientationArray(),
access_location::host,
access_mode::readwrite);

// access move sizes
ArrayHandle<Scalar> h_d(this->m_d, access_location::host, access_mode::read);
ArrayHandle<Scalar> h_a(this->m_a, access_location::host, access_mode::read);

// loop through N particles in a shuffled order
for (unsigned int cur_chain = 0; cur_chain < this->m_pdata->getN() * m_update_fraction;
cur_chain++)
Expand Down
2 changes: 0 additions & 2 deletions hoomd/hpmc/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
particles and `SDF` samples the pressure.
"""

from __future__ import print_function

from hoomd import _hoomd
from hoomd.operation import Compute
from hoomd.hpmc import _hpmc
Expand Down
2 changes: 1 addition & 1 deletion hoomd/hpmc/nec/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
nselect=1,
):
# initialize base class
super().__init__(default_d, default_a, 0.5, nselect)
super().__init__(default_d, default_a, 0.5, nselect, 1.0)

# Set base parameter dict for hpmc chain integrators
param_dict = ParameterDict(
Expand Down
3 changes: 2 additions & 1 deletion hoomd/hpmc/pytest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ set(files __init__.py
test_shape_updater.py
test_shape_utils.py
test_move_size_tuner.py
test_nec.py
test_pair_lennard_jones.py
test_pair_expanded_gaussian.py
test_pair_lj_gauss.py
test_pair_lj_gauss.py
test_pair_opp.py
test_pair_step.py
test_pair_union.py
Expand Down
15 changes: 15 additions & 0 deletions hoomd/hpmc/pytest/test_nec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2009-2024 The Regents of the University of Michigan.
# Part of HOOMD-blue, released under the BSD 3-Clause License.

import hoomd
import pytest


@pytest.mark.serial
def test_nec(simulation_factory, lattice_snapshot_factory):
snap = lattice_snapshot_factory(particle_types=["A"])
simulation = simulation_factory(snap)
sphere = hoomd.hpmc.nec.integrate.Sphere()
sphere.shape["A"] = {"diameter": 1.0}
simulation.operations.integrator = sphere
simulation.run(10)

0 comments on commit 58b7ba5

Please sign in to comment.