def force_update(timestep):
for particle in hoomd.group.all():
force = (-particle.position[1], particle.position[0], 0.0)
hoomd.data.force_data_proxy(force, particle)
return 1
hoomd.context.initialize("")
system = hoomd.init.create_lattice(unitcell=hoomd.lattice.sq(a=1.4), n=15)
all = hoomd.group.all()
N = len(all)
hoomd.md.integrate.mode_standard(dt=0.002)
hoomd.md.integrate.langevin(group=all, kT=0.0, seed=123, noiseless_r=True)
hoomd.run(2000, callback=force_update, callback_period=10)
--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
To post to this group, send email to hoomd...@googlegroups.com.
Visit this group at https://groups.google.com/group/hoomd-users.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users+unsubscribe@googlegroups.com.
To post to this group, send email to hoomd-users@googlegroups.com.
Visit this group at https://groups.google.com/group/hoomd-users.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hoomd-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users+unsubscribe@googlegroups.com.
class ForceField {
public:
void setSize(/*const input of all public parameters*/) {}; // resizes ffield with specified parameters
void setValue (const unsigned long &t, const unsigned long &m, const unsigned long &n,
const unsigned long &l, const Scalar3 &value); // set Values in ffield
//gets Values from field
Scalar3 getValue (const unsigned long &t, const unsigned long &m, const unsigned long &n, const unsigned long &l);
unsigned long _m,_n,_l,_t; // Size of the force field matrix mxnxlxt
double _ml,_nl,_ll,_tl; // Length after which the force field repeats itself, time interval of repeat
private:
GPUVector< Scalar3 > ffield;
};
class force_field(_external_force):
def __init__(self, forcefield ,name=""):
hoomd.util.print_status_line();
# initialize the base class
_external_force.__init__(self, name);
# create the c++ mirror class
if not hoomd.context.exec_conf.isCUDAEnabled():
self.cpp_force = _md.PotentialExternalForceField(hoomd.context.current.system_definition,self.name);
else:
self.cpp_force = _md.PotentialExternalForceFieldGPU(hoomd.context.current.system_definition,self.name);
hoomd.context.current.system.addCompute(self.cpp_force, self.force_name);
# setup the coefficient options
self.required_coeffs = None;
self.field_coeff = None;
self.forceField = forcefield;
def process_coeff(self, coeff):
pass;
def process_field_coeff(self,field):
pass;
def process_forcefield(self, forcefield):
return forcefield;
def update_coeffs(self):
[...]
if self.forceField:
forcefield = self.process_forcefield(self.forceField);
self.cpp_force.setForceField(forcefield);
template<class evaluator>
void PotentialExternal<evaluator>::setForceField(field_type field)
{
m_field = field;
}
class EvaluatorExternalForceField
{
public:
//! type of parameters this external potential accepts
typedef struct param{} param_type;
typedef class ForceField field_type;
//! Constructs the constraint evaluator
/*! \param X position of particle
\param box box dimensions
\param forcefield ForceField object containing force field data
*/
DEVICE EvaluatorExternalForceField(Scalar3 X, const BoxDim& box, const param_type& params,
const field_type& field ,const field_type& forcefield)
: m_pos(X),
m_box(box)
{
m_field = forcefield;
}
/*
the needs and set functions are just plain copys from EvaluatorExternalPeriodic.h
*/
DEVICE void evalForceEnergyAndVirial(Scalar3& F, Scalar& energy, Scalar* virial)
{
static long int timestep=0;
long int m,n,l,t; // as previously introduced, the matrix elements
F.x = Scalar(0.0);
F.y = Scalar(0.0);
F.z = Scalar(0.0);
energy = Scalar(0.0);
// evaluate matrix elements
t = (timestep/m_field._tl)%m_field._t;
m = lround(fmod((m_pos.x) / m_field._ml, m_field._m));
if (m<0) {m += m_field._m;}
n = lround(fmod((m_pos.y)/m_field._nl,m_field._n));
if (n<0) {n += m_field._n;}
l = lround(fmod((m_pos.z)/m_field._ll,m_field._l));
if (l<0) {l += m_field._l;}
F = m_field.getValue(t,m,n,l); // <- The programm crashes on first call of getValue()
timestep ++;
}
#ifndef NVCC
//! Get the name of this potential
/*! \returns The potential name. Must be short and all lowercase, as this is the name energies will be logged as
via analyze.log.
*/
static std::string getName()
{
return std::string("forcefield");
}
#endif
protected:
Scalar3 m_pos; //!< particle position
BoxDim m_box; //!< box dimensions
ForceField m_field; //!< forcefield data
};
To unsubscribe from this group and stop receiving emails from it, send an email to hoomd-users...@googlegroups.com.
}
DEVICE void evalForceEnergyAndVirial(Scalar3& F, Scalar& energy, Scalar* virial)
{
static long int timestep=0; // should give the current timestep
long int m,n,l,t; // matrix element numbers
F.x = Scalar(0.0);
F.y = Scalar(0.0);
F.z = Scalar(0.0);
energy = Scalar(0.0);
t = (timestep/m_field.getTl())%m_field.getT();
m = lround(fmod((m_pos.x) / m_field._ml, m_field._m));
if (m<0) {m += m_field._m;}
n = lround(fmod((m_pos.y)/m_field._nl,m_field._n));
if (n<0) {n += m_field._n;}
l = lround(fmod((m_pos.z)/m_field._ll,m_field._l));
if (l<0) {l += m_field._l;}
F = m_field.getValue(t,m,n,l); // <- this throws the error
timestep ++;
}
#ifndef NVCC
//! Get the name of this potential
/*! \returns The potential name. Must be short and all lowercase, as this is the name energies will be logged as
via analyze.log.
*/
static std::string getName()
{
return std::string("forcefield");
}
#endif
protected:
Scalar3 m_pos; //!< particle position
BoxDim m_box; //!< box dimensions
ForceField m_field; //!< forcefield data
};
m_field = forcefield<span style="color: #660;"
Thanks a lot Jens for the prompt response and the effort!
I still have a couple of questions, will you also implemented a callback function for the active force class?
Can I use the new force.constant() before it is implemented in the next release? When do you think it will be realesed?
Last but not least. Is there an efficient way to impose a spatial dependent translational/rotational diffusio=f(x,y)?
Thanks again, you guys should get a medal for all the effort you put in this.