ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/LJ_FF.cpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/LJ_FF.cpp (file contents):
Revision 378 by mmeineke, Fri Mar 21 17:42:12 2003 UTC vs.
Revision 447 by mmeineke, Thu Apr 3 20:21:54 2003 UTC

# Line 7 | Line 7 | using namespace std;
7  
8   #ifdef IS_MPI
9   #include <mpi.h>
10 #include <mpi++.h>
10   #endif //is_mpi
11  
12   #include "ForceFields.hpp"
# Line 43 | Line 42 | namespace LJ_NS{
42    MPI_Datatype mpiAtomStructType;
43    
44   #endif
45 +
46 +  class LinkedAtomType {
47 +  public:
48 +    LinkedAtomType(){
49 +      next = NULL;
50 +      name[0] = '\0';
51 +    }
52 +    ~LinkedAtomType(){ if( next != NULL ) delete next; }
53 +
54 +    LinkedAtomType* find(char* key){
55 +      if( !strcmp(name, key) ) return this;
56 +      if( next != NULL ) return next->find(key);
57 +      return NULL;
58 +    }
59 +    
60 +
61 +    void add( atomStruct &info ){
62 +    
63 +      // check for duplicates
64 +      
65 +      if( !strcmp( info.name, name ) ){
66 +        sprintf( painCave.errMsg,
67 +                 "Duplicate LJ atom type \"%s\" found in "
68 +                 "the LJ_FF param file./n",
69 +                 name );
70 +        painCave.isFatal = 1;
71 +        simError();
72 +      }
73 +      
74 +      if( next != NULL ) next->add(info);
75 +      else{
76 +        next = new LinkedAtomType();
77 +        strcpy(next->name, info.name);
78 +        next->mass     = info.mass;
79 +        next->epslon   = info.epslon;
80 +        next->sigma    = info.sigma;
81 +        next->ident    = info.ident;
82 +      }
83 +    }
84 +    
85 +
86 + #ifdef IS_MPI
87 +    
88 +    void duplicate( atomStruct &info ){
89 +      strcpy(info.name, name);
90 +      info.mass     = mass;
91 +      info.epslon   = epslon;
92 +      info.sigma    = sigma;
93 +      info.ident    = ident;
94 +      info.last     = 0;
95 +    }
96 +
97 +
98 + #endif
99 +
100 +    char name[15];
101 +    double mass;
102 +    double epslon;
103 +    double sigma;
104 +    int ident;
105 +    LinkedAtomType* next;
106 +  };
107 +
108 +  LinkedAtomType* headAtomType;
109 +  LinkedAtomType* currentAtomType;
110 +
111   }
112  
113   using namespace LJ_NS;
# Line 60 | Line 125 | LJ_FF::LJ_FF(){
125    char temp[200];
126    char errMsg[1000];
127  
128 +  headAtomType = NULL;
129 +  currentAtomType = NULL;
130 +
131    // do the funtion wrapping
132    wrapMeFF( this );
133  
# Line 142 | Line 210 | LJ_FF::~LJ_FF(){
210  
211   LJ_FF::~LJ_FF(){
212  
213 +  if( headAtomType != NULL ) delete headAtomType;
214 +
215   #ifdef IS_MPI
216    if( worldRank == 0 ){
217   #endif // is_mpi
# Line 158 | Line 228 | void LJ_FF::initForceField( int ljMixRule ){
228    initFortran( ljMixRule, 0 );
229   }
230  
231 + void LJ_FF::cleanMe( void ){
232  
233 < void LJ_FF::initializeAtoms( void ){
233 > #ifdef IS_MPI
234    
235 <  class LinkedType {
165 <  public:
166 <    LinkedType(){
167 <      next = NULL;
168 <      name[0] = '\0';
169 <    }
170 <    ~LinkedType(){ if( next != NULL ) delete next; }
235 >  // keep the linked list in the mpi version
236  
237 <    LinkedType* find(char* key){
173 <      if( !strcmp(name, key) ) return this;
174 <      if( next != NULL ) return next->find(key);
175 <      return NULL;
176 <    }
177 <    
237 > #else // is_mpi
238  
239 <    void add( atomStruct &info ){
180 <    
181 <      // check for duplicates
182 <      
183 <      if( !strcmp( info.name, name ) ){
184 <        sprintf( painCave.errMsg,
185 <                 "Duplicate LJ atom type \"%s\" found in "
186 <                 "the LJ_FF param file./n",
187 <                 name );
188 <        painCave.isFatal = 1;
189 <        simError();
190 <      }
191 <      
192 <      if( next != NULL ) next->add(info);
193 <      else{
194 <        next = new LinkedType();
195 <        strcpy(next->name, info.name);
196 <        next->mass     = info.mass;
197 <        next->epslon   = info.epslon;
198 <        next->sigma    = info.sigma;
199 <        next->ident    = info.ident;
200 <      }
201 <    }
202 <    
239 >  // delete the linked list in the single processor version
240  
241 < #ifdef IS_MPI
205 <    
206 <    void duplicate( atomStruct &info ){
207 <      strcpy(info.name, name);
208 <      info.mass     = mass;
209 <      info.epslon   = epslon;
210 <      info.sigma    = sigma;
211 <      info.ident    = ident;
212 <      info.last     = 0;
213 <    }
241 >  if( headAtomType != NULL ) delete headAtomType;
242  
243 + #endif // is_mpi
244 + }
245  
246 < #endif
246 > void LJ_FF::readParams( void ){
247  
218    char name[15];
219    double mass;
220    double epslon;
221    double sigma;
222    int ident;
223    LinkedType* next;
224  };
225  
226  LinkedType* headAtomType;
227  LinkedType* currentAtomType;
248    atomStruct info;
249    info.last = 1; // initialize last to have the last set.
250                   // if things go well, last will be set to 0
# Line 232 | Line 252 | void LJ_FF::initializeAtoms( void ){
252    int i;
253    int identNum;
254    
255 <  Atom** the_atoms;
256 <  int nAtoms;
237 <  the_atoms = entry_plug->atoms;
238 <  nAtoms = entry_plug->n_atoms;
239 <  
240 <  
255 >
256 >  bigSigma = 0.0;
257   #ifdef IS_MPI
258    if( worldRank == 0 ){
259   #endif
260      
261      // read in the atom types.
262  
263 <    headAtomType = new LinkedType;
263 >    headAtomType = new LinkedAtomType;
264      
265      fastForward( "AtomTypes", "initializeAtoms" );
266  
# Line 316 | Line 332 | void LJ_FF::initializeAtoms( void ){
332      
333      MPIcheckPoint();
334  
335 <    headAtomType = new LinkedType;
335 >    headAtomType = new LinkedAtomType;
336      recieveFrcStruct( &info, mpiAtomStructType );
337      
338      while( !info.last ){
# Line 380 | Line 396 | void LJ_FF::initializeAtoms( void ){
396      currentAtomType = currentAtomType->next;
397    }
398        
399 +  entry_plug->useLJ = 1;
400 +
401   #ifdef IS_MPI
402    sprintf( checkPointMsg,
403             "LJ_FF atom structures successfully sent to fortran\n" );
404    MPIcheckPoint();
405   #endif // is_mpi
406  
407 + }
408 +
409 +
410 + void LJ_FF::initializeAtoms( int nAtoms, Atom** the_atoms ){
411    
412 +  int i;
413  
414    // initialize the atoms
415    
416 <  double bigSigma = 0.0;
416 >
417    Atom* thisAtom;
418  
419    for( i=0; i<nAtoms; i++ ){
# Line 412 | Line 435 | void LJ_FF::initializeAtoms( void ){
435  
436      if( bigSigma < currentAtomType->sigma ) bigSigma = currentAtomType->sigma;
437    }
438 + }
439  
440 + void LJ_FF::initializeBonds( int nBonds, Bond** BondArray,
441 +                             bond_pair* the_bonds ){
442    
443 < #ifdef IS_MPI
418 <  double tempBig = bigSigma;
419 <  MPI::COMM_WORLD.Allreduce( &tempBig, &bigSigma, 1, MPI_DOUBLE, MPI_MAX );
420 < #endif  //is_mpi
421 <
422 <  //calc rCut and rList
423 <
424 <  entry_plug->rCut = 2.5 * bigSigma;
425 <  if(entry_plug->rCut > (entry_plug->box_x / 2.0))
426 <    entry_plug->rCut = entry_plug->box_x / 2.0;
427 <  if(entry_plug->rCut > (entry_plug->box_y / 2.0))
428 <    entry_plug->rCut = entry_plug->box_y / 2.0;
429 <  if(entry_plug->rCut > (entry_plug->box_z / 2.0))
430 <    entry_plug->rCut = entry_plug->box_z / 2.0;
431 <
432 <  entry_plug->rList = entry_plug->rCut + 1.0;
433 <
434 <  entry_plug->useLJ = 1;
435 <
436 <  // clean up the memory
437 <  
438 <  delete headAtomType;
439 <
440 < #ifdef IS_MPI
441 <  sprintf( checkPointMsg, "LJ_FF atoms initialized succesfully" );
442 <  MPIcheckPoint();
443 < #endif // is_mpi
444 <
445 < }
446 <
447 < void LJ_FF::initializeBonds( bond_pair* the_bonds ){
448 <  
449 <    if( entry_plug->n_bonds ){
443 >    if( nBonds ){
444        sprintf( painCave.errMsg,
445                 "LJ_FF does not support bonds.\n" );
446        painCave.isFatal = 1;
447        simError();
448      }
455 #ifdef IS_MPI
456  MPIcheckPoint();
457 #endif // is_mpi
458
449   }
450  
451 < void LJ_FF::initializeBends( bend_set* the_bends ){
451 > void LJ_FF::initializeBends( int nBends, Bend** bendArray,
452 >                             bend_set* the_bends ){
453  
454 <    if( entry_plug->n_bends ){
454 >    if( nBends ){
455        sprintf( painCave.errMsg,
456                 "LJ_FF does not support bends.\n" );
457        painCave.isFatal = 1;
458        simError();
459      }
469 #ifdef IS_MPI
470  MPIcheckPoint();
471 #endif // is_mpi
472
460   }
461  
462 < void LJ_FF::initializeTorsions( torsion_set* the_torsions ){
462 > void LJ_FF::initializeTorsions( int nTorsions, Torsion** torsionArray,
463 >                                torsion_set* the_torsions ){
464  
465 <    if( entry_plug->n_torsions ){
465 >    if( nTorsions ){
466        sprintf( painCave.errMsg,
467                 "LJ_FF does not support torsions.\n" );
468        painCave.isFatal = 1;
469        simError();
470      }
483 #ifdef IS_MPI
484  MPIcheckPoint();
485 #endif // is_mpi
486
471   }
472  
473   void LJ_FF::fastForward( char* stopText, char* searchOwner ){

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines