| 1 | 
mmeineke | 
561 | 
#include <iostream> | 
| 2 | 
  | 
  | 
 | 
| 3 | 
  | 
  | 
using namespace std; | 
| 4 | 
  | 
  | 
 | 
| 5 | 
  | 
  | 
 | 
| 6 | 
gezelter | 
829 | 
#include <stdlib.h> | 
| 7 | 
mmeineke | 
377 | 
 | 
| 8 | 
  | 
  | 
#ifdef IS_MPI | 
| 9 | 
  | 
  | 
#include <mpi.h> | 
| 10 | 
  | 
  | 
#endif // is_mpi | 
| 11 | 
  | 
  | 
 | 
| 12 | 
  | 
  | 
 | 
| 13 | 
chuckv | 
892 | 
#ifdef PROFILE | 
| 14 | 
  | 
  | 
#include "mdProfile.hpp" | 
| 15 | 
  | 
  | 
#endif | 
| 16 | 
  | 
  | 
 | 
| 17 | 
mmeineke | 
377 | 
#include "simError.h" | 
| 18 | 
  | 
  | 
#include "ForceFields.hpp" | 
| 19 | 
  | 
  | 
#include "Atom.hpp" | 
| 20 | 
  | 
  | 
#include "fortranWrappers.hpp" | 
| 21 | 
  | 
  | 
 | 
| 22 | 
  | 
  | 
 | 
| 23 | 
mmeineke | 
420 | 
void ForceFields::calcRcut( void ){ | 
| 24 | 
  | 
  | 
 | 
| 25 | 
  | 
  | 
#ifdef IS_MPI | 
| 26 | 
  | 
  | 
  double tempBig = bigSigma; | 
| 27 | 
mmeineke | 
447 | 
  MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX, | 
| 28 | 
  | 
  | 
                 MPI_COMM_WORLD); | 
| 29 | 
mmeineke | 
420 | 
#endif  //is_mpi | 
| 30 | 
  | 
  | 
 | 
| 31 | 
  | 
  | 
  //calc rCut and rList | 
| 32 | 
  | 
  | 
 | 
| 33 | 
mmeineke | 
841 | 
  entry_plug->setDefaultRcut( 2.5 * bigSigma );   | 
| 34 | 
tim | 
781 | 
     | 
| 35 | 
mmeineke | 
420 | 
} | 
| 36 | 
  | 
  | 
 | 
| 37 | 
gezelter | 
1097 | 
void ForceFields::setRcut( double LJrcut ) { | 
| 38 | 
  | 
  | 
   | 
| 39 | 
  | 
  | 
#ifdef IS_MPI | 
| 40 | 
  | 
  | 
  double tempBig = bigSigma; | 
| 41 | 
  | 
  | 
  MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX, | 
| 42 | 
  | 
  | 
                 MPI_COMM_WORLD); | 
| 43 | 
  | 
  | 
#endif  //is_mpi | 
| 44 | 
  | 
  | 
   | 
| 45 | 
  | 
  | 
  if (LJrcut < 2.5 * bigSigma) { | 
| 46 | 
  | 
  | 
    sprintf( painCave.errMsg, | 
| 47 | 
  | 
  | 
             "Setting Lennard-Jones cutoff radius to %lf.\n" | 
| 48 | 
  | 
  | 
             "\tThis value is smaller than %lf, which is\n" | 
| 49 | 
  | 
  | 
             "\t2.5 * bigSigma, where bigSigma is the largest\n" | 
| 50 | 
  | 
  | 
             "\tvalue of sigma present in the simulation.\n" | 
| 51 | 
  | 
  | 
             "\tThis is potentially a problem since the LJ potential may\n" | 
| 52 | 
  | 
  | 
             "\tbe appreciable at this distance.  If you don't want the\n" | 
| 53 | 
  | 
  | 
             "\tsmaller cutoff, change the LJrcut variable.\n", | 
| 54 | 
  | 
  | 
             LJrcut, 2.5*bigSigma); | 
| 55 | 
  | 
  | 
    painCave.isFatal = 0; | 
| 56 | 
  | 
  | 
    simError(); | 
| 57 | 
  | 
  | 
  } else { | 
| 58 | 
  | 
  | 
    sprintf( painCave.errMsg, | 
| 59 | 
  | 
  | 
             "Setting Lennard-Jones cutoff radius to %lf.\n" | 
| 60 | 
  | 
  | 
             "\tThis value is larger than %lf, which is\n" | 
| 61 | 
  | 
  | 
             "\t2.5 * bigSigma, where bigSigma is the largest\n" | 
| 62 | 
  | 
  | 
             "\tvalue of sigma present in the simulation. This should\n" | 
| 63 | 
  | 
  | 
             "\tnot be a problem, but could adversely effect performance.\n", | 
| 64 | 
  | 
  | 
             LJrcut, 2.5*bigSigma); | 
| 65 | 
  | 
  | 
    painCave.isFatal = 0; | 
| 66 | 
  | 
  | 
    simError(); | 
| 67 | 
  | 
  | 
  } | 
