Skip to content

Commit 5a5fca4

Browse files
jinnyjcmphoward
andauthored
Refactor wall potential (#115)
* Refactor wall potential * Revise unit test and documentation * Rename parameter epsilon to A * Apply suggestions from code review --------- Co-authored-by: Michael Howard <[email protected]>
1 parent 25ba1c6 commit 5a5fca4

14 files changed

+387
-177
lines changed

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Contents
5656
module-azplugins-external
5757
module-azplugins-flow
5858
module-azplugins-pair
59+
module-azplugins-wall
5960

6061
.. toctree::
6162
:maxdepth: 1

doc/module-azplugins-wall.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.. Copyright (c) 2018-2020, Michael P. Howard
2+
.. Copyright (c) 2021-2025, Auburn University
3+
.. Part of azplugins, released under the BSD 3-Clause License.
4+
5+
azplugins.wall
6+
--------------
7+
8+
.. rubric:: Overview
9+
10+
.. py:currentmodule:: hoomd.azplugins.wall
11+
12+
.. autosummary::
13+
:nosignatures:
14+
15+
LJ93
16+
17+
.. rubric:: Details
18+
19+
.. automodule:: hoomd.azplugins.wall
20+
:synopsis: Wall potentials.
21+
:members: LJ93
22+
:no-inherited-members:
23+
:show-inheritance:

src/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(python_files
3232
external.py
3333
flow.py
3434
pair.py
35+
wall.py
3536
)
3637

3738
# TODO: Add names of all bond evaluators
@@ -48,6 +49,11 @@ set(_pair_evaluators
4849
PerturbedLennardJones
4950
)
5051

52+
# TODO: Add names of all wall evaluators
53+
set(_wall_evaluators
54+
LJ93
55+
)
56+
5157
# TODO: Add names of all dpd evaluators
5258
set(_dpd_evaluators
5359
GeneralWeight
@@ -96,6 +102,25 @@ foreach(_evaluator ${_pair_evaluators})
96102
endif()
97103
endforeach()
98104

105+
# process wall potentials
106+
foreach(_evaluator ${_wall_evaluators})
107+
configure_file(export_PotentialExternalWall.cc.inc
108+
export_PotentialExternalWall${_evaluator}.cc
109+
@ONLY)
110+
set(_${COMPONENT_NAME}_sources ${_${COMPONENT_NAME}_sources} export_PotentialExternalWall${_evaluator}.cc)
111+
112+
if (ENABLE_HIP)
113+
configure_file(export_PotentialExternalWallGPU.cc.inc
114+
export_PotentialExternalWall${_evaluator}GPU.cc
115+
@ONLY)
116+
configure_file(PotentialExternalWallGPUKernel.cu.inc
117+
PotentialExternalWall${_evaluator}GPUKernel.cu
118+
@ONLY)
119+
set(_${COMPONENT_NAME}_sources ${_${COMPONENT_NAME}_sources} export_PotentialExternalWall${_evaluator}GPU.cc)
120+
set(_${COMPONENT_NAME}_cu_sources ${_${COMPONENT_NAME}_cu_sources} PotentialExternalWall${_evaluator}GPUKernel.cu)
121+
endif()
122+
endforeach()
123+
99124
# process DPD potentials
100125
foreach(_evaluator ${_dpd_evaluators})
101126
configure_file(export_PotentialPairDPDThermo.cc.inc
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2018-2020, Michael P. Howard
2+
// Copyright (c) 2021-2025, Auburn University
3+
// Part of azplugins, released under the BSD 3-Clause License.
4+
5+
// Adapted from hoomd/md/export_PotentialExternalWallGPUKernel.cu.inc of HOOMD-blue.
6+
// Copyright (c) 2009-2024 The Regents of the University of Michigan.
7+
// Part of HOOMD-blue, released under the BSD 3-Clause License.
8+
9+
// See CMakeLists.txt for the source of these variables to be processed by CMake's
10+
// configure_file().
11+
12+
// clang-format off
13+
#include "hoomd/md/PotentialExternalGPU.cuh"
14+
#include "hoomd/md/EvaluatorWalls.h"
15+
#include "WallEvaluator@[email protected]"
16+
17+
#define EVALUATOR_CLASS hoomd::md::EvaluatorWalls<hoomd::azplugins::detail::WallEvaluator@_evaluator@>
18+
// clang-format on
19+
20+
namespace hoomd
21+
{
22+
namespace md
23+
{
24+
namespace kernel
25+
{
26+
template __attribute__((visibility("default"))) hipError_t
27+
gpu_compute_potential_external_forces<EVALUATOR_CLASS>(
28+
const external_potential_args_t& external_potential_args,
29+
const typename EVALUATOR_CLASS::param_type* d_params,
30+
const typename EVALUATOR_CLASS::field_type* d_field);
31+
} // end namespace kernel
32+
} // end namespace md
33+
} // end namespace hoomd

src/WallEvaluatorLJ93.h

Lines changed: 61 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -10,91 +10,94 @@
1010
#ifndef AZPLUGINS_WALL_EVALUATOR_LJ_93_H_
1111
#define AZPLUGINS_WALL_EVALUATOR_LJ_93_H_
1212

13-
#ifndef NVCC
14-
#include <string>
15-
#endif
16-
17-
#include "hoomd/HOOMDMath.h"
13+
#include "PairEvaluator.h"
1814

19-
#ifdef NVCC
15+
#ifdef __HIPCC__
2016
#define DEVICE __device__
2117
#else
2218
#define DEVICE
2319
#endif
2420

21+
namespace hoomd
22+
{
2523
namespace azplugins
2624
{
2725
namespace detail
2826
{
29-
//! Evaluates the Lennard-Jones 9-3 wall force
27+
//! Define the paramter type used by this wall potential evaluator
28+
struct WallParametersLJ93 : public PairParameters
29+
{
30+
#ifndef __HIPCC__
31+
WallParametersLJ93() : sigma_3(0), A(0) { }
32+
33+
WallParametersLJ93(pybind11::dict v, bool managed = false)
34+
{
35+
auto sigma(v["sigma"].cast<Scalar>());
36+
A = v["A"].cast<Scalar>();
37+
38+
sigma_3 = sigma * sigma * sigma;
39+
}
40+
41+
pybind11::dict asDict()
42+
{
43+
pybind11::dict v;
44+
v["sigma"] = std::cbrt(sigma_3);
45+
v["A"] = A;
46+
return v;
47+
}
48+
#endif // __HIPCC__
49+
50+
Scalar sigma_3; //!< Lennard-Jones sigma
51+
Scalar A; //!< Hamaker constant
52+
}
53+
54+
#if HOOMD_LONGREAL_SIZE == 32
55+
__attribute__((aligned(8)));
56+
#else
57+
__attribute__((aligned(16)));
58+
#endif
59+
60+
//! Class for evaluating the Lennard-Jones 9-3 wall force
3061
/*!
3162
* WallEvaluatorLJ93 computes the Lennard-Jones 9-3 wall potential, which is derived from
3263
* integrating the standard Lennard-Jones potential between a point particle and a half plane:
3364
*
34-
* \f[ V(r) = \varepsilon \left( \frac{2}{15}\left(\frac{\sigma}{r}\right)^9 -
35-
* \left(\frac{\sigma}{r}\right)^3 \right) \f]
65+
* \f[ V(r) = A \left[ \frac{2}{15}\left(\frac{\sigma}{r}\right)^9 -
66+
* \left(\frac{\sigma}{r}\right)^3 \right] \f]
3667
*
37-
* where \f$\sigma\f$ is the diameter of Lennard-Jones particles in the wall, and \f$ \varepsilon
38-
* \f$ is the effective Hamaker constant \f$ \varepsilon = (2/3) \pi \varepsilon_{\rm LJ} \rho_{\rm
39-
* w} \sigma^3 \f$ with \f$\varepsilon_{\rm LJ}\f$ the energy of interaction and \f$\rho_{\rm w}\f$
40-
* the density of particles in the wall. Evaluation of this energy is simplified into the following
68+
* where \f$\sigma\f$ is the diameter of Lennard-Jones particles in the wall, and \f$ A \f$ is the
69+
* Hamaker constant \f$ A = (2/3) \pi \varepsilon_{\rm LJ} \rho_{\rm w} \sigma^3 \f$ with
70+
* \f$\varepsilon_{\rm LJ}\f$ the energy of interaction and \f$\rho_{\rm w}\f$ the density of
71+
* particles in the wall. Evaluation of this energy is simplified into the following
4172
* parameters:
4273
*
43-
* - \verbatim lj1 = (2.0/15.0) * epsilon * pow(sigma,9.0) \endverbatim
44-
* - \verbatim lj2 = epsilon * pow(sigma,3.0) \endverbatim
74+
* - \verbatim lj1 = (2.0/15.0) * A * pow(sigma,9.0) \endverbatim
75+
* - \verbatim lj2 = A * pow(sigma,3.0) \endverbatim
4576
*
4677
* The force acting on the particle is then
47-
* \f[ F(r)/r = \frac{\varepsilon}{r^2} \left ( \frac{6}{5}\left(\frac{\sigma}{r}\right)^9 - 3
78+
* \f[ F(r)/r = \frac{A}{r^2} \left ( \frac{6}{5}\left(\frac{\sigma}{r}\right)^9 - 3
4879
* \left(\frac{\sigma}{r}\right)^3 \right) \f]
4980
*/
50-
class WallEvaluatorLJ93
81+
class WallEvaluatorLJ93 : public PairEvaluator
5182
{
5283
public:
53-
//! Define the parameter type used by this wall potential evaluator
54-
typedef Scalar2 param_type;
84+
typedef WallParametersLJ93 param_type;
5585

5686
//! Constructor
5787
/*!
58-
* \param _rsq Squared distance between particles
88+
* \param _rsq Sqaured distance between particles
5989
* \param _rcutsq Cutoff radius squared
60-
* \param _params Pair potential parameters, given by typedef above
90+
* \param _params Wall potential paramters, given by typedef above
6191
*
6292
* The functor initializes its members from \a _params.
6393
*/
6494
DEVICE WallEvaluatorLJ93(Scalar _rsq, Scalar _rcutsq, const param_type& _params)
65-
: rsq(_rsq), rcutsq(_rcutsq), lj1(_params.x), lj2(_params.y)
66-
{
67-
}
68-
69-
//! LJ 9-3 doesn't use diameter
70-
DEVICE static bool needsDiameter()
95+
: PairEvaluator(_rsq, _rcutsq)
7196
{
72-
return false;
97+
lj1 = (Scalar(2.0) / Scalar(15.0)) * _params.A * _params.sigma_3 * _params.sigma_3
98+
* _params.sigma_3;
99+
lj2 = _params.A * _params.sigma_3;
73100
}
74-
//! Accept the optional diameter values
75-
/*!
76-
* \param di Diameter of particle
77-
* \param dj Dummy diameter
78-
*
79-
* \note The way HOOMD computes wall forces by recycling evaluators requires that we give
80-
* a second diameter, even though this is meaningless for the potential.
81-
*/
82-
DEVICE void setDiameter(Scalar di, Scalar dj) { }
83-
84-
//! LJ 9-3 doesn't use charge
85-
DEVICE static bool needsCharge()
86-
{
87-
return false;
88-
}
89-
//! Accept the optional charge values
90-
/*!
91-
* \param qi Charge of particle
92-
* \param qj Dummy charge
93-
*
94-
* \note The way HOOMD computes wall forces by recycling evaluators requires that we give
95-
* a second charge, even though this is meaningless for the potential.
96-
*/
97-
DEVICE void setCharge(Scalar qi, Scalar qj) { }
98101

99102
//! Evaluate the force and energy
100103
/*!
@@ -135,22 +138,22 @@ class WallEvaluatorLJ93
135138
return false;
136139
}
137140

138-
#ifndef NVCC
141+
#ifndef __HIPCC__
139142
//! Return the name of this potential
140143
static std::string getName()
141144
{
142145
return std::string("lj93");
143146
}
144147
#endif
145148

146-
protected:
147-
Scalar rsq; //!< Stored rsq from the constructor
148-
Scalar rcutsq; //!< Stored rcutsq from the constructor
149-
Scalar lj1; //!< lj1 parameter extracted from the params passed to the constructor
150-
Scalar lj2; //!< lj2 parameter extracted from the params passed to the constructor
149+
private:
150+
Scalar lj1;
151+
Scalar lj2;
151152
};
153+
152154
} // end namespace detail
153155
} // end namespace azplugins
156+
} // end namespace hoomd
154157

155158
#undef DEVICE
156159
#endif // AZPLUGINS_WALL_EVALUATOR_LJ_93_H_

src/WallPotentials.cu

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)