ESPResSo 3.2.0-163-g57ad263-git
Extensible Simulation Package for Soft Matter Research
reaction_field.h
Go to the documentation of this file.
00001 /*
00002   Copyright (C) 2010,2011,2012,2013 The ESPResSo project
00003   Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010 
00004     Max-Planck-Institute for Polymer Research, Theory Group
00005   
00006   This file is part of ESPResSo.
00007   
00008   ESPResSo is free software: you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation, either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   ESPResSo is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
00020 */
00021 #ifndef REACTION_FIELD_H
00022 #define REACTION_FIELD_H
00023 /** \file reaction_field.h
00024  *  Routines to calculate the Reaction Field Energy or/and force 
00025  *  for a particle pair.
00026  *  M. Neumann, J. Chem. Phys 82, 5663 (1985)
00027  *  \ref forces.c
00028  *
00029 */
00030 
00031 #include "utils.h"
00032 #include "interaction_data.h"
00033 #include "particle_data.h"
00034 #include "mol_cut.h"
00035 
00036 #ifdef ELECTROSTATICS
00037 
00038 /** Structure to hold Reaction Field Parameters. */
00039 typedef struct {
00040   /** ionic strength . */
00041   double kappa;
00042   /** epsilon1 (continuum dielectric constant inside) . */
00043   double epsilon1;
00044   /** epsilon2 (continuum dielectric constant outside) . */
00045   double epsilon2;
00046   /** Cutoff for Reaction Field interaction. */
00047   double r_cut;
00048   /** B important prefactor . */
00049   double B;
00050 } Reaction_field_params;
00051 
00052 /** Structure containing the Reaction Field parameters. */
00053 extern Reaction_field_params rf_params;
00054 
00055 /** \name Functions */
00056 /************************************************************/
00057 /*@{*/
00058 
00059 ///
00060 int rf_set_params(double kappa,double epsilon1,double epsilon2, double r_cut);
00061 
00062 MDINLINE void add_rf_coulomb_pair_force_no_cutoff(Particle *p1, Particle *p2, double d[3], double dist, double force[3])
00063 {
00064    int j;
00065    double fac;
00066    fac = 1.0 / (dist*dist*dist)  +  rf_params.B / (rf_params.r_cut*rf_params.r_cut*rf_params.r_cut);
00067    fac *= coulomb.prefactor * p1->p.q * p2->p.q;
00068    
00069    for (j=0;j<3;j++)
00070          force[j] += fac * d[j];
00071    
00072    ONEPART_TRACE(if(p1->p.identity==check_id) fprintf(stderr,"%d: OPT: RF   f = (%.3e,%.3e,%.3e) with part id=%d at dist %f fac %.3e\n",this_node,p1->f.f[0],p1->f.f[1],p1->f.f[2],p2->p.identity,dist,fac));
00073    ONEPART_TRACE(if(p2->p.identity==check_id) fprintf(stderr,"%d: OPT: RF   f = (%.3e,%.3e,%.3e) with part id=%d at dist %f fac %.3e\n",this_node,p2->f.f[0],p2->f.f[1],p2->f.f[2],p1->p.identity,dist,fac));
00074 }
00075 
00076 /** Computes the Reaction Field pair force and adds this
00077     force to the particle forces (see \ref tclcommand_inter). 
00078     @param p1        Pointer to first particle.
00079     @param p2        Pointer to second/middle particle.
00080     @param d         Vector pointing from p1 to p2.
00081     @param dist      Distance between p1 and p2.
00082     @param force     returns the force on particle 1.
00083 */
00084 MDINLINE void add_rf_coulomb_pair_force(Particle *p1, Particle *p2, double d[3], double dist, double force[3])
00085 {
00086    if (dist < rf_params.r_cut)
00087    {
00088       add_rf_coulomb_pair_force_no_cutoff(p1,p2,d,dist,force);
00089    }
00090 }
00091 
00092 MDINLINE double rf_coulomb_pair_energy_no_cutoff(Particle *p1, Particle *p2, double dist)
00093 {
00094    double  fac;
00095    fac = 1.0 / dist  -  (rf_params.B*dist*dist) / (2*rf_params.r_cut*rf_params.r_cut*rf_params.r_cut);
00096    //cut off part
00097    fac -= (1-rf_params.B/2)  / rf_params.r_cut;
00098    fac *= coulomb.prefactor * p1->p.q * p2->p.q;
00099    return fac;
00100 }
00101 
00102 MDINLINE double rf_coulomb_pair_energy(Particle *p1, Particle *p2, double dist)
00103 {
00104   if (dist < rf_params.r_cut)
00105   {
00106      return rf_coulomb_pair_energy_no_cutoff(p1,p2,dist);
00107   }
00108   return 0.0;
00109 }
00110 
00111 /*from I. G. Tironi et al., J. Chem. Phys. 102, 5451 (1995)*/
00112 #ifdef INTER_RF
00113 
00114 ///
00115 int interrf_set_params(int part_type_a, int part_type_b,int rf_on);
00116 
00117 MDINLINE void add_interrf_pair_force(Particle *p1, Particle *p2, IA_parameters *ia_params,
00118                                 double d[3], double dist, double force[3])
00119 {
00120 #ifdef ONEPART_DEBUG
00121   double fac=0.0 ; /* TODO: this  variable was not declared. Now the code compiles, but I have no idea of what value to assign to it (MS) */
00122 #endif
00123   if ((ia_params->rf_on ==1) && CUTOFF_CHECK(dist < rf_params.r_cut)) {
00124      add_rf_coulomb_pair_force_no_cutoff(p1,p2,d, dist,force);
00125   }
00126 
00127   ONEPART_TRACE(if(p1->p.identity==check_id) fprintf(stderr,"%d: OPT: INTER_RF   f = (%.3e,%.3e,%.3e) with part id=%d at dist %f fac %.3e\n",this_node,p1->f.f[0],p1->f.f[1],p1->f.f[2],p2->p.identity,dist,fac));
00128   ONEPART_TRACE(if(p2->p.identity==check_id) fprintf(stderr,"%d: OPT: INTER_RF   f = (%.3e,%.3e,%.3e) with part id=%d at dist %f fac %.3e\n",this_node,p2->f.f[0],p2->f.f[1],p2->f.f[2],p1->p.identity,dist,fac));
00129 }
00130 
00131 MDINLINE double interrf_pair_energy(Particle *p1, Particle *p2,IA_parameters *ia_params, double dist)
00132 {
00133   double val;
00134   if ((ia_params->rf_on==1) && CUTOFF_CHECK(dist < rf_params.r_cut)) {
00135      val=rf_coulomb_pair_energy_no_cutoff(p1,p2,dist);
00136      return val;
00137   }
00138   return 0.0;
00139 }
00140 
00141 #endif
00142 
00143 /*@}*/
00144 #endif
00145 
00146 #endif