1 | //
|
---|
2 | // integrator.h --- definition of the electron density integrator
|
---|
3 | //
|
---|
4 | // Copyright (C) 1997 Limit Point Systems, Inc.
|
---|
5 | //
|
---|
6 | // Author: Curtis Janssen <cljanss@limitpt.com>
|
---|
7 | // Maintainer: LPS
|
---|
8 | //
|
---|
9 | // This file is part of the SC Toolkit.
|
---|
10 | //
|
---|
11 | // The SC Toolkit is free software; you can redistribute it and/or modify
|
---|
12 | // it under the terms of the GNU Library General Public License as published by
|
---|
13 | // the Free Software Foundation; either version 2, or (at your option)
|
---|
14 | // any later version.
|
---|
15 | //
|
---|
16 | // The SC Toolkit is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU Library General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU Library General Public License
|
---|
22 | // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
|
---|
23 | // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
24 | //
|
---|
25 | // The U.S. Government is granted a limited license as per AL 91-7.
|
---|
26 | //
|
---|
27 |
|
---|
28 | #ifndef _chemistry_qc_dft_integrator_h
|
---|
29 | #define _chemistry_qc_dft_integrator_h
|
---|
30 |
|
---|
31 | #ifdef __GNUC__
|
---|
32 | #pragma interface
|
---|
33 | #endif
|
---|
34 |
|
---|
35 | #include <util/state/state.h>
|
---|
36 | #include <util/group/thread.h>
|
---|
37 | #include <chemistry/qc/dft/functional.h>
|
---|
38 | #include <chemistry/qc/basis/extent.h>
|
---|
39 | #include <chemistry/qc/wfn/density.h>
|
---|
40 |
|
---|
41 | namespace sc {
|
---|
42 |
|
---|
43 | /** An abstract base class for integrating the electron density. */
|
---|
44 | class DenIntegrator: virtual public SavableState {
|
---|
45 | protected:
|
---|
46 | Ref<Wavefunction> wfn_;
|
---|
47 | //clj Ref<ShellExtent> extent_;
|
---|
48 | Ref<BatchElectronDensity> den_;
|
---|
49 |
|
---|
50 | Ref<ThreadGrp> threadgrp_;
|
---|
51 | Ref<MessageGrp> messagegrp_;
|
---|
52 |
|
---|
53 | double value_;
|
---|
54 | double accuracy_;
|
---|
55 |
|
---|
56 | double *alpha_vmat_;
|
---|
57 | double *beta_vmat_;
|
---|
58 |
|
---|
59 | //clj double *alpha_dmat_;
|
---|
60 | //clj double *beta_dmat_;
|
---|
61 | //clj double *dmat_bound_;
|
---|
62 |
|
---|
63 | int spin_polarized_;
|
---|
64 |
|
---|
65 | int need_density_; // specialization must set to 1 if it needs density_
|
---|
66 | double density_;
|
---|
67 | int nbasis_;
|
---|
68 | int nshell_;
|
---|
69 | int n_integration_center_;
|
---|
70 | int natom_;
|
---|
71 | int compute_potential_integrals_; // 1 if potential integrals are needed
|
---|
72 |
|
---|
73 | int linear_scaling_;
|
---|
74 | int use_dmat_bound_;
|
---|
75 |
|
---|
76 | void init_integration(const Ref<DenFunctional> &func,
|
---|
77 | const RefSymmSCMatrix& densa,
|
---|
78 | const RefSymmSCMatrix& densb,
|
---|
79 | double *nuclear_gradient);
|
---|
80 | void done_integration();
|
---|
81 |
|
---|
82 | void init_object();
|
---|
83 | public:
|
---|
84 | /// Construct a new DenIntegrator.
|
---|
85 | DenIntegrator();
|
---|
86 | /// Construct a new DenIntegrator given the KeyVal input.
|
---|
87 | DenIntegrator(const Ref<KeyVal> &);
|
---|
88 | /// Construct a new DenIntegrator given the StateIn data.
|
---|
89 | DenIntegrator(StateIn &);
|
---|
90 | ~DenIntegrator();
|
---|
91 | void save_data_state(StateOut &);
|
---|
92 |
|
---|
93 | /// Returns the wavefunction used for the integration.
|
---|
94 | Ref<Wavefunction> wavefunction() const { return wfn_; }
|
---|
95 | /// Returns the result of the integration.
|
---|
96 | double value() const { return value_; }
|
---|
97 |
|
---|
98 | /// Sets the accuracy to use in the integration.
|
---|
99 | void set_accuracy(double a);
|
---|
100 | double get_accuracy(void) {return accuracy_; }
|
---|
101 | /** Call with non zero if the potential integrals are to be computed.
|
---|
102 | They can be returned with the vmat() member. */
|
---|
103 | void set_compute_potential_integrals(int);
|
---|
104 | /** Returns the alpha potential integrals. Stored as
|
---|
105 | the lower triangular, row-major format. */
|
---|
106 | const double *alpha_vmat() const { return alpha_vmat_; }
|
---|
107 | /** Returns the beta potential integrals. Stored as
|
---|
108 | the lower triangular, row-major format. */
|
---|
109 | const double *beta_vmat() const { return beta_vmat_; }
|
---|
110 |
|
---|
111 | /** Called before integrate. Does not need to be called again
|
---|
112 | unless the geometry changes or done is called. */
|
---|
113 | virtual void init(const Ref<Wavefunction> &);
|
---|
114 | /// Must be called between calls to init.
|
---|
115 | virtual void done();
|
---|
116 | /** Performs the integration of the given functional using the given
|
---|
117 | alpha and beta density matrices. The nuclear derivative
|
---|
118 | contribution is placed in nuclear_grad, if it is non-null. */
|
---|
119 | virtual void integrate(const Ref<DenFunctional> &,
|
---|
120 | const RefSymmSCMatrix& densa =0,
|
---|
121 | const RefSymmSCMatrix& densb =0,
|
---|
122 | double *nuclear_grad = 0) = 0;
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | /** An abstract base class for computing grid weights. */
|
---|
127 | class IntegrationWeight: virtual public SavableState {
|
---|
128 |
|
---|
129 | protected:
|
---|
130 |
|
---|
131 | Ref<Molecule> mol_;
|
---|
132 | double tol_;
|
---|
133 |
|
---|
134 | void fd_w(int icenter, SCVector3 &point, double *fd_grad_w);
|
---|
135 |
|
---|
136 | public:
|
---|
137 | IntegrationWeight();
|
---|
138 | IntegrationWeight(const Ref<KeyVal> &);
|
---|
139 | IntegrationWeight(StateIn &);
|
---|
140 | ~IntegrationWeight();
|
---|
141 | void save_data_state(StateOut &);
|
---|
142 |
|
---|
143 | void test(int icenter, SCVector3 &point);
|
---|
144 | void test();
|
---|
145 |
|
---|
146 | /// Initialize the integration weight object.
|
---|
147 | virtual void init(const Ref<Molecule> &, double tolerance);
|
---|
148 | /// Called when finished with the integration weight object.
|
---|
149 | virtual void done();
|
---|
150 | /** Computes the weight for a given center at a given point in space.
|
---|
151 | Derivatives of the weigth with respect to nuclear coordinates are
|
---|
152 | optionally returned in grad_w. This must be called after init, but
|
---|
153 | before done. It must also be thread-safe. */
|
---|
154 | virtual double w(int center, SCVector3 &point, double *grad_w = 0) = 0;
|
---|
155 | };
|
---|
156 |
|
---|
157 |
|
---|
158 | /** Implements Becke's integration weight scheme. */
|
---|
159 | class BeckeIntegrationWeight: public IntegrationWeight {
|
---|
160 |
|
---|
161 | int n_integration_centers;
|
---|
162 | SCVector3 *centers;
|
---|
163 | double *atomic_radius;
|
---|
164 |
|
---|
165 | double **a_mat;
|
---|
166 | double **oorab;
|
---|
167 |
|
---|
168 | void compute_grad_p(int gc, int ic, int wc, SCVector3&r, double p,
|
---|
169 | SCVector3&g);
|
---|
170 | void compute_grad_nu(int gc, int bc, SCVector3 &point, SCVector3 &grad);
|
---|
171 |
|
---|
172 | double compute_t(int ic, int jc, SCVector3 &point);
|
---|
173 | double compute_p(int icenter, SCVector3&point);
|
---|
174 |
|
---|
175 | public:
|
---|
176 | BeckeIntegrationWeight();
|
---|
177 | BeckeIntegrationWeight(const Ref<KeyVal> &);
|
---|
178 | BeckeIntegrationWeight(StateIn &);
|
---|
179 | ~BeckeIntegrationWeight();
|
---|
180 | void save_data_state(StateOut &);
|
---|
181 |
|
---|
182 | void init(const Ref<Molecule> &, double tolerance);
|
---|
183 | void done();
|
---|
184 | double w(int center, SCVector3 &point, double *grad_w = 0);
|
---|
185 | };
|
---|
186 |
|
---|
187 | /** An abstract base class for radial integrators. */
|
---|
188 | class RadialIntegrator: virtual public SavableState {
|
---|
189 | protected:
|
---|
190 | int nr_;
|
---|
191 | public:
|
---|
192 | RadialIntegrator();
|
---|
193 | RadialIntegrator(const Ref<KeyVal> &);
|
---|
194 | RadialIntegrator(StateIn &);
|
---|
195 | ~RadialIntegrator();
|
---|
196 | void save_data_state(StateOut &);
|
---|
197 |
|
---|
198 | virtual int nr() const = 0;
|
---|
199 | virtual double radial_value(int ir, int nr, double radii,
|
---|
200 | double &multiplier) = 0;
|
---|
201 | };
|
---|
202 |
|
---|
203 |
|
---|
204 | /** An abstract base class for angular integrators. */
|
---|
205 | class AngularIntegrator: virtual public SavableState{
|
---|
206 | protected:
|
---|
207 | public:
|
---|
208 | AngularIntegrator();
|
---|
209 | AngularIntegrator(const Ref<KeyVal> &);
|
---|
210 | AngularIntegrator(StateIn &);
|
---|
211 | ~AngularIntegrator();
|
---|
212 | void save_data_state(StateOut &);
|
---|
213 |
|
---|
214 | virtual int nw(void) const = 0;
|
---|
215 | virtual int num_angular_points(double r_value, int ir) = 0;
|
---|
216 | virtual double angular_point_cartesian(int iangular, double r,
|
---|
217 | SCVector3 &integration_point) const = 0;
|
---|
218 | };
|
---|
219 |
|
---|
220 |
|
---|
221 | /** An implementation of a radial integrator using the Euler-Maclaurin
|
---|
222 | weights and grid points. */
|
---|
223 | class EulerMaclaurinRadialIntegrator: public RadialIntegrator {
|
---|
224 | public:
|
---|
225 | EulerMaclaurinRadialIntegrator();
|
---|
226 | EulerMaclaurinRadialIntegrator(int i);
|
---|
227 | /** Constructs a EulerMaclaurinRadialIntegrator from KeyVal input.
|
---|
228 | The <tt>nr</tt> keyword gives the number of radial integration
|
---|
229 | points. The default is 75. */
|
---|
230 | EulerMaclaurinRadialIntegrator(const Ref<KeyVal> &);
|
---|
231 | EulerMaclaurinRadialIntegrator(StateIn &);
|
---|
232 | ~EulerMaclaurinRadialIntegrator();
|
---|
233 | void save_data_state(StateOut &);
|
---|
234 |
|
---|
235 | int nr() const;
|
---|
236 | double radial_value(int ir, int nr, double radii, double &multiplier);
|
---|
237 |
|
---|
238 | void print(std::ostream & =ExEnv::out0()) const;
|
---|
239 | };
|
---|
240 |
|
---|
241 | /** An implementation of a Lebedev angular integrator. It uses code
|
---|
242 | written by Dr. Dmitri N. Laikov.
|
---|
243 |
|
---|
244 | This can generate grids with the following numbers of points: 6, 14,
|
---|
245 | 26, 38, 50, 74, 86, 110, 146, 170, 194, 230, 266, 302, 350, 386, 434,
|
---|
246 | 482, 530, 590, 650, 698, 770, 830, 890, 974, 1046, 1118, 1202, 1274,
|
---|
247 | 1358, 1454, 1538, 1622, 1730, 1814, 1910, 2030, 2126, 2222, 2354, 2450,
|
---|
248 | 2558, 2702, 2810, 2930, 3074, 3182, 3314, 3470, 3590, 3722, 3890, 4010,
|
---|
249 | 4154, 4334, 4466, 4610, 4802, 4934, 5090, 5294, 5438, 5606, and 5810.
|
---|
250 |
|
---|
251 | V.I. Lebedev, and D.N. Laikov
|
---|
252 | "A quadrature formula for the sphere of the 131st
|
---|
253 | algebraic order of accuracy"
|
---|
254 | Doklady Mathematics, Vol. 59, No. 3, 1999, pp. 477-481.
|
---|
255 |
|
---|
256 | V.I. Lebedev
|
---|
257 | "A quadrature formula for the sphere of 59th algebraic
|
---|
258 | order of accuracy"
|
---|
259 | Russian Acad. Sci. Dokl. Math., Vol. 50, 1995, pp. 283-286.
|
---|
260 |
|
---|
261 | V.I. Lebedev, and A.L. Skorokhodov
|
---|
262 | "Quadrature formulas of orders 41, 47, and 53 for the sphere"
|
---|
263 | Russian Acad. Sci. Dokl. Math., Vol. 45, 1992, pp. 587-592.
|
---|
264 |
|
---|
265 | V.I. Lebedev
|
---|
266 | "Spherical quadrature formulas exact to orders 25-29"
|
---|
267 | Siberian Mathematical Journal, Vol. 18, 1977, pp. 99-107.
|
---|
268 |
|
---|
269 | V.I. Lebedev
|
---|
270 | "Quadratures on a sphere"
|
---|
271 | Computational Mathematics and Mathematical Physics, Vol. 16,
|
---|
272 | 1976, pp. 10-24.
|
---|
273 |
|
---|
274 | V.I. Lebedev
|
---|
275 | "Values of the nodes and weights of ninth to seventeenth
|
---|
276 | order Gauss-Markov quadrature formulae invariant under the
|
---|
277 | octahedron group with inversion"
|
---|
278 | Computational Mathematics and Mathematical Physics, Vol. 15,
|
---|
279 | 1975, pp. 44-51.
|
---|
280 |
|
---|
281 | */
|
---|
282 | class LebedevLaikovIntegrator: public AngularIntegrator {
|
---|
283 | protected:
|
---|
284 | int npoint_;
|
---|
285 | double *x_, *y_, *z_, *w_;
|
---|
286 |
|
---|
287 | void init(int n);
|
---|
288 | public:
|
---|
289 | LebedevLaikovIntegrator();
|
---|
290 | /**
|
---|
291 | Construct a LebedevLaikovIntegrator using the given KeyVal input.
|
---|
292 | The <tt>n</tt> keyword gives the number of angular points. The
|
---|
293 | default is 302.
|
---|
294 | */
|
---|
295 | LebedevLaikovIntegrator(const Ref<KeyVal> &);
|
---|
296 | LebedevLaikovIntegrator(StateIn &);
|
---|
297 | LebedevLaikovIntegrator(int);
|
---|
298 | ~LebedevLaikovIntegrator();
|
---|
299 | void save_data_state(StateOut &);
|
---|
300 |
|
---|
301 | int nw(void) const;
|
---|
302 | int num_angular_points(double r_value, int ir);
|
---|
303 | double angular_point_cartesian(int iangular, double r,
|
---|
304 | SCVector3 &integration_point) const;
|
---|
305 | void print(std::ostream & =ExEnv::out0()) const;
|
---|
306 | };
|
---|
307 |
|
---|
308 | /** An implementation of an angular integrator using the Gauss-Legendre
|
---|
309 | weights and grid points. */
|
---|
310 | class GaussLegendreAngularIntegrator: public AngularIntegrator {
|
---|
311 | protected:
|
---|
312 | int ntheta_;
|
---|
313 | int nphi_;
|
---|
314 | int Ktheta_;
|
---|
315 | int ntheta_r_;
|
---|
316 | int nphi_r_;
|
---|
317 | int Ktheta_r_;
|
---|
318 | double *theta_quad_weights_;
|
---|
319 | double *theta_quad_points_;
|
---|
320 |
|
---|
321 | int get_ntheta(void) const;
|
---|
322 | void set_ntheta(int i);
|
---|
323 | int get_nphi(void) const;
|
---|
324 | void set_nphi(int i);
|
---|
325 | int get_Ktheta(void) const;
|
---|
326 | void set_Ktheta(int i);
|
---|
327 | int get_ntheta_r(void) const;
|
---|
328 | void set_ntheta_r(int i);
|
---|
329 | int get_nphi_r(void) const;
|
---|
330 | void set_nphi_r(int i);
|
---|
331 | int get_Ktheta_r(void) const;
|
---|
332 | void set_Ktheta_r(int i);
|
---|
333 | int nw(void) const;
|
---|
334 | double sin_theta(SCVector3 &point) const;
|
---|
335 | void gauleg(double x1, double x2, int n);
|
---|
336 | public:
|
---|
337 | GaussLegendreAngularIntegrator();
|
---|
338 | /**
|
---|
339 | Contract a GaussLegendreAngularIntegrator from KeyVal input.
|
---|
340 | This class is for testing, the LebedevLaikovIntegrator
|
---|
341 | is preferred for normal use. The following parameters
|
---|
342 | are read: <tt>ntheta</tt>, <tt>nphi</tt>, and <tt>Ktheta</tt>.
|
---|
343 | */
|
---|
344 | GaussLegendreAngularIntegrator(const Ref<KeyVal> &);
|
---|
345 | GaussLegendreAngularIntegrator(StateIn &);
|
---|
346 | ~GaussLegendreAngularIntegrator();
|
---|
347 | void save_data_state(StateOut &);
|
---|
348 |
|
---|
349 | int num_angular_points(double r_value, int ir);
|
---|
350 | double angular_point_cartesian(int iangular, double r,
|
---|
351 | SCVector3 &integration_point) const;
|
---|
352 | void print(std::ostream & =ExEnv::out0()) const;
|
---|
353 | };
|
---|
354 |
|
---|
355 | /** An implementation of an integrator using any combination of
|
---|
356 | a RadialIntegrator and an AngularIntegrator. */
|
---|
357 | class RadialAngularIntegrator: public DenIntegrator {
|
---|
358 | private:
|
---|
359 | int prune_grid_;
|
---|
360 | double **Alpha_coeffs_;
|
---|
361 | int gridtype_;
|
---|
362 | int **nr_points_, *xcoarse_l_;
|
---|
363 | int npruned_partitions_;
|
---|
364 | double *grid_accuracy_;
|
---|
365 | int dynamic_grids_;
|
---|
366 | int natomic_rows_;
|
---|
367 | int max_gridtype_;
|
---|
368 | protected:
|
---|
369 | Ref<IntegrationWeight> weight_;
|
---|
370 | Ref<RadialIntegrator> radial_user_;
|
---|
371 | Ref<AngularIntegrator> angular_user_;
|
---|
372 | Ref<AngularIntegrator> ***angular_grid_;
|
---|
373 | Ref<RadialIntegrator> **radial_grid_;
|
---|
374 | public:
|
---|
375 | RadialAngularIntegrator();
|
---|
376 | /** Construct a RadialAngularIntegrator from KeyVal input.
|
---|
377 |
|
---|
378 | The accepted keyword are listed below. The most important keyword
|
---|
379 | is <tt>grid</tt>. The <tt>dynamic</tt> and <tt>prune_grid</tt>
|
---|
380 | options may be of occassional interest.
|
---|
381 | <dl>
|
---|
382 |
|
---|
383 | <dt><tt>grid</tt><dd>Specifies the fineness of the grid. Possible
|
---|
384 | values are <tt>xcoarse</tt>, <tt>coarse</tt>, <tt>medium</tt>,
|
---|
385 | <tt>fine</tt>, <tt>xfine</tt>, and <tt>ultrafine</tt>, in order of
|
---|
386 | increasing accuracy and cost. The default is <tt>fine</tt>.
|
---|
387 |
|
---|
388 | <dt><tt>dynamic</tt><dd>This gives a boolean value that, if true,
|
---|
389 | will cause the grids to start out coarse, and approach the
|
---|
390 | requested <tt>grid</tt> value as more accuracy is required, when
|
---|
391 | the calculation is close to convergence. The default is true.
|
---|
392 |
|
---|
393 | <dt><tt>prune_grid</tt><dd>This gives a boolean value that, if
|
---|
394 | true, will cause more course angular grids to be used near
|
---|
395 | nuclei. The default is true. When this is true, further control
|
---|
396 | over pruning can be obtained with the <tt>angular_points</tt>
|
---|
397 | and <tt>alpha_coeffs</tt> keywords.
|
---|
398 |
|
---|
399 | <dt><tt>radial</tt><dd>Specifies the RadialIntegrator object. If
|
---|
400 | this is given, then specifying the <tt>grid</tt> and
|
---|
401 | <tt>dynamic</tt> keywords will not affect the radial grid. The
|
---|
402 | default is controlled by other options, but is always one of
|
---|
403 | several EulerMaclaurinRadialIntegrator objects.
|
---|
404 |
|
---|
405 | <dt><tt>angular</tt><dd>Specifies the AngularIntegrator object. If
|
---|
406 | this is given, then specifying the <tt>grid</tt>,
|
---|
407 | <tt>prune_grid</tt>, and <tt>dynamic</tt> keywords will not affect
|
---|
408 | the angular grid. The default is controlled by other options,
|
---|
409 | but is always one of several LebedevLaikovIntegrator objects.
|
---|
410 |
|
---|
411 | <dt><tt>weight</tt><dd>Specifies the IntegrationWeight object.
|
---|
412 | The default is BeckeIntegrationWeight.
|
---|
413 |
|
---|
414 | </dl>
|
---|
415 | */
|
---|
416 | RadialAngularIntegrator(const Ref<KeyVal> &);
|
---|
417 | RadialAngularIntegrator(StateIn &);
|
---|
418 | ~RadialAngularIntegrator();
|
---|
419 | void save_data_state(StateOut &);
|
---|
420 |
|
---|
421 | void integrate(const Ref<DenFunctional> &,
|
---|
422 | const RefSymmSCMatrix& densa =0,
|
---|
423 | const RefSymmSCMatrix& densb =0,
|
---|
424 | double *nuclear_gradient = 0);
|
---|
425 | void print(std::ostream & =ExEnv::out0()) const;
|
---|
426 | AngularIntegrator *get_angular_grid(double radius, double atomic_radius,
|
---|
427 | int charge, int deriv_order);
|
---|
428 | RadialIntegrator *get_radial_grid(int charge, int deriv_order);
|
---|
429 | void init_default_grids(void);
|
---|
430 | int angular_grid_offset(int i);
|
---|
431 | void set_grids(void);
|
---|
432 | int get_atomic_row(int i);
|
---|
433 | void init_parameters(void);
|
---|
434 | void init_parameters(const Ref<KeyVal>& keyval);
|
---|
435 | void init_pruning_coefficients(const Ref<KeyVal>& keyval);
|
---|
436 | void init_pruning_coefficients(void);
|
---|
437 | void init_alpha_coefficients(void);
|
---|
438 | int select_dynamic_grid(void);
|
---|
439 | Ref<IntegrationWeight> weight() { return weight_; }
|
---|
440 | };
|
---|
441 |
|
---|
442 | }
|
---|
443 |
|
---|
444 | #endif
|
---|
445 |
|
---|
446 | // Local Variables:
|
---|
447 | // mode: c++
|
---|
448 | // c-file-style: "CLJ"
|
---|
449 | // End:
|
---|