2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #pragma warning( push )
54 #pragma warning( disable : 4103 4244 )
57 #include <boost/python.hpp>
58 using namespace boost::python
;
60 #include "ConstExternalFieldDipoleForceCompute.h"
61 #include "QuaternionMath.h"
65 /*! \file ConstExternalFieldDipoleForceCompute.cc
66 \brief Contains code for the ConstExternalFieldDipoleForceCompute class
69 /*! \param sysdef SystemDefinition containing the ParticleData to compute forces on
70 \param field_x x component of field
71 \param field_y y component of field
72 \param field_z z component of field
73 \param p p component of field
74 \note This class doesn't actually do anything with the particle data. It just returns a constant force
76 ConstExternalFieldDipoleForceCompute::ConstExternalFieldDipoleForceCompute(boost::shared_ptr
<SystemDefinition
> sysdef
, Scalar field_x
=0.0,Scalar field_y
=0.0, Scalar field_z
=0.0,Scalar p
=0.0)
77 : ForceCompute(sysdef
)
79 setParams(field_x
,field_y
,field_z
,p
);
82 /*! \param field_x x component of field
83 \param field_y y component of field
84 \param field_z z component of field
85 \param p p component of field
87 f.{x,y,z} are components of the field, f.w is the magnitude of the
88 moment in the z direction
90 void ConstExternalFieldDipoleForceCompute::setParams(Scalar field_x
,Scalar field_y
, Scalar field_z
,Scalar p
)
92 field
=make_scalar4(field_x
,field_y
,field_z
,p
);
95 /*! \brief Compute the torque applied = Cross[p,Field]
96 \param timestep Current timestep
98 void ConstExternalFieldDipoleForceCompute::computeForces(unsigned int timestep
)
101 ArrayHandle
<Scalar4
> h_orientation(m_pdata
->getOrientationArray(),access_location::host
,access_mode::read
);
102 ArrayHandle
<Scalar4
> h_torque(m_torque
,access_location::host
,access_mode::overwrite
);
104 // number of particles
105 unsigned int num_particles
= m_pdata
->getN();
107 // compute the torques
108 for (unsigned int i
=0; i
<num_particles
; i
++)
110 // rotation operator for this particle
111 Scalar4 rot
= h_orientation
.data
[i
];
112 //Hermitian conjugate
114 // compute the Hermitian conjugate
116 // base particle orientation is in z direction
118 Scalar4 base
= {0,0,1,0};
119 // to be filled by the actual moment
121 // a temporary variable
123 // do half the rotation
124 quatvec(rot
,base
,temp
);
126 quatquat(temp
,rot_H
,moment
);
129 // the resulting vector is the last three components of moment
130 // because we got it by doing a quat * quat
132 // Torque = moment X field
133 // that means recipe for cross product is
134 // [(zz-yw),(xw-zy),(yy-xz)]
135 // cf. usual [(yz-zy),(zx-xz),(xy-yx)]
137 // also field.w stores magnitude of dipole moment, so, here we go
139 // reuse temp to compute the torque
140 h_torque
.data
[i
].x
= field
.w
*(field
.z
*moment
.z
-field
.y
*moment
.w
);
141 h_torque
.data
[i
].y
= field
.w
*(field
.x
*moment
.w
-field
.z
*moment
.y
);
142 h_torque
.data
[i
].z
= field
.w
*(field
.y
*moment
.y
-field
.x
*moment
.z
);
143 h_torque
.data
[i
].w
= Scalar(0);
148 void export_ConstExternalFieldDipoleForceCompute()
150 class_
< ConstExternalFieldDipoleForceCompute
, boost::shared_ptr
<ConstExternalFieldDipoleForceCompute
>,
151 bases
<ForceCompute
>, boost::noncopyable
>
152 ("ConstExternalFieldDipoleForceCompute", init
< boost::shared_ptr
<SystemDefinition
>, Scalar
,Scalar
,Scalar
,Scalar
>())
153 .def("setParams", &ConstExternalFieldDipoleForceCompute::setParams
)
158 #pragma warning( pop )