MADNESS 0.10.1
GuessFactory.h
Go to the documentation of this file.
1/*
2 * GuessFactory.h
3 *
4 * Created on: Sep 27, 2018
5 * Author: kottmanj
6 *
7 * Guess Factory for TDHF which can be used standalone for other purposes
8 */
9
10#ifndef SRC_APPS_CHEM_GUESSFACTORY_H_
11#define SRC_APPS_CHEM_GUESSFACTORY_H_
12
13#include <madness.h>
14
15namespace madness {
16
17// avoid confusion with other projects which may use similar generic names
18namespace guessfactory{
19
20// convenience macros
21#define SPLITCOORD(x,y,z,r) double x=r[0]-origin[0]; double y=r[1]-origin[1];double z=r[2]-origin[2];
22
23/// compute the centroid of a function i.e. c[xi]=<f|xi|f>/<f|f> i.e. position expectation value
25
26template<typename T, std::size_t NDIM>
27std::vector<coord_3d> compute_centroids(const std::vector<Function<T,NDIM> > & vf);
28
29/// little helper for coord (Vector<3>) and Tensor data formats
30template<typename T, size_t NDIM>
32 Vector<T,NDIM> result;
33 MADNESS_ASSERT(size_t(t.size()) >= NDIM);
34 for (size_t i = 0; i < NDIM; ++i)
35 result[i] = t[i];
36 return result;
37}
38
39
40
41/// create excitation operators with unaryop (faster as explicit construction and multiplication)
42/// Guess function do not need to be perfectly refined
44public:
46 exfunc(f), cdata(FunctionCommonData<double, 3>::get(FunctionDefaults<3>::get_k())) {
47 }
48
49 /// multiplies the target function by the excitation operator defined by exfunc
50 void operator ()(const Key<3>& key, Tensor<double>& t) const;
51 void operator ()(const Key<3>& key, Tensor<double_complex>& t) const;
52 /// shared pointer to object of excitation operator
53 std::shared_ptr<FunctionFunctorInterface<double,3> > exfunc;
55 template <typename Archive> void serialize(Archive& ar) {}
56};
57
58/// creates a plane-wave: sin (or cos) with argument (npi/L*x)
60public:
61 PlaneWaveFunctor(std::vector<double> vn,std::vector<bool> vc, const coord_3d& c) : L(FunctionDefaults<3>::get_cell_width()), n(vn), cosinus(vc), origin(c) {}
62
63 typedef double resultT;
64
65 /// for explicit construction of this plane-wave function
66 double operator ()(const coord_3d& r) const;
67 /// operator for the 1D plane waves
68 double operator ()(const double& x, const int& dim) const;
69 /// in case this is needed at some point
70 double operator()(const coord_1d & x, const int& dim)const{
71 return (*this)(x[0],dim);
72 }
73
74 std::string name(const bool& compact = false) const;
75
77 const std::vector<double> n;
78 const std::vector<bool> cosinus;
80
81
82};
83
84/// GaussFunctor to let the exciation operators go to zero at the boundaries
85/// totally symmetric
86class GaussFunctor : public FunctionFunctorInterface<double,3> {
87public:
89 GaussFunctor(const double& width): width_(width){
90 MADNESS_ASSERT(not(width<0.0));
91 }
92 GaussFunctor(const double& width, const coord_3d c): width_(width), center(c){
93 MADNESS_ASSERT(not(width<0.0));
94 }
95 GaussFunctor(const double& width, const Tensor<double> c): width_(width), center(tensor_to_coord<double,3>(c)){
96 MADNESS_ASSERT(not(width<0.0));
97 }
98 const double width_;
100
101 /// explicit construction
102 double operator ()(const coord_3d& rr) const;
103
104
105};
106
107/// Project a general 3D polynomial to the MRA Grid
109public :
110 /// simple xyz moments constructor
112 // general polynomials or sums of polynomials
113 PolynomialFunctor(const std::string input, const double& damp_width=0.0, const coord_3d& c=coord_3d()) : input_string_(input), data_(read_string(input)), dampf(damp_width), center(c) {}
114 PolynomialFunctor(const std::string input,const double& damp_width, const Tensor<double>& c) : input_string_(input), data_(read_string(input)), dampf(damp_width), center(tensor_to_coord<double,3>(c)) {}
115
116 /// construction by coordinates
117 double operator ()(const coord_3d& rr) const;
118
119 /// create the value of the polynomial according to the data in the data_ structure
120 double compute_value(const coord_3d& r) const;
121
122 /// convert a given axis to the appropriate input string
123 std::string axis_to_string(const int& axis)const{
124 std::string result;
125 if(axis==0) result="x 1.0";
126 else if(axis==1) result="y 1.0";
127 else if (axis==2) result="z 1.0";
128 else MADNESS_EXCEPTION("polynomial functor only defined up to 3 dimensions",1);
129 return result;
130 }
131
132protected:
133 const std::string input_string_;
134 /// The data for the construction of the polynomial chain
135 /// every entry of data_ is vector containing the threee exponents and the coefficient of a monomial dx^ay^bz^c , data_[i] = (a,b,c,d)
136 const std::vector<std::vector<double>> data_;
137 /// damping function
140public:
141 std::vector<std::vector<double> > read_string(const std::string string) const;
142 void test();
143 std::vector<std::vector<double> > give_data(){return data_;}
144};
145
146/// instead of x,y,z use sin(x), sin(y), sin(z)
147/// shows the same transformation behaviour but does not grow unbounded with larger x,y,z values
149public:
150 /// c++11 constructor inheritance
152 // overload
153 /// create the value of the polynomial according to the data in the data_ structure
154 /// instead of x,y,z use sin(x), sin(y), sin(z)
155 double compute_value(const coord_3d& r) const;
156};
157
158
159
160/// excite a vector of functions with a specific excitation operator
161/// @param[in/out] vf the function which gets excited, exop*f on return
162/// @param[in] exop_input , the excitation operator defined by a string (see the polynomial_functor class for details)
163/// @return exop*vf i.e. result[i]=exop*vf[i]
164vector_real_function_3d apply_polynomial_exop(vector_real_function_3d& vf, const std::string& exop_input, std::vector<coord_3d> centers = std::vector<coord_3d>(), const bool& fence = false);
165/// convenience wrapper
166real_function_3d apply_polynomial_exop(real_function_3d& f, const std::string& exop_input, coord_3d center = coord_3d(), const bool& fence = false);
167
168/// excite a vector of functions with a specific excitation operator
169/// @param[in/out] vf the function which gets excited, exop*f on return
170/// @param[in] exop_input, the excitation operator defined by a string (see the polynomial_functor class for details)
171/// @param[in] the centers of the vf functions, if none were given they are recomputed
172/// @return exop*vf i.e. result[i]=exop*vf[i]
173//template<typename T, std::size_t NDIM>
174//std::vector<Function<T,NDIM> > apply_trigonometric_exop(std::vector<Function<T,NDIM> >& vf,
175// const std::string& exop_input, std::vector<coord_3d> centers = std::vector<coord_3d>(), const bool& fence = false);
176/// excite a vector of functions with a specific excitation operator
177/// @param[in/out] vf the function which gets excited, exop*f on return
178/// @param[in] exop_input, the excitation operator defined by a string (see the polynomial_functor class for details)
179/// @param[in] the centers of the vf functions, if none were given they are recomputed
180/// @return exop*vf i.e. result[i]=exop*vf[i]
181template<typename T, std::size_t NDIM>
182std::vector<Function<T,NDIM> > apply_trigonometric_exop(std::vector<Function<T,NDIM> >& vf,
183 const std::string& exop_input, std::vector<coord_3d> centers, const bool& fence) {
184 if (vf.empty()) return vf;
185
186 //recompute centers if necessary
187 if (centers.empty()) centers = compute_centroids(vf);
188
189 ExopUnaryOpStructure exop(std::make_shared<PolynomialTrigonometricsFunctor>(PolynomialTrigonometricsFunctor(exop_input)));
190 for (auto& f : vf) f.unaryop(exop, false);
191 if (fence) vf.front().world().gop.fence();
192 return vf;
193}
194
195
196/// convenience wrapper
197template<typename T, std::size_t NDIM>
198Function<T,NDIM> apply_trigonometric_exop(Function<T,NDIM>& f, const std::string& exop_input, coord_3d center, const bool& fence) {
199 std::vector<Function<T,NDIM> > vf(1, f);
200 std::vector<coord_3d> centers(1, center);
201 return apply_trigonometric_exop(vf, exop_input, centers, fence).front();
202}
203//template<typename T, std::size_t NDIM>
204//std::vector<Function<T,NDIM> > apply_trigonometric_exop(Function<T,NDIM>& f, const std::string& exop_input, coord_3d center = coord_3d(), const bool& fence = false);
205
206
207/// Makes an excitation operator string based on predefined keywords
208std::vector<std::string> make_predefined_exop_strings(const std::string what);
209/// Makes an automated excitation operator string for the excitation operators needed to create virtuals from the reference orbitals
210std::vector<std::string> make_auto_polynom_strings(const size_t order);
211
212
213} /* namespace guessfactory */
214} /* namespace madness */
215
216#endif /* SRC_APPS_CHEM_GUESSFACTORY_H_ */
long size() const
Returns the number of elements in the tensor.
Definition basetensor.h:138
FunctionCommonData holds all Function data common for given k.
Definition function_common_data.h:52
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:204
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:66
A tensor is a multidimension array.
Definition tensor.h:317
A simple, fixed dimension vector.
Definition vector.h:64
void serialize(Archive &ar)
Definition GuessFactory.h:55
void operator()(const Key< 3 > &key, Tensor< double > &t) const
multiplies the target function by the excitation operator defined by exfunc
Definition GuessFactory.cc:124
std::shared_ptr< FunctionFunctorInterface< double, 3 > > exfunc
shared pointer to object of excitation operator
Definition GuessFactory.h:53
ExopUnaryOpStructure(const std::shared_ptr< FunctionFunctorInterface< double, 3 > > &f)
Definition GuessFactory.h:45
FunctionCommonData< double, 3 > cdata
Definition GuessFactory.h:54
Definition GuessFactory.h:86
GaussFunctor(const double &width)
Definition GuessFactory.h:89
GaussFunctor(const double &width, const Tensor< double > c)
Definition GuessFactory.h:95
GaussFunctor(const double &width, const coord_3d c)
Definition GuessFactory.h:92
double operator()(const coord_3d &rr) const
explicit construction
Definition GuessFactory.cc:199
const coord_3d center
Definition GuessFactory.h:99
const double width_
Definition GuessFactory.h:98
creates a plane-wave: sin (or cos) with argument (npi/L*x)
Definition GuessFactory.h:59
const coord_3d origin
Definition GuessFactory.h:79
const std::vector< bool > cosinus
Definition GuessFactory.h:78
double operator()(const coord_3d &r) const
for explicit construction of this plane-wave function
Definition GuessFactory.cc:214
double operator()(const coord_1d &x, const int &dim) const
in case this is needed at some point
Definition GuessFactory.h:70
std::string name(const bool &compact=false) const
Definition GuessFactory.cc:232
const std::vector< double > n
Definition GuessFactory.h:77
double resultT
Definition GuessFactory.h:63
const Tensor< double > L
Definition GuessFactory.h:76
PlaneWaveFunctor(std::vector< double > vn, std::vector< bool > vc, const coord_3d &c)
Definition GuessFactory.h:61
Project a general 3D polynomial to the MRA Grid.
Definition GuessFactory.h:108
PolynomialFunctor(const std::string input, const double &damp_width=0.0, const coord_3d &c=coord_3d())
Definition GuessFactory.h:113
coord_3d center
Definition GuessFactory.h:139
const std::vector< std::vector< double > > data_
Definition GuessFactory.h:136
double compute_value(const coord_3d &r) const
create the value of the polynomial according to the data in the data_ structure
Definition GuessFactory.cc:148
std::vector< std::vector< double > > give_data()
Definition GuessFactory.h:143
GaussFunctor dampf
damping function
Definition GuessFactory.h:138
double operator()(const coord_3d &rr) const
construction by coordinates
Definition GuessFactory.cc:138
PolynomialFunctor(const std::string input, const double &damp_width, const Tensor< double > &c)
Definition GuessFactory.h:114
void test()
Definition GuessFactory.cc:114
const std::string input_string_
Definition GuessFactory.h:133
std::vector< std::vector< double > > read_string(const std::string string) const
Definition GuessFactory.cc:158
PolynomialFunctor(const int &axis)
simple xyz moments constructor
Definition GuessFactory.h:111
std::string axis_to_string(const int &axis) const
convert a given axis to the appropriate input string
Definition GuessFactory.h:123
double compute_value(const coord_3d &r) const
Definition GuessFactory.cc:189
General header file for using MADNESS.
#define MADNESS_EXCEPTION(msg, value)
Macro for throwing a MADNESS exception.
Definition madness_exception.h:119
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
std::vector< std::string > make_predefined_exop_strings(const std::string what)
Makes an excitation operator string based on predefined keywords.
Definition GuessFactory.cc:252
vector_real_function_3d apply_polynomial_exop(vector_real_function_3d &vf, const std::string &exop_input, std::vector< coord_3d > centers, const bool &fence)
Definition GuessFactory.cc:56
coord_3d compute_centroid(const real_function_3d &f)
compute the centroid of a function i.e. c[xi]=<f|xi|f>/<f|f> i.e. position expectation value
Definition GuessFactory.cc:14
std::vector< Function< T, NDIM > > apply_trigonometric_exop(std::vector< Function< T, NDIM > > &vf, const std::string &exop_input, std::vector< coord_3d > centers, const bool &fence)
Definition GuessFactory.h:182
Vector< T, NDIM > tensor_to_coord(const Tensor< T > &t)
little helper for coord (Vector<3>) and Tensor data formats
Definition GuessFactory.h:31
std::vector< coord_3d > compute_centroids(const std::vector< Function< T, NDIM > > &vf)
Definition GuessFactory.cc:27
std::vector< std::string > make_auto_polynom_strings(const size_t order)
Makes an automated excitation operator string for the excitation operators needed to create virtuals ...
Definition GuessFactory.cc:348
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::vector< real_function_3d > vector_real_function_3d
Definition functypedefs.h:79
NDIM & f
Definition mra.h:2416
Function< double, 3 > real_function_3d
Definition functypedefs.h:65
Vector< double, 3 > coord_3d
Definition funcplot.h:1042
static const double c
Definition relops.cc:10
static const std::size_t NDIM
Definition testpdiff.cc:42
std::size_t axis
Definition testpdiff.cc:59