Skip to content

Commit

Permalink
Refactor general weight DPD potential (#81)
Browse files Browse the repository at this point in the history
* Refactor Filenames DPDGeneralWeight

* Rename parameters, add parameter struct

* Add python class

* Add test for DPDGeneralWeight

* Fix typo and formatting

* Move potentials to be alphabetical in pair.py

* Remove unneccessary files

* Fix whitespace

* Fix docstring

* Remove trailing whitespace

* More whitespaces

* Fix missing GPU in module.cc

* configure whitespace settings

* EOF fix?

* more whitespace?

* Add blank line

* Applied clang-format

* Remove whitespace from test py file

* Apply formatting pre-commit :wq

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add DPD framework - rename files for consistency

* add template class

* Fix infrastructure

* Fix wrong import GPU

* More wrong imports

* kT = 0 for potential test

* Change RNG identifier

* Add system test for DPD temperature

* remove termalize momenta for just testing termostat

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix formatting

* attempt to fix mpi in dpd test

* Update unit-test.yaml

* Simplify and fix DPD thermostat test

* Follow azplugins naming conventions for DPD potential

* Simplify pair potential special case

* Cleanup DPD documentation

* Don't execute GPU tests on GitHub Actions

---------

Co-authored-by: Antonia Statt <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Michael Howard <[email protected]>
  • Loading branch information
4 people authored Jul 16, 2024
1 parent b32e900 commit 0c520e0
Show file tree
Hide file tree
Showing 17 changed files with 432 additions and 167 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ env:
# skip running the CPU tests in GPU builds
_HOOMD_SKIP_CPU_TESTS_WHEN_GPUS_PRESENT_: 1
# Require GPU tests in GPU builds.
_HOOMD_REQUIRE_GPU_TESTS_IN_GPU_BUILDS_: 1
# _HOOMD_REQUIRE_GPU_TESTS_IN_GPU_BUILDS_: 1

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ python -m pytest --pyargs hoomd.azplugins
Contributions are welcomed and appreciated! Fork and create a pull request on
[GitHub][4]. Be sure to follow the [HOOMD-blue guidelines for developers][5]! We
value the input and experiences all users and contributors bring to
`relentless`.
`azplugins`.

## History

Expand Down
2 changes: 2 additions & 0 deletions doc/module-azplugins-pair.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ azplugins.pair
:nosignatures:

Colloid
DPDGeneralWeight
Hertz
PerturbedLennardJones
TwoPatchMorse
Expand All @@ -22,6 +23,7 @@ azplugins.pair
.. automodule:: hoomd.azplugins.pair
:synopsis: Pair potentials.
:members: Colloid,
DPDGeneralWeight,
Hertz,
PerturbedLennardJones,
TwoPatchMorse
Expand Down
26 changes: 25 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ set(_bond_evaluators
DoubleWell
)

# TODO: Add names of all pair evaluators`
# TODO: Add names of all pair evaluators
set(_pair_evaluators
Colloid
Hertz
PerturbedLennardJones
)

# TODO: Add names of all dpd evaluators
set(_dpd_evaluators
GeneralWeight
)

# TODO: Add names of all anisotropic pair evaluators
set(_aniso_pair_evaluators
TwoPatchMorse
Expand Down Expand Up @@ -77,6 +82,25 @@ foreach(_evaluator ${_pair_evaluators})
endif()
endforeach()

# process DPD potentials
foreach(_evaluator ${_dpd_evaluators})
configure_file(export_PotentialPairDPDThermo.cc.inc
export_PotentialPairDPDThermo${_evaluator}.cc
@ONLY)
set(_${COMPONENT_NAME}_sources ${_${COMPONENT_NAME}_sources} export_PotentialPairDPDThermo${_evaluator}.cc)

if (ENABLE_HIP)
configure_file(export_PotentialPairDPDThermoGPU.cc.inc
export_PotentialPairDPDThermo${_evaluator}GPU.cc
@ONLY)
configure_file(PotentialPairDPDThermoGPUKernel.cu.inc
PotentialPairDPDThermo${_evaluator}GPUKernel.cu
@ONLY)
set(_${COMPONENT_NAME}_sources ${_${COMPONENT_NAME}_sources} export_PotentialPairDPDThermo${_evaluator}GPU.cc)
set(_${COMPONENT_NAME}_cu_sources ${_${COMPONENT_NAME}_cu_sources} PotentialPairDPDThermo${_evaluator}GPUKernel.cu)
endif()
endforeach()

# process anisotropic pair potentials
foreach(_evaluator ${_aniso_pair_evaluators})
configure_file(export_AnisoPotentialPair.cc.inc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,64 @@
// Part of azplugins, released under the BSD 3-Clause License.

/*!
* \file DPDEvaluatorGeneralWeight.h
* \file DPDPairEvaluatorGeneralWeight.h
* \brief Defines the dpd force evaluator using generalized weight functions.
*/

#ifndef AZPLUGINS_DPD_EVALUATOR_GENERAL_WEIGHT_H_
#define AZPLUGINS_DPD_EVALUATOR_GENERAL_WEIGHT_H_
#ifndef AZPLUGINS_DPD_PAIR_EVALUATOR_GENERAL_WEIGHT_H_
#define AZPLUGINS_DPD_PAIR_EVALUATOR_GENERAL_WEIGHT_H_

#include "PairEvaluator.h"

#include "RNGIdentifiers.h"
#include "hoomd/HOOMDMath.h"
#include "hoomd/RandomNumbers.h"

#ifdef NVCC
#ifdef __HIPCC__
#define DEVICE __device__
#else
#define DEVICE
#include <string>
#endif

namespace hoomd
{
namespace azplugins
{
namespace detail
{

struct PairParametersDPDGeneralWeight : public PairParameters
{
#ifndef __HIPCC__
PairParametersDPDGeneralWeight() : A(0), gamma(0), s(0) { }

PairParametersDPDGeneralWeight(pybind11::dict v, bool managed = false)
{
A = v["A"].cast<Scalar>();
gamma = v["gamma"].cast<Scalar>();
s = v["s"].cast<Scalar>();
}

pybind11::dict asDict()
{
pybind11::dict v;
v["A"] = A;
v["gamma"] = gamma;
v["s"] = s;
return v;
}
#endif // __HIPCC__

Scalar A;
Scalar gamma;
Scalar s;
}
#if HOOMD_LONGREAL_SIZE == 32
__attribute__((aligned(16)));
#else
__attribute__((aligned(32)));
#endif

//! Evaluator for DPD generalized dissipative / random weight functions
/*!
* Implements the generalized weight functions described in;
Expand Down Expand Up @@ -57,21 +90,25 @@ namespace detail
* where \a s is usually 2 for the "standard" DPD method. Refer to the original paper for more
* details.
*/
class DPDEvaluatorGeneralWeight : public PairEvaluator
class DPDPairEvaluatorGeneralWeight : public PairEvaluator
{
public:
//! Three parameters are used by this DPD potential evaluator
typedef Scalar3 param_type;
typedef PairParametersDPDGeneralWeight param_type;

//! Constructs the DPD potential evaluator
/*!
* \param _rsq Squared distance beteen the particles
* \param _rcutsq Sqauared distance at which the potential goes to 0
* \param _params Per type pair parameters of this potential
*/
DEVICE DPDEvaluatorGeneralWeight(Scalar _rsq, Scalar _rcutsq, const param_type& _params)
: PairEvaluator(_rsq, _rcutsq), a(_params.x), gamma(_params.y), s(_params.z)
DEVICE
DPDPairEvaluatorGeneralWeight(Scalar _rsq, Scalar _rcutsq, const param_type& _params)
: PairEvaluator(_rsq, _rcutsq)
{
A = _params.A;
gamma = _params.gamma;
s = _params.s;
}

//! Set seed, i and j (particle tags), and the timestep
Expand All @@ -82,7 +119,7 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator
* \param timestep Timestep to evaluate forces at
*/
DEVICE void
set_seed_ij_timestep(unsigned int seed, unsigned int i, unsigned int j, unsigned int timestep)
set_seed_ij_timestep(uint16_t seed, unsigned int i, unsigned int j, unsigned int timestep)
{
m_seed = seed;
m_i = i;
Expand Down Expand Up @@ -136,8 +173,8 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator
Scalar rcut = Scalar(1.0) / rcutinv;

// force is easy to calculate
force_divr = a * (rinv - rcutinv);
pair_eng = a * (rcut - r) - Scalar(0.5) * a * rcutinv * (rcutsq - rsq);
force_divr = A * (rinv - rcutinv);
pair_eng = A * (rcut - r) - Scalar(0.5) * A * rcutinv * (rcutsq - rsq);

return true;
}
Expand Down Expand Up @@ -187,15 +224,16 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator
}

// Generate a single random number
hoomd::RandomGenerator rng(azplugins::RNGIdentifier::DPDEvaluatorGeneralWeight,
m_seed,
m_oi,
m_oj,
m_timestep);
hoomd::RandomGenerator rng(
hoomd::Seed(hoomd::azplugins::detail::RNGIdentifier::DPDEvaluatorGeneralWeight,
m_timestep,
m_seed),
hoomd::Counter(m_oi, m_oj));

Scalar alpha = hoomd::UniformDistribution<Scalar>(-1, 1)(rng);

// conservative dpd
force_divr = a * (rinv - rcutinv);
force_divr = A * (rinv - rcutinv);

// conservative force only
force_divr_cons = force_divr;
Expand All @@ -208,7 +246,7 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator
force_divr += fast::rsqrt(m_deltaT / (m_T * gamma * Scalar(6.0))) * wR * alpha;

// conservative energy only
pair_eng = a * (rcut - r) - Scalar(0.5) * a * rcutinv * (rcutsq - rsq);
pair_eng = A * (rcut - r) - Scalar(0.5) * A * rcutinv * (rcutsq - rsq);

return true;
}
Expand All @@ -225,11 +263,11 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator
#endif

protected:
Scalar a; //!< Strength of repulsion
Scalar A; //!< Strength of repulsion
Scalar gamma; //!< Drag term
Scalar s; //!< Exponent for the dissipative weight function

unsigned int m_seed; //!< User set seed for PRNG
uint16_t m_seed; //!< User set seed for PRNG
unsigned int m_i; //!< Tag of first particle for PRNG
unsigned int m_j; //!< Tag of second particle for PRNG
unsigned int m_timestep; //!< timestep for use in PRNG
Expand All @@ -241,7 +279,8 @@ class DPDEvaluatorGeneralWeight : public PairEvaluator

} // end namespace detail
} // end namespace azplugins
} // end namespace hoomd

#undef DEVICE

#endif // AZPLUGINS_DPD_EVALUATOR_GENERAL_WEIGHT_H_
#endif // AZPLUGINS_DPD_PAIR_EVALUATOR_GENERAL_WEIGHT_H_
18 changes: 0 additions & 18 deletions src/DPDPotentialGeneralWeight.cu

This file was deleted.

48 changes: 0 additions & 48 deletions src/DPDPotentials.cuh

This file was deleted.

70 changes: 0 additions & 70 deletions src/DPDPotentials.h

This file was deleted.

Loading

0 comments on commit 0c520e0

Please sign in to comment.