QMCPACK
ParticleBConds.h
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2016 Jeongnim Kim and QMCPACK developers.
6 //
7 // File developed by: Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 //
10 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
11 //////////////////////////////////////////////////////////////////////////////////////
12 
13 
14 #ifndef QMCPLUSPLUS_PARTICLE_BCONDS_H
15 #define QMCPLUSPLUS_PARTICLE_BCONDS_H
16 
17 #include <config.h>
18 #include "CPU/SIMD/vmath.hpp"
19 #include "Lattice/CrystalLattice.h"
20 
21 namespace qmcplusplus
22 {
23 template<int N, unsigned D>
24 struct PowerOfN
25 {
26  enum
27  {
28  value = N * PowerOfN<N, D - 1>::value
29  };
30 };
31 
32 template<int N>
33 struct PowerOfN<N, 0>
34 {
35  enum
36  {
37  value = 1
38  };
39 };
40 
41 /** @defgroup BoundaryHandlers Templates to handle boundary conditions
42  * @brief generic Boundary condition handler
43  *
44  * @tparam T real data type
45  * @tparam D physical dimension
46  * @tparam SC supercell type
47  *
48  * Default method for any dimension with OPEN boundary condition.
49  * \htmlonly
50  <table>
51  <th>
52  <td>SC</td><td>3D</td><td>2D</td><td>1D</td><td>comment</td>
53  </th>
54  <tr><td>SUPERCELL_OPEN </td><td>n n n</td><td>n n</td><td>n</td><td>open boudary conditions </td> </tr>
55  <tr><td>SUPERCELL_BULK </td><td>p p p</td><td>NA </td><td>NA</td><td>periodic boundary conditions in 3 dimensions, general cell</td> </tr>
56  <tr><td>SUPERCELL_BULK+TwoPowerD </td><td>p p p</td><td>NA </td><td>NA</td><td>periodic boundary conditions in 3 dimensions, orthorombic cell</td></tr>
57  <tr><td>SUPERCELL_SLAB </td><td>p p n</td><td>p p</td><td>NA</td><td>periodic boundary conditions in 2 dimensions, general cell</td></tr>
58  <tr><td>SUPERCELL_SLAB+TwoPowerD </td><td>p p n</td><td>p p</td><td>NA</td><td>periodic boundary conditions in 2 dimensions, orthorombic cell</td></tr>
59  <tr><td>SUPERCELL_WIRE </td><td>p n n</td><td>p n</td><td>p</td><td>periodic boundary conditions in 1 dimension</td></tr>
60  </table>
61  * \endhtmlonly
62  * Specialization of DTD_BConds should implement
63  * - apply_bc(TinyVector<T,D>& displ): apply BC on displ, Cartesian displacement vector, and returns |displ|^2
64  * - apply_bc(dr,r,rinv): apply BC on displacements
65  * - apply_bc(dr,r): apply BC without inversion calculations
66  * - evaluate_rsq(dr,rr,n): apply BC on dr, and compute r*r
67  */
68 template<class T, unsigned D, int SC>
69 struct DTD_BConds
70 {
71  /** constructor: doing nothing */
72  inline DTD_BConds(const CrystalLattice<T, D>& lat) {}
73 
74  /** apply BC on displ and return |displ|^2
75  * @param displ a displacement vector in the Cartesian coordinate
76  * @return \f$|displ|^2\f$
77  */
78  inline T apply_bc(TinyVector<T, D>& displ) const { return dot(displ, displ); }
79 
80  /** apply BC on dr and evaluate r and rinv
81  * @param dr vector of displacements, in and out
82  * @param r vector of distances
83  * @param rinv vector of 1/r
84  *
85  * The input displacement vectors are not modified with the open boundary conditions.
86  */
87  inline void apply_bc(std::vector<TinyVector<T, D>>& dr, std::vector<T>& r, std::vector<T>& rinv) const
88  {
89  const int n = dr.size();
90  for (int i = 0; i < n; ++i)
91  rinv[i] = dot(dr[i], dr[i]);
92  simd::sqrt(&rinv[0], &r[0], n);
93  simd::inv(&r[0], &rinv[0], n);
94  }
95 
96  inline void apply_bc(std::vector<TinyVector<T, D>>& dr, std::vector<T>& r) const
97  {
98  for (int i = 0; i < dr.size(); ++i)
99  r[i] = std::sqrt(dot(dr[i], dr[i]));
100  }
101 
102  inline void evaluate_rsquared(TinyVector<T, D>* restrict dr, T* restrict rr, int n)
103  {
104  for (int i = 0; i < n; ++i)
105  rr[i] = dot(dr[i], dr[i]);
106  }
107 };
108 
109 } // namespace qmcplusplus
110 
111 #if OHMMS_DIM == 3
113 #elif OHMMS_DIM == 2
115 #endif
116 
117 #endif // OHMMS_PARTICLE_BCONDS_H
a class that defines a supercell in D-dimensional Euclean space.
DTD_BConds(const CrystalLattice< T, D > &lat)
constructor: doing nothing
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
void apply_bc(std::vector< TinyVector< T, D >> &dr, std::vector< T > &r) const
void apply_bc(std::vector< TinyVector< T, D >> &dr, std::vector< T > &r, std::vector< T > &rinv) const
apply BC on dr and evaluate r and rinv
Declaration of CrystalLattice<T,D>
T apply_bc(TinyVector< T, D > &displ) const
apply BC on displ and return |displ|^2
void evaluate_rsquared(TinyVector< T, D > *restrict dr, T *restrict rr, int n)
void inv(const T *restrict in, T *restrict out, int n)
Definition: vmath.hpp:65
MakeReturn< UnaryNode< FnSqrt, typename CreateLeaf< Vector< T1, C1 > >::Leaf_t > >::Expression_t sqrt(const Vector< T1, C1 > &l)
Tensor< typename BinaryReturn< T1, T2, OpMultiply >::Type_t, D > dot(const AntiSymTensor< T1, D > &lhs, const AntiSymTensor< T2, D > &rhs)
void sqrt(T *restrict inout, SIZET n)
Definition: vmath.hpp:52