Merge branch 'maint'
[hoomd-blue.git] / libhoomd / computes / EvaluatorConstraintSphere.h
blob779244008fd0a76a7956e9f9fa9ef28a5b5a7fb8
1 /*
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
32 permission.
34 Disclaimer
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 __EVALUATOR_CONSTRAINT_SPHERE_H__
53 #define __EVALUATOR_CONSTRAINT_SPHERE_H__
55 #include "HOOMDMath.h"
57 /*! \file EvaluatorConstraintSphere.h
58 \brief Defines the constraint evaluator class for spheres
61 // need to declare these class methods with __device__ qualifiers when building in nvcc
62 // DEVICE is __host__ __device__ when included in nvcc and blank when included into the host compiler
63 #ifdef NVCC
64 #define DEVICE __device__
65 #else
66 #define DEVICE
67 #endif
69 //! Class for evaluating sphere constraints
70 /*! <b>General Overview</b>
71 EvaluatorConstraintSphere is a low level computation helper class to aid in evaluating particle constraints on a
72 sphere. Given a sphere at a given position and radius, it will find the nearest point on the sphere to a given
73 point.
75 class EvaluatorConstraintSphere
77 public:
78 //! Constructs the constraint evaluator
79 /*! \param _P Position of the sphere
80 \param _r Radius of the sphere
82 DEVICE EvaluatorConstraintSphere(Scalar3 _P, Scalar _r)
83 : P(_P), r(_r)
87 //! Evaluate the closest point on the sphere
88 /*! \param U unconstrained point
90 \return Nearest point on the sphere
92 DEVICE Scalar3 evalClosest(const Scalar3& U)
94 // compute the vector pointing from P to V
95 Scalar3 V;
96 V.x = U.x - P.x;
97 V.y = U.y - P.y;
98 V.z = U.z - P.z;
100 // compute 1/magnitude of V
101 Scalar magVinv = fast::rsqrt(V.x*V.x + V.y*V.y + V.z*V.z);
103 // compute Vhat, the unit vector pointing in the direction of V
104 Scalar3 Vhat;
105 Vhat.x = magVinv * V.x;
106 Vhat.y = magVinv * V.y;
107 Vhat.z = magVinv * V.z;
109 // compute resulting constrained point
110 Scalar3 C;
111 #if(NVCC && __CUDA_ARCH__ < 200)
112 C.x = P.x + __fmul_rn(Vhat.x,r);
113 C.y = P.y + __fmul_rn(Vhat.y,r);
114 C.z = P.z + __fmul_rn(Vhat.z,r);
115 #else
116 C.x = P.x + Vhat.x * r;
117 C.y = P.y + Vhat.y * r;
118 C.z = P.z + Vhat.z * r;
119 #endif
121 return C;
124 protected:
125 Scalar3 P; //!< Position of the sphere
126 Scalar r; //!< radius of the sphere
130 #endif // __PAIR_EVALUATOR_LJ_H__