ESPResSo 3.2.0-167-g2c9ead1-git
Extensible Simulation Package for Soft Matter Research
lj.c
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 #include "utils.h"
00022 
00023 #ifdef LENNARD_JONES
00024 #include "lj.h"
00025 #include "mol_cut.h"
00026 #include "communication.h"
00027 
00028 /** set the force cap for the LJ interaction.
00029     @param ljforcecap the maximal force, 0 to disable, -1 for individual cutoff
00030     for each of the interactions.
00031 */
00032 int ljforcecap_set_params(double ljforcecap)
00033 {
00034   mpi_cap_forces(ljforcecap);
00035   
00036   return ES_OK;
00037 }
00038 
00039 int lennard_jones_set_params(int part_type_a, int part_type_b,
00040                                       double eps, double sig, double cut,
00041                                       double shift, double offset,
00042                                       double cap_radius, double min)
00043 {
00044   IA_parameters *data = get_ia_param_safe(part_type_a, part_type_b);
00045 
00046   if (!data) return ES_ERROR;
00047 
00048   data->LJ_eps    = eps;
00049   data->LJ_sig    = sig;
00050   data->LJ_cut    = cut;
00051   data->LJ_shift  = shift;
00052   data->LJ_offset = offset;
00053   if (cap_radius > 0) {
00054     data->LJ_capradius = cap_radius;
00055   }
00056   if (min > 0) {
00057     data->LJ_min = min;
00058   }
00059   
00060   /* broadcast interaction parameters */
00061   mpi_bcast_ia_params(part_type_a, part_type_b);
00062 
00063   mpi_cap_forces(force_cap);
00064 
00065   return ES_OK;
00066 }
00067 
00068 /** calculate lj_capradius from force_cap */
00069 void calc_lj_cap_radii()
00070 {
00071   /* do not compute cap radii if force capping is "individual" */
00072   if( force_cap != -1.0 ){
00073     int i,j,cnt=0;
00074     IA_parameters *params;
00075     double force=0.0, rad=0.0, step, frac2, frac6;
00076 
00077     for(i=0; i<n_particle_types; i++) {
00078       for(j=0; j<n_particle_types; j++) {
00079         params = get_ia_param(i,j);
00080         if(force_cap > 0.0 && params->LJ_eps > 0.0) {
00081     /* I think we have to solve this numerically... and very crude as well */
00082     cnt=0;
00083     rad = params->LJ_sig;
00084     step = -0.1 * params->LJ_sig;
00085     force=0.0;
00086     
00087     while(step != 0) {
00088       frac2 = SQR(params->LJ_sig/rad);
00089       frac6 = frac2*frac2*frac2;
00090       force = 48.0 * params->LJ_eps * frac6*(frac6 - 0.5)/rad;
00091       if((step < 0 && force_cap < force) || (step > 0 && force_cap > force)) {
00092         step = - (step/2.0); 
00093       }
00094       if(fabs(force-force_cap) < 1.0e-6) step=0;
00095       rad += step; cnt++;
00096     } 
00097           params->LJ_capradius = rad;
00098         }
00099         else {
00100     params->LJ_capradius = 0.0; 
00101         }
00102         FORCE_TRACE(fprintf(stderr,"%d: Ptypes %d-%d have cap_radius %f and cap_force %f (iterations: %d)\n",
00103           this_node,i,j,rad,force,cnt));
00104       }
00105     }
00106   }
00107 }
00108 
00109 #endif /* ifdef LENNARD_JONES */