LJTable.C

Go to the documentation of this file.
00001 
00007 #include "InfoStream.h"
00008 #include "LJTable.h"
00009 #include "Node.h"
00010 #include "Parameters.h"
00011 // #define DEBUGM
00012 #include "Debug.h"
00013 
00014 
00015 //----------------------------------------------------------------------  
00016 LJTable::LJTable()
00017 {
00018   table_dim = Node::Object()->parameters->get_num_vdw_params();
00019   table_alloc = new char[2*table_dim*table_dim*sizeof(TableEntry) + 31];
00020   char *table_align = table_alloc;
00021   while ( (long)table_align % 32 ) table_align++;
00022   table = (TableEntry *) table_align;
00023 
00024   for (register int i=0; i < table_dim; i++)
00025     for (register int j=i; j < table_dim; j++)
00026     {
00027       TableEntry *curij = &(table[2*(i*table_dim+j)]);
00028       TableEntry *curji = &(table[2*(j*table_dim+i)]);
00029       compute_vdw_params(i,j,curij,curij+1);
00030 
00031       // Copy to transpose entry
00032       *curji = *curij;
00033       *(curji + 1) = *(curij + 1);
00034     }
00035 
00036 }
00037 
00038 //----------------------------------------------------------------------  
00039 LJTable::~LJTable()
00040 {
00041   delete [] table_alloc;
00042 }
00043 
00044 //----------------------------------------------------------------------
00045 void LJTable::compute_vdw_params(int i, int j,
00046                                  LJTable::TableEntry *cur, 
00047                                  LJTable::TableEntry *cur_scaled)
00048 {
00049   Parameters *params = Node::Object()->parameters;
00050   SimParameters *simParams = Node::Object()->simParameters;
00051   int useGeom = simParams->vdwGeometricSigma;
00052   Bool tabulatedEnergies = simParams->tabulatedEnergies;
00053 
00054   Real A, B, A14, B14;
00055   int K = -1;
00056   // BigReal sigma_max;
00057   //  We need the A and B parameters for the Van der Waals.  These can
00058   //  be explicitly be specified for this pair or calculated from the
00059   //  sigma and epsilon values for the two atom types
00060 //  printf("Looking at interaction of  %i with %i\n", i, j);
00061   if ( tabulatedEnergies && params->get_table_pair_params(i,j,&K)) {
00062 //    printf("Making this interaction tabulated. %i %i %i\n", i, j, K);
00063 #ifdef NAMD_CUDA
00064     NAMD_die("Tabulated energies are not supported in CUDA-enabled NAMD");
00065 #endif
00066     if ( K < 0 ) NAMD_bug(
00067         "LJTable::compute_vdw_params: energy table index is negative");
00068 
00069     cur->A = -1 - K;
00070     cur->B = 0;
00071     cur_scaled->A = -1 - K;
00072     cur_scaled->B = 0;
00073   }
00074   else if (params->get_vdw_pair_params(i,j, &A, &B, &A14, &B14))
00075   {
00076     cur->A = A;
00077     cur->B = B;
00078     cur_scaled->A = A14;
00079     cur_scaled->B = B14;
00080 
00081     if ( tabulatedEnergies && ( cur->A < 0 || cur_scaled->A < 0 ) )
00082       NAMD_die("LJ A is negative with tabulatedEnergies enabled");
00083 
00084     // BigReal sigma_ij, sigma_ij14;
00085 
00086     // if ((B == 0) || (A/B < 0)) sigma_ij = 0;
00087     // else sigma_ij = pow((BigReal)(A/B),(BigReal)(1./6.));
00088 
00089     // if ((B14 == 0) || (A14/B14 < 0)) sigma_ij14 = 0;
00090     // else sigma_ij14 = pow((BigReal)(A14/B14),(BigReal)(1./6.));
00091 
00092     // sigma_max = ( sigma_ij > sigma_ij14 ? sigma_ij : sigma_ij14 );
00093   }
00094   else
00095   {
00096     //  We didn't find explicit parameters for this pair. So instead,
00097     //  get the parameters for each atom type separately and use them
00098     //  to calculate the values we need
00099     Real sigma_i, sigma_i14, epsilon_i, epsilon_i14;
00100     Real sigma_j, sigma_j14, epsilon_j, epsilon_j14;
00101 
00102     params->get_vdw_params(&sigma_i, &epsilon_i, &sigma_i14,
00103                                        &epsilon_i14,i);
00104     params->get_vdw_params(&sigma_j, &epsilon_j, &sigma_j14, 
00105                                        &epsilon_j14,j);
00106         
00107     BigReal sigma_ij =
00108        useGeom ? sqrt(sigma_i*sigma_j) : 0.5*(sigma_i+sigma_j);
00109     BigReal sigma_ij14 =
00110        useGeom ? sqrt(sigma_i14*sigma_j14) : 0.5 * (sigma_i14+sigma_j14);
00111     BigReal epsilon_ij = sqrt(epsilon_i*epsilon_j);
00112     BigReal epsilon_ij14 = sqrt(epsilon_i14*epsilon_j14);
00113 
00114     // sigma_max = ( sigma_ij > sigma_ij14 ? sigma_ij : sigma_ij14 );
00115 
00116     //  Calculate sigma^6
00117     sigma_ij *= sigma_ij*sigma_ij;
00118     sigma_ij *= sigma_ij;
00119     sigma_ij14 *= sigma_ij14*sigma_ij14;
00120     sigma_ij14 *= sigma_ij14;
00121     
00122     //  Calculate LJ constants A & B
00123     cur->B = 4.0 * sigma_ij * epsilon_ij;
00124     cur->A = cur->B * sigma_ij;
00125     cur_scaled->B = 4.0 * sigma_ij14 * epsilon_ij14;
00126     cur_scaled->A = cur_scaled->B * sigma_ij14;
00127 
00128     if ( tabulatedEnergies && ( cur->A < 0 || cur_scaled->A < 0 ) )
00129       NAMD_die("LJ A is negative with tabulatedEnergies enabled");
00130   }
00131   //  Calculate exclcut2
00132   // cur_scaled->exclcut2 = cur->exclcut2 = 0.64 * sigma_max * sigma_max;
00133 
00134 }
00135 

Generated on Sat Nov 18 01:17:14 2017 for NAMD by  doxygen 1.4.7