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: joaander
52 #ifndef __BOND_EVALUATOR_HARMONIC_H__
53 #define __BOND_EVALUATOR_HARMONIC_H__
59 #include "HOOMDMath.h"
61 /*! \file EvaluatorBondHarmonic.h
62 \brief Defines the bond evaluator class for harmonic potentials
65 // need to declare these class methods with __device__ qualifiers when building in nvcc
66 // DEVICE is __host__ __device__ when included in nvcc and blank when included into the host compiler
68 #define DEVICE __device__
73 //! Class for evaluating the harmonic bond potential
74 /*! Evaluates the harmonic bond potential in an identical manner to EvaluatorPairLJ for pair potentials. See that
75 class for a full motivation and design specifics.
77 params.x is the K stiffness parameter, and params.y is the r_0 equilibrium rest length.
79 class EvaluatorBondHarmonic
82 //! Define the parameter type used by this pair potential evaluator
83 typedef Scalar2 param_type
;
85 //! Constructs the pair potential evaluator
86 /*! \param _rsq Squared distance beteen the particles
87 \param _params Per type pair parameters of this potential
89 DEVICE
EvaluatorBondHarmonic(Scalar _rsq
, const param_type
& _params
)
90 : rsq(_rsq
),K(_params
.x
), r_0(_params
.y
)
94 //! Harmonic doesn't use diameter
95 DEVICE
static bool needsDiameter() { return false; }
97 //! Accept the optional diameter values
98 /*! \param da Diameter of particle a
99 \param db Diameter of particle b
101 DEVICE
void setDiameter(Scalar da
, Scalar db
) { }
103 //! Harmonic doesn't use charge
104 DEVICE
static bool needsCharge() { return false; }
106 //! Accept the optional charge values
107 /*! \param qa Charge of particle a
108 \param qb Charge of particle b
110 DEVICE
void setCharge(Scalar qa
, Scalar qb
) { }
112 //! Evaluate the force and energy
113 /*! \param force_divr Output parameter to write the computed force divided by r.
114 \param bond_eng Output parameter to write the computed bond energy
116 \return True if they are evaluated or false if the bond
117 energy is not defined
119 DEVICE
bool evalForceAndEnergy(Scalar
& force_divr
, Scalar
& bond_eng
)
121 Scalar r
= sqrt(rsq
);
122 force_divr
= K
* (r_0
/ r
- Scalar(1.0));
124 // if the result is not finite, it is likely because of a division by 0, setting force_divr to 0 will
125 // correctly result in a 0 force in this case
126 if (!isfinite(force_divr
))
128 force_divr
= Scalar(0);
130 bond_eng
= Scalar(0.5) * K
* (r_0
- r
) * (r_0
- r
);
136 //! Get the name of this potential
137 /*! \returns The potential name. Must be short and all lowercase, as this is the name energies will be logged as
140 static std::string
getName()
142 return std::string("harmonic");
147 Scalar rsq
; //!< Stored rsq from the constructor
148 Scalar K
; //!< K parameter
149 Scalar r_0
; //!< r_0 parameter
153 #endif // __BOND_EVALUATOR_HARMONIC_H__