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: Ken Esler, kpesler@gmail.com, University of Illinois at Urbana-Champaign
8 // Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
9 // Jeremy McMinnis, jmcminis@gmail.com, University of Illinois at Urbana-Champaign
10 // Mark A. Berrill, berrillma@ornl.gov, Oak Ridge National Laboratory
11 //
12 // File created by: Jeongnim Kim, jeongnim.kim@gmail.com, University of Illinois at Urbana-Champaign
13 //////////////////////////////////////////////////////////////////////////////////////
14
15
16 /** @file BasisSetBase.h
17 * @brief Declaration of a base class of BasisSet
18 */
19 #ifndef QMCPLUSPLUS_ORBITALSETTRAITS_H
20 #define QMCPLUSPLUS_ORBITALSETTRAITS_H
21
22 #include "Configuration.h"
23 #include "type_traits/scalar_traits.h"
24 #include "Optimize/VariableSet.h"
25
26 namespace qmcplusplus
27 {
28 /** dummy class for templated classes
29 */
30 struct DummyGrid
31 {
locateDummyGrid32 inline void locate(double r) {}
makeCloneDummyGrid33 DummyGrid* makeClone() const { return new DummyGrid; }
34 };
35
36 typedef TinyVector<int, 4> QuantumNumberType;
37
38 enum
39 {
40 q_n = 0,
41 q_l,
42 q_m,
43 q_s
44 };
45
46 /** trait class to handel a set of Orbitals
47 */
48 template<typename T>
49 struct OrbitalSetTraits //: public OrbitalTraits<T>
50 {
51 enum
52 {
53 DIM = OHMMS_DIM
54 };
55 typedef typename scalar_traits<T>::real_type RealType;
56 typedef typename scalar_traits<T>::value_type ValueType;
57 typedef int IndexType;
58 typedef TinyVector<RealType, DIM> PosType;
59 typedef TinyVector<ValueType, DIM> GradType;
60 typedef Tensor<ValueType, DIM> HessType;
61 typedef Tensor<ValueType, DIM> TensorType;
62 typedef TinyVector<Tensor<ValueType, DIM>, DIM> GradHessType;
63 typedef Vector<IndexType> IndexVector_t;
64 typedef Vector<ValueType> ValueVector_t;
65 typedef Matrix<ValueType> ValueMatrix_t;
66 typedef Vector<GradType> GradVector_t;
67 typedef Matrix<GradType> GradMatrix_t;
68 typedef Vector<HessType> HessVector_t;
69 typedef Matrix<HessType> HessMatrix_t;
70 typedef Vector<GradHessType> GradHessVector_t;
71 typedef Matrix<GradHessType> GradHessMatrix_t;
72 typedef VectorSoaContainer<ValueType, DIM + 2> VGLVector_t;
73 };
74
75 ///typedef for a set of variables that are varied during an optimization
76 using opt_variables_type = optimize::VariableSet;
77 ///typedef for a set of variables that can be varied
78 using variable_map_type = optimize::VariableSet::variable_map_type;
79
80 /** evaluate log(psi) as log(|psi|) and phase
81 * @param psi real/complex value
82 * @return complex<T>(log(|psi|), arg(psi))
83 *
84 * The return value is always complex regardless of the type of psi.
85 * The sign of of a real psi value is represented in the complex part of the return value.
86 * The phase of std::log(complex) is in range [-pi, pi] defined in C++
87 */
88 template<typename T>
convertValueToLog(const std::complex<T> & logpsi)89 inline std::complex<T> convertValueToLog(const std::complex<T>& logpsi)
90 {
91 return std::log(logpsi);
92 }
93
94 template<typename T>
convertValueToLog(const T logpsi)95 inline std::complex<T> convertValueToLog(const T logpsi)
96 {
97 return std::log(std::complex<T>(logpsi));
98 }
99
100 /** evaluate psi based on log(psi)
101 * @param logpsi complex value
102 * @return exp(log(psi))
103 *
104 * LogToValue<ValueType>::convert(complex) is the reverse operation of convertValueToLog(ValueType)
105 */
106 template<typename T>
107 struct LogToValue
108 {
109 template<typename T1>
convertLogToValue110 inline static T convert(const std::complex<T1>& logpsi)
111 {
112 return std::real(std::exp(logpsi));
113 }
114 };
115
116 template<typename T>
117 struct LogToValue<std::complex<T>>
118 {
119 template<typename T1, typename = std::enable_if_t<!std::is_same<T, T1>::value>>
120 inline static std::complex<T> convert(const std::complex<T1>& logpsi)
121 {
122 std::complex<T> tmp(std::real(logpsi), std::imag(logpsi));
123 return std::exp(tmp);
124 }
125
126 inline static std::complex<T> convert(const std::complex<T>& logpsi)
127 {
128 return std::exp(logpsi);
129 }
130 };
131
132 } // namespace qmcplusplus
133
134 #endif
135