1 /*
2  *                This source code is part of
3  *
4  *                     E  R  K  A  L  E
5  *                             -
6  *                       DFT from Hel
7  *
8  * Written by Susi Lehtola, 2010-2011
9  * Copyright (c) 2010-2011, Susi Lehtola
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  */
16 
17 /**
18  * This file contains the necessary stuff needed to evaluate the TDLDA
19  * integrals in Casida formalism.
20  */
21 
22 #ifndef ERKALE_CASIDAGRID
23 #define ERKALE_CASIDAGRID
24 
25 #include "casida.h"
26 #include "../dftgrid.h"
27 
28 /// Perform integral over atomic grid
29 class CasidaShell : public AngularGrid {
30   /// Stack of values of orbitals at grid points: orbs[nspin][ngrid][norb]
31   std::vector< std::vector< std::vector<double> > > orbs;
32 
33   /// Values of the exchange part of \f$ \frac {\delta^2 E_{xc} [\rho_\uparrow,\rho_\downarrow]} {\delta \rho_\sigma ({\bf r}) \delta \rho_\tau ({\bf r})} \f$
34   std::vector<double> fx;
35   /// Values of the correlation part
36   std::vector<double> fc;
37 
38  public:
39   /// Constructor. Need to set tolerance as well before using constructor!
40   CasidaShell(bool lobatto=false);
41   /// Destructor
42   ~CasidaShell();
43 
44   /// Evaluate values of orbitals at grid points
45   void compute_orbs(const std::vector<arma::mat> & C);
46 
47   /// Evaluate fx and fc
48   void eval_fxc(int x_func, int c_func);
49 
50   /// Evaluate Kxc
51   void Kxc(const std::vector< std::vector<states_pair_t> > & pairs, arma::mat & K) const;
52 
53   void free();
54 };
55 
56 /// Perform integral over molecular grid
57 class CasidaGrid {
58   /// Work grids
59   std::vector<CasidaShell> wrk;
60   /// Angular grids
61   std::vector<angshell_t> grids;
62 
63   /// Basis set
64   const BasisSet * basp;
65   /// Verbose operation?
66   bool verbose;
67   /// Use Lobatto quadrature?
68   bool use_lobatto;
69 
70   /// Construct grid
71   void construct(const std::vector<arma::mat> & P, double tol, int x_func, int c_func);
72   /// Prune shells without points
73   void prune_shells();
74 
75  public:
76   CasidaGrid(const BasisSet * bas, bool verbose=false, bool lobatto=false);
77   ~CasidaGrid();
78 
79   /// Evaluate Kxc
80   void Kxc(const std::vector<arma::mat> & P, double tol, int x_func, int c_func, const std::vector<arma::mat> & C, const std::vector < std::vector<states_pair_t> > & pairs, arma::mat & Kx);
81   /// Print out grid composition
82   void print_grid() const;
83 };
84 
85 #endif
86