| 68 | 
  | 
  | 
   | 
| 69 | 
  | 
  | 
  //calc rCut and rList | 
| 70 | 
  | 
  | 
   | 
| 71 | 
  | 
  | 
  entry_plug->setDefaultRcut( LJrcut ); | 
| 72 | 
  | 
  | 
} | 
| 73 | 
  | 
  | 
 | 
| 74 | 
mmeineke | 
377 | 
void ForceFields::doForces( int calcPot, int calcStress ){ | 
| 75 | 
  | 
  | 
 | 
| 76 | 
  | 
  | 
  int i, isError; | 
| 77 | 
  | 
  | 
  double* frc; | 
| 78 | 
  | 
  | 
  double* pos; | 
| 79 | 
  | 
  | 
  double* trq; | 
| 80 | 
  | 
  | 
  double* A; | 
| 81 | 
tim | 
1136 | 
  double* u_l; | 
| 82 | 
  | 
  | 
  double* rc; | 
| 83 | 
  | 
  | 
  double* massRatio; | 
| 84 | 
mmeineke | 
670 | 
  SimState* config; | 
| 85 | 
mmeineke | 
377 | 
 | 
| 86 | 
  | 
  | 
  short int passedCalcPot = (short int)calcPot; | 
| 87 | 
  | 
  | 
  short int passedCalcStress = (short int)calcStress; | 
| 88 | 
  | 
  | 
 | 
| 89 | 
gezelter | 
484 | 
  // forces are zeroed here, before any are accumulated. | 
| 90 | 
mmeineke | 
377 | 
  // NOTE: do not rezero the forces in Fortran. | 
| 91 | 
  | 
  | 
 | 
| 92 | 
  | 
  | 
  for(i=0; i<entry_plug->n_atoms; i++){ | 
| 93 | 
gezelter | 
484 | 
    entry_plug->atoms[i]->zeroForces();     | 
| 94 | 
mmeineke | 
377 | 
  } | 
| 95 | 
  | 
  | 
 | 
| 96 | 
chuckv | 
892 | 
#ifdef PROFILE | 
| 97 | 
  | 
  | 
  startProfile(pro7); | 
| 98 | 
  | 
  | 
#endif | 
| 99 | 
  | 
  | 
   | 
| 100 | 
mmeineke | 
423 | 
  for(i=0; i<entry_plug->n_mol; i++ ){ | 
| 101 | 
gezelter | 
1097 | 
    // CalcForces in molecules takes care of mapping rigid body coordinates | 
| 102 | 
  | 
  | 
    // into atomic coordinates | 
| 103 | 
mmeineke | 
428 | 
    entry_plug->molecules[i].calcForces(); | 
| 104 | 
mmeineke | 
389 | 
  } | 
| 105 | 
  | 
  | 
 | 
| 106 | 
chuckv | 
892 | 
#ifdef PROFILE | 
| 107 | 
  | 
  | 
  endProfile( pro7 ); | 
| 108 | 
  | 
  | 
#endif | 
| 109 | 
  | 
  | 
 | 
| 110 | 
mmeineke | 
670 | 
  config = entry_plug->getConfiguration(); | 
| 111 | 
mmeineke | 
597 | 
   | 
| 112 | 
mmeineke | 
670 | 
  frc = config->getFrcArray(); | 
| 113 | 
  | 
  | 
  pos = config->getPosArray(); | 
| 114 | 
  | 
  | 
  trq = config->getTrqArray(); | 
| 115 | 
  | 
  | 
  A   = config->getAmatArray(); | 
| 116 | 
  | 
  | 
  u_l = config->getUlArray(); | 
| 117 | 
tim | 
1136 | 
  rc = config->getRcArray(); | 
| 118 | 
  | 
  | 
  massRatio = config->getMassRatioArray(); | 
| 119 | 
mmeineke | 
561 | 
 | 
| 120 | 
mmeineke | 
377 | 
  isError = 0; | 
| 121 | 
  | 
  | 
  entry_plug->lrPot = 0.0; | 
| 122 | 
mmeineke | 
393 | 
 | 
| 123 | 
chuckv | 
479 | 
  for (i=0; i<9; i++) { | 
| 124 | 
  | 
  | 
    entry_plug->tau[i] = 0.0; | 
| 125 | 
  | 
  | 
  } | 
| 126 | 
chuckv | 
438 | 
 | 
| 127 | 
mmeineke | 
841 | 
 | 
| 128 | 
chuckv | 
892 | 
#ifdef PROFILE | 
| 129 | 
  | 
  | 
  startProfile(pro8); | 
| 130 | 
  | 
  | 
#endif | 
| 131 | 
  | 
  | 
 | 
| 132 | 
mmeineke | 
377 | 
  fortranForceLoop( pos, | 
| 133 | 
tim | 
1142 | 
                    rc, | 
| 134 | 
  | 
  | 
                    massRatio, | 
| 135 | 
mmeineke | 
377 | 
                    A, | 
| 136 | 
  | 
  | 
                    u_l, | 
| 137 | 
  | 
  | 
                    frc, | 
| 138 | 
  | 
  | 
                    trq, | 
| 139 | 
chuckv | 
479 | 
                    entry_plug->tau, | 
| 140 | 
mmeineke | 
377 | 
                    &(entry_plug->lrPot),  | 
| 141 | 
  | 
  | 
                    &passedCalcPot, | 
| 142 | 
  | 
  | 
                    &passedCalcStress, | 
| 143 | 
  | 
  | 
                    &isError ); | 
| 144 | 
  | 
  | 
 | 
| 145 | 
tim | 
1136 | 
 | 
| 146 | 
chuckv | 
892 | 
#ifdef PROFILE | 
| 147 | 
  | 
  | 
  endProfile(pro8); | 
| 148 | 
  | 
  | 
#endif | 
| 149 | 
mmeineke | 
841 | 
 | 
| 150 | 
  | 
  | 
 | 
| 151 | 
mmeineke | 
377 | 
  if( isError ){ | 
| 152 | 
  | 
  | 
    sprintf( painCave.errMsg, | 
| 153 | 
  | 
  | 
             "Error returned from the fortran force calculation.\n" ); | 
| 154 | 
  | 
  | 
    painCave.isFatal = 1; | 
| 155 | 
  | 
  | 
    simError(); | 
| 156 | 
  | 
  | 
  } | 
| 157 | 
  | 
  | 
 | 
| 158 | 
gezelter | 
1097 | 
  for(i=0; i<entry_plug->n_mol; i++ ){ | 
| 159 | 
  | 
  | 
    entry_plug->molecules[i].atoms2rigidBodies(); | 
| 160 | 
  | 
  | 
  } | 
| 161 | 
  | 
  | 
 | 
| 162 | 
  | 
  | 
 | 
| 163 | 
mmeineke | 
377 | 
#ifdef IS_MPI | 
| 164 | 
  | 
  | 
  sprintf( checkPointMsg, | 
| 165 | 
  | 
  | 
           "returned from the force calculation.\n" ); | 
| 166 | 
  | 
  | 
  MPIcheckPoint(); | 
| 167 | 
  | 
  | 
#endif // is_mpi | 
| 168 | 
mmeineke | 
597 | 
   | 
| 169 | 
mmeineke | 
377 | 
 | 
| 170 | 
  | 
  | 
} | 
| 171 | 
  | 
  | 
 | 
