Skip to content

Refactor integrator #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/ConstantFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#endif // __HIPCC__

#ifndef PYBIND11_EXPORT
#define PYBIND11_EXPORT __attribute__((visibility("default")))
#define _PYBIND11_EXPORT __attribute__((visibility("default")))
#else
#define _PYBIND11_EXPORT PYBIND11_EXPORT
#endif

namespace hoomd
Expand All @@ -27,7 +29,7 @@ namespace azplugins
{

//! Position-independent flow along a vector
class PYBIND11_EXPORT ConstantFlow
class _PYBIND11_EXPORT ConstantFlow
{
public:
//! Constructor
Expand Down Expand Up @@ -68,6 +70,6 @@ class PYBIND11_EXPORT ConstantFlow
} // namespace hoomd

#undef HOSTDEVICE
#undef PYBIND11_EXPORT
#undef _PYBIND11_EXPORT

#endif // AZPLUGINS_CONSTANT_FLOW_H_
8 changes: 5 additions & 3 deletions src/ParabolicFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#endif // __HIPCC__

#ifndef PYBIND11_EXPORT
#define PYBIND11_EXPORT __attribute__((visibility("default")))
#define _PYBIND11_EXPORT __attribute__((visibility("default")))
#else
#define _PYBIND11_EXPORT PYBIND11_EXPORT
#endif

namespace hoomd
Expand All @@ -48,7 +50,7 @@ namespace azplugins
* \note The user must properly establish no flux of particles through the channel
* walls through an appropriate wall potential.
*/
class PYBIND11_EXPORT ParabolicFlow
class _PYBIND11_EXPORT ParabolicFlow
{
public:
//! Construct parabolic flow profile
Expand Down Expand Up @@ -101,6 +103,6 @@ class PYBIND11_EXPORT ParabolicFlow
} // namespace hoomd

#undef HOSTDEVICE
#undef PYBIND11_EXPORT
#undef _PYBIND11_EXPORT

#endif // AZPLUGINS_PARABOLIC_FLOW_H_
19 changes: 12 additions & 7 deletions src/RNGIdentifiers.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,23 @@
#ifndef AZPLUGINS_RNG_IDENTIFIERS_H_
#define AZPLUGINS_RNG_IDENTIFIERS_H_

#include <cstdint>

namespace hoomd
{
namespace azplugins
{

namespace detail
{
struct RNGIdentifier
{
// hoomd's identifiers, changed by +/- 1
static const uint32_t DPDEvaluatorGeneralWeight = 0x4a84f5d1;
static const uint32_t TwoStepBrownianFlow = 0x431287fe;
static const uint32_t TwoStepLangevinFlow = 0x89abcdee;
static const uint32_t ParticleEvaporator = 0x3eb8536f;
static const uint8_t DPDEvaluatorGeneralWeight = 200;
static const uint8_t TwoStepBrownianFlow = 201;
static const uint8_t TwoStepLangevinFlow = 202;
static const uint8_t ParticleEvaporator = 203;
};

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

#endif // AZPLUGINS_RNG_IDENTIFIERS_H_
71 changes: 24 additions & 47 deletions src/TwoStepBrownianFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,39 @@
#ifndef AZPLUGINS_TWO_STEP_BROWNIAN_FLOW_H_
#define AZPLUGINS_TWO_STEP_BROWNIAN_FLOW_H_

#ifdef NVCC
#ifdef __HIPCC__
#error This header cannot be compiled by nvcc
#endif

#include "hoomd/RandomNumbers.h"
#include "hoomd/extern/pybind/include/pybind11/pybind11.h"
#include "hoomd/md/TwoStepLangevinBase.h"
#include <pybind11/pybind11.h>

#include "RNGIdentifiers.h"

namespace hoomd
{
namespace azplugins
{

//! Integrates part of the system forward in two steps with Brownian dynamics under flow
/*!
* \note Only translational motion is supported by this integrator.
*/
template<class FlowField> class PYBIND11_EXPORT TwoStepBrownianFlow : public TwoStepLangevinBase
template<class FlowField> class PYBIND11_EXPORT TwoStepBrownianFlow : public md::TwoStepLangevinBase
{
public:
//! Constructor
TwoStepBrownianFlow(std::shared_ptr<SystemDefinition> sysdef,
std::shared_ptr<ParticleGroup> group,
std::shared_ptr<Variant> T,
std::shared_ptr<FlowField> flow_field,
unsigned int seed,
bool use_lambda,
Scalar lambda,
bool noiseless)
: TwoStepLangevinBase(sysdef, group, T, seed, use_lambda, lambda), m_flow_field(flow_field),
: md::TwoStepLangevinBase(sysdef, group, T), m_flow_field(flow_field),
m_noiseless(noiseless)
{
m_exec_conf->msg->notice(5) << "Constructing TwoStepBrownianFlow" << std::endl;
if (m_sysdef->getNDimensions() < 3)
{
m_exec_conf->msg->error() << "flow.brownian is only supported in 3D" << std::endl;
throw std::runtime_error("Brownian dynamics in flow is only supported in 3D");
}
}
Expand Down Expand Up @@ -75,10 +72,6 @@ template<class FlowField> class PYBIND11_EXPORT TwoStepBrownianFlow : public Two
/*!
* \param flow_field New flow field to apply
*/
void setFlowField(std::shared_ptr<FlowField> flow_field)
{
m_flow_field = flow_field;
}

//! Get the flag for if noise is applied to the motion
bool getNoiseless() const
Expand All @@ -105,13 +98,8 @@ void TwoStepBrownianFlow<FlowField>::integrateStepOne(unsigned int timestep)
{
if (m_aniso)
{
m_exec_conf->msg->error() << "azplugins.integrate: anisotropic particles are not supported "
"with brownian flow integrators."
<< std::endl;
throw std::runtime_error("Anisotropic integration not supported with brownian flow");
}
if (m_prof)
m_prof->push("Brownian step");

ArrayHandle<Scalar4> h_pos(m_pdata->getPositions(),
access_location::host,
Expand All @@ -121,16 +109,15 @@ void TwoStepBrownianFlow<FlowField>::integrateStepOne(unsigned int timestep)
ArrayHandle<Scalar4> h_net_force(m_pdata->getNetForce(),
access_location::host,
access_mode::read);
ArrayHandle<Scalar> h_diameter(m_pdata->getDiameters(),
access_location::host,
access_mode::read);
ArrayHandle<Scalar> h_gamma(m_gamma, access_location::host, access_mode::read);

const Scalar currentTemp = m_T->getValue(timestep);
const Scalar currentTemp = (*m_T)(timestep);
const FlowField& flow_field = *m_flow_field;

const BoxDim& box = m_pdata->getBox();

uint16_t seed = m_sysdef->getSeed();

// perform the first half step of velocity verlet
unsigned int group_size = m_group->getNumMembers();
for (unsigned int group_idx = 0; group_idx < group_size; group_idx++)
Expand All @@ -141,13 +128,7 @@ void TwoStepBrownianFlow<FlowField>::integrateStepOne(unsigned int timestep)
const Scalar4 postype = h_pos.data[idx];
Scalar3 pos = make_scalar3(postype.x, postype.y, postype.z);
const unsigned int type = __scalar_as_int(postype.w);
Scalar gamma;
if (m_use_lambda)
gamma = m_lambda * h_diameter.data[idx];
else
{
gamma = h_gamma.data[type];
}
const Scalar gamma = h_gamma.data[type];

// get the flow velocity at the current position
const Scalar3 flow_vel = flow_field(pos);
Expand All @@ -158,10 +139,11 @@ void TwoStepBrownianFlow<FlowField>::integrateStepOne(unsigned int timestep)
coeff = Scalar(0.0);

// draw random force
hoomd::RandomGenerator rng(azplugins::RNGIdentifier::TwoStepBrownianFlow,
m_seed,
h_tag.data[idx],
timestep);
hoomd::RandomGenerator rng(
hoomd::Seed(hoomd::azplugins::detail::RNGIdentifier::TwoStepBrownianFlow,
timestep,
seed),
hoomd::Counter(h_tag.data[idx]));
hoomd::UniformDistribution<Scalar> uniform(-coeff, coeff);
const Scalar3 random_force = make_scalar3(uniform(rng), uniform(rng), uniform(rng));

Expand All @@ -176,9 +158,6 @@ void TwoStepBrownianFlow<FlowField>::integrateStepOne(unsigned int timestep)
// write out the position
h_pos.data[idx] = make_scalar4(pos.x, pos.y, pos.z, type);
}

if (m_prof)
m_prof->pop();
}

namespace detail
Expand All @@ -190,21 +169,19 @@ void export_TwoStepBrownianFlow(pybind11::module& m, const std::string& name)
namespace py = pybind11;
typedef TwoStepBrownianFlow<FlowField> BrownianFlow;

py::class_<BrownianFlow, std::shared_ptr<BrownianFlow>>(m,
name.c_str(),
py::base<TwoStepLangevinBase>())
py::class_<BrownianFlow, std::shared_ptr<BrownianFlow>>(
m,
name.c_str(),
py::base<hoomd::md::TwoStepLangevinBase>())
.def(py::init<std::shared_ptr<SystemDefinition>,
std::shared_ptr<ParticleGroup>,
std::shared_ptr<Variant>,
std::shared_ptr<FlowField>,
unsigned int,
bool,
Scalar,
bool>())
.def("setFlowField", &BrownianFlow::setFlowField)
.def("setNoiseless", &BrownianFlow::setNoiseless);
.def_property_readonly("flow_field", &BrownianFlow::getFlowField)
.def_property("noiseless", &BrownianFlow::getNoiseless, &BrownianFlow::setNoiseless);
}
} // end namespace detail
} // end namespace azplugins

} // end namespace detail
} // end namespace azplugins
} // end namespace hoomd
#endif // AZPLUGINS_TWO_STEP_BROWNIAN_FLOW_H_
Loading