MADNESS  version 0.9
basisfunction.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id: test_problems.h 1856 2010-04-06 14:03:52Z mgr522 $
32 */
33 
39 #ifndef MADNESS_INTERIOR_BC_BASISFUNCTION_H__INCLUDED
40 #define MADNESS_INTERIOR_BC_BASISFUNCTION_H__INCLUDED
41 
42 //#define WORLD_INSTANTIATE_STATIC_TEMPLATES
43 #include <madness/mra/mra.h>
44 #include <string>
45 
46 using namespace madness;
47 
50 class GaussianBF : public FunctionFunctorInterface<double, 3> {
51  private:
52  GaussianBF() {}
53 
54  protected:
55  std::vector<double> contract_coeffs;
56  std::vector<double> exponents;
58  int n;
59 
60  public:
62  GaussianBF(std::vector<double> &contract_coeffs,
63  std::vector<double> &exponents,
64  const Vector<double, 3> &c)
65  : contract_coeffs(contract_coeffs), exponents(exponents),
66  n(0) {
67 
68  center[0] = c[0];
69  center[1] = c[1];
70  center[2] = c[2];
71  }
72 
73  virtual ~GaussianBF() {}
74 
75  std::vector<Vector<double, 3> > special_points() const {
76  std::vector<Vector<double, 3> > pts(0);
77  pts.push_back(center);
78  return pts;
79  }
80 
81  Level special_level() { return 7; }
82 };
83 
85 class SBF : public GaussianBF {
86  protected:
87  std::vector<double> norms;
88 
89  public:
90  SBF(std::vector<double> &contract_coeffs,
91  std::vector<double> &exponents,
92  Vector<double, 3> &center)
93  : GaussianBF(contract_coeffs, exponents, center),
94  norms(contract_coeffs.size()) {
95 
96  int i;
97 
98  // print a warning if there are more coefficients than exponents
99  n = contract_coeffs.size();
100  i = exponents.size();
101  if(n != i) {
102  print("Error: different number of contraction coefficients " \
103  "and exponents.");
104  // use as many as possible...
105  if(i < n)
106  n = i;
107  }
108 
109  for(i = 0; i < n; ++i) {
110  norms[i] = pow(8.0*exponents[i]*exponents[i]*exponents[i] /
112  }
113  }
114 
115  double operator() (const Vector<double, 3> &pt) const {
116  double r2, ret;
117 
118  r2 = (center[0] - pt[0])*(center[0] - pt[0]) +
119  (center[1] - pt[1])*(center[1] - pt[1]) +
120  (center[2] - pt[2])*(center[2] - pt[2]);
121 
122  ret = 0.0;
123  for(int i = 0; i < n; ++i)
124  ret += contract_coeffs[i] * norms[i] *
125  exp(-exponents[i] * r2);
126 
127  return ret;
128  }
129 };
130 
132 class PBF : public GaussianBF {
133  protected:
134  std::vector<double> norms;
135  int dir;
136 
137  public:
138  static const int X = 0, Y = 1, Z = 2;
139 
140  PBF(std::vector<double> &contract_coeffs,
141  std::vector<double> &exponents,
142  Vector<double, 3> &center, int dir)
143  : GaussianBF(contract_coeffs, exponents, center),
144  norms(contract_coeffs.size()), dir(dir) {
145 
146  int i;
147 
148  // print a warning if there are more coefficients than exponents
149  n = contract_coeffs.size();
150  i = exponents.size();
151  if(n != i) {
152  print("Error: different number of contraction coefficients " \
153  "and exponents.");
154  // use as many as possible...
155  if(i < n)
156  n = i;
157  }
158 
159  for(i = 0; i < n; ++i) {
160  norms[i] = pow(128.0*exponents[i]*exponents[i]*exponents[i]
161  *exponents[i]*exponents[i] /
163  }
164  }
165 
166  double operator() (const Vector<double, 3> &pt) const {
167  double r2, ret;
169 
170  d[0] = pt[0] - center[0];
171  d[1] = pt[1] - center[1];
172  d[2] = pt[2] - center[2];
173 
174  r2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
175 
176  ret = 0.0;
177  for(int i = 0; i < n; ++i)
178  ret += contract_coeffs[i] * norms[i] *
179  exp(-exponents[i] * r2);
180 
181  switch(dir) {
182  case X:
183  ret *= d[0];
184  break;
185  case Y:
186  ret *= d[1];
187  break;
188  case Z:
189  ret *= d[2];
190  break;
191  }
192 
193  return ret;
194  }
195 };
196 
198 class DBF : public GaussianBF {
199  protected:
200  std::vector<double> norms;
201  int dir;
202 
203  public:
204  static const int XX = 0, XY = 1, XZ = 2, YY = 3, YZ = 4, ZZ = 5;
205 
206  DBF(std::vector<double> &contract_coeffs,
207  std::vector<double> &exponents,
208  Vector<double, 3> &center, int dir)
209  : GaussianBF(contract_coeffs, exponents, center),
210  norms(contract_coeffs.size()), dir(dir) {
211 
212  int i;
213 
214  // print a warning if there are more coefficients than exponents
215  n = contract_coeffs.size();
216  i = exponents.size();
217  if(n != i) {
218  print("Error: different number of contraction coefficients " \
219  "and exponents.");
220  // use as many as possible...
221  if(i < n)
222  n = i;
223  }
224 
225  for(i = 0; i < n; ++i) {
226  norms[i] = 2048.0*exponents[i]*exponents[i]*exponents[i]
227  *exponents[i]*exponents[i]*exponents[i]*exponents[i] /
229  if(dir == XX || dir == YY || dir == ZZ)
230  norms[i] /= 9.0;
231  norms[i] = pow(norms[i], 0.25);
232  }
233  }
234 
235  double operator() (const Vector<double, 3> &pt) const {
236  double r2, ret;
238 
239  d[0] = pt[0] - center[0];
240  d[1] = pt[1] - center[1];
241  d[2] = pt[2] - center[2];
242 
243  r2 = d[0]*d[0] + d[1]*d[1] + d[2]*d[2];
244 
245  ret = 0.0;
246  for(int i = 0; i < n; ++i)
247  ret += contract_coeffs[i] * norms[i] *
248  exp(-exponents[i] * r2);
249 
250  switch(dir) {
251  case XX:
252  ret *= d[0]*d[0];
253  break;
254  case XY:
255  ret *= d[0]*d[1];
256  break;
257  case XZ:
258  ret *= d[0]*d[2];
259  break;
260  case YY:
261  ret *= d[1]*d[1];
262  break;
263  case YZ:
264  ret *= d[1]*d[2];
265  break;
266  case ZZ:
267  ret *= d[2]*d[2];
268  break;
269  }
270 
271  return ret;
272  }
273 };
274 
275 #endif // MADNESS_INTERIOR_BC_BASISFUNCTION_H__INCLUDED
const mpreal exp(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2234
const double pi
Mathematical constant pi.
Definition: constants.h:44
std::vector< double > norms
Definition: basisfunction.h:87
Main include file for MADNESS and defines Function interface.
int n
Definition: basisfunction.h:58
std::vector< double > norms
Definition: basisfunction.h:134
PBF(std::vector< double > &contract_coeffs, std::vector< double > &exponents, Vector< double, 3 > &center, int dir)
Definition: basisfunction.h:140
virtual ~GaussianBF()
Definition: basisfunction.h:73
int dir
Definition: basisfunction.h:135
std::vector< double > exponents
Definition: basisfunction.h:56
int dir
Definition: basisfunction.h:201
Level special_level()
Override this change level refinement for special points (default is 6)
Definition: basisfunction.h:81
Vector< double, 3 > center
Definition: basisfunction.h:57
Abstract Gaussian basis function. Must be overriden to specify angular momenta (s, p, d, etc.).
Definition: basisfunction.h:50
std::vector< double > norms
Definition: basisfunction.h:200
SBF(std::vector< double > &contract_coeffs, std::vector< double > &exponents, Vector< double, 3 > &center)
Definition: basisfunction.h:90
std::vector< double > contract_coeffs
Definition: basisfunction.h:55
int Level
Definition: key.h:58
A p basis function.
Definition: basisfunction.h:132
An s basis function.
Definition: basisfunction.h:85
DBF(std::vector< double > &contract_coeffs, std::vector< double > &exponents, Vector< double, 3 > &center, int dir)
Definition: basisfunction.h:206
GaussianBF(std::vector< double > &contract_coeffs, std::vector< double > &exponents, const Vector< double, 3 > &c)
Sets up the basis function data.
Definition: basisfunction.h:62
Abstract base class interface required for functors used as input to Functions.
Definition: function_interface.h:58
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
std::vector< Vector< double, 3 > > special_points() const
Override this to return list of special points to be refined more deeply.
Definition: basisfunction.h:75
A d basis function.
Definition: basisfunction.h:198