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:
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
66
67 /// for explicit construction of this plane-wave function
68 double operator ()(const coord_3d& r) const override;
69 /// operator for the 1D plane waves
70 double operator ()(const double& x, const int& dim) const;
71 /// in case this is needed at some point
72 double operator()(const coord_1d & x, const int& dim) const {
73 return (*this)(x[0],dim);
74 }
75
76 std::string name(const bool& compact = false) const;
77
79 const std::vector<double> n;
80 const std::vector<bool> cosinus;
82
83
84};
85
86/// GaussFunctor to let the exciation operators go to zero at the boundaries
87/// totally symmetric
88class GaussFunctor : public FunctionFunctorInterface<double,3> {
89public:
91 GaussFunctor(const double& width): width_(width){
92 MADNESS_ASSERT(not(width<0.0));
93 }
94 GaussFunctor(const double& width, const coord_3d c): width_(width), center(c){
95 MADNESS_ASSERT(not(width<0.0));
96 }
97 GaussFunctor(const double& width, const Tensor<double> c): width_(width), center(tensor_to_coord<double,3>(c)){
98 MADNESS_ASSERT(not(width<0.0));
99 }
100 const double width_;
102
104
105 /// explicit construction
106 double operator ()(const coord_3d& rr) const override;
107
108
109};
110
111/// Project a general 3D polynomial to the MRA Grid
113public :
114 /// simple xyz moments constructor
116 // general polynomials or sums of polynomials
117 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) {}
118 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)) {}
119
121 /// construction by coordinates
122 double operator ()(const coord_3d& rr) const override;
123
124 /// create the value of the polynomial according to the data in the data_ structure
125 double compute_value(const coord_3d& r) const;
126
127 /// convert a given axis to the appropriate input string
128 std::string axis_to_string(const int& axis)const{
129 std::string result;
130 if(axis==0) result="x 1.0";
131 else if(axis==1) result="y 1.0";
132 else if (axis==2) result="z 1.0";
133 else MADNESS_EXCEPTION("polynomial functor only defined up to 3 dimensions",1);
134 return result;
135 }
136
137protected:
138 const std::string input_string_;
139 /// The data for the construction of the polynomial chain
140 /// 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)
141 const std::vector<std::vector<double>> data_;
142 /// damping function
145public:
146 std::vector<std::vector<double> > read_string(const std::string string) const;
147 void test();
148 std::vector<std::vector<double> > give_data(){return data_;}
149};
150
151/// instead of x,y,z use sin(x), sin(y), sin(z)
152/// shows the same transformation behaviour but does not grow unbounded with larger x,y,z values
154public:
155 /// c++11 constructor inheritance
157 // overload
158 /// create the value of the polynomial according to the data in the data_ structure
159 /// instead of x,y,z use sin(x), sin(y), sin(z)
160 double compute_value(const coord_3d& r) const;
161};
162
163
164
165/// excite a vector of functions with a specific excitation operator
166/// @param[in/out] vf the function which gets excited, exop*f on return
167/// @param[in] exop_input , the excitation operator defined by a string (see the polynomial_functor class for details)
168/// @return exop*vf i.e. result[i]=exop*vf[i]
169vector_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);
170/// convenience wrapper
171real_function_3d apply_polynomial_exop(real_function_3d& f, const std::string& exop_input, coord_3d center = coord_3d(), const bool& fence = false);
172
173/// excite a vector of functions with a specific excitation operator
174/// @param[in/out] vf the function which gets excited, exop*f on return
175/// @param[in] exop_input, the excitation operator defined by a string (see the polynomial_functor class for details)
176/// @param[in] the centers of the vf functions, if none were given they are recomputed
177/// @return exop*vf i.e. result[i]=exop*vf[i]
178//template<typename T, std::size_t NDIM>
179//std::vector<Function<T,NDIM> > apply_trigonometric_exop(std::vector<Function<T,NDIM> >& vf,
180// const std::string& exop_input, std::vector<coord_3d> centers = std::vector<coord_3d>(), const bool& fence = false);
181/// excite a vector of functions with a specific excitation operator
182/// @param[in/out] vf the function which gets excited, exop*f on return
183/// @param[in] exop_input, the excitation operator defined by a string (see the polynomial_functor class for details)
184/// @param[in] the centers of the vf functions, if none were given they are recomputed
185/// @return exop*vf i.e. result[i]=exop*vf[i]
186template<typename T, std::size_t NDIM>
187std::vector<Function<T,NDIM> > apply_trigonometric_exop(std::vector<Function<T,NDIM> >& vf,
188 const std::string& exop_input, std::vector<coord_3d> centers, const bool& fence) {
189 if (vf.empty()) return vf;
190
191 //recompute centers if necessary
192 if (centers.empty()) centers = compute_centroids(vf);
193
194 ExopUnaryOpStructure exop(std::make_shared<PolynomialTrigonometricsFunctor>(PolynomialTrigonometricsFunctor(exop_input)));
195 for (auto& f : vf) f.unaryop(exop, false);
196 if (fence) vf.front().world().gop.fence();
197 return vf;
198}
199
200
201/// convenience wrapper
202template<typename T, std::size_t NDIM>
203Function<T,NDIM> apply_trigonometric_exop(Function<T,NDIM>& f, const std::string& exop_input, coord_3d center, const bool& fence) {
204 std::vector<Function<T,NDIM> > vf(1, f);
205 std::vector<coord_3d> centers(1, center);
206 return apply_trigonometric_exop(vf, exop_input, centers, fence).front();
207}
208//template<typename T, std::size_t NDIM>
209//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);
210
211
212/// Makes an excitation operator string based on predefined keywords
213std::vector<std::string> make_predefined_exop_strings(const std::string what);
214/// Makes an automated excitation operator string for the excitation operators needed to create virtuals from the reference orbitals
215std::vector<std::string> make_auto_polynom_strings(const size_t order);
216
217
218} /* namespace guessfactory */
219} /* namespace madness */
220
221#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:100
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:70
A tensor is a multidimensional array.
Definition tensor.h:318
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:88
GaussFunctor(const double &width)
Definition GuessFactory.h:91
GaussFunctor(const double &width, const Tensor< double > c)
Definition GuessFactory.h:97
GaussFunctor(const double &width, const coord_3d c)
Definition GuessFactory.h:94
double operator()(const coord_3d &rr) const override
explicit construction
Definition GuessFactory.cc:197
const coord_3d center
Definition GuessFactory.h:101
const double width_
Definition GuessFactory.h:100
creates a plane-wave: sin (or cos) with argument (npi/L*x)
Definition GuessFactory.h:59
const coord_3d origin
Definition GuessFactory.h:81
const std::vector< bool > cosinus
Definition GuessFactory.h:80
double operator()(const coord_1d &x, const int &dim) const
in case this is needed at some point
Definition GuessFactory.h:72
std::string name(const bool &compact=false) const
Definition GuessFactory.cc:230
const std::vector< double > n
Definition GuessFactory.h:79
double resultT
Definition GuessFactory.h:63
const Tensor< double > L
Definition GuessFactory.h:78
PlaneWaveFunctor(std::vector< double > vn, std::vector< bool > vc, const coord_3d &c)
Definition GuessFactory.h:61
double operator()(const coord_3d &r) const override
for explicit construction of this plane-wave function
Definition GuessFactory.cc:212
Project a general 3D polynomial to the MRA Grid.
Definition GuessFactory.h:112
PolynomialFunctor(const std::string input, const double &damp_width=0.0, const coord_3d &c=coord_3d())
Definition GuessFactory.h:117
coord_3d center
Definition GuessFactory.h:144
const std::vector< std::vector< double > > data_
Definition GuessFactory.h:141
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:148
GaussFunctor dampf
damping function
Definition GuessFactory.h:143
PolynomialFunctor(const std::string input, const double &damp_width, const Tensor< double > &c)
Definition GuessFactory.h:118
void test()
Definition GuessFactory.cc:114
double operator()(const coord_3d &rr) const override
construction by coordinates
Definition GuessFactory.cc:138
const std::string input_string_
Definition GuessFactory.h:138
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:115
std::string axis_to_string(const int &axis) const
convert a given axis to the appropriate input string
Definition GuessFactory.h:128
double compute_value(const coord_3d &r) const
Definition GuessFactory.cc:187
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:250
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:187
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:346
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
std::vector< real_function_3d > vector_real_function_3d
Definition functypedefs.h:94
NDIM & f
Definition mra.h:2620
Function< double, 3 > real_function_3d
Definition functypedefs.h:80
Vector< double, 3 > coord_3d
Definition funcplot.h:1042
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
static const double c
Definition relops.cc:10
constexpr std::size_t NDIM
Definition testgconv.cc:54
std::size_t axis
Definition testpdiff.cc:59