MADNESS  version 0.9
nemo.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 
34 //#define WORLD_INSTANTIATE_STATIC_TEMPLATES
35 
46 #ifndef NEMO_H_
47 #define NEMO_H_
48 
49 #include <madness/mra/mra.h>
50 #include <madness/mra/funcplot.h>
51 #include <madness/mra/operator.h>
52 #include <madness/mra/lbdeux.h>
53 #include <chem/SCF.h>
54 #include <chem/correlationfactor.h>
55 #include <examples/nonlinsol.h>
56 #include <madness/mra/vmra.h>
57 
58 namespace madness {
59 
60 
61 // this class needs to be moved to vmra.h !!
62 
63 // This class is used to store information for the non-linear solver
64 template<typename T, std::size_t NDIM>
65 class vecfunc {
66 public:
68  std::vector<Function<T, NDIM> > x;
69 
70  vecfunc(World& world, const std::vector<Function<T, NDIM> >& x1) :
71  world(world), x(x1) {
72  }
73 
74  vecfunc(const std::vector<Function<T, NDIM> >& x1) :
75  world(x1[0].world()), x(x1) {
76  }
77 
78  vecfunc(const vecfunc& other) :
79  world(other.world), x(other.x) {
80  }
81 
82  vecfunc& operator=(const vecfunc& other) {
83  x = other.x;
84  return *this;
85  }
86 
87  vecfunc operator-(const vecfunc& b) const {
88  return vecfunc(world, sub(world, x, b.x));
89  }
90 
91  vecfunc operator+=(const vecfunc& b) { // Operator+= necessary
92  x = add(world, x, b.x);
93  return *this;
94  }
95 
96  vecfunc operator*(double a) const { // Scale by a constant necessary
97 
98  PROFILE_BLOCK(Vscale);
99  std::vector<Function<T,NDIM> > result(x.size());
100  for (unsigned int i=0; i<x.size(); ++i) {
101  result[i]=mul(a,x[i],false);
102  }
103  world.gop.fence();
104 
105 // scale(world, x, a);
106  return result;
107  }
108 };
109 
111 template<typename T, std::size_t NDIM>
113  Tensor<T> i = inner(a.world, a.x, b.x);
114  return i.sum();
115 }
116 
117 // The default constructor for functions does not initialize
118 // them to any value, but the solver needs functions initialized
119 // to zero for which we also need the world object.
120 template<typename T, std::size_t NDIM>
121 struct allocator {
123  const int n;
124 
127  allocator(World& world, const int nn) :
128  world(world), n(nn) {
129  }
130 
133  return vecfunc<T, NDIM>(world, zero_functions<T, NDIM>(world, n));
134  }
135 };
136 
140 
141 public:
142 
144 
147  Nemo(World& world1, std::shared_ptr<SCF> calc) :
148  world(world1), calc(calc), coords_sum(-1.0) {
149 
150  // construct the Poisson solver
152  CoulombOperatorPtr(world, calc->param.lo, calc->param.econv));
153 
154  // construct the nuclear correlation factor:
156  R = nuclear_correlation->function();
157  R_inverse = nuclear_correlation->inverse();
158 
159  }
160 
161  double value() {return value(calc->molecule.get_all_coords());}
162 
163  double value(const Tensor<double>& x);
164 
165  Tensor<double> gradient(const Tensor<double>& x) {
166  MADNESS_EXCEPTION("no nemo gradients", 1);
167  }
168 
169  std::shared_ptr<SCF> get_calc() const {return calc;}
170 
172  tensorT compute_fock_matrix(const vecfuncT& nemo, const tensorT& occ) const;
173 
174 private:
175 
177  World& world;
178 
180 
181 public:
182 
185 
188 
191 
192 private:
193 
195  mutable double coords_sum;
196 
199 
200  void print_nuclear_corrfac() const;
201 
203  double solve();
204 
206  double compute_energy(const vecfuncT& psi, const vecfuncT& Jpsi,
207  const vecfuncT& Kpsi) const;
208 
210 
219  void compute_nemo_potentials(const vecfuncT& nemo, vecfuncT& psi,
220  vecfuncT& Jnemo, vecfuncT& Knemo, vecfuncT& Vnemo,
221  vecfuncT& Unemo) const;
222 
224  void normalize(vecfuncT& nemo) const;
225 
227 
229  void orthonormalize(vecfuncT& nemo) const;
230 
232  real_function_3d get_coulomb_potential(const vecfuncT& psi) const;
233 
235  vecfuncT localize(const vecfuncT& nemo) const;
236 
237  vecfuncT apply_exchange(const vecfuncT& nemo, const vecfuncT& psi) const;
238 
239  template<typename solverT>
240  void rotate_subspace(World& world, const tensorT& U, solverT& solver,
241  int lo, int nfunc, double trantol) const;
242 
244  template<typename T, size_t NDIM>
245  void save_function(const Function<T,NDIM>& f, const std::string name) const;
246 
247 };
248 
249 }
250 
251 #endif /* NEMO_H_ */
252 
SCFParameters param
Definition: tkato/SCF.h:63
WorldGopInterface & gop
Global operations.
Definition: worldfwd.h:462
Definition: shared_ptr_bits.h:38
The Nemo class.
Definition: nemo.h:138
real_function_3d R
the nuclear correlation factor
Definition: nemo.h:187
Main include file for MADNESS and defines Function interface.
vecfunc & operator=(const vecfunc &other)
Definition: nemo.h:82
std::vector< Function< T, NDIM > > x
Definition: nemo.h:68
::std::string string
Definition: gtest-port.h:872
World & world
Definition: nemo.h:67
std::shared_ptr< SCF > get_calc() const
Definition: nemo.h:169
vecfunc(const std::vector< Function< T, NDIM > > &x1)
Definition: nemo.h:74
NDIM & f
Definition: mra.h:2179
std::shared_ptr< NuclearCorrelationFactor > nuclear_correlation
the nuclear correlation factor
Definition: nemo.h:184
Function< TENSOR_RESULT_TYPE(L, R), NDIM > add(const Function< L, NDIM > &left, const Function< R, NDIM > &right, bool fence=true)
Same as operator+ but with optional fence and no automatic compression.
Definition: mra.h:1734
std::shared_ptr< NuclearCorrelationFactor > create_nuclear_correlation_factor(World &world, const SCF &calc)
create and return a new nuclear correlation factor
Definition: correlationfactor.cc:48
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product
Definition: nemo.h:112
double econv
Energy convergence.
Definition: scfparam.h:59
Implements most functionality of separated operators.
allocator(World &world, const int nn)
Definition: nemo.h:127
vecfunc operator*(double a) const
Definition: nemo.h:96
#define PROFILE_BLOCK(name)
Definition: worldprofile.h:197
vecfunc operator+=(const vecfunc &b)
Definition: nemo.h:91
Nemo(World &world1, std::shared_ptr< SCF > calc)
ctor
Definition: nemo.h:147
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
vecfunc(World &world, const std::vector< Function< T, NDIM > > &x1)
Definition: nemo.h:70
Defines operations on vectors of FunctionsThis file defines a number of operations on vectors of func...
The interface to be provided by functions to be optimized.
Definition: solvers.h:176
Generalized version of NonlinearSolver not limited to a single madness function.
Definition: nonlinsol.h:174
Example implementation of Krylov-subspace nonlinear equation solver.
Function< TENSOR_RESULT_TYPE(L, R), NDIM > sub(const Function< L, NDIM > &left, const Function< R, NDIM > &right, bool fence=true)
Same as operator- but with optional fence and no automatic compression.
Definition: mra.h:1778
tensorT compute_fock_matrix(const vecfuncT &nemo, const tensorT &occ) const
compute the Fock matrix from scratch
Definition: apps/chem/nemo.cc:163
double psi(const Vector< double, 3 > &r)
Definition: apps/ii/hatom_energy.cc:42
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
vector< functionT > vecfuncT
Definition: chem/corepotential.cc:61
Tensor< double > tensorT
Definition: chem/distpm.cc:13
Definition: nemo.h:65
vecfunc< T, NDIM > operator()()
allocate a vector of n empty functions
Definition: nemo.h:132
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
A multiresolution adaptive numerical function.
Definition: derivative.h:61
Tensor< double > gradient(const Tensor< double > &x)
Should return the derivative of the function.
Definition: nemo.h:165
Definition: nemo.h:121
World & world
Definition: nemo.h:122
Implements (2nd generation) static load/data balancing for functions.
double lo
Smallest length scale we need to resolve.
Definition: scfparam.h:88
Defines/implements plotting interface for functions.
double value()
Definition: nemo.h:161
real_function_3d R_inverse
the inverse nuclear correlation factor
Definition: nemo.h:190
vecfunc operator-(const vecfunc &b) const
Definition: nemo.h:87
#define MADNESS_EXCEPTION(msg, value)
Definition: worldexc.h:88
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const int n
Definition: nemo.h:123
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
Function< TENSOR_RESULT_TYPE(Q, T), NDIM > mul(const Q alpha, const Function< T, NDIM > &f, bool fence=true)
Returns new function equal to alpha*f(x) with optional fence.
Definition: mra.h:1528
vecfunc(const vecfunc &other)
Definition: nemo.h:78