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.
50 // Maintainer: dnlebard
52 /*! \file CGCMMAngleForceComputeGPU.cc
53 \brief Defines CGCMMAngleForceComputeGPU
57 #pragma warning( push )
58 #pragma warning( disable : 4244 )
61 #include "CGCMMAngleForceComputeGPU.h"
63 #include <boost/python.hpp>
64 using namespace boost::python
;
66 #include <boost/bind.hpp>
67 using namespace boost
;
71 /*! \param sysdef System to compute angle forces on
73 CGCMMAngleForceComputeGPU::CGCMMAngleForceComputeGPU(boost::shared_ptr
<SystemDefinition
> sysdef
)
74 : CGCMMAngleForceCompute(sysdef
)
76 // can't run on the GPU if there aren't any GPUs in the execution configuration
77 if (!exec_conf
->isCUDAEnabled())
79 m_exec_conf
->msg
->error() << "Creating a CGCMMAngleForceComputeGPU with no GPU in the execution configuration" << endl
;
80 throw std::runtime_error("Error initializing CGCMMAngleForceComputeGPU");
83 prefact
[0] = Scalar(0.0);
84 prefact
[1] = Scalar(6.75);
85 prefact
[2] = Scalar(2.59807621135332);
86 prefact
[3] = Scalar(4.0);
88 cgPow1
[0] = Scalar(0.0);
89 cgPow1
[1] = Scalar(9.0);
90 cgPow1
[2] = Scalar(12.0);
91 cgPow1
[3] = Scalar(12.0);
93 cgPow2
[0] = Scalar(0.0);
94 cgPow2
[1] = Scalar(6.0);
95 cgPow2
[2] = Scalar(4.0);
96 cgPow2
[3] = Scalar(6.0);
98 // allocate and zero device memory
99 GPUArray
<Scalar2
> params (m_CGCMMAngle_data
->getNTypes(),exec_conf
);
100 m_params
.swap(params
);
101 GPUArray
<Scalar2
> CGCMMsr(m_CGCMMAngle_data
->getNTypes(),exec_conf
);
102 m_CGCMMsr
.swap(CGCMMsr
);
103 GPUArray
<Scalar4
> CGCMMepow(m_CGCMMAngle_data
->getNTypes(),exec_conf
);
104 m_CGCMMepow
.swap(CGCMMepow
);
106 m_tuner
.reset(new Autotuner(32, 1024, 32, 5, 100000, "cgcmm_angle", this->m_exec_conf
));
109 CGCMMAngleForceComputeGPU::~CGCMMAngleForceComputeGPU()
113 /*! \param type Type of the angle to set parameters for
114 \param K Stiffness parameter for the force computation
115 \param t_0 Equilibrium angle (in radians) for the force computation
116 \param cg_type the type of course grained angle we are using
117 \param eps the well depth
118 \param sigma the particle radius
120 Sets parameters for the potential of a particular angle type and updates the
121 parameters on the GPU.
123 void CGCMMAngleForceComputeGPU::setParams(unsigned int type
, Scalar K
, Scalar t_0
, unsigned int cg_type
, Scalar eps
, Scalar sigma
)
125 CGCMMAngleForceCompute::setParams(type
, K
, t_0
, cg_type
, eps
, sigma
);
127 const Scalar myPow1
= cgPow1
[cg_type
];
128 const Scalar myPow2
= cgPow2
[cg_type
];
129 const Scalar myPref
= prefact
[cg_type
];
131 Scalar my_rcut
= sigma
*exp(Scalar(1.0)/(myPow1
-myPow2
)*log(myPow1
/myPow2
));
133 ArrayHandle
<Scalar2
> h_params(m_params
, access_location::host
, access_mode::readwrite
);
134 ArrayHandle
<Scalar2
> h_CGCMMsr(m_CGCMMsr
, access_location::host
, access_mode::readwrite
);
135 ArrayHandle
<Scalar4
> h_CGCMMepow(m_CGCMMepow
, access_location::host
, access_mode::readwrite
);
136 // update the local copy of the memory
137 h_params
.data
[type
] = make_scalar2(K
, t_0
);
138 h_CGCMMsr
.data
[type
] = make_scalar2(sigma
, my_rcut
);
139 h_CGCMMepow
.data
[type
] = make_scalar4(eps
, myPow1
, myPow2
, myPref
);
142 /*! Internal method for computing the forces on the GPU.
143 \post The force data on the GPU is written with the calculated forces
145 \param timestep Current time step of the simulation
147 Calls gpu_compute_CGCMM_angle_forces to do the dirty work.
149 void CGCMMAngleForceComputeGPU::computeForces(unsigned int timestep
)
152 if (m_prof
) m_prof
->push(exec_conf
, "CGCMM Angle");
154 // the angle table is up to date: we are good to go. Call the kernel
155 ArrayHandle
<Scalar4
> d_pos(m_pdata
->getPositions(), access_location::device
, access_mode::read
);
157 BoxDim box
= m_pdata
->getGlobalBox();
159 //Not necessary - force and virial are zeroed in the kernel
160 //m_force.memclear();
161 //m_virial.memclear();
162 ArrayHandle
<Scalar4
> d_force(m_force
,access_location::device
,access_mode::overwrite
);
163 ArrayHandle
<Scalar
> d_virial(m_virial
,access_location::device
,access_mode::overwrite
);
164 ArrayHandle
<Scalar2
> d_params(m_params
, access_location::device
, access_mode::read
);
165 ArrayHandle
<Scalar2
> d_CGCMMsr(m_CGCMMsr
, access_location::device
, access_mode::read
);
166 ArrayHandle
<Scalar4
> d_CGCMMepow(m_CGCMMepow
, access_location::device
, access_mode::read
);
168 ArrayHandle
<AngleData::members_t
> d_gpu_anglelist(m_CGCMMAngle_data
->getGPUTable(), access_location::device
,access_mode::read
);
169 ArrayHandle
<unsigned int> d_gpu_angle_pos_list(m_CGCMMAngle_data
->getGPUPosTable(), access_location::device
,access_mode::read
);
170 ArrayHandle
<unsigned int> d_gpu_n_angles(m_CGCMMAngle_data
->getNGroupsArray(), access_location::device
, access_mode::read
);
174 gpu_compute_CGCMM_angle_forces(d_force
.data
,
180 d_gpu_anglelist
.data
,
181 d_gpu_angle_pos_list
.data
,
182 m_CGCMMAngle_data
->getGPUTableIndexer().getW(),
187 m_CGCMMAngle_data
->getNTypes(),
189 m_exec_conf
->getComputeCapability());
191 if (exec_conf
->isCUDAErrorCheckingEnabled())
195 if (m_prof
) m_prof
->pop(exec_conf
);
198 void export_CGCMMAngleForceComputeGPU()
200 class_
<CGCMMAngleForceComputeGPU
, boost::shared_ptr
<CGCMMAngleForceComputeGPU
>, bases
<CGCMMAngleForceCompute
>, boost::noncopyable
>
201 ("CGCMMAngleForceComputeGPU", init
< boost::shared_ptr
<SystemDefinition
> >())