MADNESS  version 0.9
abinitdftsolventsolver.h
Go to the documentation of this file.
1 /*
2 
3  This file is part of MADNESS.
4 
5  Copyright (C) 2007,2010 Oak Ridge National Laboratory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21  For more information please contact:
22 
23  Robert J. Harrison
24  Oak Ridge National Laboratory
25  One Bethel Valley Road
26  P.O. Box 2008, MS-6367
27 
28  email: harrisonrj@ornl.gov
29  tel: 865-241-3937
30  fax: 865-572-0680
31 $Id$
32 */
33 
48 #ifndef MADNESS_ABINITDFTSOLVENTSOLVER_H
49 #define MADNESS_ABINITDFTSOLVENTSOLVER_H
50 #include <madness/mra/mra.h>
51 #include <madness/constants.h>
52 #include <ctime>
53 #include <madness/tensor/solvers.h>
54 #include <madness/mra/funcplot.h>
55 #include <examples/nonlinsol.h>
56 
58 
59 //define a class for the Gygi potential and the surface cavity
61 private:
62  const realfunc& rho; //electronic density
63  const realfunc& rhot; //density for the dielectric functional
64  const double& rho_0; // the density at the solut-solvent interface
65  const double& epsilon; //assyptotic value of the dielectric functional
66  const int& maxiter; // maximum iterations in the solver
67  World& world;
68  const double& Gamma; //the surface tention of the solvent
69  const double& beta;
70  const double& minlen; // minimul in the coulomb operator
71  const double& thresh;
72  real_convolution_3d op; //< Coulomb operator
73  static const double cutrho;// = 1e-12; //cutoff value of the density (problematics with some compilers)
74  //utility function
75 
76  //unary operator to determine the reciprocal of a madness function
77  template<typename T,int DIM>
78  struct Reciprocal {
79  void operator()(const Key<DIM>& key, Tensor<T>& t) const {
80  UNARY_OPTIMIZED_ITERATOR(T, t,*_p0=1.0/(*_p0));
81  }
82  template <typename Archive>void serialize(Archive& ar) {}
83  };
84  //Binary operator to multiply grad U and depsilondrho
85  struct Bop {
86  void operator()(const Key<3>& key,
87  real_tensor U,
88  const real_tensor& gradu,
89  const real_tensor& dedrho) const {
90  ITERATOR(U,
91  double d = gradu(IND);
92  double p = dedrho(IND);
93  // if (std::abs(p)<1e-12 || std::abs(d)<1e-12)
94  if (std::abs(p)<cutrho || std::abs(d)<cutrho)
95  U(IND) = 0.0;
96  else
97  U(IND) = d*d*p;
98  );
99  }
100 
101  template <typename Archive>
102  void serialize(Archive& ar) {}
103  };
104 
105  //Compute the dielectric cavity on the go
106  template<typename T,int DIM>
107  struct Epsilon_rho {
108  double rho0;
109  double beta;
110  double epsilon;
111  double cutrho;
112 
113  Epsilon_rho() {};
114 
115  Epsilon_rho(double rho0, double beta, double epsilon, double cutrho)
116  : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
117  {}
118 
119  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
121  T rho = std::fabs(*_p0);
122  if(rho < cutrho)
123  //if(rho < 1e-12)
124  *_p0 = epsilon;
125  else {
126  T ratio = std::pow(rho/rho0,2.0*beta);
127  T result = (epsilon + ratio)/(1.0 + ratio);
128  //if (result > epsilon) {
129  // print("!!!", *_p0, rho0, beta, epsilon, ratio, result);
130  // throw "done";
131  // }
132  *_p0 = result;
133  }
134  );
135  }
136 
137  template <typename Archive>void serialize(Archive& ar) {
138  ar & rho0 & beta & epsilon & cutrho;
139  }
140  };
141  //Compute the normalization constant of the density on the go
142  template<typename T,int DIM>
143  struct normconst{
144  double rho0;
145  double beta;
146  double epsilon;
147  double cutrho;
148  normconst(){}
149  normconst(double rho0, double beta, double epsilon, double cutrho)
150  : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
151  {}
152 
153  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
155  T rho = std::fabs(*_p0);
156  if(rho < cutrho)
157  //if(rho < 1e-12)
158  *_p0 = 0.0;
159  else {
160  T ratio = std::pow(rho/rho0,2.0*beta);
161  *_p0 = (epsilon - 1.0)/(epsilon + ratio);
162  }
163  );
164  }
165  template <typename Archive>void serialize(Archive& ar) {
166  ar & rho0 & beta & epsilon & cutrho;
167  }
168  };
169  //Compute the derivative of the dielectric cavity on the go
170  template<typename T,int DIM>
171  struct dEpsilon_drho{
172  double rho0;
173  double beta;
174  double epsilon;
175  double cutrho;
176  dEpsilon_drho(){}
177  dEpsilon_drho(double rho0, double beta, double epsilon, double cutrho)
178  : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
179  {}
180 
181  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
183  T rho = std::fabs(*_p0);
184  if(rho < 1e-12)
185  *_p0 = 0.0;
186  else {
187  double fac = (1.0 - epsilon)/rho0;
188  T ratone = std::pow(rho/rho0,2.0*beta -1.0);
189  T ratio = std::pow(rho/rho0,2.0*beta);
190  *_p0 = (fac*2.0*beta*ratone)/((1.0 + ratio)*(1.0 + ratio));
191  }
192  );
193  }
194  template <typename Archive>void serialize(Archive& ar) {
195  ar & rho0 & beta & epsilon & cutrho;
196  }
197  };
198  //Compute the derivative of the characteristic function on the go
199  //r = rho/rho0
200  template<typename T,int DIM>
201  struct derivative_characteristic_func{
202  double rho0;
203  double beta;
204  double epsilon;
205  double cutrho;
206  derivative_characteristic_func(){}
207  derivative_characteristic_func(double rho0, double beta,double cutrho)
208  : rho0(rho0), beta(beta), cutrho(cutrho)
209  {}
210 
211  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
213  T r = std::max(1e-12,((*_p0)/rho0));
214  double twobeta = 2.0*beta;
215  T r2b = std::pow(r,twobeta);
216  *_p0 = twobeta*r2b/(rho0*r*(1.0 + r2b)*(1.0 + r2b));
217  );
218  }
219  template<typename Archive>void serialize(Archive& ar) {
220  ar & rho0 & beta & epsilon & cutrho;
221  }
222  };
223  //Compute the characteristic function
224  //r = rho/rho0
225  template<typename T,int DIM>
226  struct characteristic_func{
227  double rho0;
228  double beta;
229  double cutrho;
230  characteristic_func(){}
231  characteristic_func(double rho0, double beta, double cutrho)
232  : rho0(rho0), beta(beta), cutrho(cutrho)
233  {}
234 
235  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
237  T r = std::abs(*_p0)/rho0;
238  if(r < 1e-12)
239  *_p0 = 0.0;
240  else {
241  double twobeta = 2.0*beta;
242  //T ratone = std::pow(rho/rho0,2.0*beta-1);
243  T r2b = std::pow(r,twobeta);
244  *_p0 = r2b/(1.0 + r2b);
245  }
246  );
247  }
248  template<typename Archive>void serialize(Archive& ar) {
249  ar & rho0 & beta & cutrho;
250  }
251  };
252  //Compute the ratio of the derivative of epsilon by epsilon on the go
253  template<typename T,int DIM>
254  struct ratioepsilon{
255  double rho0;
256  double beta;
257  double epsilon;
258  double cutrho;
259  ratioepsilon(){}
260  ratioepsilon(double rho0, double beta, double epsilon, double cutrho)
261  : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
262  {}
263 
264  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
266  T rho = std::fabs(*_p0);
267  if(rho < 1e-12)
268  *_p0 = 0.0;
269  else {
270  // double fac = (1.0 - epsilon)/rho0;
271  // T ratone = std::pow(std::fabs(*_p0)/rho0,2.0*beta -1.0);
272  //
273  // *_p0 = (fac*2.0*beta*ratone)/((1.0 + ratio)*(epsilon + ratio));
274 
275  T r = std::pow(rho/rho0,2.0*beta);
276  T rs = std::pow(rho/rho0,4.0*beta);
277  *_p0 = 2.0*beta*(1.0-epsilon)*(r + rs)/(rho*(1+r)*(1+r)*(epsilon+r));
278  }
279  );
280  }
281  template <typename Archive>void serialize(Archive& ar) {
282  ar & rho0 & beta & epsilon & cutrho;
283  }
284  };
285  //Compute the reciprocal of dielectric cavity on the go
286  template<typename T,int DIM>
287  struct repsilon_rho {
288  double rho0;
289  double beta;
290  double epsilon;
291  double cutrho;
292  repsilon_rho(){}
293  repsilon_rho(double rho0, double beta, double epsilon, double cutrho)
294  : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
295  {}
296  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
298  T rho = std::fabs(*_p0);
299  if(rho < 1e-12)
300  *_p0 = 1.0/epsilon;
301  else {
302  T ratio = std::pow(rho/rho0,2*beta);
303  *_p0 = (1.0 + ratio)/(epsilon + ratio);
304  }
305  );
306  }
307  template <typename Archive>void serialize(Archive& ar) {
308  ar & rho0 & beta & epsilon & cutrho;
309  }
310  };
311  //Use UNARY operator to obtain the point-wise norm of the electric field
312  template<typename T,int DIM>
313  struct square_root {
314  square_root() {};
315  void operator()(const Key<DIM>& key,Tensor<T>& t) const {
317  *_p0 = std::pow((*_p0),0.5);
318  );
319  }
320 
321  template <typename Archive>void serialize(Archive& ar) {}
322  };
323  //gradient of density
324  realfunc grad_of(const realfunc& dens) const {
325  real_derivative_3d Dx = free_space_derivative<double,3>(dens.world(), 0);
326  real_derivative_3d Dy = free_space_derivative<double,3>(dens.world(), 1);
327  real_derivative_3d Dz = free_space_derivative<double,3>(dens.world(), 2);
328  return (Dx(dens) + Dy(dens) + Dz(dens));
329  }
330 
331  //reciprocal of gradient of density
332  realfunc re_grad_rho(const realfunc& dens) const{
333  realfunc value = grad_of(dens);
334  value.unaryop(Reciprocal<double,3>());
335  return value;
336  }
337 
338 public:
339  //make epsilon
341  realfunc value = copy(rho);
342  value.unaryop(Epsilon_rho<double,3>(rho_0, beta, epsilon,cutrho));
343  return value;
344  }
345  //make normalization constant
347  realfunc value = copy(rho);
348  value.unaryop(normconst<double,3>(rho_0, beta, epsilon,cutrho));
349  return value;
350  }
351  //make dielectric surface
353  realfunc value = copy(rho);
354  real_derivative_3d Dx = free_space_derivative<double,3>(rho.world(), 0);
355  real_derivative_3d Dy = free_space_derivative<double,3>(rho.world(), 1);
356  real_derivative_3d Dz = free_space_derivative<double,3>(rho.world(), 2);
357  value.unaryop(derivative_characteristic_func<double,3>(rho_0, beta,cutrho));
358  return value*value*(Dx(rho)*Dx(rho) +Dy(rho)*Dy(rho) + Dz(rho)*Dz(rho));
359  }
360  //make characteristic function
362  realfunc value = copy(rho);
363  value.unaryop(characteristic_func<double,3>(rho_0, beta ,cutrho));
364  return value;
365  }
366 
367  //make reciprocal of epsilon
369  realfunc value = copy(rho);
370  value.unaryop(repsilon_rho<double,3>(rho_0, beta, epsilon,cutrho));
371  return value;
372  }
373 
374  //make derivative of epsilon
376  realfunc value = copy(rho);
377  value.unaryop(dEpsilon_drho<double,3>(rho_0, beta,epsilon,cutrho));
378  return value;
379  }
380  //make ratio of the derivative of epsilon w.r.t rho by epsilon
382  realfunc value = copy(rho);
383  value.unaryop(ratioepsilon<double,3>(rho_0, beta,epsilon,cutrho));
384  return value;
385  }
386 
387  //cavitation energy
388  double cavitation_energy() const {
389  double quantum_surface = make_surface().trace();
390  double convfact = 6.423049507e-4; // 1N/m = 6.423049507e-4a.u
391  return convfact*Gamma*quantum_surface;
392  }
393 
394  //cavitation potential to be included in the KS equation
396  double rnorm = 1.0/grad_of(rho).norm2();
397  double fac = 2.0*beta*Gamma;
398  real_derivative_3d Dx = free_space_derivative<double,3>(rho.world(), 0);
399  real_derivative_3d Dy = free_space_derivative<double,3>(rho.world(), 1);
400  real_derivative_3d Dz = free_space_derivative<double,3>(rho.world(), 2);
401  realfunc gradxrho = Dx(rho);
402  realfunc gradyrho = Dy(rho);
403  realfunc gradzrho = Dz(rho);
404  realfunc gxGgx = gradxrho*(Dx(gradxrho) + Dx(gradyrho) + Dx(gradzrho));
405  realfunc gyGgy = gradyrho*(Dy(gradxrho) + Dy(gradyrho) + Dy(gradzrho));
406  realfunc gzGgz = gradzrho*(Dz(gradxrho) + Dz(gradyrho) + Dz(gradzrho));
407  realfunc gradnormrho = (gxGgx + gyGgy + gzGgz).scale(rnorm);
408  realfunc scoef = (make_surface().norm2())*re_grad_rho(rho);
409  realfunc ddelG = fac*scoef*gradnormrho;
410  double convfact = 6.423049507e-4; // 1N/m = 6.423049507e-4a.u
411  return ddelG.scale(convfact);
412  }
413  //compute the gradient of epsilon[rho]
415  realfunc value =copy(rho) ;
416  real_derivative_3d Dx = free_space_derivative<double,3>(rho.world(), 0);
417  real_derivative_3d Dy = free_space_derivative<double,3>(rho.world(), 1);
418  real_derivative_3d Dz = free_space_derivative<double,3>(rho.world(), 2);
419  realfunc grad = (Dx(rho) + Dy(rho) + Dz(rho));
420  realfunc depdrho = copy(rho);
421  depdrho.unaryop(dEpsilon_drho<double,3>(rho_0, beta,epsilon,cutrho));
422  // return make_depsilon_drho()*grad_of(rhot);
423  return grad*value;
424  }
425  //compute the surface charge
427  real_derivative_3d Dx = free_space_derivative<double,3>(rho.world(), 0);
428  real_derivative_3d Dy = free_space_derivative<double,3>(rho.world(), 1);
429  real_derivative_3d Dz = free_space_derivative<double,3>(rho.world(), 2);
430  realfunc pgrad = (Dx(rho)*Dx(u) + Dy(rho)*Dy(u) + Dz(rho)*Dz(u));
431  // realfunc gradU = grad_of(u);
432  const double rfourpi = 1.0/(4.0*constants::pi);
433  return (make_ratioepsilon()*pgrad).scale(rfourpi);
434  }
435  // Given the full Laplace potential and the external electric field compute the surface charge
436  real_function_3d make_Laplace_surface_charge(const real_function_3d& u,std::vector<double> E=std::vector<double>(3,0.0)) const {
437  real_derivative_3d Dx = free_space_derivative<double,3>(world, 0);
438  real_derivative_3d Dy = free_space_derivative<double,3>(world, 1);
439  real_derivative_3d Dz = free_space_derivative<double,3>(world, 2);
440  //double fac = -1.0/(4.0*constants::pi);
441  real_function_3d dx = -E[0] + Dx(u);
442  real_function_3d dy = -E[1] + Dy(u);
443  real_function_3d dz = -E[2] + Dz(u);
444  realfunc pgrad = (Dx(rho)*dx + Dy(rho)*dy + Dz(rho)*dz);
445  //const double rfourpi = 1.0/(4.0*constants::pi);
446  return (make_ratioepsilon()*pgrad);
447  }
448  //Define the electrostatic potential
449  realfunc ESP()const {
450  const bool USE_SOLVER = true;
451  double tol = std::max(1e-7,FunctionDefaults<3>::get_thresh());
452  realfunc charge = make_repsilon()*rhot;
453  realfunc tcharge = make_normconst()*rhot; //total molecular charge in solvent
454  realfunc U0 = op(charge); //U
455  // double einf = -1.0/epsilon;
456  realfunc U = op(rhot);
457  // realfunc Ug = op(tcharge);//U0
458  // realfunc Ur = U;// - Uvac;
459  double unorm = U.norm2();
460  //print("U.norm2: ", unorm);
461  /*coord_3d lo(0.0), hi(0.0);
462  lo[0] = -20.0;
463  hi[0] = 20.0;
464  plot_line("iso_rho.dat", 10001, hi, lo,rho);
465  plot_line("iso_dfree_drho.dat", 10001, hi, lo,dfree_drho());
466  plot_line("potential.dat", 10001, hi, lo,U0);
467  plot_line("iso_epsilon.dat", 10001, hi, lo,make_epsilon());
468  plotdx(make_epsilon(),"iso_epsilon_pot.dx");
469  plot_line("iso_ratioepsilon.dat", 10001, hi, lo,make_ratioepsilon());
470  //plot_line("repsilon.dat", 10001, hi, lo,make_repsilon());
471  plot_line("iso_depsilondrho.dat", 10001, hi, lo,make_depsilon_drho());
472  plot_line("iso_depsilondr.dat", 10001, hi, lo,depsilon_dr());
473  // plot_line("iso_pot.dat", 10001, hi, lo,U);
474  plot_line("iso_surfacecharge.dat", 10001, hi, lo,make_surfcharge(U));
475  // throw "done";*/
476  if (USE_SOLVER) {
477  madness::NonlinearSolver solver(20);//(5);
478  // This section employs a non-linear equation solver from solvers.h
479  // http://onlinelibrary.wiley.com/doi/10.1002/jcc.10108/abstract
480  if (world.rank() == 0){
481  print("\n\n");//for formating output
482  madness::print(" Computing the Electrostatic Potential ");
483  madness::print(" ______________________ \n ");
484 
485  madness::print("iteration residue norm2 soln(10.0) ");
486  }
487 
488  for (int iter=0; iter<maxiter; iter++) {
489  realfunc uvec = U;
490  realfunc Scharge = make_surfcharge(U);// - Uvac);
491  realfunc rvec = (U - U0 - op(Scharge)).truncate();
492  //plotdx(op(Scharge),"iso_surface_pot.dx");
493  realfunc U_new = solver.update(uvec,rvec);
494  double err = rvec.norm2();
495  if (world.rank()==0)
496  // madness::print(" ", iter," " , err," ",U(coord_3d(10.0)));
497  std::printf("%8d %22.10f %22.10f \n", iter,err,U(coord_3d(10.0)));
498  if (err >0.3*unorm) U = 0.5*U + 0.5*U_new;
499  else
500  U = U_new;
501  if(err < 10.0*tol) break;
502  }
503  }
504  //plot_line("iso_total_pot.dat", 10001, hi, lo,U);
505  //plotdx(U,"iso_total_pot.dx");
506  // throw "done";
507  realfunc rxtnpot = U - op(rhot);
508  return rxtnpot;
509  }
510  //Defining the polarization of the dielectric continuum in the presence of
511  // an external electric field. Used in the response of solvated molecule
512  real_function_3d Laplace_ESP(std::vector<double>E) const {
513  // Initial guess is constant dielectric
514  const double fac = -1.0/(4.0*constants::pi);
515  real_function_3d u(world);// guess pot is zero;
516  double unorm = 0.0;//u.norm2();
517  NonlinearSolver solver(20);
518  //print for formating
519  if (world.rank()==0){
520  print("\n\n");//for formating output
521  madness::print(" Computing the Dielectric Resonse to the External Electric Field ");
522  madness::print(" ______________________ \n ");
523  }
524  for (int iter=0; iter<maxiter; iter++) {
525  double start = wall_time();
526  real_function_3d surface_charge = make_Laplace_surface_charge(u,E);
527  real_function_3d r = (u - op(surface_charge).scale(fac)).truncate(.032*FunctionDefaults<3>::get_thresh());
528  double sigtot = surface_charge.trace()*fac;
529  //surface_charge.clear();
530  real_function_3d unew = solver.update(u, r);
531  double change = (unew-u).norm2();
532  if (world.rank()==0){
533  print("iter", iter, "change", change,
534  "soln(10.0)", u(coord_3d(10.0)),
535  "surface charge", sigtot,"used",wall_time()-start);
536  }
537  // Step restriction
538  if (change > 0.3*unorm)
539  u = 0.5*unew + 0.5*u;
540  else
541  u = unew;
542 
543  if (change < std::max(1e-4,10.0*thresh)) break;
544  }
545  if (world.rank()==0)
546  print("\n\n");
547  coord_3d lo(0.0),hi(0.0);
548  lo[1]=-50.0, hi[1]=50.0;
549  plot_line("ab_laplace_surfcharge.dat", 1001, hi, lo, make_Laplace_surface_charge(u,E).scale(fac));
550  plot_line("ab_laplace_pot.dat", 1001, hi, lo, u);
551  return u;
552  }
553 //Defining the derivative of the ESP w.r.t rho
554 // this function is very noisy and is not called
555  realfunc dESP_drho(const realfunc& u)const {
556  realfunc gu = grad_of(u);
557  realfunc dedrho= make_depsilon_drho();
558  realfunc ues = binary_op(gu,dedrho, Bop());
559  double coef = -1.0/(8.0*constants::pi);
560  realfunc dep = u + ues.scale(coef);
561  realfunc gusq = gu*gu;;
562  coord_3d lo(0.0), hi(0.0);
563  lo[0] = -20.0;
564  hi[0] = 20.0;
565  plot_line("iso_square_gradU.dat", 10001, hi, lo,gusq);
566  return dep;
567  }
568  //computes components of the the electric field due to the surface charge
570  vector_real_function_3d E(3);//=std::vector<double>(3,0.0);
571  real_derivative_3d Dx = free_space_derivative<double,3>(u.world(), 0);
572  real_derivative_3d Dy = free_space_derivative<double,3>(u.world(), 1);
573  real_derivative_3d Dz = free_space_derivative<double,3>(u.world(), 2);
574  double fac = -1.0/(4.0*constants::pi);
575  real_function_3d Sigmax =(Dx(u)).scale(fac), Sigmay = (Dy(u)).scale(fac),Sigmaz = (Dz(u)).scale(fac); //excess charge on colloid surface
576  E[0] = Dx(op(Sigmax)), E[1] = Dy(op(Sigmay)), E[2] = Dz(op(Sigmaz)) ;
577  coord_3d lo(0.0),hi(0.0);
578  lo[1]=-50.0, hi[1]=50.0;
579  plot_line("ab_sigma.dat", 1001, hi, lo, E[0], E[1], E[2]);
580  // real_function_3d uxc = op(Sigma); //coulomb potential due to excess charge
581 
582  return E;
583  }
584  //calculate the average reaction field(\int C(r)F_r(r)d \tau/\int C(r)d\tau
585  double ave_rxn_field(const real_function_3d& u,const real_function_3d& mask)const {
586  real_function_3d pdtx = mask*make_electric_field(u)[0];
587  real_function_3d pdty = mask*make_electric_field(u)[1];
588  real_function_3d pdtz = mask*make_electric_field(u)[2];
589  double numx = pdtx.trace(), numy = pdty.trace(), numz = pdtz.trace();
590  double denominator = mask.trace();
591  double Favx = numx/denominator, Favy = numy/denominator,Favz = numz/denominator;
592  return std::sqrt(std::pow(Favx,2.0) + std::pow(Favy,2.0) + std::pow(Favz,2.0));
593  }
594  //Defining the Constructor
596  const realfunc& rhot,
597  const double& rho_0,
598  const double& epsilon,
599  const int& maxiter,
600  World& world,
601  const double& Gamma,
602  const double& beta,
603  const double& minlen)
604  :rho(rho),
605  rhot(rhot),
606  rho_0(rho_0),
607  epsilon(epsilon),
608  maxiter(maxiter),
609  world(world),
610  Gamma(Gamma),
611  beta(beta),
612  minlen(minlen),
613  thresh(FunctionDefaults<3>::get_thresh()),
614  op(CoulombOperator(world, minlen, thresh)){}
615 };
616 const double DFTSolventSolver::cutrho = 1e-12; //cutoff value of the density (problematics with some compilers)
617 #endif
A simple Krylov-subspace nonlinear equation solver.
Definition: nonlinsol.h:91
#define ITERATOR(t, exp)
Definition: tensor_macros.h:249
Main include file for MADNESS and defines Function interface.
#define IND
Definition: tensor_macros.h:204
realfunc make_normconst() const
Definition: abinitdftsolventsolver.h:346
void truncate(World &world, std::vector< Function< T, NDIM > > &v, double tol=0.0, bool fence=true)
Truncates a vector of functions.
Definition: vmra.h:194
Defines common mathematical and physical constants.
real_function_3d realfunc
Definition: abinitdftsolventsolver.h:57
realfunc ESP() const
Definition: abinitdftsolventsolver.h:449
Vector< double, 3 > coord_3d
Definition: funcplot.h:634
real_function_3d Laplace_ESP(std::vector< double >E) const
Definition: abinitdftsolventsolver.h:512
real_function_3d make_Laplace_surface_charge(const real_function_3d &u, std::vector< double > E=std::vector< double >(3, 0.0)) const
Definition: abinitdftsolventsolver.h:436
Defines interfaces for optimization and non-linear equation solvers.
std::vector< real_function_3d > vector_real_function_3d
Definition: functypedefs.h:79
double ave_rxn_field(const real_function_3d &u, const real_function_3d &mask) const
Definition: abinitdftsolventsolver.h:585
Function< T, NDIM > & scale(const Q q, bool fence=true)
Inplace, scale the function by a constant. No communication except for optional fence.
Definition: mra.h:896
Function< double, 3 > real_function_3d
Definition: functypedefs.h:65
realfunc make_surface() const
Definition: abinitdftsolventsolver.h:352
double cavitation_energy() const
Definition: abinitdftsolventsolver.h:388
Derivative< double, 3 > real_derivative_3d
Definition: functypedefs.h:170
realfunc dESP_drho(const realfunc &u) const
Definition: abinitdftsolventsolver.h:555
World & world() const
Returns the world.
Definition: mra.h:622
double norm2() const
Returns the 2-norm of the function ... global sum ... works in either basis.
Definition: mra.h:650
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
#define max(a, b)
Definition: lda.h:53
void scale(World &world, std::vector< Function< T, NDIM > > &v, const std::vector< Q > &factors, bool fence=true)
Scales inplace a vector of functions by distinct values.
Definition: vmra.h:290
realfunc make_depsilon_drho() const
Definition: abinitdftsolventsolver.h:375
Function< double, NDIM > update(const Function< double, NDIM > &u, const Function< double, NDIM > &r, const double rcondtol=1e-8, const double cabsmax=1000.0)
Computes next trial solution vector.
Definition: nonlinsol.h:111
void print(const tensorT &t)
Definition: DFcode/mcpfit.cc:140
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
Example implementation of Krylov-subspace nonlinear equation solver.
T trace() const
Returns global value of int(f(x),x) ... global comm required.
Definition: mra.h:1034
DFTSolventSolver(const realfunc &rho, const realfunc &rhot, const double &rho_0, const double &epsilon, const int &maxiter, World &world, const double &Gamma, const double &beta, const double &minlen)
Definition: abinitdftsolventsolver.h:595
#define UNARY_OPTIMIZED_ITERATOR(X, x, exp)
Definition: tensor_macros.h:658
SeparatedConvolution< double, 3 > real_convolution_3d
Definition: functypedefs.h:121
Tensor< double > real_tensor
Definition: functypedefs.h:40
realfunc make_repsilon() const
Definition: abinitdftsolventsolver.h:368
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
enable_if_c< is_serializable< T >::value &&is_output_archive< Archive >::value >::type serialize(const Archive &ar, const T *t, unsigned int n)
Definition: archive.h:615
double norm2(World &world, const std::vector< Function< T, NDIM > > &v)
Computes the 2-norm of a vector of functions.
Definition: vmra.h:325
realfunc make_ratioepsilon() const
Definition: abinitdftsolventsolver.h:381
A multiresolution adaptive numerical function.
Definition: derivative.h:61
realfunc depsilon_dr() const
Definition: abinitdftsolventsolver.h:414
realfunc dfree_drho() const
Definition: abinitdftsolventsolver.h:395
NonlinearSolverND< 3 > NonlinearSolver
Definition: nonlinsol.h:149
void plot_line(const char *filename, int npt, const Vector< double, NDIM > &lo, const Vector< double, NDIM > &hi, const Function< T, NDIM > &f)
Generates ASCII file tabulating f(r) at npoints along line r=lo,...,hi.
Definition: funcplot.h:388
realfunc make_surfcharge(const realfunc &u) const
Definition: abinitdftsolventsolver.h:426
realfunc make_characteristic_func() const
Definition: abinitdftsolventsolver.h:361
realfunc make_epsilon() const
Definition: abinitdftsolventsolver.h:340
vector_real_function_3d make_electric_field(const real_function_3d &u) const
Definition: abinitdftsolventsolver.h:569
Defines/implements plotting interface for functions.
void unaryop(T(*f)(T))
Inplace unary operation on function values.
Definition: mra.h:840
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
Function< TENSOR_RESULT_TYPE(L, R), NDIM > binary_op(const Function< L, NDIM > &left, const Function< R, NDIM > &right, const opT &op, bool fence=true)
Generate new function = op(left,right) where op acts on the function values.
Definition: mra.h:1593
double wall_time()
Returns the wall time in seconds relative to arbitrary origin.
Definition: world.cc:248
Definition: abinitdftsolventsolver.h:60