OpenMPCD
AdditivePair.hpp
1 #ifndef OPENMPCD_PAIRPOTENTIALS_ADDITIVEPAIR_HPP
2 #define OPENMPCD_PAIRPOTENTIALS_ADDITIVEPAIR_HPP
3 
4 #include <OpenMPCD/PairPotentials/Base.hpp>
5 
8 
9 namespace OpenMPCD
10 {
11 namespace PairPotentials
12 {
13 
14 /**
15  * Represents a potential that consists of the sum of two other potentials.
16  */
17 template<typename T = FP>
18 class AdditivePair : public Base<T>
19 {
20 public:
21  /**
22  * The constructor.
23  *
24  * @throw OpenMPCD::NULLPointerException
25  * If `OPENMPCD_DEBUG` is defined, throws if `potential1 == nullptr`
26  * or `potential2 == nullptr`.
27  *
28  * @param[in] potential1 A pointer to the first potential.
29  * This pointer must remain valid as long as this
30  * instance exists.
31  * @param[in] potential2 A pointer to the second potential.
32  * This pointer must remain valid as long as this
33  * instance exists.
34  */
37  const Base<T>* const potential1, const Base<T>* const potential2)
38  : potential1(potential1), potential2(potential2)
39  {
40  #ifdef OPENMPCD_DEBUG
41  if(potential1 == NULL || potential2 == NULL)
42  {
44  NULLPointerException, "`potential1`, `potential2`");
45  }
46  #endif
47  }
48 
49  /**
50  * Returns the force vector of the interaction for a given position vector.
51  *
52  * @param[in] R The relative position vector.
53  */
55  Vector3D<T> force(const Vector3D<T>& R) const
56  {
57  return potential1->force(R) + potential2->force(R);
58  }
59 
60  /**
61  * Returns the potential of the interaction for a given position vector.
62  *
63  * @param[in] R The relative position vector.
64  */
66  T potential(const Vector3D<T>& R) const
67  {
68  return potential1->potential(R) + potential2->potential(R);
69  }
70 
71 private:
72  const Base<T>* const potential1; ///< The first potential.
73  const Base<T>* const potential2; ///< The second potential.
74 }; //class AdditivePair
75 
76 } //namespace PairPotentials
77 } //namespace OpenMPCD
78 #endif //OPENMPCD_PAIRPOTENTIALS_ADDITIVEPAIR_HPP
OPENMPCD_THROW
#define OPENMPCD_THROW(ExceptionType, message)
Throws the given ExceptionType, passing the given message along with file and line number information...
Definition: Exceptions.hpp:22
OpenMPCD::Vector3D
3-dimensional vector.
Definition: Vector3D.hpp:38
OpenMPCD::PairPotentials::AdditivePair::force
OPENMPCD_CUDA_HOST_AND_DEVICE Vector3D< T > force(const Vector3D< T > &R) const
Returns the force vector of the interaction for a given position vector.
Definition: AdditivePair.hpp:55
OPENMPCD_CUDA_HOST_AND_DEVICE
#define OPENMPCD_CUDA_HOST_AND_DEVICE
Denotes a function to be callable both from the Host and from a CUDA Device.
Definition: Macros.hpp:15
OpenMPCD::PairPotentials::AdditivePair::AdditivePair
OPENMPCD_CUDA_HOST_AND_DEVICE AdditivePair(const Base< T > *const potential1, const Base< T > *const potential2)
The constructor.
Definition: AdditivePair.hpp:36
OPENMPCD_DEBUG_ASSERT.hpp
OpenMPCD::PairPotentials::AdditivePair::potential
OPENMPCD_CUDA_HOST_AND_DEVICE T potential(const Vector3D< T > &R) const
Returns the potential of the interaction for a given position vector.
Definition: AdditivePair.hpp:66
OpenMPCD::PairPotentials::Base
Abstract base class for pair potentials.
Definition: PairPotentials/Base.hpp:24
OpenMPCD::PairPotentials::AdditivePair
Represents a potential that consists of the sum of two other potentials.
Definition: AdditivePair.hpp:18
Utilities.hpp
OpenMPCD::NULLPointerException
NULL-pointer exception.
Definition: Exceptions.hpp:96