| 172 | 
  | 
  | 
 | 
| 173 | 
  | 
  | 
void ForceFields::initFortran(int ljMixPolicy, int useReactionField ){ | 
| 174 | 
  | 
  | 
   | 
| 175 | 
  | 
  | 
  int isError; | 
| 176 | 
  | 
  | 
   | 
| 177 | 
  | 
  | 
  isError = 0; | 
| 178 | 
  | 
  | 
  initFortranFF( &ljMixPolicy, &useReactionField, &isError ); | 
| 179 | 
  | 
  | 
   | 
| 180 | 
  | 
  | 
  if(isError){ | 
| 181 | 
  | 
  | 
    sprintf( painCave.errMsg, | 
| 182 | 
  | 
  | 
             "ForceField error: There was an error initializing the forceField in fortran.\n" ); | 
| 183 | 
  | 
  | 
    painCave.isFatal = 1; | 
| 184 | 
  | 
  | 
    simError(); | 
| 185 | 
  | 
  | 
  } | 
| 186 | 
  | 
  | 
 | 
| 187 | 
  | 
  | 
   | 
| 188 | 
  | 
  | 
#ifdef IS_MPI | 
| 189 | 
  | 
  | 
  sprintf( checkPointMsg, "ForceField successfully initialized the fortran component list.\n" ); | 
| 190 | 
  | 
  | 
  MPIcheckPoint(); | 
| 191 | 
  | 
  | 
#endif // is_mpi | 
| 192 | 
  | 
  | 
   | 
| 193 | 
  | 
  | 
} |