| 1 | #include <iostream> | 
| 2 |  | 
| 3 | using namespace std; | 
| 4 |  | 
| 5 |  | 
| 6 | #include <cstdlib> | 
| 7 |  | 
| 8 | #ifdef IS_MPI | 
| 9 | #include <mpi.h> | 
| 10 | #endif // is_mpi | 
| 11 |  | 
| 12 |  | 
| 13 | #include "simError.h" | 
| 14 | #include "ForceFields.hpp" | 
| 15 | #include "Atom.hpp" | 
| 16 | #include "fortranWrappers.hpp" | 
| 17 |  | 
| 18 |  | 
| 19 | void ForceFields::calcRcut( void ){ | 
| 20 |  | 
| 21 | #ifdef IS_MPI | 
| 22 | double tempBig = bigSigma; | 
| 23 | MPI_Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX, | 
| 24 | MPI_COMM_WORLD); | 
| 25 | #endif  //is_mpi | 
| 26 |  | 
| 27 | //calc rCut and rList | 
| 28 |  | 
| 29 | entry_plug->setRcut( 2.5 * bigSigma ); | 
| 30 | } | 
| 31 |  | 
| 32 | void ForceFields::doForces( int calcPot, int calcStress ){ | 
| 33 |  | 
| 34 | int i, isError; | 
| 35 | double* frc; | 
| 36 | double* pos; | 
| 37 | double* trq; | 
| 38 | double* A; | 
| 39 | double* u_l;; | 
| 40 | DirectionalAtom* dAtom; | 
| 41 |  | 
| 42 | short int passedCalcPot = (short int)calcPot; | 
| 43 | short int passedCalcStress = (short int)calcStress; | 
| 44 |  | 
| 45 | // forces are zeroed here, before any are accumulated. | 
| 46 | // NOTE: do not rezero the forces in Fortran. | 
| 47 |  | 
| 48 | for(i=0; i<entry_plug->n_atoms; i++){ | 
| 49 | entry_plug->atoms[i]->zeroForces(); | 
| 50 | } | 
| 51 |  | 
| 52 | for(i=0; i<entry_plug->n_mol; i++ ){ | 
| 53 | entry_plug->molecules[i].calcForces(); | 
| 54 | } | 
| 55 |  | 
| 56 |  | 
| 57 |  | 
| 58 | frc = Atom::getFrcArray(); | 
| 59 | pos = Atom::getPosArray(); | 
| 60 | trq = Atom::getTrqArray(); | 
| 61 | A   = Atom::getAmatArray(); | 
| 62 | u_l = Atom::getUlArray(); | 
| 63 |  | 
| 64 | isError = 0; | 
| 65 | entry_plug->lrPot = 0.0; | 
| 66 |  | 
| 67 | for (i=0; i<9; i++) { | 
| 68 | entry_plug->tau[i] = 0.0; | 
| 69 | } | 
| 70 |  | 
| 71 | fortranForceLoop( pos, | 
| 72 | A, | 
| 73 | u_l, | 
| 74 | frc, | 
| 75 | trq, | 
| 76 | entry_plug->tau, | 
| 77 | &(entry_plug->lrPot), | 
| 78 | &passedCalcPot, | 
| 79 | &passedCalcStress, | 
| 80 | &isError ); | 
| 81 |  | 
| 82 | if( isError ){ | 
| 83 | sprintf( painCave.errMsg, | 
| 84 | "Error returned from the fortran force calculation.\n" ); | 
| 85 | painCave.isFatal = 1; | 
| 86 | simError(); | 
| 87 | } | 
| 88 |  | 
| 89 | #ifdef IS_MPI | 
| 90 | sprintf( checkPointMsg, | 
| 91 | "returned from the force calculation.\n" ); | 
| 92 | MPIcheckPoint(); | 
| 93 | #endif // is_mpi | 
| 94 |  | 
| 95 |  | 
| 96 | } | 
| 97 |  | 
| 98 |  | 
| 99 | void ForceFields::initFortran(int ljMixPolicy, int useReactionField ){ | 
| 100 |  | 
| 101 | int isError; | 
| 102 |  | 
| 103 | isError = 0; | 
| 104 | initFortranFF( &ljMixPolicy, &useReactionField, &isError ); | 
| 105 |  | 
| 106 | if(isError){ | 
| 107 | sprintf( painCave.errMsg, | 
| 108 | "ForceField error: There was an error initializing the forceField in fortran.\n" ); | 
| 109 | painCave.isFatal = 1; | 
| 110 | simError(); | 
| 111 | } | 
| 112 |  | 
| 113 |  | 
| 114 | #ifdef IS_MPI | 
| 115 | sprintf( checkPointMsg, "ForceField successfully initialized the fortran component list.\n" ); | 
| 116 | MPIcheckPoint(); | 
| 117 | #endif // is_mpi | 
| 118 |  | 
| 119 | } |