ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp
(Generate patch)

Comparing trunk/mdtools/interface_implementation/TraPPE_ExFF.cpp (file contents):
Revision 141 by chuckv, Wed Oct 16 22:24:44 2002 UTC vs.
Revision 147 by mmeineke, Fri Oct 18 20:35:33 2002 UTC

# Line 11 | Line 11 | int myNode;
11  
12   #ifdef IS_MPI
13  
14 + #include "mpiForceField.h"
15 +
16   int myNode;
17  
18   // Declare the structures that will be passed by MPI
# Line 28 | Line 30 | MPI_Datatype mpiAtomStructType;
30   } atomStruct;
31   MPI_Datatype mpiAtomStructType;
32  
33 + typedef struct{
34 +  char nameA[15];
35 +  char nameB[15];
36 +  char type[30];
37 +  double d0;
38 +  int last;      //  0  -> default
39 +                 //  1  -> tells nodes to stop listening
40 +                 // -1  -> an error has occured. (handled in mpiForceField)
41 + } bondStruct;
42 + MPI_Datatype mpiBondStructType;
43 +
44 + typedef struct{
45 +  char nameA[15];
46 +  char nameB[15];
47 +  char nameC[15];
48 +  char type[30];
49 +  double k1, k2, k3, t0;
50 +  int last;      //  0  -> default
51 +                 //  1  -> tells nodes to stop listening
52 +                 // -1  -> an error has occured. (handled in mpiForceField)
53 + } bendStruct;
54 + MPI_Datatype mpiBendStructType;
55 +
56 + typedef struct{
57 +  char nameA[15];
58 +  char nameB[15];
59 +  char nameC[15];
60 +  char nameD[15];
61 +  char type[30];
62 +  double k1, k2, k3, k4;
63 +  int last;      //  0  -> default
64 +                 //  1  -> tells nodes to stop listening
65 +                 // -1  -> an error has occured. (handled in mpiForceField)
66 + } TorsionStruct;
67 + MPI_Datatype mpiTorsionStructType;
68 +
69   #endif
70  
71  
# Line 42 | Line 80 | TraPPE_ExFF::TraPPE_ExFF(){
80   #ifdef IS_MPI
81    int i;
82    int mpiError;
83 <
83 >  
84    mpiError = MPI_Comm_rank(MPI_COMM_WORLD,&myNode);
85 +  
86 +  // **********************************************************************
87 +  // Init the atomStruct mpi type
88  
89    atomStruct atomProto; // mpiPrototype
90    int atomBC[3] = {15,4,2};  // block counts
# Line 66 | Line 107 | TraPPE_ExFF::TraPPE_ExFF(){
107    MPI_Type_commit(&mpiAtomStructType);
108  
109  
110 +  // **********************************************************************
111 +  // Init the bondStruct mpi type
112 +  
113 +  bondStruct bondProto; // mpiPrototype
114 +  int bondBC[3] = {60,1,1};  // block counts
115 +  MPI_Aint bondDspls[3];           // displacements
116 +  MPI_Datatype bondMbrTypes[3];    // member mpi types
117 +  
118 +  MPI_Address(&bondProto.nameA, &bondDspls[0]);
119 +  MPI_Address(&bondProto.d0,    &bondDspls[1]);
120 +  MPI_Address(&bondProto.last,  &bondDspls[2]);
121 +  
122 +  bondMbrTypes[0] = MPI_CHAR;
123 +  bondMbrTypes[1] = MPI_DOUBLE;
124 +  bondMbrTypes[2] = MPI_INT;
125 +  
126 +  for (i=2; i >= 0; i--) bondDspls[i] -= bondDspls[0];
127 +  
128 +  MPI_Type_struct(3, bondBC, bondDspls, bondMbrTypes, &mpiBondStructType);
129 +  MPI_Type_commit(&mpiBondStructType);
130  
131 +
132 +  // **********************************************************************
133 +  // Init the bendStruct mpi type
134 +  
135 +  bendStruct bendProto; // mpiPrototype
136 +  int bendBC[3] = {75,4,1};  // block counts
137 +  MPI_Aint bendDspls[3];           // displacements
138 +  MPI_Datatype bendMbrTypes[3];    // member mpi types
139 +  
140 +  MPI_Address(&bendProto.nameA, &bendDspls[0]);
141 +  MPI_Address(&bendProto.k1,    &bendDspls[1]);
142 +  MPI_Address(&bendProto.last,  &bendDspls[2]);
143 +  
144 +  bendMbrTypes[0] = MPI_CHAR;
145 +  bendMbrTypes[1] = MPI_DOUBLE;
146 +  bendMbrTypes[2] = MPI_INT;
147 +  
148 +  for (i=2; i >= 0; i--) bendDspls[i] -= bendDspls[0];
149 +  
150 +  MPI_Type_struct(3, bendBC, bendDspls, bendMbrTypes, &mpiBendStructType);
151 +  MPI_Type_commit(&mpiBendStructType);
152 +
153 +
154 +  // **********************************************************************
155 +  // Init the torsionStruct mpi type
156 +  
157 +  torsionStruct torsionProto; // mpiPrototype
158 +  int torsionBC[3] = {90,4,1};  // block counts
159 +  MPI_Aint torsionDspls[3];           // displacements
160 +  MPI_Datatype torsionMbrTypes[3];    // member mpi types
161 +  
162 +  MPI_Address(&torsionProto.nameA, &torsionDspls[0]);
163 +  MPI_Address(&torsionProto.k1,    &torsionDspls[1]);
164 +  MPI_Address(&torsionProto.last,  &torsionDspls[2]);
165 +  
166 +  torsionMbrTypes[0] = MPI_CHAR;
167 +  torsionMbrTypes[1] = MPI_DOUBLE;
168 +  torsionMbrTypes[2] = MPI_INT;
169 +  
170 +  for (i=2; i >= 0; i--) torsionDspls[i] -= torsionDspls[0];
171 +  
172 +  MPI_Type_struct(3, torsionBC, torsionDspls, torsionMbrTypes,
173 +                  &mpiTorsionStructType);
174 +  MPI_Type_commit(&mpiTorsionStructType);
175  
176 +  // ***********************************************************************
177 +  
178    if( myNode == 0 ){
179   #endif
180      
# Line 225 | Line 332 | void TraPPE_ExFF::initializeAtoms( void ){
332    the_atoms = entry_plug->atoms;
333    nAtoms = entry_plug->n_atoms;
334    
228  // read in the atom types.
229
230  rewind( frcFile );
231  headAtomType = new LinkedType;
232  currentAtomType = headAtomType;
335    
336 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
337 <  lineNum++;
338 <  if( eof_test == NULL ){
339 <    fprintf( stderr, "Error in reading Atoms from force file.\n" );
340 <    exit(8);
341 <  }
342 <
343 <  
344 <  while( !foundAtom ){
345 <    while( eof_test != NULL && readLine[0] != '#' ){
346 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
347 <      lineNum++;
246 <    }
336 > #ifdef IS_MPI
337 >  if( myNode == 0 ){
338 > #endif
339 >    
340 >    // read in the atom types.
341 >    
342 >    rewind( frcFile );
343 >    headAtomType = new LinkedType;
344 >    currentAtomType = headAtomType;
345 >    
346 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
347 >    lineNum++;
348      if( eof_test == NULL ){
349 <      fprintf( stderr,
249 <               "Error in reading Atoms from force file at line %d.\n",
250 <               lineNum );
349 >      fprintf( stderr, "Error in reading Atoms from force file.\n" );
350        exit(8);
351      }
253
254    the_token = strtok( readLine, " ,;\t#\n" );
255    foundAtom = !strcmp( "AtomTypes", the_token );
352      
353 <    if( !foundAtom ){
354 <      eof_test = fgets( readLine, sizeof(readLine), frcFile );
355 <      lineNum++;
356 <
353 >    
354 >    while( !foundAtom ){
355 >      while( eof_test != NULL && readLine[0] != '#' ){
356 >        eof_test = fgets( readLine, sizeof(readLine), frcFile );
357 >        lineNum++;
358 >      }
359        if( eof_test == NULL ){
360          fprintf( stderr,
361                   "Error in reading Atoms from force file at line %d.\n",
362                   lineNum );
363          exit(8);
364 <      }
267 <    }
268 <  }
269 <
270 <  // we are now at the AtomTypes section.
271 <
272 <  eof_test = fgets( readLine, sizeof(readLine), frcFile );
273 <  lineNum++;
274 <  
275 <  if( eof_test == NULL ){
276 <    fprintf( stderr,
277 <             "Error in reading Atoms from force file at line %d.\n",
278 <             lineNum );
279 <    exit(8);
280 <  }
281 <
282 <  while( readLine[0] != '#' && eof_test != NULL ){
283 <    
284 <    if( readLine[0] != '!' ){
364 >      }
365        
366 <      the_token = strtok( readLine, " \n\t,;" );
367 <      if( the_token != NULL ){
366 >      the_token = strtok( readLine, " ,;\t#\n" );
367 >      foundAtom = !strcmp( "AtomTypes", the_token );
368 >      
369 >      if( !foundAtom ){
370 >        eof_test = fgets( readLine, sizeof(readLine), frcFile );
371 >        lineNum++;
372          
373 <        strcpy( currentAtomType->name, the_token );
374 <
375 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
376 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
373 >        if( eof_test == NULL ){
374 >          fprintf( stderr,
375 >                   "Error in reading Atoms from force file at line %d.\n",
376 >                   lineNum );
377            exit(8);
378 <        }
379 <
380 <        sscanf( the_token, "%d", &currentAtomType->isDipole );
381 <
382 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
383 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
384 <          exit(8);
385 <        }
386 <
387 <        sscanf( the_token, "%lf", &currentAtomType->mass );
388 <
389 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
390 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
391 <          exit(8);
392 <        }
378 >        }
379 >      }
380 >    }
381 >    
382 >    // we are now at the AtomTypes section.
383 >    
384 >    eof_test = fgets( readLine, sizeof(readLine), frcFile );
385 >    lineNum++;
386 >    
387 >    if( eof_test == NULL ){
388 >      fprintf( stderr,
389 >               "Error in reading Atoms from force file at line %d.\n",
390 >               lineNum );
391 >      exit(8);
392 >    }
393 >    
394 >    while( readLine[0] != '#' && eof_test != NULL ){
395 >      
396 >      if( readLine[0] != '!' ){
397          
398 <        sscanf( the_token, "%lf", &currentAtomType->epslon );
399 <        
400 <        if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
401 <          fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
402 <          exit(8);
315 <        }
316 <
317 <        sscanf( the_token, "%lf", &currentAtomType->sigma );
318 <        
319 <        if( currentAtomType->isDipole ){
398 >        the_token = strtok( readLine, " \n\t,;" );
399 >        if( the_token != NULL ){
400 >          
401 >          strcpy( currentAtomType->name, the_token );
402 >          
403            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
404              fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
405              exit(8);
406            }
407            
408 <          sscanf( the_token, "%lf", &currentAtomType->dipole );
408 >          sscanf( the_token, "%d", &currentAtomType->isDipole );
409 >          
410 >          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
411 >            fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
412 >            exit(8);
413 >          }
414 >          
415 >          sscanf( the_token, "%lf", &currentAtomType->mass );
416 >          
417 >          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
418 >            fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
419 >            exit(8);
420 >          }
421 >          
422 >          sscanf( the_token, "%lf", &currentAtomType->epslon );
423 >          
424 >          if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
425 >            fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
426 >            exit(8);
427 >          }
428 >          
429 >          sscanf( the_token, "%lf", &currentAtomType->sigma );
430 >          
431 >          if( currentAtomType->isDipole ){
432 >            if( ( the_token = strtok( NULL, " \n\t,;" ) ) == NULL ){
433 >              fprintf( stderr, "Error parseing AtomTypes: line %d\n", lineNum );
434 >              exit(8);
435 >            }
436 >            
437 >            sscanf( the_token, "%lf", &currentAtomType->dipole );
438 >          }
439          }
440        }
441 +      
442 +      tempAtomType = new LinkedType;
443 +      currentAtomType->next = tempAtomType;
444 +      currentAtomType = tempAtomType;
445 +      
446 +      eof_test = fgets( readLine, sizeof(readLine), frcFile );
447 +      lineNum++;
448      }
449 <    
450 <    tempAtomType = new LinkedType;
331 <    currentAtomType->next = tempAtomType;
332 <    currentAtomType = tempAtomType;
333 <    
334 <    eof_test = fgets( readLine, sizeof(readLine), frcFile );
335 <    lineNum++;
449 >
450 > #ifdef IS_MPI
451    }
452  
453 +  else{
454 +    
455 +    // listen for the structs
456 +    
457 +  }
458 + #endif
459 +
460    
461    // initialize the atoms
462    
# Line 424 | Line 546 | void TraPPE_ExFF::initializeBonds( bond_pair* the_bond
546        return NULL;
547      }
548      
549 + #ifdef IS_MPI
550 +    void add( bondStruct &info ){
551 +      if( next != NULL ) next->add(info);
552 +      else{
553 +        next = new LinkedType();
554 +        strcpy(next->nameA, info.nameA);
555 +        strcpy(next->nameB, info.nameB);
556 +        strcpy(next->type,  info.type);
557 +        next->d0 = info.d0;
558 +      }
559 +    }
560 +    
561 +    void duplicate( bondStruct &info ){
562 +      strcpy(info.nameA, nameA);
563 +      strcpy(info.nameB, nameB);
564 +      strcpy(info.type,  type);
565 +      info.d0   = d0;
566 +      info.last = 0;
567 +    }
568 +
569 +
570 + #endif
571 +
572      char nameA[15];
573      char nameB[15];
574      char type[30];
# Line 612 | Line 757 | void TraPPE_ExFF::initializeBends( bend_set* the_bends
757            && !strcmp( nameC, key1 ) ) return this;
758        if( next != NULL ) return next->find(key1, key2, key3);
759        return NULL;
760 +    }
761 +    
762 + #ifdef IS_MPI
763 +
764 +    void add( bendStruct &info ){
765 +      if( next != NULL ) next->add(info);
766 +      else{
767 +        next = new LinkedType();
768 +        strcpy(next->nameA, info.nameA);
769 +        strcpy(next->nameB, info.nameB);
770 +        strcpy(next->nameC, info.nameC);
771 +        strcpy(next->type,  info.type);
772 +        next->k1 = info.k1;
773 +        next->k2 = info.k2;
774 +        next->k3 = info.k3;
775 +        next->t0 = info.t0;
776 +      }
777      }
778      
779 +    void duplicate( bendStruct &info ){
780 +      strcpy(info.nameA, nameA);
781 +      strcpy(info.nameB, nameB);
782 +      strcpy(info.nameC, nameC);
783 +      strcpy(info.type,  type);
784 +      info.k1   = k1;
785 +      info.k2   = k2;
786 +      info.k3   = k3;
787 +      info.t0   = t0;
788 +      info.last = 0;
789 +    }
790 +
791 + #endif
792 +
793      char nameA[15];
794      char nameB[15];
795      char nameC[15];
# Line 840 | Line 1016 | void TraPPE_ExFF::initializeTorsions( torsion_set* the
1016  
1017        if( next != NULL ) return next->find(key1, key2, key3, key4);
1018        return NULL;
1019 +    }
1020 +    
1021 + #ifdef IS_MPI
1022 +
1023 +    void add( torsionStruct &info ){
1024 +      if( next != NULL ) next->add(info);
1025 +      else{
1026 +        next = new LinkedType();
1027 +        strcpy(next->nameA, info.nameA);
1028 +        strcpy(next->nameB, info.nameB);
1029 +        strcpy(next->nameC, info.nameC);
1030 +        strcpy(next->type,  info.type);
1031 +        next->k1 = info.k1;
1032 +        next->k2 = info.k2;
1033 +        next->k3 = info.k3;
1034 +        next->k4 = info.k4;
1035 +      }
1036      }
1037      
1038 +    void duplicate( torsionStruct &info ){
1039 +      strcpy(info.nameA, nameA);
1040 +      strcpy(info.nameB, nameB);
1041 +      strcpy(info.nameC, nameC);
1042 +      strcpy(info.nameD, nameD);
1043 +      strcpy(info.type,  type);
1044 +      info.k1   = k1;
1045 +      info.k2   = k2;
1046 +      info.k3   = k3;
1047 +      info.k4   = k4;
1048 +      info.last = 0;
1049 +    }
1050 +
1051 + #endif
1052 +
1053      char nameA[15];
1054      char nameB[15];
1055      char nameC[15];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines