MADNESS  version 0.9
eigsolver.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$
32 */
33 #ifndef EIGSOLVER_H_
34 #define EIGSOLVER_H_
35 #include <madness/mra/mra.h>
36 #include <madness/world/world.h>
37 #include <vector>
39 
40 namespace madness
41 {
42 //***************************************************************************
51 template <typename T, int NDIM>
53 {
54  typedef Function<T,NDIM> funcT;
55 public:
56  virtual void iterateOutput(const std::vector<funcT>& phis,
57  const std::vector<double>& eigs, const Function<double, NDIM>& rho, const int& iter, bool periodic) = 0;
58 
59  virtual ~IEigSolverObserver() {};
60 };
61 //***************************************************************************
62 
63 class KPoint
64 {
65 public:
66  KPoint(double kx, double ky, double kz, double weight)
67  {
68  _kx = kx; _ky = ky; _kz = kz;
69  _weight = weight;
70  }
71 
72  //*************************************************************************
73  double kx() {return _kx;}
74  double ky() {return _ky;}
75  double kz() {return _kz;}
76  //*************************************************************************
77 
78  //*************************************************************************
79  double weight() {return _weight;}
80  //*************************************************************************
81 
82 private:
83  //*************************************************************************
84  // the actual k-point
85  double _kx;
86  double _ky;
87  double _kz;
88  //*************************************************************************
89 
90  //*************************************************************************
91  // weight
92  double _weight;
93  //*************************************************************************
94 
95 };
96 
97 //***************************************************************************
98 template <typename T, int NDIM>
100 {
101  // Typedef's
102  typedef Function<T,NDIM> funcT;
103 public:
104  //*************************************************************************
105  // Constructor
106  EigSolverOp(World& world, double coeff, double thresh)
107  : _world(world), _coeff(coeff), _thresh(thresh) {}
108  //*************************************************************************
109 
110  //*************************************************************************
111  // Destructor
112  virtual ~EigSolverOp() {}
113  //*************************************************************************
114 
115  //*************************************************************************
117  virtual bool is_od() = 0;
118  //*************************************************************************
119 
120  //*************************************************************************
122  virtual bool is_rd() = 0;
123  //*************************************************************************
124 
125  //*************************************************************************
127  virtual void prepare_op(funcT rho) {}
128  //*************************************************************************
129 
130  //*************************************************************************
132  virtual funcT op_o(const std::vector<funcT>& phis, const funcT& psi)
133  {
135  return func;
136  }
137  //*************************************************************************
138 
139  //*************************************************************************
141  virtual funcT op_r(const funcT& rho, const funcT& psi)
142  {
144  return func;
145  }
146  //*************************************************************************
147 
148  //*************************************************************************
150  virtual std::vector<funcT> multi_op_o(const std::vector<funcT>& phis)
151  {
152  // Collection of empty functions
153  std::vector<funcT> newphis(phis.size(), FunctionFactory<T,NDIM>(_world));
154  for (unsigned int pi = 0; pi < phis.size(); pi++)
155  {
156  newphis[pi] = op_o(phis, phis[pi]);
157  }
158  _world.gop.fence();
159  return newphis;
160  }
161  //*************************************************************************
162 
163  //*************************************************************************
165  virtual std::vector<funcT> multi_op_r(const funcT& rho, const std::vector<funcT>& phis)
166  {
167  std::vector<funcT> newphis(phis.size(), FunctionFactory<T,NDIM>(_world));
168  for (unsigned int pi = 0; pi < phis.size(); pi++)
169  {
170  newphis[pi] = op_r(rho, phis[pi]);
171  }
172  _world.gop.fence();
173  return newphis;
174  }
175  //*************************************************************************
176 
177  //*************************************************************************
178  double coeff() {return _coeff;}
179  //*************************************************************************
180 
181  //*************************************************************************
183  {
184  return _messageME;
185  }
186  //*************************************************************************
187 
188  //*************************************************************************
190  //*************************************************************************
191 
192 protected:
193  //*************************************************************************
194  double thresh() {return _thresh;}
195  //*************************************************************************
196 
197  //*************************************************************************
199  {
200  _messageME = messageME;
201  }
202  //*************************************************************************
203 
204 private:
205  //*************************************************************************
206  double _coeff;
207  //*************************************************************************
208 
209  //*************************************************************************
210  double _thresh;
211  //*************************************************************************
212 
213  //*************************************************************************
214  std::string _messageME;
215  //*************************************************************************
216 
217 };
218 //***************************************************************************
219 
220 //***************************************************************************
225 template <typename T, int NDIM>
227 {
228 public:
229  //*************************************************************************
230  // Typedef's
232 // typedef KPoint<NDIM> kvecT;
236  //*************************************************************************
237 
238  //*************************************************************************
240  EigSolver(World& world, std::vector<funcT> phis, std::vector<double> eigs,
241  std::vector<EigSolverOp<T,NDIM>*> ops, std::vector<kvecT> kpoints,
243  //*************************************************************************
244 
245  //*************************************************************************
247  EigSolver(World& world, std::vector<funcT> phis, std::vector<double> eigs,
248  std::vector<EigSolverOp<T,NDIM>*> ops, ElectronicStructureParams params);
249  //*************************************************************************
250 
251  //*************************************************************************
253  virtual ~EigSolver();
254  //*************************************************************************
255 
256  //*************************************************************************
259  void solve(int maxits);
260  //*************************************************************************
261 
262  //*************************************************************************
265  void multi_solve(int maxits);
266  //*************************************************************************
267 
268  //*************************************************************************
269  double get_eig(int indx)
270  {
271  return _eigs[indx];
272  }
273  //*************************************************************************
274 
275  //*************************************************************************
276  funcT get_phi(int indx)
277  {
278  return _phis[indx];
279  }
280  //*************************************************************************
281 
282  //*************************************************************************
283  const std::vector<funcT>& phis()
284  {
285  return _phis;
286  }
287  //*************************************************************************
288 
289  //*************************************************************************
290  const std::vector<double>& eigs()
291  {
292  return _eigs;
293  }
294  //*************************************************************************
295 
296  //*************************************************************************
298  {
299  _obs.push_back(obs);
300  }
301  //*************************************************************************
302 
303  //*************************************************************************
305  T matrix_element(const funcT& phii, const funcT& phij);
306  //*************************************************************************
307 
308  //*************************************************************************
310  void print_matrix_elements(const funcT& phii, const funcT& phij);
311  //*************************************************************************
312 
313  //*************************************************************************
315  void prepare_ops();
316  //*************************************************************************
317 
318  //*************************************************************************
320  void make_bsh_operators();
321  //*************************************************************************
322 
323  //*************************************************************************
324  void update_occupation();
325  //*************************************************************************
326 
327  //*************************************************************************
329  static funcT compute_rho(std::vector<funcT> phis, std::vector<double> occs,
330  const World& world);
331  //*************************************************************************
332 
333 private:
334  //*************************************************************************
336  std::vector<funcT> _phis;
337  //*************************************************************************
338 
339  //*************************************************************************
341  std::vector<double> _eigs;
342  //*************************************************************************
343 
344  //*************************************************************************
346  std::vector< EigSolverOp<T,NDIM>* > _ops;
347  //*************************************************************************
348 
349  //*************************************************************************
351  std::vector<kvecT> _kpoints;
352  //*************************************************************************
353 
354  //*************************************************************************
355  World& _world;
356  //*************************************************************************
357 
358  //*************************************************************************
359  // List of the obs
360  std::vector<IEigSolverObserver<T,NDIM>*> _obs;
361  //*************************************************************************
362 
363  // Electronic charge density
364  //*************************************************************************
366  //*************************************************************************
367 
368  //*************************************************************************
369  // List of the ops
370  std::vector<poperatorT> _bops;
371  //*************************************************************************
372 
373  //*************************************************************************
374  // List of the occupation numbers
375  std::vector<double> _occs;
376  //*************************************************************************
377 
378  //*************************************************************************
380  //*************************************************************************
381 
382 };
383 //***************************************************************************
384 
385 }
386 
387 #endif /*EIGSOLVER_H_*/
388 
Vector< double, NDIM > kvecT
Definition: eigsolver.h:233
WorldGopInterface & gop
Global operations.
Definition: worldfwd.h:462
Definition: eigsolver.h:52
std::string messsageME()
Definition: eigsolver.h:182
double thresh()
Definition: eigsolver.h:194
void print_matrix_elements(const funcT &phii, const funcT &phij)
Prints a matrix element given the left and right functions.
Definition: eigsolver.cc:243
virtual funcT op_r(const funcT &rho, const funcT &psi)
Density-dependent portion of operator.
Definition: eigsolver.h:141
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
Main include file for MADNESS and defines Function interface.
double get_eig(int indx)
Definition: eigsolver.h:269
const std::vector< funcT > & phis()
Definition: eigsolver.h:283
virtual std::vector< funcT > multi_op_o(const std::vector< funcT > &phis)
Orbital-dependent portion of operator.
Definition: eigsolver.h:150
Definition: eigsolver.h:63
virtual ~IEigSolverObserver()
Definition: eigsolver.h:59
Definition: electronicstructureparams.h:45
virtual std::vector< funcT > multi_op_r(const funcT &rho, const std::vector< funcT > &phis)
Density-dependent portion of operator.
Definition: eigsolver.h:165
double coeff()
Definition: eigsolver.h:178
::std::string string
Definition: gtest-port.h:872
void make_bsh_operators()
Makes the BSH Green's functions for the parallel solver (multi_solve()).
Definition: eigsolver.cc:215
double kz()
Definition: eigsolver.h:75
T matrix_element(const funcT &phii, const funcT &phij)
Computes a matrix element given the left and right functions.
Definition: eigsolver.cc:144
void messageME(std::string messageME)
Definition: eigsolver.h:198
void addObserver(IEigSolverObserver< T, NDIM > *obs)
Definition: eigsolver.h:297
double ky()
Definition: eigsolver.h:74
This header should include pretty much everything needed for the parallel runtime.
virtual ~EigSolver()
Destructor.
Definition: eigsolver.cc:89
void prepare_ops()
Preprocesses the operators for doing an iteration of "eigensolving".
Definition: eigsolver.cc:129
void solve(int maxits)
Definition: eigsolver.cc:280
double kx()
Definition: eigsolver.h:73
void multi_solve(int maxits)
Definition: eigsolver.cc:414
Function< T, NDIM > funcT
Definition: eigsolver.h:231
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
virtual void prepare_op(funcT rho)
Build the potential from a density if a density-dependent operator.
Definition: eigsolver.h:127
EigSolver(World &world, std::vector< funcT > phis, std::vector< double > eigs, std::vector< EigSolverOp< T, NDIM > * > ops, std::vector< kvecT > kpoints, ElectronicStructureParams params)
Constructor for periodic system.
Definition: eigsolver.cc:56
std::shared_ptr< operatorT > poperatorT
Definition: eigsolver.h:235
EigSolverOp(World &world, double coeff, double thresh)
Definition: eigsolver.h:106
double psi(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:42
virtual funcT op_o(const std::vector< funcT > &phis, const funcT &psi)
Orbital-dependent portion of operator.
Definition: eigsolver.h:132
Definition: eigsolver.h:99
virtual void iterateOutput(const std::vector< funcT > &phis, const std::vector< double > &eigs, const Function< double, NDIM > &rho, const int &iter, bool periodic)=0
virtual ~EigSolverOp()
Definition: eigsolver.h:112
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
void fence()
Synchronizes all processes in communicator AND globally ensures no pending AM or tasks.
Definition: worldgop.cc:52
void update_occupation()
Definition: eigsolver.cc:169
A multiresolution adaptive numerical function.
Definition: derivative.h:61
static funcT compute_rho(std::vector< funcT > phis, std::vector< double > occs, const World &world)
Computes the electronic density.
Definition: eigsolver.cc:108
Definition: eigsolver.h:226
World & _world
Definition: eigsolver.h:189
KPoint(double kx, double ky, double kz, double weight)
Definition: eigsolver.h:66
funcT get_phi(int indx)
Definition: eigsolver.h:276
virtual bool is_rd()=0
Is there a density-dependent term?
FunctionFactory implements the named-parameter idiom for Function.
Definition: funcimpl.h:70
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const std::vector< double > & eigs()
Definition: eigsolver.h:290
double weight()
Definition: eigsolver.h:79
virtual bool is_od()=0
Is there an orbitally-dependent term?
SeparatedConvolution< double, NDIM > operatorT
Definition: eigsolver.h:234