48 #ifndef MADNESS_ABINITDFTSOLVENTSOLVER_H 
   49 #define MADNESS_ABINITDFTSOLVENTSOLVER_H 
   65   const double& epsilon; 
 
   73   static const double cutrho;
 
   77   template<
typename T,
int DIM>
 
   79     void operator()(
const Key<DIM>& key, Tensor<T>& t)
 const {
 
   82     template <
typename Archive>
void serialize(Archive& ar) {}
 
   86       void operator()(
const Key<3>& key,
 
   91                      double d = gradu(
IND);
 
   92                      double p = dedrho(
IND);
 
   94                      if (std::abs(p)<cutrho || std::abs(d)<cutrho)
 
  101         template <
typename Archive>
 
  106   template<
typename T,
int DIM>
 
  115       Epsilon_rho(
double rho0, 
double beta, 
double epsilon, 
double cutrho)
 
  116           : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
 
  119     void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  126                                  T ratio = std::pow(rho/rho0,2.0*beta);
 
  127                                  T result  = (epsilon + ratio)/(1.0 + ratio);
 
  137     template <
typename Archive>
void serialize(Archive& ar) {
 
  138         ar & rho0 & beta & epsilon & cutrho;
 
  142   template<
typename T,
int DIM>
 
  149       normconst(
double rho0, 
double beta, 
double epsilon, 
double cutrho)
 
  150           : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
 
  153       void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  160                                        T ratio = std::pow(rho/rho0,2.0*beta);
 
  161                                        *_p0 = (epsilon - 1.0)/(epsilon + ratio);
 
  165       template <
typename Archive>
void serialize(Archive& ar) {
 
  166           ar & rho0 & beta & epsilon & cutrho;
 
  170   template<
typename T,
int DIM>
 
  171   struct dEpsilon_drho{
 
  177       dEpsilon_drho(
double rho0, 
double beta, 
double epsilon, 
double cutrho)
 
  178           : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
 
  181     void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  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));
 
  194     template <
typename Archive>
void serialize(Archive& ar) {
 
  195         ar & rho0 & beta & epsilon & cutrho;
 
  200   template<
typename T,
int DIM>
 
  201   struct derivative_characteristic_func{
 
  206       derivative_characteristic_func(){}
 
  207       derivative_characteristic_func(
double rho0, 
double beta,
double cutrho)
 
  208           : rho0(rho0), beta(beta), cutrho(cutrho)
 
  211     void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  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));
 
  219       template<
typename Archive>
void serialize(Archive& ar) {
 
  220           ar & rho0 & beta & epsilon & cutrho;
 
  225   template<
typename T,
int DIM>
 
  226   struct characteristic_func{
 
  230       characteristic_func(){}
 
  231       characteristic_func(
double rho0, 
double beta, 
double cutrho)
 
  232           : rho0(rho0), beta(beta), cutrho(cutrho)
 
  235     void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  237                                T r = std::abs(*_p0)/rho0;
 
  241                                    double twobeta = 2.0*beta;
 
  243                                    T r2b = std::pow(r,twobeta);
 
  244                                    *_p0 = r2b/(1.0 + r2b);
 
  248       template<
typename Archive>
void serialize(Archive& ar) {
 
  249           ar & rho0 & beta & cutrho;
 
  253     template<
typename T,
int DIM>
 
  260         ratioepsilon(
double rho0, 
double beta, 
double epsilon, 
double cutrho)
 
  261             : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
 
  264         void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  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));
 
  281         template <
typename Archive>
void serialize(Archive& ar) {
 
  282             ar & rho0 & beta & epsilon & cutrho;
 
  286   template<
typename T,
int DIM>
 
  287   struct repsilon_rho {
 
  293       repsilon_rho(
double rho0, 
double beta, 
double epsilon, 
double cutrho)
 
  294           : rho0(rho0), beta(beta), epsilon(epsilon), cutrho(cutrho)
 
  296     void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  302                                  T ratio = std::pow(rho/rho0,2*beta);
 
  303                                  *_p0 = (1.0 + ratio)/(epsilon + ratio);
 
  307     template <
typename Archive>
void serialize(Archive& ar) {
 
  308         ar & rho0 & beta & epsilon & cutrho;
 
  312     template<
typename T,
int DIM>
 
  315         void operator()(
const Key<DIM>& key,Tensor<T>& t)
 const {
 
  317                                      *_p0 = std::pow((*_p0),0.5);
 
  321         template <
typename Archive>
void serialize(Archive& ar) {}
 
  328     return (Dx(dens) + Dy(dens) + Dz(dens));
 
  334     value.
unaryop(Reciprocal<double,3>());
 
  342     value.
unaryop(Epsilon_rho<double,3>(rho_0, beta, epsilon,cutrho));
 
  348     value.
unaryop(normconst<double,3>(rho_0, beta, epsilon,cutrho));
 
  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));
 
  363       value.
unaryop(characteristic_func<double,3>(rho_0, beta ,cutrho));
 
  370     value.
unaryop(repsilon_rho<double,3>(rho_0, beta, epsilon,cutrho));
 
  377     value.
unaryop(dEpsilon_drho<double,3>(rho_0, beta,epsilon,cutrho));
 
  383     value.
unaryop(ratioepsilon<double,3>(rho_0, beta,epsilon,cutrho));
 
  390       double convfact = 6.423049507e-4; 
 
  391       return convfact*Gamma*quantum_surface;
 
  396       double rnorm = 1.0/grad_of(rho).
norm2();
 
  397       double fac = 2.0*beta*Gamma;
 
  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));
 
  409       realfunc ddelG = fac*scoef*gradnormrho;
 
  410       double convfact = 6.423049507e-4; 
 
  411       return ddelG.
scale(convfact);
 
  419         realfunc grad = (Dx(rho) + Dy(rho) + Dz(rho));
 
  421         depdrho.
unaryop(dEpsilon_drho<double,3>(rho_0, beta,epsilon,cutrho));
 
  430     realfunc pgrad = (Dx(rho)*Dx(u) + Dy(rho)*Dy(u) + Dz(rho)*Dz(u));
 
  444         realfunc pgrad = (Dx(rho)*dx + Dy(rho)*dy + Dz(rho)*dz);
 
  450     const bool USE_SOLVER = 
true;
 
  451     double tol = 
std::max(1e-7,FunctionDefaults<3>::get_thresh());
 
  459     double unorm = U.
norm2();
 
  480       if (world.rank() == 0){
 
  488       for (
int iter=0; iter<maxiter; iter++) {
 
  494           double err = rvec.
norm2();
 
  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;
 
  501           if(err < 10.0*tol) 
break;
 
  519         if (world.rank()==0){
 
  521             madness::print(
"            Computing the Dielectric Resonse to the External Electric Field           ");
 
  524         for (
int iter=0; iter<maxiter; iter++) {
 
  528             double sigtot = surface_charge.trace()*fac;
 
  531             double change = (unew-u).
norm2();
 
  532             if (world.rank()==0){
 
  533                 print(
"iter", iter, 
"change", change,
 
  535                       "surface charge", sigtot,
"used",
wall_time()-start);
 
  538             if (change > 0.3*unorm) 
 
  539                 u = 0.5*unew + 0.5*u;
 
  543             if (change < 
std::max(1e-4,10.0*thresh)) 
break;
 
  548         lo[1]=-50.0, hi[1]=50.0;
 
  550         plot_line(
"ab_laplace_pot.dat", 1001, hi, lo, u);
 
  565     plot_line(
"iso_square_gradU.dat", 10001, hi, lo,gusq);
 
  576         E[0] = Dx(op(Sigmax)), E[1] = Dy(op(Sigmay)), E[2] = Dz(op(Sigmaz)) ;
 
  578         lo[1]=-50.0, hi[1]=50.0;
 
  579         plot_line(
"ab_sigma.dat", 1001, hi, lo, E[0], E[1], E[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));
 
  598                   const double& epsilon,
 
  603                   const double& minlen)
 
  613     thresh(FunctionDefaults<3>::get_thresh()),
 
  614     op(CoulombOperator(world, minlen, thresh)){}
 
  616 const double DFTSolventSolver::cutrho = 1e-12;  
 
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
const double pi
Definition: navstokes_cosines.cc:91
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