QMCPACK
OhmmsTinyMeta.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 //
9 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef OHMMS_TINY_META_H
14 #define OHMMS_TINY_META_H
15 
16 
17 namespace qmcplusplus
18 {
19 /* \note
20  * For optimization, operators for TinyVector and Tensor classes are specalized for D.
21  * Instead of using PETE generated operators, the operators for TinyVector, Tensor and TinyMatrix
22  * classes are explicitly implemented in several files.
23  * The collections are rather arbitrary but follow the r1/src/AppTypes pattern closely.
24  * This file is included by TinyVector.h, Tensor.h, and TinyMatrix.h.
25  * Therefore, users do not have to include this file.
26  */
27 
28 // forward declarations
29 template<class T, unsigned D>
30 struct TinyVector;
31 template<class T, unsigned D>
32 class Tensor;
33 template<class T, unsigned D>
34 class SymTensor;
35 template<class T, unsigned D>
36 class AntiSymTensor;
37 template<class T, unsigned D1, unsigned D2>
38 class TinyMatrix;
39 
40 // generic OTAssign and OTBinary functors (OT = OhmmsTiny)
41 template<class T1, class T2, class OP>
42 struct OTAssign
43 {};
44 template<class T1, class T2, class OP>
45 struct OTBinary
46 {};
47 
48 // generic Dot-product functors
49 template<class T1, class T2>
50 struct OTDot
51 {};
52 } // namespace qmcplusplus
53 
54 ////////////////////////////////////////////////////////////////////////////////
55 // TinyVectorOps.h assignment/unary and binary operators for TinyVector
56 // TensorOps.h assignment/unary and binary operators for Tensors
57 // TinyVectorTensorOps.h binary operators for TinyVector and Tensor combinations
58 // TinyMatrixOps.h assignment/unary and binary operators for TinyMatrix
59 ////////////////////////////////////////////////////////////////////////////////
60 #include <cassert>
61 #define PAssert(condition) assert(condition)
63 #include "OhmmsPETE/TensorOps.h"
66 
67 // macros to generate a set of binary and unary combintions for each operator
68 // e.g., OHMMS_META_BINARY_OPERATORS(TinyVector,operator+,OpAdd)
69 // generates
70 // a) TinyVector + TinyVector
71 // b) TinyVector + scalar
72 // c) scalar + TinyVector
73 // TinyVector.h and Tensor.h choose appropriate operators.
74 
75 #define OHMMS_META_BINARY_OPERATORS(TENT, FUNC, TAG) \
76  \
77  template<class T1, class T2, unsigned D> \
78  struct BinaryReturn<TENT<T1, D>, TENT<T2, D>, TAG> \
79  { \
80  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D>; \
81  }; \
82  \
83  template<class T1, class T2, unsigned D> \
84  inline typename BinaryReturn<TENT<T1, D>, TENT<T2, D>, TAG>::Type_t FUNC(const TENT<T1, D>& v1, \
85  const TENT<T2, D>& v2) \
86  { \
87  return OTBinary<TENT<T1, D>, TENT<T2, D>, TAG>::apply(v1, v2, TAG()); \
88  } \
89  \
90  template<class T1, class T2, unsigned D> \
91  struct BinaryReturn<TENT<T1, D>, T2, TAG> \
92  { \
93  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D>; \
94  }; \
95  \
96  template<class T1, class T2, unsigned D> \
97  struct BinaryReturn<T1, TENT<T2, D>, TAG> \
98  { \
99  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D>; \
100  }; \
101  \
102  template<class T1, class T2, unsigned D> \
103  inline typename BinaryReturn<TENT<T1, D>, T2, TAG>::Type_t FUNC(const TENT<T1, D>& v1, const T2& x) \
104  { \
105  return OTBinary<TENT<T1, D>, T2, TAG>::apply(v1, x, TAG()); \
106  } \
107  \
108  template<class T1, class T2, unsigned D> \
109  inline typename BinaryReturn<T1, TENT<T2, D>, TAG>::Type_t FUNC(const T1& x, const TENT<T2, D>& v2) \
110  { \
111  return OTBinary<T1, TENT<T2, D>, TAG>::apply(x, v2, TAG()); \
112  }
113 
114 #define OHMMS_META_ACCUM_OPERATORS(TENT, FUNC, TAG) \
115  \
116  template<class T1, class T2, unsigned D> \
117  inline TENT<T1, D>& FUNC(TENT<T1, D>& v1, const TENT<T2, D>& v2) \
118  { \
119  OTAssign<TENT<T1, D>, TENT<T2, D>, TAG>::apply(v1, v2, TAG()); \
120  return v1; \
121  } \
122  \
123  template<class T1, class T2, unsigned D> \
124  inline TENT<T1, D>& FUNC(TENT<T1, D>& v1, const T2& v2) \
125  { \
126  OTAssign<TENT<T1, D>, T2, TAG>::apply(v1, v2, TAG()); \
127  return v1; \
128  }
129 
130 #define OHMMS_TINYMAT_BINARY_OPERATORS(TENT, FUNC, TAG) \
131  \
132  template<class T1, class T2, unsigned D1, unsigned D2> \
133  struct BinaryReturn<TENT<T1, D1, D2>, TENT<T2, D1, D2>, TAG> \
134  { \
135  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D1, D2>; \
136  }; \
137  \
138  template<class T1, class T2, unsigned D1, unsigned D2> \
139  inline typename BinaryReturn<TENT<T1, D1, D2>, TENT<T2, D1, D2>, TAG>::Type_t FUNC(const TENT<T1, D1, D2>& v1, \
140  const TENT<T2, D1, D2>& v2) \
141  { \
142  return OTBinary<TENT<T1, D1, D2>, TENT<T2, D1, D2>, TAG>::apply(v1, v2, TAG()); \
143  } \
144  \
145  template<class T1, class T2, unsigned D1, unsigned D2> \
146  struct BinaryReturn<TENT<T1, D1, D2>, T2, TAG> \
147  { \
148  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D1, D2>; \
149  }; \
150  \
151  template<class T1, class T2, unsigned D1, unsigned D2> \
152  struct BinaryReturn<T1, TENT<T2, D1, D2>, TAG> \
153  { \
154  using Type_t = TENT<typename BinaryReturn<T1, T2, TAG>::Type_t, D1, D2>; \
155  }; \
156  \
157  template<class T1, class T2, unsigned D1, unsigned D2> \
158  inline typename BinaryReturn<TENT<T1, D1, D2>, T2, TAG>::Type_t FUNC(const TENT<T1, D1, D2>& v1, const T2& x) \
159  { \
160  return OTBinary<TENT<T1, D1, D2>, T2, TAG>::apply(v1, x, TAG()); \
161  } \
162  \
163  template<class T1, class T2, unsigned D1, unsigned D2> \
164  inline typename BinaryReturn<T1, TENT<T2, D1, D2>, TAG>::Type_t FUNC(const T1& x, const TENT<T2, D1, D2>& v2) \
165  { \
166  return OTBinary<T1, TENT<T2, D1, D2>, TAG>::apply(x, v2, TAG()); \
167  }
168 
169 #define OHMMS_TINYMAT_ACCUM_OPERATORS(TENT, FUNC, TAG) \
170  \
171  template<class T1, class T2, unsigned D1, unsigned D2> \
172  inline TENT<T1, D1, D2>& FUNC(TENT<T1, D1, D2>& v1, const TENT<T2, D1, D2>& v2) \
173  { \
174  OTAssign<TENT<T1, D1, D2>, TENT<T2, D1, D2>, TAG>::apply(v1, v2, TAG()); \
175  return v1; \
176  } \
177  \
178  template<class T1, class T2, unsigned D1, unsigned D2> \
179  inline TENT<T1, D1, D2>& FUNC(TENT<T1, D1, D2>& v1, const T2& v2) \
180  { \
181  OTAssign<TENT<T1, D1, D2>, T2, TAG>::apply(v1, v2, TAG()); \
182  return v1; \
183  }
184 
185 #endif // OHMMS_TINY_META_H
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32