MADNESS  0.10.1
SCFProtocol.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 
32  $Id$
33 */
34 
35 /// \file SCFProtocol.h
36 /// \brief solution protocol for SCF calculations
37 
38 
39 #ifndef MADNESS_CHEM_SCFPROTOCOL_H__INCLUDED
40 #define MADNESS_CHEM_SCFPROTOCOL_H__INCLUDED
41 
42 namespace madness {
43 
45 
46 /// struct for running a protocol of subsequently tightening precision
47 class SCFProtocol {
48 public:
50  : world(w), converged(false),
52  thresh(1.e-4), econv(1.e-4), dconv(1.e-3), user_dconv(1.e-20) {
53  user_dconv=param.dconv();
54  }
55 
57 
58  bool converged; ///< flag if protocol has converged
59 
60  double start_prec; ///< starting precision, typically 1.e-4
61  double current_prec; ///< current precision
62  double end_prec; ///< final precision
63 
64  double thresh; ///< numerical precision of representing functions
65  double econv; ///< energy convergence of SCF calculations
66  double dconv; ///< density convergence of SCF calculations
67  double user_dconv; ///< density convergence provided by user
68 
69  void initialize() {
70 
71  // don't do anything if this protocol is already converged
72  if (converged) return;
73 
76 
77  if (world.rank()==0) {
78  std::stringstream ss;
79  ss <<"\nstarting protocol at time" << std::setw(8) << std::setprecision(2)
80  << wall_time() << "s";
81  print(ss.str());
82  print("precision steps ",start_prec," --> ",end_prec);
83  print("protocol: thresh",thresh,"econv ",econv,"dconv",dconv);
84  }
85  }
86 
87  bool finished() const {return converged;}
88 
89  /// go to the next level
91  if (current_prec*0.9999>end_prec) {
92  current_prec*=0.1;
95  } else {
96  converged=true;
97  }
98 
99  return *this;
100  }
101 
102  /// infer thresholds starting from a target precision
103  void infer_thresholds(const double prec) {
104  econv=prec;
105  thresh=econv;
106  dconv=std::min(1.e-3,sqrt(econv)*0.1);
107 // dconv=std::min(1.e-3,econv*10.0);
108  if (approx(current_prec,end_prec)) dconv=user_dconv; // respect the user
109  }
110 
111  /// compare two positive doubles to be equal
112  bool approx(const double a, const double b) const {
113  return (std::abs(a/b-1.0)<1.e-12);
114  }
115 };
116 
117 
118 
119 } // namespace madness
120 
121 
122 #endif /* SRC_APPS_CHEM_SCFPROTOCOL_H_ */
double w(double t, double eps)
Definition: DKops.h:22
struct for running a protocol of subsequently tightening precision
Definition: SCFProtocol.h:47
double user_dconv
density convergence provided by user
Definition: SCFProtocol.h:67
double end_prec
final precision
Definition: SCFProtocol.h:62
World & world
Definition: SCFProtocol.h:56
bool finished() const
Definition: SCFProtocol.h:87
void initialize()
Definition: SCFProtocol.h:69
bool converged
flag if protocol has converged
Definition: SCFProtocol.h:58
double dconv
density convergence of SCF calculations
Definition: SCFProtocol.h:66
double current_prec
current precision
Definition: SCFProtocol.h:61
double thresh
numerical precision of representing functions
Definition: SCFProtocol.h:64
SCFProtocol & operator++()
go to the next level
Definition: SCFProtocol.h:90
double start_prec
starting precision, typically 1.e-4
Definition: SCFProtocol.h:60
void infer_thresholds(const double prec)
infer thresholds starting from a target precision
Definition: SCFProtocol.h:103
bool approx(const double a, const double b) const
compare two positive doubles to be equal
Definition: SCFProtocol.h:112
SCFProtocol(World &w, const CalculationParameters &param)
Definition: SCFProtocol.h:49
double econv
energy convergence of SCF calculations
Definition: SCFProtocol.h:65
A parallel world class.
Definition: world.h:132
ProcessID rank() const
Returns the process rank in this World (same as MPI_Comm_rank()).
Definition: world.h:318
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition: print.h:225
double wall_time()
Returns the wall time in seconds relative to an arbitrary origin.
Definition: timers.cc:48
static long abs(long a)
Definition: tensor.h:218
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
Definition: CalculationParameters.h:51
InputParameters param
Definition: tdse.cc:203